Change in vdsm[master]: netconf: make ifcfg's rollback cover new added networks

wudxw at linux.vnet.ibm.com wudxw at linux.vnet.ibm.com
Mon Jul 22 14:07:56 UTC 2013


Mark Wu has uploaded a new change for review.

Change subject: netconf: make ifcfg's rollback cover new added networks
......................................................................

netconf: make ifcfg's rollback cover new added networks

This patch make ifcfg's rollback also cover new added networks, then
then we don't need track the new added networks and delete them on
connectivity exception.

This patch also changes _sortModifiedIfcfgs to use in-memory backups
instead of cfg files on disk. It could me more efficient.

Change-Id: Iabcfb10119d303f81f505a6065e3139eddb3b049
Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
---
M lib/vdsm/ipwrapper.py
M tests/netconfTests.py
M vdsm/configNetwork.py
M vdsm/netconf/ifcfg.py
4 files changed, 29 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/14/17214/1

diff --git a/lib/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py
index 77659d7..b313ad0 100644
--- a/lib/vdsm/ipwrapper.py
+++ b/lib/vdsm/ipwrapper.py
@@ -243,3 +243,13 @@
     command = [_IP_BINARY.cmd, 'rule', 'del']
     command += rule
     _execCmd(command)
+
+
+def linkSet(link):
+    command = [_IP_BINARY.cmd, 'link', 'set'] + link
+    _execCmd(command)
+
+
+def linkDel(link):
+    command = [_IP_BINARY.cmd, 'link', 'del'] + link
+    _execCmd(command)
diff --git a/tests/netconfTests.py b/tests/netconfTests.py
index 919a5eb..f508bef 100644
--- a/tests/netconfTests.py
+++ b/tests/netconfTests.py
@@ -110,6 +110,8 @@
              os.path.join(self._tempdir, 'ifcfg-')),
             (ifcfg, 'ifdown', lambda x: 0),
             (ifcfg, 'ifup', lambda *x: 0),
+            (ifcfg, 'linkSet', lambda x:0),
+            (ifcfg, 'linkDel', lambda x:0),
             (libvirtCfg, 'createNetwork', lambda *x: None),
             (libvirtCfg, 'removeNetwork', lambda *x: None),
         ]):
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index c0d31f2..f247942 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -473,7 +473,6 @@
     logger = logging.getLogger("setupNetworks")
     _netinfo = netinfo.NetInfo()
     configurator = Ifcfg()
-    networksAdded = set()
 
     logger.debug("Setting up network according to configuration: "
                  "networks:%r, bondings:%r, options:%r" % (networks,
@@ -506,8 +505,6 @@
                 if 'remove' in networkAttrs:
                     del networks[network]
                     del libvirt_nets[network]
-            else:
-                networksAdded.add(network)
 
         _handleBondings(bondings, configurator)
 
@@ -530,13 +527,6 @@
             if not clientSeen(int(options.get('connectivityTimeout',
                                   CONNECTIVITY_TIMEOUT_DEFAULT))):
                 logger.info('Connectivity check failed, rolling back')
-                for network in networksAdded:
-                    # If the new added network was created on top of
-                    # existing bond, we need to keep the bond on rollback
-                    # flow, else we will break the new created bond.
-                    delNetwork(network, force=True,
-                               implicitBonding=networks[network].
-                               get('bonding') in bondings)
                 raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
                                          'connectivity check failed')
     except:
diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py
index c338722..e742ea5 100644
--- a/vdsm/netconf/ifcfg.py
+++ b/vdsm/netconf/ifcfg.py
@@ -36,6 +36,7 @@
 from vdsm import constants
 from vdsm import netinfo
 from vdsm import utils
+from vdsm.ipwrapper import linkSet, linkDel
 import libvirtCfg
 import neterrors as ne
 
@@ -319,28 +320,31 @@
                    'Vlan': [],
                    'Slave': [],
                    'Other': []}
-        for confFile, _ in self._backups.iteritems():
+        newAdded = []
+        for confFile, content in self._backups.iteritems():
             if not confFile.startswith(netinfo.NET_CONF_PREF):
                 continue
-            try:
-                content = file(confFile).read()
-            except IOError as e:
-                if e.errno == os.errno.ENOENT:
-                    continue
-                else:
-                    raise
             dev = confFile[len(netinfo.NET_CONF_PREF):]
+            if content is None:
+                newAdded.append(dev)
+            else:
+                devdict[self._devType(content)].append(dev)
 
-            devdict[self._devType(content)].append(dev)
-
-        return devdict['Other'] + devdict['Vlan'] + devdict['Bridge']
+        return (devdict['Other'] + devdict['Vlan'] + devdict['Bridge'],
+                newAdded)
 
     def _stopAtomicDevices(self):
-        for dev in reversed(self._sortModifiedIfcfgs()):
+        changed, added = self._sortModifiedIfcfgs()
+        for dev in added:
+            if dev in netinfo.nics() or dev in netinfo.REQUIRED_BONDINGS:
+                linkSet(['dev', dev, 'down'])
+            else:
+                linkDel(['dev', dev])
+        for dev in reversed(changed):
             ifdown(dev)
 
     def _startAtomicDevices(self):
-        for dev in self._sortModifiedIfcfgs():
+        for dev in self._sortModifiedIfcfgs()[0]:
             try:
                 ifup(dev)
             except ConfigNetworkError:


-- 
To view, visit http://gerrit.ovirt.org/17214
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iabcfb10119d303f81f505a6065e3139eddb3b049
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw at linux.vnet.ibm.com>


More information about the vdsm-patches mailing list