Change in vdsm[master]: virt: migration: use contextmanager for monitor

fromani at redhat.com fromani at redhat.com
Fri Mar 21 11:06:16 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: virt: migration: use contextmanager for monitor
......................................................................

virt: migration: use contextmanager for monitor

This patch factors the MigrationMonitorThread
control in a context manager to make code
clearer and less cluttered.

Change-Id: Ie7fcd0bedf4f30cc0bcab03339322df1fc5434e8
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/migration.py
1 file changed, 13 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/25978/1

diff --git a/vdsm/migration.py b/vdsm/migration.py
index 8c33f1e..73d29e8 100644
--- a/vdsm/migration.py
+++ b/vdsm/migration.py
@@ -18,6 +18,7 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+from contextlib import contextmanager
 import pickle
 import threading
 import time
@@ -255,6 +256,17 @@
             self._recover(str(e))
             self.log.error("Failed to migrate", exc_info=True)
 
+    @contextmanager
+    def migrationMonitor(self, startTime):
+        self._monitorThread = MigrationMonitorThread(self._vm,
+                                                     startTime,
+                                                     int(self._downtime))
+        self._monitorThread.start()
+        try:
+            yield
+        finally:
+            self._monitorThread.stop()
+
     def _startUnderlyingMigration(self, startTime):
         if self._mode == 'file':
             hooks.before_vm_hibernate(self._vm._dom.XMLDesc(0), self._vm.conf)
@@ -293,12 +305,7 @@
             self._vm.log.debug('starting migration to %s '
                                'with miguri %s', duri, muri)
 
-            self._monitorThread = MigrationMonitorThread(self._vm,
-                                                         startTime,
-                                                         int(self._downtime))
-            self._monitorThread.start()
-
-            try:
+            with self.migrationMonitor(startTime):
                 if ('qxl' in self._vm.conf['display'] and
                         self._vm.conf.get('clientIp')):
                     SPICE_MIGRATION_HANDOVER_TIME = 120
@@ -322,9 +329,6 @@
                         None, maxBandwidth)
                 else:
                     self._raiseAbortError()
-
-            finally:
-                self._monitorThread.stop()
 
     def stop(self):
         # if its locks we are before the migrateToURI2()


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7fcd0bedf4f30cc0bcab03339322df1fc5434e8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list