Skip to content

Commit 1f7b1af

Browse files
costasdphilpep
authored andcommitted
iproute2: fix tests after moving Module
1 parent fb3301d commit 1f7b1af

File tree

2 files changed

+55
-41
lines changed

2 files changed

+55
-41
lines changed

test/test_modules.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -650,18 +650,22 @@ def test_interface(host, family):
650650
assert default_itf.exists
651651

652652

653-
def test_iproute2_addresses(host):
653+
@pytest.mark.parametrize(
654+
"family",
655+
["inet", None],
656+
)
657+
def test_iproute2_addresses(host, family):
654658
assert host.iproute2.exists
655659

656-
addresses = host.iproute2.addresses()
660+
addresses = host.iproute2(family=family).addresses()
657661

658662
assert len(addresses) > 0
659663
assert addresses[0].get("ifname") and addresses[0].get("ifindex")
660664

661-
filtered_addresses = host.iproute2.addresses(ifname="lo")
665+
filtered_addresses = host.iproute2(family=family).addresses(ifname="lo")
662666
assert filtered_addresses[0].get("ifname") == "lo" and len(filtered_addresses) == 1
663667

664-
filtered_addresses2 = host.iproute2.addresses(local="127.0.0.1")
668+
filtered_addresses2 = host.iproute2(family=family).addresses(local="127.0.0.1")
665669
assert (
666670
filtered_addresses2[0].get("ifname") == "lo" and len(filtered_addresses2) == 1
667671
)
@@ -670,7 +674,7 @@ def test_iproute2_addresses(host):
670674
def test_iproute2_links(host):
671675
assert host.iproute2.exists
672676

673-
links = host.iproute2.links()
677+
links = host.iproute2().links()
674678
assert len(links) > 0 and len(links) < 4
675679

676680
assert links[0].get("ifname") and links[0].get("ifindex")
@@ -679,17 +683,19 @@ def test_iproute2_links(host):
679683
def test_iproute2_routes(host):
680684
assert host.iproute2.exists
681685

682-
routes = host.iproute2.routes()
686+
routes = host.iproute2().routes()
683687
assert len(routes) > 0
684688

685-
filtered_routes = host.iproute2.routes(table="local", scope="host", src="127.0.0.1")
689+
filtered_routes = host.iproute2().routes(
690+
table="local", scope="host", src="127.0.0.1"
691+
)
686692
assert filtered_routes[0].get("protocol") == "kernel" and len(filtered_routes) > 1
687693

688694

689695
def test_iproute2_rules(host):
690696
assert host.iproute2.exists
691697

692-
rules = host.iproute2.rules()
698+
rules = host.iproute2().rules()
693699
assert len(rules) > 0 and len(rules) < 4
694700
assert rules[0].get("priority") == 0
695701
assert rules[0].get("src") == "all"
@@ -698,21 +704,21 @@ def test_iproute2_rules(host):
698704
cmd = host.run("ip rule add from 1.2.3.4/32 table 123")
699705
assert cmd.exit_status == 0, f"{cmd.stdout}\n{cmd.stderr}"
700706

701-
rules_123 = host.iproute2.rules(src="1.2.3.4/32")
707+
rules_123 = host.iproute2().rules(src="1.2.3.4/32")
702708
assert len(rules_123) > 0
703709
assert rules_123[0].get("src") == "1.2.3.4"
704710

705711

706712
def test_iproute2_tunnels(host):
707713
assert host.iproute2.exists
708714

709-
tunnels = host.iproute2.tunnels()
715+
tunnels = host.iproute2().tunnels()
710716
assert len(tunnels) > 0
711717

712718
cmd = host.run("ip tunnel add test mode ipip remote 127.0.0.1")
713719
assert cmd.exit_status == 0, f"{cmd.stdout}\n{cmd.stderr}"
714720

715-
tunnels = host.iproute2.tunnels(ifname="test")
721+
tunnels = host.iproute2().tunnels(ifname="test")
716722
assert len(tunnels) > 0
717723
assert tunnels[0].get("ifname") == "test"
718724
assert tunnels[0].get("mode") == "ip/ip"
@@ -722,42 +728,42 @@ def test_iproute2_tunnels(host):
722728
def test_iproute2_vrfs(host):
723729
assert host.iproute2.exists
724730

725-
vrfs = host.iproute2.vrfs()
731+
vrfs = host.iproute2().vrfs()
726732
assert len(vrfs) == 0
727733

728734

729735
def test_iproute2_netns(host):
730736
assert host.iproute2.exists
731737

732-
namespaces = host.iproute2.netns()
738+
namespaces = host.iproute2().netns()
733739
assert len(namespaces) == 0
734740

735741
cmd = host.run("ip netns add test")
736742
assert cmd.exit_status == 0, f"{cmd.stdout}\n{cmd.stderr}"
737743

