66
77class TestInterfacesRenderer (unittest .TestCase , _TabsMixin ):
88
9+ def test_no_ip (self ):
10+ o = Raspbian ({
11+ "interfaces" : [
12+ {
13+ "name" : "eth0" ,
14+ "type" : "ethernet"
15+ }
16+ ]
17+ })
18+
19+ expected = """# config: /etc/network/interfaces
20+
21+ auto eth0
22+ iface eth0 inet manual
23+
24+ """
25+
26+ self .assertEqual (o .render (), expected )
27+
28+ def test_multi_no_ip (self ):
29+ o = Raspbian ({
30+ "interfaces" : [
31+ {
32+ "name" : "eth0" ,
33+ "type" : "ethernet"
34+ },
35+ {
36+ "name" : "eth1" ,
37+ "type" : "ethernet"
38+ }
39+ ]
40+ })
41+
42+ expected = """# config: /etc/network/interfaces
43+
44+ auto eth0
45+ iface eth0 inet manual
46+
47+ auto eth1
48+ iface eth1 inet manual
49+
50+ """
51+
52+ self .assertEqual (o .render (), expected )
53+
954 def test_ipv4_static (self ):
1055 o = Raspbian ({
1156 "interfaces" : [
@@ -31,6 +76,79 @@ def test_ipv4_static(self):
3176address 10.0.0.1
3277netmask 255.255.255.240
3378
79+ '''
80+ self .assertEqual (o .render (), expected )
81+
82+ def test_multi_ipv4_static (self ):
83+ o = Raspbian ({
84+ "interfaces" : [
85+ {
86+ "name" : "eth0" ,
87+ "type" : "ethernet" ,
88+ "addresses" : [
89+ {
90+ "family" : "ipv4" ,
91+ "proto" : "static" ,
92+ "address" : "10.0.0.1" ,
93+ "mask" : 28
94+ }
95+ ]
96+ },
97+ {
98+ "name" : "eth1" ,
99+ "type" : "ethernet" ,
100+ "addresses" : [
101+ {
102+ "family" : "ipv4" ,
103+ "proto" : "static" ,
104+ "address" : "10.0.0.2" ,
105+ "mask" : 28
106+ }
107+ ]
108+ }
109+ ]
110+ })
111+
112+ expected = '''# config: /etc/network/interfaces
113+
114+ auto eth0
115+ iface eth0 inet static
116+ address 10.0.0.1
117+ netmask 255.255.255.240
118+
119+ auto eth1
120+ iface eth1 inet static
121+ address 10.0.0.2
122+ netmask 255.255.255.240
123+
124+ '''
125+ self .assertEqual (o .render (), expected )
126+
127+ def test_ipv6_static (self ):
128+ o = Raspbian ({
129+ "interfaces" : [
130+ {
131+ "name" : "eth0" ,
132+ "type" : "ethernet" ,
133+ "addresses" : [
134+ {
135+ "family" : "ipv6" ,
136+ "proto" : "static" ,
137+ "address" : "fe80::ba27:ebff:fe1c:5477" ,
138+ "mask" : 64
139+ }
140+ ]
141+ }
142+ ]
143+ })
144+
145+ expected = '''# config: /etc/network/interfaces
146+
147+ auto eth0
148+ iface eth0 inet6 static
149+ address fe80::ba27:ebff:fe1c:5477
150+ netmask 64
151+
34152'''
35153 self .assertEqual (o .render (), expected )
36154
@@ -48,6 +166,18 @@ def test_ipv6_static(self):
48166 "mask" : 64
49167 }
50168 ]
169+ },
170+ {
171+ "name" : "eth1" ,
172+ "type" : "ethernet" ,
173+ "addresses" : [
174+ {
175+ "family" : "ipv6" ,
176+ "proto" : "static" ,
177+ "address" : "2001:db8:0:0:0:ff00:42:8329" ,
178+ "mask" : 64
179+ }
180+ ]
51181 }
52182 ]
53183 })
@@ -59,6 +189,11 @@ def test_ipv6_static(self):
59189address fe80::ba27:ebff:fe1c:5477
60190netmask 64
61191
192+ auto eth1
193+ iface eth1 inet6 static
194+ address 2001:db8:0:0:0:ff00:42:8329
195+ netmask 64
196+
62197'''
63198 self .assertEqual (o .render (), expected )
64199
@@ -120,6 +255,43 @@ def test_ipv4_dhcp(self):
120255auto eth0
121256iface eth0 inet dhcp
122257
258+ '''
259+ self .assertEqual (o .render (), expected )
260+
261+ def test_multi_ipv4_dhcp (self ):
262+ o = Raspbian ({
263+ "interfaces" : [
264+ {
265+ "name" : "eth0" ,
266+ "type" : "ethernet" ,
267+ "addresses" : [
268+ {
269+ "proto" : "dhcp" ,
270+ "family" : "ipv4"
271+ }
272+ ]
273+ },
274+ {
275+ "name" : "eth1" ,
276+ "type" : "ethernet" ,
277+ "addresses" : [
278+ {
279+ "proto" : "dhcp" ,
280+ "family" : "ipv4"
281+ }
282+ ]
283+ }
284+ ]
285+ })
286+
287+ expected = '''# config: /etc/network/interfaces
288+
289+ auto eth0
290+ iface eth0 inet dhcp
291+
292+ auto eth1
293+ iface eth1 inet dhcp
294+
123295'''
124296 self .assertEqual (o .render (), expected )
125297
@@ -144,6 +316,43 @@ def test_ipv6_dhcp(self):
144316auto eth0
145317iface eth0 inet6 dhcp
146318
319+ '''
320+ self .assertEqual (o .render (), expected )
321+
322+ def test_ipv6_dhcp (self ):
323+ o = Raspbian ({
324+ "interfaces" : [
325+ {
326+ "name" : "eth0" ,
327+ "type" : "ethernet" ,
328+ "addresses" : [
329+ {
330+ "proto" : "dhcp" ,
331+ "family" : "ipv6"
332+ }
333+ ]
334+ },
335+ {
336+ "name" : "eth1" ,
337+ "type" : "ethernet" ,
338+ "addresses" : [
339+ {
340+ "proto" : "dhcp" ,
341+ "family" : "ipv6"
342+ }
343+ ]
344+ }
345+ ]
346+ })
347+
348+ expected = '''# config: /etc/network/interfaces
349+
350+ auto eth0
351+ iface eth0 inet6 dhcp
352+
353+ auto eth1
354+ iface eth1 inet6 dhcp
355+
147356'''
148357 self .assertEqual (o .render (), expected )
149358
@@ -181,7 +390,7 @@ def test_multiple_ip(self):
181390 o = Raspbian ({
182391 "interfaces" : [
183392 {
184- "name" : "eth0.1 " ,
393+ "name" : "eth0" ,
185394 "type" : "ethernet" ,
186395 "autostart" : True ,
187396 "addresses" : [
@@ -210,14 +419,14 @@ def test_multiple_ip(self):
210419
211420 expected = '''# config: /etc/network/interfaces
212421
213- auto eth0.1
214- iface eth0.1 inet static
422+ auto eth0
423+ iface eth0 inet static
215424address 192.168.1.1
216425netmask 255.255.255.0
217- iface eth0.1 inet static
426+ iface eth0 inet static
218427address 192.168.2.1
219428netmask 255.255.255.0
220- iface eth0.1 inet6 static
429+ iface eth0 inet6 static
221430address fd87::1
222431netmask 128
223432
0 commit comments