Alon Bar-Lev has uploaded a new change for review.

Change subject: vdsm: bridge: attempt to rollback if bridge creation failed
......................................................................

vdsm: bridge: attempt to rollback if bridge creation failed

Currently vdsm-bootstrap, host-deploy, vdsm-reg do not rollback network
configuration if addNetwork fails.

The sequence should be:
- addNetwork
- vdsm-restore-net-config -> rollback
- vdsm-store-net-config -> commit

Supporting non-node setup is not important to 3.3 as only legacy nodes
still use the ovirt-host-deploy bridge plugin.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=979570
Change-Id: Id9e6b0d076f3a16f036e149258454da395569797
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M ChangeLog
M src/plugins/ovirt-host-deploy/vdsm/bridge.py
2 files changed, 47 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-host-deploy 
refs/changes/24/17124/1

diff --git a/ChangeLog b/ChangeLog
index f338cc2..15104da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
  * vdsm: bridge: fix format typo when querying network manager, thanks to
    Pascal Jakobi for reporting.
  * vdsm: bridge: fix python compatibility issue and network manager.
+ * vdsm: bridge: attempt to rollback if bridge creation failed.
  * vdsm: hardware: do not fail if cannot read msr, rhbz#916589.
  * vdsm: vdsmid: do not attempt to install dmidecode on platforms other than
    x86.
diff --git a/src/plugins/ovirt-host-deploy/vdsm/bridge.py 
b/src/plugins/ovirt-host-deploy/vdsm/bridge.py
index d985d1b..fd3a172 100644
--- a/src/plugins/ovirt-host-deploy/vdsm/bridge.py
+++ b/src/plugins/ovirt-host-deploy/vdsm/bridge.py
@@ -32,8 +32,10 @@
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-host-deploy')
 
 
+from otopi import constants as otopicons
 from otopi import util
 from otopi import plugin
+from otopi import transaction
 
 
 from ovirt_host_deploy import constants as odeploycons
@@ -56,6 +58,44 @@
         VdsmEnv.MANAGEMENT_BRIDGE_NAME -- management bridge name.
 
     """
+
+    class NetworkSetupTransaction(transaction.TransactionElement):
+        """yum transaction element."""
+
+        def __init__(self, parent):
+            self._parent = parent
+
+        def __str__(self):
+            return _("NetworkSetup Transaction")
+
+        def prepare(self):
+            pass
+
+        def abort(self):
+            self._parent.logger.debug('Rollback network transaction')
+            rc, stdout, stderr = self._parent.execute(
+                (
+                    os.path.join(
+                        odeploycons.FileLocations.VDSM_DATA_DIR,
+                        'vdsm-restore-net-config',
+                    ),
+                ),
+                raiseOnError=False,
+            )
+            if rc != 0:
+                self._parent.logger.error(
+                    _('Cannot create rollback network transaction')
+                )
+
+        def commit(self):
+            self._parent.execute(
+                (
+                    os.path.join(
+                        odeploycons.FileLocations.VDSM_DATA_DIR,
+                        'vdsm-store-net-config',
+                    ),
+                ),
+            )
 
     """
     3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP...
@@ -717,6 +757,12 @@
         condition=lambda self: self._enabled,
     )
     def _misc(self):
+        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
+            self.NetworkSetupTransaction(
+                parent=self,
+            )
+        )
+
         if self.services.exists('libvirtd'):
             if not self.services.supportsDependency:
                 self.services.state('messagebus', True)
@@ -754,20 +800,6 @@
             ),
             timeout=self.environment[odeploycons.VdsmEnv.CONNECTION_TIMEOUT],
             retries=self.environment[odeploycons.VdsmEnv.CONNECTION_RETRIES],
-        )
-
-    @plugin.event(
-        stage=plugin.Stages.STAGE_TRANSACTION_END,
-        condition=lambda self: self._enabled,
-    )
-    def _transaction_end(self):
-        self.execute(
-            (
-                os.path.join(
-                    odeploycons.FileLocations.VDSM_DATA_DIR,
-                    'vdsm-store-net-config',
-                ),
-            ),
         )
 
     @plugin.event(


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9e6b0d076f3a16f036e149258454da395569797
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-host-deploy
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to