738-
namespaces = host.iproute2.netns()
744+
namespaces = host.iproute2().netns()
739745
assert len(namespaces) == 1
740746
assert namespaces[0].get("name") == "test"
741747

742748

743749
def test_iproute2_bridge_vlan(host):
744750
assert host.iproute2.bridge_exists
745751

746-
vlans = host.iproute2.bridge_vlan()
752+
vlans = host.iproute2().bridge_vlan()
747753
assert len(vlans) == 0
748754

749755

750756
def test_iproute2_bridge_fdb(host):
751757
assert host.iproute2.bridge_exists
752758

753-
fdb = host.iproute2.bridge_fdb()
759+
fdb = host.iproute2().bridge_fdb()
754760
assert len(fdb) > 0
755761

756762

757763
def test_iproute2_bridge_mdb(host):
758764
assert host.iproute2.bridge_exists
759765

760-
mdb = host.iproute2.bridge_mdb()
766+
mdb = host.iproute2().bridge_mdb()
761767
assert len(mdb) == 1
762768
assert len(mdb[0].get("mdb")) == 0
763769
assert len(mdb[0].get("router")) == 0
@@ -766,5 +772,5 @@ def test_iproute2_bridge_mdb(host):
766772
def test_iproute2_bridge_link(host):
767773
assert host.iproute2.bridge_exists
768774

769-
links = host.iproute2.bridge_link()
775+
links = host.iproute2().bridge_link()
770776
assert len(links) == 0

testinfra/modules/iproute2.py

+31-23
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def bridge_exists(self):
8080
def addresses(self, address=None, ifname=None, local=None):
8181
"""Returns the addresses associated with interfaces
8282
83-
>>> host.iproute2.addresses()
83+
>>> host.iproute2().addresses()
8484
[{'ifindex': 1,
8585
'ifname': 'lo',
8686
'flags': ['LOOPBACK', 'UP', 'LOWER_UP'],
@@ -114,11 +114,12 @@ def addresses(self, address=None, ifname=None, local=None):
114114
* local
115115
116116
"""
117+
raise NotImplementedError
117118

118119
def links(self):
119120
"""Returns links and their state.
120121
121-
>>> host.iproute2.links()
122+
>>> host.iproute2().links()
122123
[{'ifindex': 1,
123124
'ifname': 'lo',
124125
'flags': ['LOOPBACK', 'UP', 'LOWER_UP'],
@@ -133,13 +134,14 @@ def links(self):
133134
'broadcast': '00:00:00:00:00:00'}]
134135
135136
"""
137+
raise NotImplementedError
136138

137139
def routes(
138140
self, table="all", device=None, scope=None, proto=None, src=None, metric=None
139141
):
140142
"""Returns the routes installed in *all* routing tables.
141143
142-
>>> host.iproute2.routes()
144+
>>> host.iproute2().routes()
143145
[{'dst': '169.254.0.0/16',
144146
'dev': 'wlp4s0',
145147
'scope': 'link',
@@ -165,6 +167,7 @@ def routes(
165167
* metric
166168
167169
"""
170+
raise NotImplementedError
168171

