Ido Barkan has uploaded a new change for review.

Change subject: net: tests: add requiresUnifiedPersistence decorator
......................................................................

net: tests: add requiresUnifiedPersistence decorator

So we can stop repeating
if vdsm.config.config.get('vars', 'net_persistence') == 'ifcfg':
    ...
boiler plate.

Change-Id: I618a3782d2393d8382ea66e50ea47845cc74132a
Signed-off-by: Ido Barkan <[email protected]>
---
M tests/functional/networkTests.py
1 file changed, 64 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/07/44307/1

diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 4b4dbf8..99a4d3f 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -189,6 +189,18 @@
         device_name, None, ipv4_address, IP_MASK, IP_GATEWAY)
 
 
+def requiresUnifiedPersistence(reason):
+    def wrapper(test_method):
+        @wraps(test_method)
+        def wrapped_test_method(*args, **kwargs):
+            if vdsm.config.config.get('vars', 'net_persistence') == 'ifcfg':
+                raise SkipTest(reason)
+            test_method(*args, **kwargs)
+        return wrapped_test_method
+    return wrapper
+
+
+
 @expandPermutations
 class NetworkTest(TestCaseBase):
 
@@ -287,11 +299,11 @@
                              '%s found unexpectedly' % bondName)
         else:
             self.assertTrue(bondName not in netinfo.bondings or (set(nics) !=
-                            set(netinfo.bondings[bondName]['slaves'])),
+                                                                 
set(netinfo.bondings[bondName]['slaves'])),
                             '%s found unexpectedly' % bondName)
         if config is not None:
             self.assertTrue(bondName not in config.bonds or (set(nics) !=
-                            set(config.bonds[bondName].get('nics'))),
+                                                             
set(config.bonds[bondName].get('nics'))),
                             '%s found unexpectedly in running config' %
                             bondName)
 
@@ -473,7 +485,7 @@
         with dummyIf(2) as nics:
             status, msg = self.setupNetworks(
                 {NETWORK_NAME:
-                    {'bonding': BONDING_NAME, 'bridged': bridged}},
+                     {'bonding': BONDING_NAME, 'bridged': bridged}},
                 {BONDING_NAME: {'nics': nics, 'options': 'mode=2'}}, NOCHK)
             self.assertEqual(status, SUCCESS, msg)
             self.assertNetworkExists(NETWORK_NAME, bridged)
@@ -501,8 +513,8 @@
             with nonChangingOperstate(BONDING_NAME):
                 status, msg = self.setupNetworks(
                     {NETWORK_NAME:
-                        {'bonding': BONDING_NAME, 'bridged': bridged,
-                         'vlan': VLAN_ID}},
+                         {'bonding': BONDING_NAME, 'bridged': bridged,
+                          'vlan': VLAN_ID}},
                     {}, NOCHK)
             self.assertEqual(status, SUCCESS, msg)
             self.assertNetworkExists(NETWORK_NAME, bridged)
@@ -618,7 +630,7 @@
                                                        bond=bond_name,
                                                        nics=nics,
                                                        opts={'bridged':
-                                                             bridged})
+                                                                 bridged})
                 self.assertEqual(status, errors.ERR_BAD_BONDING, msg)
 
     @cleanupNet
@@ -1103,11 +1115,11 @@
 
         with dummyIf(3) as nics:
             networks = {NETWORK_NAME + '1':
-                        dict(bonding=BONDING_NAME, bridged=bridged,
-                             vlan='100'),
+                            dict(bonding=BONDING_NAME, bridged=bridged,
+                                 vlan='100'),
                         NETWORK_NAME + '2':
-                        dict(bonding=BONDING_NAME, bridged=bridged,
-                             vlan='200', mtu=MIDI)
+                            dict(bonding=BONDING_NAME, bridged=bridged,
+                                 vlan='200', mtu=MIDI)
                         }
             bondings = {BONDING_NAME: dict(nics=nics[:2])}
             status, msg = self.setupNetworks(networks, bondings, NOCHK)
