Change in vdsm[master]: virt: move recovery load into VmState

fromani at redhat.com fromani at redhat.com
Tue Jan 5 14:18:54 UTC 2016


Francesco Romani has uploaded a new change for review.

Change subject: virt: move recovery load into VmState
......................................................................

virt: move recovery load into VmState

The newly added VmState class should also handle
the load of a recovery file, which up until now
is handled using a function of recovery.py.

This duplicates some logic; this patch moves the
load code into VmState class.

Change-Id: Iea65e129c6016f5b75fc228eaf88492a0d10d39f
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/recovery.py
1 file changed, 24 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/89/51389/1

diff --git a/vdsm/virt/recovery.py b/vdsm/virt/recovery.py
index 0e0af0e..ea02494 100644
--- a/vdsm/virt/recovery.py
+++ b/vdsm/virt/recovery.py
@@ -63,6 +63,26 @@
             else:
                 self.log.debug('save after cleanup')
 
+    def load(self, cif):
+        try:
+            self._log.debug("recovery: trying with VM %s", vmid)
+            if response.is_error(cif.createVm(self._restore(),
+                                              vmRecover=True)):
+                return False
+        except:
+            self._log.exception("Error recovering VM: %s", vmid)
+            return False
+        else:
+            return True
+
+    def _restore(self):
+        with open(self._recovery_file) as src:
+            params = pickle.load(src)
+        now = time.time()
+        pt = float(params.pop('startTime', now))
+        params['elapsedTimeOffset'] = now - pt
+        return params
+
     def _dump(self, data):
         with tempfile.NamedTemporaryFile(
             dir=constants.P_VDSM_RUN,
@@ -115,7 +135,8 @@
     num_doms = len(doms)
     for idx, v in enumerate(doms):
         vm_id = v.UUIDString()
-        if _vm_from_file(cif, vm_id):
+        vm_state = VmState(vm_id)
+        if vm_state.load(cif):
             cif.log.info(
                 'recovery [1:%d/%d]: recovered domain %s from libvirt',
                 idx+1, num_doms, vm_id)
@@ -141,7 +162,8 @@
             ' Will try to recover them.', num_rec_vms)
 
     for idx, vm_id in enumerate(rec_vms):
-        if _vm_from_file(cif, vm_id):
+        vm_state = VmState(vm_id)
+        if vm_state.load(cif):
             cif.log.info(
                 'recovery [2:%d/%d]: recovered domain %s'
                 ' from data file', idx+1, num_rec_vms, vm_id)
@@ -159,23 +181,6 @@
             if vm_id not in cif.vmContainer:
                 vms.append(vm_id)
     return vms
-
-
-def _vm_from_file(cif, vmid):
-    try:
-        recovery_file = constants.P_VDSM_RUN + vmid + ".recovery"
-        params = pickle.load(file(recovery_file))
-        now = time.time()
-        pt = float(params.pop('startTime', now))
-        params['elapsedTimeOffset'] = now - pt
-        cif.log.debug("recovery: trying with domain %s", vmid)
-        if response.is_error(cif.createVm(params, vmRecover=True)):
-            return None
-    except:
-        cif.log.debug("Error recovering VM", exc_info=True)
-        return None
-    else:
-        return recovery_file
 
 
 def clean_vm_files(cif):


-- 
To view, visit https://gerrit.ovirt.org/51389
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea65e129c6016f5b75fc228eaf88492a0d10d39f
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