integration tests: Warn if test run changes network state

Ideally, the tests clean up after themselves. Try to catch differences
by comparing the host state from before and after the test run and warn
if there are differences.

Signed-off-by: Till Maas <opensource@till.name>
This commit is contained in:
Till Maas 2019-11-19 17:39:01 +01:00 committed by Gris Ge
parent 759d8a47b9
commit e287866df6

View File

@ -19,9 +19,12 @@
import logging
import subprocess
import warnings
import pytest
import libnmstate
from .testlib import ifacelib
@ -39,7 +42,7 @@ def logging_setup():
@pytest.fixture(scope='session', autouse=True)
def ethx_init():
def ethx_init(diff_initial_state):
""" Remove any existing definitions on the ethX interfaces. """
ifacelib.ifaces_init('eth1', 'eth2')
@ -60,6 +63,23 @@ port0_up = eth1_up
port1_up = eth2_up
@pytest.fixture(scope='session', autouse=True)
def diff_initial_state():
old_state = libnmstate.show()
yield
new_state = libnmstate.show()
if old_state != new_state:
warnings.warn(
'Network state after test run does not match network state '
'before test run:\n {}\n'.format(
libnmstate.prettystate.format_desired_current_state_diff(
old_state, new_state
),
)
)
def pytest_report_header(config):
return REPORT_HEADER.format(
rpms=_get_package_nvr('NetworkManager'), osname=_get_osname()