@@ -1118,8 +1130,8 @@
                            nics[1])
 
             network = {NETWORK_NAME + '3':
-                       dict(bonding=BONDING_NAME, vlan='300', mtu=JUMBO,
-                            bridged=bridged)}
+                           dict(bonding=BONDING_NAME, vlan='300', mtu=JUMBO,
+                                bridged=bridged)}
             status, msg = self.setupNetworks(network, {}, NOCHK)
 
             self.assertEquals(status, SUCCESS, msg)
@@ -1235,7 +1247,7 @@
             with self.vdsm_net.pinger():
                 # Add initial vlanned net over bond
                 self._createBondedNetAndCheck(0, {'nics': nics[:2],
-                                              'options': 'mode=3 miimon=250'},
+                                                  'options': 'mode=3 
miimon=250'},
                                               bridged)
 
                 _waitForKnownOperstate(BONDING_NAME)
@@ -1244,19 +1256,19 @@
                     self._createBondedNetAndCheck(1,
                                                   {'nics': nics[:2],
                                                    'options':
-                                                   'mode=3 miimon=250'},
+                                                       'mode=3 miimon=250'},
                                                   bridged)
                     # Add additional vlanned net over the increasing bond
                     self._createBondedNetAndCheck(2,
                                                   {'nics': nics,
                                                    'options':
-                                                   'mode=3 miimon=250'},
+                                                       'mode=3 miimon=250'},
                                                   bridged)
                     # Add additional vlanned net over the changing bond
                     self._createBondedNetAndCheck(3,
                                                   {'nics': nics[1:],
                                                    'options':
-                                                   'mode=3 miimon=250'},
+                                                       'mode=3 miimon=250'},
                                                   bridged)
 
                 # Add a network changing bond options
@@ -1266,7 +1278,7 @@
                         self._createBondedNetAndCheck(4,
                                                       {'nics': nics[1:],
                                                        'options':
-                                                       'mode=4 miimon=9'},
+                                                           'mode=4 miimon=9'},
                                                       bridged)
 
                 # cleanup
@@ -1423,7 +1435,7 @@
                                                        bond=BONDING_NAME,
                                                        nics=nics,
                                                        opts={'bridged':
-                                                             bridged})
+                                                                 bridged})
                 self.assertEquals(status, SUCCESS, msg)
                 hwaddr = self.vdsm_net.netinfo.bondings[BONDING_NAME]['hwaddr']
 
@@ -1461,6 +1473,8 @@
 
             self.vdsm_net.save_config()
 
+    @requiresUnifiedPersistence("with ifcfg persistence, this test is "
+                                "irrelevant")
     @cleanupNet
     @RequireVethMod
     @ValidateRunningAsRoot
