Skip to content

Commit

Permalink
tests integ: Introduce a link state monitor decorator
Browse files Browse the repository at this point in the history
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 <edwardh@redhat.com>
  • Loading branch information
EdDev committed Jun 8, 2019
1 parent 01c3f5f commit faffb6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tests/integration/nm/ipv4_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@
IPV4_ADDRESS1 = '192.0.2.251'


@iproutelib.ip_monitor_assert_stable_link_up(TEST_IFACE)
def test_interface_ipv4_change(eth1_up):
with iproutelib.ip_monitor(object_type='link', dev=TEST_IFACE) as result:
with mainloop():
_modify_interface(
ipv4_state={
'enabled': True,
'dhcp': False,
'address': [
{'ip': IPV4_ADDRESS1, 'prefix-length': 24}
]
}
)

assert len(iproutelib.get_non_up_events(result, dev='eth1')) == 0
with mainloop():
_modify_interface(
ipv4_state={
'enabled': True,
'dhcp': False,
'address': [
{'ip': IPV4_ADDRESS1, 'prefix-length': 24}
]
}
)

nm.nmclient.client(refresh=True)
ipv4_current_state = _get_ipv4_current_state(TEST_IFACE)
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/testlib/iproutelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import threading
import time

import six


TIMEOUT = 10

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


def ip_monitor_assert_stable_link_up(dev, timeout=10):
def decorator(func):
@six.wraps(func)
def wrapper_ip_monitor(*args, **kwargs):
with ip_monitor('link', dev, timeout) as result:
func(*args, **kwargs)
assert len(get_non_up_events(result, dev)) == 0, ('result: ' +
result.out)
return wrapper_ip_monitor
return decorator


@contextmanager
def ip_monitor(object_type, dev, timeout=10):
result = IpMonitorResult()
Expand Down

0 comments on commit faffb6e

Please sign in to comment.