Change in vdsm[master]: [WIP] a more delicate rollback

danken at redhat.com danken at redhat.com
Tue Nov 27 08:53:59 UTC 2012


Dan Kenigsberg has uploaded a new change for review.

Change subject: [WIP] a more delicate rollback
......................................................................

[WIP] a more delicate rollback

If things go wrong during setupNetwork, we try to revert the networking
state to what it used to be. Until this patch, we stopped the network
service, reverted all ifcfg-* files, and restarted networking.

This procedure disruppted all connection, even those unrelated to the
ones being set up.

With this change, we are taking down only affected devices, and revert
them to their pre-setupNetwork state.

Change-Id: If413164a34a1e6f0d7e4ef75ba931e630a26e666
Signed-off-by: Dan Kenigsberg <danken at redhat.com>
---
M vdsm/configNetwork.py
1 file changed, 37 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/06/9506/1

diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 09d70ac..6e8649c 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -320,6 +320,41 @@
                 open(confFile, 'w').write(content)
             logging.info('Restored %s', confFile)
 
+    def _devType(self, content):
+        if re.search('^TYPE=Bridge$', content, re.MULTILINE):
+            return "Bridge"
+        elif re.search('^VLAN=yes$', content, re.MULTILINE):
+            return "Vlan"
+        else:
+            return "Other"
+
+    def _sortModifiedIfcfgs(self):
+        devdict = {'Bridge': [],
+                   'Vlan': [],
+                   'Other': []}
+        for confFile, _ in self._backups.iteritems():
+            try:
+                content = file(confFile).read()
+            except IOError as e:
+                if e.errno == os.errno.ENOENT:
+                    continue
+                else:
+                    raise
+            dev = confFile[len(self.NET_CONF_PREF):]
+
+            devdict[self._devType(content)].append(dev)
+
+        return nicSort(devdict['Other']) + devdict['Vlan'] + \
+               devdict['Bridge']
+
+    def _stopAtomicDevices(self):
+        for dev in reversed(self._sortModifiedIfcfgs()):
+            ifdown(dev)
+
+    def _startAtomicDevices(self):
+        for dev in self._sortModifiedIfcfgs():
+            ifup(dev)
+
     @classmethod
     def _persistentBackup(cls, filename):
         """ Persistently backup ifcfg-* config files """
@@ -374,12 +409,12 @@
         if not self._backups and not self._networksBackups:
             return
 
-        execCmd(['/etc/init.d/network', 'stop'])
+        self._stopAtomicDevices()
 
         self.restoreAtomicNetworkBackup()
         self.restoreAtomicBackup()
 
-        execCmd(['/etc/init.d/network', 'start'])
+        self._startAtomicDevices()
 
     @classmethod
     def clearBackups(cls):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If413164a34a1e6f0d7e4ef75ba931e630a26e666
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>


More information about the vdsm-patches mailing list