Skip to content

Commit

Permalink
[raspbian] Added multi interfaces tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ritwick DSouza committed Jul 20, 2017
1 parent 696257c commit 7c5f62a
Showing 1 changed file with 214 additions and 5 deletions.
219 changes: 214 additions & 5 deletions tests/raspbian/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,51 @@

class TestInterfacesRenderer(unittest.TestCase, _TabsMixin):

def test_no_ip(self):
o = Raspbian({
"interfaces": [
{
"name": "eth0",
"type": "ethernet"
}
]
})

expected = """# config: /etc/network/interfaces
auto eth0
iface eth0 inet manual
"""

self.assertEqual(o.render(), expected)

def test_multi_no_ip(self):
o = Raspbian({
"interfaces": [
{
"name": "eth0",
"type": "ethernet"
},
{
"name": "eth1",
"type": "ethernet"
}
]
})

expected = """# config: /etc/network/interfaces
auto eth0
iface eth0 inet manual
auto eth1
iface eth1 inet manual
"""

self.assertEqual(o.render(), expected)

def test_ipv4_static(self):
o = Raspbian({
"interfaces": [
Expand All @@ -31,6 +76,79 @@ def test_ipv4_static(self):
address 10.0.0.1
netmask 255.255.255.240
'''
self.assertEqual(o.render(), expected)

def test_multi_ipv4_static(self):
o = Raspbian({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"family": "ipv4",
"proto": "static",
"address": "10.0.0.1",
"mask": 28
}
]
},
{
"name": "eth1",
"type": "ethernet",
"addresses": [
{
"family": "ipv4",
"proto": "static",
"address": "10.0.0.2",
"mask": 28
}
]
}
]
})

expected = '''# config: /etc/network/interfaces
auto eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.240
auto eth1
iface eth1 inet static
address 10.0.0.2
netmask 255.255.255.240
'''
self.assertEqual(o.render(), expected)

def test_ipv6_static(self):
o = Raspbian({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"family": "ipv6",
"proto": "static",
"address": "fe80::ba27:ebff:fe1c:5477",
"mask": 64
}
]
}
]
})

expected = '''# config: /etc/network/interfaces
auto eth0
iface eth0 inet6 static
address fe80::ba27:ebff:fe1c:5477
netmask 64
'''
self.assertEqual(o.render(), expected)

Expand All @@ -48,6 +166,18 @@ def test_ipv6_static(self):
"mask": 64
}
]
},
{
"name": "eth1",
"type": "ethernet",
"addresses": [
{
"family": "ipv6",
"proto": "static",
"address": "2001:db8:0:0:0:ff00:42:8329",
"mask": 64
}
]
}
]
})
Expand All @@ -59,6 +189,11 @@ def test_ipv6_static(self):
address fe80::ba27:ebff:fe1c:5477
netmask 64
auto eth1
iface eth1 inet6 static
address 2001:db8:0:0:0:ff00:42:8329
netmask 64
'''
self.assertEqual(o.render(), expected)

Expand Down Expand Up @@ -120,6 +255,43 @@ def test_ipv4_dhcp(self):
auto eth0
iface eth0 inet dhcp
'''
self.assertEqual(o.render(), expected)

def test_multi_ipv4_dhcp(self):
o = Raspbian({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv4"
}
]
},
{
"name": "eth1",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv4"
}
]
}
]
})

expected = '''# config: /etc/network/interfaces
auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet dhcp
'''
self.assertEqual(o.render(), expected)

Expand All @@ -144,6 +316,43 @@ def test_ipv6_dhcp(self):
auto eth0
iface eth0 inet6 dhcp
'''
self.assertEqual(o.render(), expected)

def test_ipv6_dhcp(self):
o = Raspbian({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv6"
}
]
},
{
"name": "eth1",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv6"
}
]
}
]
})

expected = '''# config: /etc/network/interfaces
auto eth0
iface eth0 inet6 dhcp
auto eth1
iface eth1 inet6 dhcp
'''
self.assertEqual(o.render(), expected)

Expand Down Expand Up @@ -181,7 +390,7 @@ def test_multiple_ip(self):
o = Raspbian({
"interfaces": [
{
"name": "eth0.1",
"name": "eth0",
"type": "ethernet",
"autostart": True,
"addresses": [
Expand Down Expand Up @@ -210,14 +419,14 @@ def test_multiple_ip(self):

expected = '''# config: /etc/network/interfaces
auto eth0.1
iface eth0.1 inet static
auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
iface eth0.1 inet static
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0
iface eth0.1 inet6 static
iface eth0 inet6 static
address fd87::1
netmask 128
Expand Down

0 comments on commit 7c5f62a

Please sign in to comment.