169172
def rules(
170173
self,
@@ -182,7 +185,7 @@ def rules(
182185
):
183186
"""Returns the rules our routing policy consists of.
184187
185-
>>> host.iproute2.rules()
188+
>>> host.iproute2().rules()
186189
[{'priority': 0, 'src': 'all', 'table': 'local'},
187190
{'priority': 32765, 'src': '1.2.3.4', 'table': '123'},
188191
{'priority': 32766, 'src': 'all', 'table': 'main'},
@@ -204,11 +207,12 @@ def rules(
204207
* dport
205208
206209
"""
210+
raise NotImplementedError
207211

208212
def tunnels(self, ifname=None):
209213
"""Returns all configured tunnels
210214
211-
>>> host.iproute2.tunnels()
215+
>>> host.iproute2().tunnels()
212216
[{'ifname': 'test1',
213217
'mode': 'ip/ip',
214218
'remote': '127.0.0.2',
@@ -220,51 +224,55 @@ def tunnels(self, ifname=None):
220224
* ifname
221225
222226
"""
227+
raise NotImplementedError
223228

224229
def vrfs(self):
225230
"""Returns all configured vrfs"""
226-
cmd = f"{self._ip} --json vrf show"
227-
out = self.check_output(cmd)
228-
return json.loads(out)
231+
raise NotImplementedError
229232

230233
def netns(self):
231234
"""Returns all configured network namespaces
232235
233-
>>> host.iproute2.netns()
236+
>>> host.iproute2().netns()
234237
[{'name': 'test'}]
235238
"""
239+
raise NotImplementedError
236240

237241
def bridge_vlan(self):
238242
"""Returns all configured vlans
239243
240-
>>> host.iproute2.bridge_vlan()
244+
>>> host.iproute2().bridge_vlan()
241245
[]
242246
"""
247+
raise NotImplementedError
243248

244249
def bridge_fdb(self):
245250
"""Returns all configured fdb entries
246251
247-
>>> host.iproute2.bridge_fdb()
252+
>>> host.iproute2().bridge_fdb()
248253
[{'mac': '33:33:00:00:00:01',
249254
'ifname': 'enp0s31f6',
250255
'flags': ['self'],
251256
'state': 'permanent'}]
252257
"""
258+
raise NotImplementedError
253259

254260
def bridge_mdb(self):
255261
"""Returns all configured mdb entries
256262
257-
>>> host.iproute2.bridge_mdb()
263+
>>> host.iproute2().bridge_mdb()
258264
[{'mdb': [], 'router': {}}]
259265
260266
"""
267+
raise NotImplementedError
261268

262269
def bridge_link(self):
263270
"""Returns all configured links
264271
265-
>>> host.iproute2.bridge_link()
272+
>>> host.iproute2().bridge_link()
266273
[]
267274
"""
275+
raise NotImplementedError
268276

269277

270278
class LinuxIProute2(IProute2):
@@ -307,7 +315,7 @@ def bridge_exists(self):
307315
def addresses(self, address=None, ifname=None, local=None):
308316
"""Returns the addresses associated with interfaces
309317
310-
>>> host.iproute2.addresses()
318+
>>> host.iproute2().addresses()
311319
[{'ifindex': 1,
312320
'ifname': 'lo',
313321
'flags': ['LOOPBACK', 'UP', 'LOWER_UP'],
@@ -362,7 +370,7 @@ def addresses(self, address=None, ifname=None, local=None):
362370
def links(self):
363371
"""Returns links and their state.
364372
365-
>>> host.iproute2.links()
373+
>>> host.iproute2().links()
366374
[{'ifindex': 1,
367375
'ifname': 'lo',
368376
'flags': ['LOOPBACK', 'UP', 'LOWER_UP'],
@@ -386,7 +394,7 @@ def routes(
386394
):
387395
"""Returns the routes installed in *all* routing tables.
388396
389-
>>> host.iproute2.routes()
397+
>>> host.iproute2().routes()
390398
[{'dst': '169.254.0.0/16',
391399
'dev': 'wlp4s0',
392400
'scope': 'link',
@@ -447,7 +455,7 @@ def rules(
447455
):
448456
"""Returns the rules our routing policy consists of.
449457
450-
>>> host.iproute2.rules()
458+
>>> host.iproute2().rules()
451459
[{'priority': 0, 'src': 'all', 'table': 'local'},
452460
{'priority': 32765, 'src': '1.2.3.4', 'table': '123'},
453461
{'priority': 32766, 'src': 'all', 'table': 'main'},
@@ -512,7 +520,7 @@ def rules(
512520
def tunnels(self, ifname=None):
513521
"""Returns all configured tunnels
514522
515-
>>> host.iproute2.tunnels()
523+
>>> host.iproute2().tunnels()
516524
[{'ifname': 'test1',
517525
'mode': 'ip/ip',
518526
'remote': '127.0.0.2',
@@ -543,7 +551,7 @@ def vrfs(self):
543551
def netns(self):
544552
"""Returns all configured network namespaces
545553
546-
>>> host.iproute2.netns()
554+
>>> host.iproute2().netns()
547555
[{'name': 'test'}]
548556
"""
549557

@@ -556,7 +564,7 @@ def netns(self):
556564
def bridge_vlan(self):
557565
"""Returns all configured vlans
558566
559-
>>> host.iproute2.bridge_vlan()
567+
>>> host.iproute2().bridge_vlan()
560568
[]
561569
"""
562570

@@ -567,7 +575,7 @@ def bridge_vlan(self):
567575
def bridge_fdb(self):
568576
"""Returns all configured fdb entries
569577
570-
>>> host.iproute2.bridge_fdb()
578+
>>> host.iproute2().bridge_fdb()
571579
[{'mac': '33:33:00:00:00:01',
572580
'ifname': 'enp0s31f6',
573581
'flags': ['self'],
@@ -581,7 +589,7 @@ def bridge_fdb(self):
581589
def bridge_mdb(self):
582590
"""Returns all configured mdb entries
583591
584-
>>> host.iproute2.bridge_mdb()
592+
>>> host.iproute2().bridge_mdb()
585593
[{'mdb': [], 'router': {}}]
586594
587595
"""
@@ -593,7 +601,7 @@ def bridge_mdb(self):
593601
def bridge_link(self):
594602
"""Returns all configured links
595603
596-
>>> host.iproute2.bridge_link()
604+
>>> host.iproute2().bridge_link()
597605
[]
598606
"""
599607

0 commit comments

Comments
 (0)