Skip to content

Commit 613736d

Browse files
committed
tests integ: Introduce a link state monitor decorator
Link state monitoring is used to detect link state changes while executing apply changes. In particular, to detect links that change to anything but UP. In order to allow simpler usage in selected tests, a decorator is introduced in addition to the existing context-manager. Note: six is used to overcome functools.wraps limitations with pytest (pytest-dev/pytest#2782) Signed-off-by: Edward Haas <[email protected]>
1 parent 053ec93 commit 613736d

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

tests/integration/nm/ipv4_test.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@
2626
IPV4_ADDRESS1 = '192.0.2.251'
2727

2828

29+
@iproutelib.ip_monitor_assert_stable_link_up(TEST_IFACE)
2930
def test_interface_ipv4_change(eth1_up):
30-
with iproutelib.ip_monitor(object_type='link', dev=TEST_IFACE) as result:
31-
with mainloop():
32-
_modify_interface(
33-
ipv4_state={
34-
'enabled': True,
35-
'dhcp': False,
36-
'address': [
37-
{'ip': IPV4_ADDRESS1, 'prefix-length': 24}
38-
]
39-
}
40-
)
41-
42-
assert len(iproutelib.get_non_up_events(result, dev='eth1')) == 0
31+
with mainloop():
32+
_modify_interface(
33+
ipv4_state={
34+
'enabled': True,
35+
'dhcp': False,
36+
'address': [
37+
{'ip': IPV4_ADDRESS1, 'prefix-length': 24}
38+
]
39+
}
40+
)
4341

4442
nm.nmclient.client(refresh=True)
4543
ipv4_current_state = _get_ipv4_current_state(TEST_IFACE)

tests/integration/testlib/iproutelib.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import threading
2121
import time
2222

23+
import six
24+
2325

2426
TIMEOUT = 10
2527

@@ -31,6 +33,18 @@ def __init__(self):
3133
self.popen = None
3234

3335

36+
def ip_monitor_assert_stable_link_up(dev, timeout=10):
37+
def decorator(func):
38+
@six.wraps(func)
39+
def wrapper_ip_monitor(*args, **kwargs):
40+
with ip_monitor('link', dev, timeout) as result:
41+
func(*args, **kwargs)
42+
assert len(get_non_up_events(result, dev)) == 0, ('result: ' +
43+
result.out)
44+
return wrapper_ip_monitor
45+
return decorator
46+
47+
3448
@contextmanager
3549
def ip_monitor(object_type, dev, timeout=10):
3650
result = IpMonitorResult()

0 commit comments

Comments
 (0)