Change in vdsm[master]: net api: Normalize the network stp flag

edwardh at redhat.com edwardh at redhat.com
Wed Jan 20 12:12:17 UTC 2016


Edward Haas has uploaded a new change for review.

Change subject: net api: Normalize the network stp flag
......................................................................

net api: Normalize the network stp flag

Normalize the network stp flag at the network api entry point.

Change-Id: I9bb49201625ccefab442756a15552175b725c87f
Signed-off-by: Edward Haas <edwardh at redhat.com>
---
M lib/vdsm/network/api.py
M lib/vdsm/network/configurators/ifcfg.py
M tests/configNetworkTests.py
3 files changed, 18 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/95/52495/1

diff --git a/lib/vdsm/network/api.py b/lib/vdsm/network/api.py
index 14a9982..539a210 100755
--- a/lib/vdsm/network/api.py
+++ b/lib/vdsm/network/api.py
@@ -160,18 +160,8 @@
     elif vlan_id is not None:
         topNetDev = Vlan(topNetDev, vlan_id, configurator, mtu=mtu)
     if bridge is not None:
-        stp = None
-        if 'stp' in opts:
-            stp = opts.pop('stp')
-        elif 'STP' in opts:
-            stp = opts.pop('STP')
-        try:
-            stp = bridges.stp_booleanize(stp)
-        except ValueError:
-            raise ConfigNetworkError(ne.ERR_BAD_PARAMS, '"%s" is not a valid '
-                                     'bridge STP value.' % stp)
         topNetDev = Bridge(bridge, configurator, port=topNetDev, mtu=mtu,
-                           stp=stp)
+                           stp=opts.get('stp', None))
         # inherit DUID from the port's existing DHCP lease (BZ#1219429)
         if topNetDev.port and bootproto == 'dhcp':
             _inherit_dhcp_unique_identifier(topNetDev, _netinfo)
@@ -971,6 +961,7 @@
         normalize.norm_mtu()
         normalize.norm_vlan()
         normalize.norm_bridged()
+        normalize.norm_stp()
 
 
 class _Normalize(object):
@@ -1002,6 +993,20 @@
         else:
             self.data['bridged'] = True
 
+    def norm_stp(self):
+        data = self.data
+        if data['bridged']:
+            stp = False
+            if 'stp' in data:
+                stp = data['stp']
+            elif 'STP' in data:
+                stp = data.pop('STP')
+            try:
+                data['stp'] = bridges.stp_booleanize(stp)
+            except ValueError:
+                raise ConfigNetworkError(ne.ERR_BAD_PARAMS, '"%s" is not '
+                                         'a valid bridge STP value.' % stp)
+
 
 def setSafeNetworkConfig():
     """Declare current network configuration as 'safe'"""
diff --git a/lib/vdsm/network/configurators/ifcfg.py b/lib/vdsm/network/configurators/ifcfg.py
index f314cd6..250e7f9 100644
--- a/lib/vdsm/network/configurators/ifcfg.py
+++ b/lib/vdsm/network/configurators/ifcfg.py
@@ -542,7 +542,7 @@
                      'force', 'blockingdhcp', 'custom',
                      'connectivityCheck', 'connectivityTimeout',
                      'implicitBonding', 'delay', 'onboot', 'forward_delay',
-                     'DELAY', 'ONBOOT']
+                     'DELAY', 'ONBOOT', 'stp']
         for k in set(kwargs.keys()).difference(set(BLACKLIST)):
             if re.match('^[a-zA-Z_]\w*$', k):
                 cfg += '%s=%s\n' % (k.upper(), pipes.quote(kwargs[k]))
diff --git a/tests/configNetworkTests.py b/tests/configNetworkTests.py
index d511601..e6a533f 100644
--- a/tests/configNetworkTests.py
+++ b/tests/configNetworkTests.py
@@ -47,6 +47,7 @@
 
     def _addNetworkWithExc(self, netName, opts, errCode):
         with self.assertRaises(errors.ConfigNetworkError) as cneContext:
+            api._canonize_networks({netName: opts})
             api._addNetwork(netName, **opts)
         self.assertEqual(cneContext.exception.errCode, errCode)
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9bb49201625ccefab442756a15552175b725c87f
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Edward Haas <edwardh at redhat.com>


More information about the vdsm-patches mailing list