Antoni Segura Puimedon has uploaded a new change for review. Change subject: net_func_tests: restore when tests don't clean up after themselves ......................................................................
net_func_tests: restore when tests don't clean up after themselves After the patch that made the rollback after each test happen only in case of exception, some tests could fail if the previous test did not perform a good cleanup. With this change, we check that the Running Config is always the original one between tests and that at the end of all the tests we'll have the original RunningConfig and PersistentConfig. Change-Id: I0678e1194c31b71c0179c7b46d697a186d44e1c1 Signed-off-by: Antoni S. Puimedon <[email protected]> --- M tests/functional/networkTests.py 1 file changed, 39 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/10/35710/1 diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py index 3ea1db0..17fe59b 100644 --- a/tests/functional/networkTests.py +++ b/tests/functional/networkTests.py @@ -41,11 +41,13 @@ from vdsm.ipwrapper import (routeExists, ruleExists, addrFlush, LinkType, getLinks, routeShowTable) +from vdsm.config import config from vdsm.constants import EXT_BRCTL from vdsm.utils import RollbackContext, execCmd, running from vdsm.netinfo import (bridges, operstate, prefix2netmask, getRouteDeviceTo, getDhclientIfaces) from vdsm import ipwrapper +from vdsm import netconfpersistence from vdsm.utils import pgrep import caps @@ -80,16 +82,18 @@ def setupModule(): """Persists network configuration.""" - vdsm = VdsProxy() - vdsm.save_config() + if config.get('vars', 'net_persistence') == 'ifcfg': + vdsm = VdsProxy() + vdsm.save_config() for _ in range(DUMMY_POOL_SIZE): dummyPool.add(dummy.create()) def tearDownModule(): """Restores the network configuration previous to running tests.""" - vdsm = VdsProxy() - vdsm.restoreNetConfig() + if config.get('vars', 'net_persistence') == 'ifcfg': + vdsm = VdsProxy() + vdsm.restoreNetConfig() for nic in dummyPool: dummy.remove(nic) @@ -220,6 +224,21 @@ def setUp(self): self.vdsm_net = VdsProxy() + if self.vdsm_net.config is not None: # unified persistence + self.pre_running_config = self.vdsm_net.config + self.pre_persistent_config = netconfpersistence.PersistentConfig() + self.skip_rest = False + + def tearDown(self): + if self.vdsm_net.config is not None: # unified persistence + diff = self.pre_running_config.diffFrom(self.vdsm_net.config) + if diff: + self.vdsm_net.setupNetworks( + diff.networks, diff.bonds, + {'connectivityCheck': False, '_inRollback=True': True}) + + # Put back whichever persistent config was at the start + self.pre_persistent_config.store() def cleanupNet(func): """ @@ -230,9 +249,24 @@ @wraps(func) def wrapper(*args, **kwargs): + self = args[0] + if self.vdsm_net.config is not None and self.skip_rest: + raise SkipTest('The environment is not clean due to a ' + 'previous test. Skipping!') with RollbackContext(on_exception_only=True) as rollback: - rollback.prependDefer(args[0].vdsm_net.restoreNetConfig) + rollback.prependDefer(self.vdsm_net.restoreNetConfig) func(*args, **kwargs) + if self.vdsm_net.config is not None: # unified persistence + # Cleaning up after messy non-failing tests + diff = self.pre_running_config.diffFrom( + self.vdsm_net.config) + if diff: + status, msg = self.vdsm_net.setupNetworks( + diff.networks, diff.bonds, + {'connectivityCheck': False, + '_inRollback=True': True}) + if status != SUCCESS: + self.skip_rest = True return wrapper def assertNetworkExists(self, networkName, bridged=None, bridgeOpts=None, -- To view, visit http://gerrit.ovirt.org/35710 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0678e1194c31b71c0179c7b46d697a186d44e1c1 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Antoni Segura Puimedon <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
