Antoni Segura Puimedon has uploaded a new change for review.

Change subject: net_func_tests: Rollback only when an error happens
......................................................................

net_func_tests: Rollback only when an error happens

Up until now, net_func_tests used RollbackContext that always
performs all the rolling back operations on context exit. This patch
adds a flag to RollbackContext that if explicitely set to True, will
only perform the rollback operations in case the context was left
due to an exception.

Change-Id: Iaeb9bf19f4bf63d3705cfdda92aa6ec7513a8b98
Signed-off-by: Antoni S. Puimedon <[email protected]>
---
M lib/vdsm/utils.py
M tests/functional/networkTests.py
2 files changed, 6 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/17/29817/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index 76c2a79..7b06ea2 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -1057,8 +1057,9 @@
 
     More examples see tests/utilsTests.py
     '''
-    def __init__(self, *args):
+    def __init__(self, on_exception_only=False):
         self._finally = []
+        self._on_exception_only = on_exception_only
 
     def __enter__(self):
         return self
@@ -1069,6 +1070,9 @@
         exception), python re-raises the original exception once this
         function is finished.
         """
+        if self._on_exception_only and exc_type is None and exc_value is None:
+            return
+
         undoExcInfo = None
         for undo, args, kwargs in self._finally:
             try:
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index b59ef01..2a58970 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -191,7 +191,7 @@
 
         @wraps(func)
         def wrapper(*args, **kwargs):
-            with RollbackContext() as rollback:
+            with RollbackContext(on_exception_only=True) as rollback:
                 rollback.prependDefer(args[0].vdsm_net.restoreNetConfig)
                 func(*args, **kwargs)
         return wrapper


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaeb9bf19f4bf63d3705cfdda92aa6ec7513a8b98
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to