Change in vdsm[master]: net: Use VLAN ID as integer across VDSM

edwardh at redhat.com edwardh at redhat.com
Wed Jan 13 16:58:34 UTC 2016


Edward Haas has uploaded a new change for review.

Change subject: net: Use VLAN ID as integer across VDSM
......................................................................

net: Use VLAN ID as integer across VDSM

Canonize and normalize VLAN ID at API entry point and use it as an
integer internally.

Change-Id: Ia3a0133560a6946c3438161fb1696f002f2cdb21
Note: Engine expects the vlan id to be an integer.
Signed-off-by: Edward Haas <edwardh at redhat.com>
---
M lib/vdsm/kernelconfig.py
M lib/vdsm/netconfpersistence.py
M lib/vdsm/network/api.py
M lib/vdsm/network/models.py
M tests/functional/utils.py
5 files changed, 24 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/02/51802/1

diff --git a/lib/vdsm/kernelconfig.py b/lib/vdsm/kernelconfig.py
index 7b69be4..e62a0e5 100644
--- a/lib/vdsm/kernelconfig.py
+++ b/lib/vdsm/kernelconfig.py
@@ -135,7 +135,7 @@
 
 def _translate_vlan(attributes, vlan):
     if vlan is not None:
-        attributes['vlan'] = str(vlan)
+        attributes['vlan'] = vlan
 
 
 def _translate_mtu(attributes, net_attr):
@@ -187,7 +187,7 @@
 def _normalize_vlan(config_copy):
     for net_attr in config_copy.networks.itervalues():
         if 'vlan' in net_attr:
-            net_attr['vlan'] = str(net_attr['vlan'])
+            net_attr['vlan'] = net_attr['vlan']
 
 
 def _normalize_bridge(config_copy):
diff --git a/lib/vdsm/netconfpersistence.py b/lib/vdsm/netconfpersistence.py
index 472a235..f4aef2a 100644
--- a/lib/vdsm/netconfpersistence.py
+++ b/lib/vdsm/netconfpersistence.py
@@ -221,8 +221,8 @@
     bond = network.get('bonding')
     vlan = network.get('vlan', '')
     if bond:
-        return [bond + vlan]
+        return [bond + str(vlan)]
     elif nic:
-        return [nic + vlan]
+        return [nic + str(vlan)]
     else:  # isolated bridged network
         return []
diff --git a/lib/vdsm/network/api.py b/lib/vdsm/network/api.py
index ddf6656..874d6b9 100755
--- a/lib/vdsm/network/api.py
+++ b/lib/vdsm/network/api.py
@@ -259,7 +259,6 @@
         dhcpv6 = utils.tobool(dhcpv6)
     if ipv6autoconf is not None:
         ipv6autoconf = utils.tobool(ipv6autoconf)
-    vlan = _vlanToInternalRepresentation(vlan)
 
     if network == '':
         raise ConfigNetworkError(ne.ERR_BAD_BRIDGE,
@@ -449,7 +448,6 @@
 
     if network not in _netinfo.networks:
         logging.info("Network %r: doesn't exist in libvirt database", network)
-        vlan = _vlanToInternalRepresentation(vlan)
         _delNonVdsmNetwork(network, vlan, bonding, nics, _netinfo,
                            configurator)
         return
@@ -591,14 +589,9 @@
 def _validateNetworkSetup(networks, bondings):
     for network, networkAttrs in networks.iteritems():
         if networkAttrs.get('remove', False):
-            net_attr_keys = set(networkAttrs)
-            if 'remove' in net_attr_keys and net_attr_keys - set(
-                    ['remove', 'custom']):
-                raise ConfigNetworkError(
-                    ne.ERR_BAD_PARAMS,
-                    "Cannot specify any attribute when removing (other "
-                    "than custom properties). specified attributes: %s" % (
-                        networkAttrs,))
+            _validate_network_remove(networkAttrs)
+        else:
+            Vlan.validateTag(networkAttrs['vlan'])
 
     currentNicsSet = set(netinfo_nics.nics())
     for bonding, bondingAttrs in bondings.iteritems():
@@ -616,6 +609,17 @@
         if not set(nics).issubset(currentNicsSet):
             raise ConfigNetworkError(ne.ERR_BAD_NIC,
                                      "Unknown nics in: %r" % list(nics))
+
+
+def _validate_network_remove(networkAttrs):
+    net_attr_keys = set(networkAttrs)
+    if 'remove' in net_attr_keys and net_attr_keys - set(
+            ['remove', 'custom']):
+        raise ConfigNetworkError(
+            ne.ERR_BAD_PARAMS,
+            "Cannot specify any attribute when removing (other "
+            "than custom properties). specified attributes: %s" % (
+                networkAttrs,))
 
 
 def _inherit_dhcp_unique_identifier(bridge, _netinfo):
@@ -952,15 +956,6 @@
     hooks.after_network_setup(_buildSetupHookDict(networks, bondings, options))
 
 
-def _vlanToInternalRepresentation(vlan):
-    if vlan is None or vlan == '':
-        vlan = None
-    else:
-        Vlan.validateTag(vlan)
-        vlan = int(vlan)
-    return vlan
-
-
 def _canonize_networks(nets):
     """
     Given networks configuration, explicitly add missing defaults.
@@ -977,6 +972,9 @@
         attrs['mtu'] = int(attrs['mtu']) if 'mtu' in attrs else (
             mtus.DEFAULT_MTU)
 
+        vlan = attrs.get('vlan', None)
+        attrs['vlan'] = None if vlan in (None, '') else int(vlan)
+
 
 def setSafeNetworkConfig():
     """Declare current network configuration as 'safe'"""
diff --git a/lib/vdsm/network/models.py b/lib/vdsm/network/models.py
index a5609fd..c9cb17c 100644
--- a/lib/vdsm/network/models.py
+++ b/lib/vdsm/network/models.py
@@ -145,6 +145,8 @@
 
     @classmethod
     def validateTag(cls, tag):
+        if tag is None:
+            return
         try:
             if not 0 <= int(tag) <= cls.MAX_ID:
                 raise ConfigNetworkError(
diff --git a/tests/functional/utils.py b/tests/functional/utils.py
index e075680..021af3a 100644
--- a/tests/functional/utils.py
+++ b/tests/functional/utils.py
@@ -165,7 +165,7 @@
 
     def _vlanInRunningConfig(self, devName, vlanId):
         for net, attrs in self.config.networks.iteritems():
-            if (vlanId == attrs.get('vlan') and
+            if (int(vlanId) == attrs.get('vlan') and
                     (attrs.get('bonding') == devName or
                      attrs.get('nic') == devName)):
                 return True


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3a0133560a6946c3438161fb1696f002f2cdb21
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