@@ -1469,9 +1483,6 @@
         restoration of bootprot=dhcp networks is down synchronously. with
         ifcfg persistence, this is what happens thanks to initscripts,
         regardless of vdsm. Hence, this test is irrelevant there. """
-        if vdsm.config.config.get('vars', 'net_persistence') == 'ifcfg':
-            raise SkipTest(
-                "with ifcfg persistence, this test is irelevant")
 
         def _get_blocking_dhcp(net_name):
             self.vdsm_net.refreshNetinfo()
@@ -1523,12 +1534,11 @@
                 {NETWORK_NAME: {'remove': True}}, {}, NOCHK)
             self.assertEquals(status, SUCCESS, msg)
 
+    @requiresUnifiedPersistence("with ifcfg persistence, "
+                                "vdsm-restore-net-config selective restoration"
+                                "is not supported")
     @cleanupNet
     def testRestoreNetworksOnlyRestoreUnchangedDevices(self):
-        if vdsm.config.config.get('vars', 'net_persistence') == 'ifcfg':
-            raise SkipTest(
-                "with ifcfg persistence, vdsm-restore-net-config selective"
-                "restoration is not supported")
         BOND_UNCHANGED = 'bond100'
         BOND_MISSING = 'bond102'
         IP_ADD_UNCHANGED = '240.0.0.100'
@@ -1614,13 +1624,11 @@
                 self.assertBondDoesntExist(BOND_MISSING, [nic_b])
                 self.assertBondDoesntExist(BOND_UNCHANGED, [nic_a])
 
+    @requiresUnifiedPersistence("with ifcfg persistence, "
+                                "vdsm-restore-net-config selective restoration"
+                                "is not supported")
     @cleanupNet
     def testSelectiveRestoreDuringUpgrade(self):
-        if vdsm.config.config.get('vars', 'net_persistence') == 'ifcfg':
-            raise SkipTest(
-                "with ifcfg persistence, vdsm-restore-net-config selective"
-                "restoration is not supported")
-
         BOND_UNCHANGED = 'bond100'
         BOND_CHANGED = 'bond101'
         IP_MGMT = '240.0.0.100'
@@ -1743,13 +1751,11 @@
                 self.assertBondDoesntExist(BOND_CHANGED, [nic_b])
                 self.assertBondDoesntExist(BOND_UNCHANGED, [nic_a])
 
+    @requiresUnifiedPersistence("with ifcfg persistence, "
+                                "vdsm-restore-net-config selective restoration"
+                                "is not supported")
     @cleanupNet
     def testSelectiveRestoreIgnoresVdsmRegParams(self):
-        if vdsm.config.config.get('vars', 'net_persistence') == 'ifcfg':
-            raise SkipTest(
-                "with ifcfg persistence, vdsm-restore-net-config selective"
-                "restoration is not supported")
-
         with dummyIf(1) as nics:
             nic,  = nics
             # let _assert_kernel_config_matches_running_config do the job
@@ -1773,7 +1779,7 @@
         with dummyIf(1) as nics:
             status, msg = self.vdsm_net.addNetwork(NETWORK_NAME, nics=nics,
                                                    opts={'bridged':
-                                                         bridged})
+                                                             bridged})
             self.assertEquals(status, SUCCESS, msg)
 
             self.assertNetworkExists(NETWORK_NAME, bridged=bridged)
@@ -1788,8 +1794,8 @@
         with dummyIf(1) as nics:
             status, msg = self.setupNetworks(
                 {NETWORK_NAME:
-                    {'nic': nics[0], 'bridged': bridged, 'ipaddr': IP_ADDRESS,
-                     'netmask': IP_MASK, 'gateway': IP_GATEWAY}},
+                     {'nic': nics[0], 'bridged': bridged, 'ipaddr': IP_ADDRESS,
+                      'netmask': IP_MASK, 'gateway': IP_GATEWAY}},
                 {}, NOCHK)
             self.assertEqual(status, SUCCESS, msg)
             self.assertNetworkExists(NETWORK_NAME, bridged)
@@ -1894,16 +1900,16 @@
                    "\n"
                    "network = network_config['request']['networks']['" +
                    NETWORK_NAME + "']\n"
-                   "assert network['custom'] == " + str(CUSTOM_PROPS) + "\n"
-                   "\n"
-                   "# setup an output config file\n"
-                   "cookie_file = open('%(cookiefile)s','w')\n"
-                   "cookie_file.write(str(network_config) + '\\n')\n"
-                   "network['bridged'] = True\n"
-                   "\n"
-                   "# output modified config back to the hook_data file\n"
-                   "with open(hook_data, 'w') as network_config_file:\n"
-                   "    json.dump(network_config, network_config_file)\n"
+                                  "assert network['custom'] == " + 
str(CUSTOM_PROPS) + "\n"
+                                                                               
        "\n"
+                                                                               
        "# setup an output config file\n"
+                                                                               
        "cookie_file = open('%(cookiefile)s','w')\n"
+                                                                               
        "cookie_file.write(str(network_config) + '\\n')\n"
+                                                                               
        "network['bridged'] = True\n"
+                                                                               
        "\n"
+                                                                               
        "# output modified config back to the hook_data file\n"
+                                                                               
        "with open(hook_data, 'w') as network_config_file:\n"
+                                                                               
        "    json.dump(network_config, network_config_file)\n"
                    )
     def testBeforeNetworkSetupHook(self, hook_cookiefile):
         with dummyIf(1) as nics:
@@ -1999,10 +2005,10 @@
         with dummyIf(2) as nics:
             status, msg = self.setupNetworks(
                 {NETWORK_NAME:
-                    {'bonding': BONDING_NAME, 'bridged': True,
-                        'vlan': VLAN_ID, 'mtu': BIG_MTU}},
+                     {'bonding': BONDING_NAME, 'bridged': True,
+                      'vlan': VLAN_ID, 'mtu': BIG_MTU}},
                 {BONDING_NAME:
-                    {'nics': nics}},
+                     {'nics': nics}},
                 NOCHK)
             self.assertEqual(status, SUCCESS, msg)
             deviceLinks = getLinks()
@@ -2420,7 +2426,7 @@
         def _get_dhclient_ifaces():
             pids = pgrep('dhclient')
             return [open('/proc/%s/cmdline' % pid).read().strip('\0')
-                    .split('\0')[-1] for pid in pids]
+                        .split('\0')[-1] for pid in pids]
 
         with veth.pair() as (server, client):
             veth.setIP(server, IP_ADDRESS, IP_CIDR)
@@ -2518,7 +2524,7 @@
         with dummyIf(2) as nics:
             status, msg = self.setupNetworks(
                 {NETWORK_NAME:
-                    {'bonding': BONDING_NAME, 'bridged': False}},
+                     {'bonding': BONDING_NAME, 'bridged': False}},
                 {BONDING_NAME: {'nics': nics}}, NOCHK)
             self.assertEqual(status, SUCCESS, msg)
             self.assertNetworkExists(NETWORK_NAME)
@@ -2542,7 +2548,7 @@
         try:
             status, msg = self.setupNetworks(
                 {NETWORK_NAME:
-                    {'bonding': BONDING_NAME, 'bridged': False}},
+                     {'bonding': BONDING_NAME, 'bridged': False}},
                 {BONDING_NAME: {'nics': nics}}, NOCHK)
             self.assertEqual(status, SUCCESS, msg)
             self.assertNetworkExists(NETWORK_NAME)
@@ -2557,13 +2563,12 @@
         self.assertNetworkDoesntExist(NETWORK_NAME)
         self.assertBondDoesntExist(BONDING_NAME, nics)
 
+    @requiresUnifiedPersistence("with ifcfg persistence, "
+                                "vdsm-restore-net-config doesn't restore "
+                                "in-kernel state")
     @cleanupNet
     @ValidateRunningAsRoot
     def test_setupNetworks_on_external_bond(self):
-        if vdsm.config.config.get('vars', 'net_persistence') == 'ifcfg':
-            raise SkipTest(
-                "with ifcfg persistence, vdsm-restore-net-config "
-                "doesn't restore in-kernel state")
         with dummyIf(2) as nics:
             with open(BONDING_MASTERS, 'w') as bonds:
                 bonds.write('+%s\n' % BONDING_NAME)
@@ -2573,7 +2578,7 @@
                         f.write('+%s\n' % nic)
                 status, msg = self.setupNetworks(
                     {NETWORK_NAME:
-                        {'bonding': BONDING_NAME, 'bridged': False}},
+                         {'bonding': BONDING_NAME, 'bridged': False}},
                     {BONDING_NAME: {'nics': nics}}, NOCHK)
                 self.assertEqual(status, SUCCESS, msg)
                 self.assertNetworkExists(NETWORK_NAME)


-- 
To view, visit https://gerrit.ovirt.org/44307
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I618a3782d2393d8382ea66e50ea47845cc74132a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ido Barkan <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to