From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 6477F37A4 for ; Thu, 14 Jul 2016 15:17:47 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 14 Jul 2016 06:17:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,362,1464678000"; d="scan'208";a="1006763070" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga001.fm.intel.com with ESMTP; 14 Jul 2016 06:17:46 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id u6EDHiIP003451; Thu, 14 Jul 2016 21:17:44 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id u6EDHfji001333; Thu, 14 Jul 2016 21:17:43 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id u6EDHfWR001329; Thu, 14 Jul 2016 21:17:41 +0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Thu, 14 Jul 2016 21:17:29 +0800 Message-Id: <1468502253-1276-4-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1468502253-1276-1-git-send-email-yong.liu@intel.com> References: <1468502253-1276-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH 3/7] framework virt_base: add vm status concept X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2016 13:17:48 -0000 1. Add vm status concept, default status is running. Status will be changed after hypervisor module detected status change. 2. Add new function support connect vm dut after migration done. Signed-off-by: Marvin Liu diff --git a/framework/virt_base.py b/framework/virt_base.py index efad384..5cd2854 100644 --- a/framework/virt_base.py +++ b/framework/virt_base.py @@ -43,6 +43,10 @@ from settings import CONFIG_ROOT_PATH from virt_dut import VirtDut from utils import remove_old_rsa_key +ST_NOTSTART = "NOTSTART" +ST_PAUSE = "PAUSE" +ST_RUNNING = "RUNNING" +ST_UNKNOWN = "UNKNOWN" class VirtBase(object): """ @@ -86,6 +90,9 @@ class VirtBase(object): # default call back function is None self.callback = None + # vm status is running by default, only be changed in internal module + self.vm_status = ST_RUNNING + def get_virt_type(self): """ Get the virtual type, such as KVM, XEN or LIBVIRT. @@ -224,7 +231,7 @@ class VirtBase(object): self.load_global_config() self.load_local_config(self.suite) - def start(self, load_config=True, set_target=True, cpu_topo='', bind_dev=True): + def start(self, load_config=True, set_target=True, cpu_topo=''): """ Start VM and instantiate the VM with VirtDut. """ @@ -237,8 +244,12 @@ class VirtBase(object): # start virutal machine self._start_vm() - # connect vm dut and init running environment - vm_dut = self.instantiate_vm_dut(set_target, cpu_topo) + if self.vm_status is ST_RUNNING: + # connect vm dut and init running environment + vm_dut = self.instantiate_vm_dut(set_target, cpu_topo) + else: + vm_dut = None + except Exception as vm_except: if self.handle_exception(vm_except): print dts.RED("Handled expection " + str(type(vm_except))) @@ -251,6 +262,25 @@ class VirtBase(object): return None return vm_dut + def migrated_start(self, set_target=True, cpu_topo=''): + """ + Instantiate the VM after migration done + There's no need to load param and start VM because VM has been started + """ + try: + if self.vm_status is ST_PAUSE: + # connect backup vm dut and it just inherited from host + vm_dut = self.instantiate_vm_dut(set_target, cpu_topo, bind_dev=False) + except Exception as vm_except: + if self.handle_exception(vm_except): + print dts.RED("Handled expection " + str(type(vm_except))) + else: + print dts.RED("Unhandled expection " + str(type(vm_except))) + + return None + + return vm_dut + def handle_exception(self, vm_except): # show exception back trace exc_type, exc_value, exc_traceback = sys.exc_info() @@ -357,10 +387,19 @@ class VirtBase(object): """ Stop the VM. """ - self.vm_dut.close() - self.vm_dut.logger.logger_exit() - self.vm_dut = None + # vm_dut may not init in migration case + if getattr(self, 'vm_dut', None): + if self.vm_status is ST_RUNNING: + self.vm_dut.close() + else: + # when vm is not running, not close session forcely + self.vm_dut.close(force=True) + + self.vm_dut.logger.logger_exit() + self.vm_dut = None + self._stop_vm() + self.virt_pool.free_all_resource(self.vm_name) def register_exit_callback(self, callback): -- 1.9.3