def test_save(self): with self.setup_env() as (testvm, tmpdir): rec = recovery.File(testvm.id) rec.save(testvm) with open(os.path.join(tmpdir, rec.name), 'rb') as f: self.assertTrue(pickle.load(f))
def _iterPersistedConnectionInfo(self): for path in glob.iglob(os.path.join(self._persistDir, "*.con")): alias = splitext(basename(path))[0] with open(path, "r") as f: conInfo = pickle.load(f) # Yield out of scope so the file is closed before giving the flow # back to calling method yield alias, conInfo
def _recoverVm(self, vmid): try: recoveryFile = constants.P_VDSM_RUN + vmid + ".recovery" params = pickle.load(file(recoveryFile)) now = time.time() pt = float(params.pop('startTime', now)) params['elapsedTimeOffset'] = now - pt self.log.debug("Trying to recover " + params['vmId']) if not self.createVm(params, vmRecover=True)['status']['code']: return recoveryFile except: self.log.debug("Error recovering VM", exc_info=True) return None
def load(self, cif): self._log.debug("recovery: trying with VM %s", self._vmid) try: with open(self._path) as src: params = pickle.load(src) self._set_elapsed_time(params) res = cif.createVm(params, vmRecover=True) except Exception: self._log.exception("Error recovering VM: %s", self._vmid) return False else: if response.is_error(res): return False return True
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