def __init__(self, test, params, env): self.vm = None self.test = test self.env = env self.params = params self.name = params.get('main_vm') self.os_version = params.get("os_version") self.os_type = params.get('os_type', 'linux') self.target = params.get('target') self.username = params.get('vm_user', 'root') self.password = params.get('vm_pwd') self.nic_index = params.get('nic_index', 0) self.export_name = params.get('export_name') self.delete_vm = 'yes' == params.get('vm_cleanup', 'yes') self.virsh_session_id = params.get("virsh_session_id") self.windows_root = params.get("windows_root", r"C:\WINDOWS") self.output_method = params.get("output_method") # Need create session after create the instance self.session = None if self.name is None: logging.error("vm name not exist") # libvirt is a default target if self.target == "libvirt" or self.target is None: self.vm = lvirt.VM(self.name, self.params, self.test.bindir, self.env.get("address_cache")) self.pv = libvirt.PoolVolumeTest(test, params) elif self.target == "ovirt": self.vm = ovirt.VMManager(self.name, self.params, self.test.bindir, self.env.get("address_cache")) else: raise ValueError("Doesn't support %s target now" % self.target)
def import_vm_to_ovirt(params, address_cache, timeout=600): """ Import VM from export domain to oVirt Data Center """ vm_name = params.get('main_vm') os_type = params.get('os_type') export_name = params.get('export_name') storage_name = params.get('storage_name') cluster_name = params.get('cluster_name') output_method = params.get('output_method') # Check oVirt status dc = ovirt.DataCenterManager(params) logging.info("Current data centers list: %s", dc.list()) cm = ovirt.ClusterManager(params) logging.info("Current cluster list: %s", cm.list()) hm = ovirt.HostManager(params) logging.info("Current host list: %s", hm.list()) sdm = ovirt.StorageDomainManager(params) logging.info("Current storage domain list: %s", sdm.list()) vm = ovirt.VMManager(vm_name, params, address_cache=address_cache) logging.info("Current VM list: %s", vm.list()) if vm_name in vm.list() and output_method != 'rhv_upload': logging.error("%s already exist", vm_name) return False wait_for_up = True if os_type == 'windows': wait_for_up = False # If output_method is None or "" or is not 'rhv_upload', treat it as # old way. if output_method != 'rhv_upload': try: # Import VM vm.import_from_export_domain(export_name, storage_name, cluster_name, timeout=timeout) logging.info("The latest VM list: %s", vm.list()) except Exception as e: # Try to delete the vm from export domain vm.delete_from_export_domain(export_name) logging.error("Import %s failed: %s", vm.name, e) return False try: # Start VM vm.start(wait_for_up=wait_for_up) except Exception as e: logging.error("Start %s failed: %s", vm.name, e) return False return True
def run(test, params, env): """ Test ovirt class """ args_dict = get_args_dict(params) logging.debug("arguments dictionary: %s" % args_dict) vm_name = params.get('vm_name') export_name = params.get('export_name') storage_name = params.get('storage_name') cluster_name = params.get('cluster_name') address_cache = env.get('address_cache') # Run test case vm = ovirt.VMManager(params, address_cache) dc = ovirt.DataCenterManager(params) cls = ovirt.ClusterManager(params) ht = ovirt.HostManager(params) sd = ovirt.StorageDomainManager(params) logging.info("Current data centers list: %s" % dc.list()) logging.info("Current cluster list: %s" % cls.list()) logging.info("Current host list: %s" % ht.list()) logging.info("Current storage domain list: %s" % sd.list()) logging.info("Current vm list: %s" % vm.list()) vm.import_from_export_domain(export_name, storage_name, cluster_name) logging.info("Current vm list: %s" % vm.list()) vm.start() if vm.is_alive(): logging.info("The %s is alive" % vm_name) vm.suspend() vm.resume() vm.shutdown() if vm.is_dead(): logging.info("The %s is dead" % vm_name)