def create_sp(volume_uuid): try: sp_option = test_util.SnapshotOption() sp_option.set_name(sp_name) sp_option.set_volume_uuid(volume_uuid) sp_option.set_session_uuid(session_uuid) sp = vol_ops.create_snapshot(sp_option) except: exc_info.append(sys.exc_info())
def migrate_volume(index): target_host = test_lib.lib_find_random_host(vms[index].get_vm()) vms[index].stop() sp_option = test_util.SnapshotOption() sp_option.set_volume_uuid(vms[index].get_vm().allVolumes[0].uuid) for i in range(0, 50): sp_option.set_name("snapshot_for_migrate_progress_%s" % (i)) sp = vol_ops.create_snapshot(sp_option) vol_ops.migrate_volume(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid) threads_result[index] = "Done"
def create(self): ''' Not recommended to be called by test case directly. Test case needs to call ZstackVolumeSnapshot.create_snapshot() ''' super(ZstackTestSnapshot, self).create() if not self.target_volume: test_util.test_fail('Can not create snapshot, before set target_volume') if not self.utility_vm: test_util.test_fail('Can not create snapshot, before set utility_vm, which will be used for doing snapshot checking. utiltiy_vm is mostly like a VR vm.') #self._live_snapshot_cap_check() self.add_checking_point() self.snapshot = vol_ops.create_snapshot(self.snapshot_option) self.target_volume.update_volume()
def migrate_volume(index): target_host = test_lib.lib_find_random_host(vms[index].get_vm()) vms[index].stop() sp_option = test_util.SnapshotOption() sp_option.set_volume_uuid(vms[index].get_vm().allVolumes[0].uuid) for i in range(0, 50): sp_option.set_name("snapshot_for_migrate_progress_%s" % (i)) sp = vol_ops.create_snapshot(sp_option) migrate_jobs[index] = str(uuid.uuid4()).replace('-', '') print 'shuang %s' % (migrate_jobs[index]) threads_result[index] = "Start" vol_ops.migrate_volume_apiid(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid, migrate_jobs[index]) threads_result[index] = "Done"
def create_snapshot(self, name): self.Maxdepth = self._config_sp_depth() sp_option = test_util.SnapshotOption() sp_option.set_name(name) sp_option.set_volume_uuid(self.target_volume.get_volume().uuid) snapshot = ZstackSnapshot() snapshot.set_utility_vm(self.utility_vm) snapshot.set_name(name) snapshot.set_target_volume(self.target_volume) snapshot.set_snapshot_tree(self) super(ZstackSnapshot, snapshot).create() # known issue if ps_type is ceph, every snapshot is a head node ps_uuid = self.target_volume.get_volume().primaryStorageUuid cond = res_ops.gen_query_conditions('uuid', '=', ps_uuid) ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0] # if it is the first snapshot or it is in ceph ps if ps.type in ['Ceph']: self.Maxdepth = 1 if self.current_snapshot: current_depth = self.current_snapshot.get_depth() next_depth = 1 if current_depth + 1 > self.Maxdepth else current_depth + 1 else: next_depth = 1 if next_depth == 1 or self.Newhead: self.heads.append(snapshot) else: self.current_snapshot.add_child(snapshot) snapshot.set_parent(self.current_snapshot) if os.environ.get('ZSTACK_SIMULATOR') != "yes": # if self.current_snapshot: # snapshot.set_checking_points(self.current_snapshot.get_checking_points()) snapshot.set_checking_points(copy.deepcopy(self._get_checking_points())) snapshot.set_checking_point() self.checking_points.append(snapshot.get_checking_point()) snapshot.snapshot = vol_ops.create_snapshot(sp_option) self.snapshot_list.append(snapshot) self.set_current_snapshot(snapshot) snapshot.set_depth(next_depth) self.Newhead = False return snapshot
def running_vm_operations(vm,bss): numa = config_ops.get_global_config_value('vm', 'numa') live_migration = config_ops.get_global_config_value('localStoragePrimaryStorage','liveMigrationWithStorage.allow') ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_uuid = vm.get_vm().uuid #change vm's instanceoffering if numa == 'false': try: vm_ops.update_vm(vm_uuic,2,2048*1024*1024) test_util.test_fail('Test Fail.Cannot change instanceoffering of running vm when NUMA is false') except: config_ops.change_global_config('vm','numa','true') vm_ops.reboot_vm(vm_uuid) vm_ops.update_vm(vm_uuid,2,2048*1024*1024) #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop ha_ops.set_vm_instance_ha_level(vm_uuid,'NeverStop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm_ops.reboot_vm(vm_uuid) vm_ops.suspend_vm(vm_uuid) vm_ops.resume_vm(vm_uuid) vm_ops.stop_vm(vm_uuid,'cold') vm_ops.start_vm(vm_uuid) #clone vms vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart') #migrate candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) migrate_host_uuids = [] if candidate_hosts == None: pass else: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': if live_migration == 'false': try: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_fail('Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' ) except: config_ops.change_global_config('localStoragePrimaryStorage','liveMigrationWithStorage.allow','true') else: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_logger('migrate vm success') else: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #change vm's password(qga) try: vm_ops.change_vm_password(vm_uuid,'root','testpassword') test_util.test_fail('Test Fail.Cannot change vm password when qga is disabled.') except: vm_ops.set_vm_qga_enable(vm_uuid) vm_ops.change_vm_password(vm_uuid,'root','testpassword') vm_ops.set_vm_qga_disable(vm_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid) sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vm_ops.stop_vm(vm_uuid) vol_ops.use_snapshot(sp.uuid) vm_ops.start_vm(vm_uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm,bss,'running') vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm.destroy() vm.expunge()
def stopped_vm_operations(vm,bss): vm_uuid = vm.get_vm().uuid ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_ops.stop_vm(vm_uuid) #Change vm's instanceoffering vm_ops.update_vm(vm_uuid,2,2048*1024*1024) #Change vm's status ha_ops.set_vm_instance_ha_level(vm_uuid,'neverstop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) if ps.type != 'LocalStorage': target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid if target_host_uuid != None: vm_ops.start_vm_with_target_host(vm_uuid,target_host_uuid) #vm_ops.stop_vm(vm_uuid) vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.reinit_vm(vm_uuid) #clone vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart') #migrate vm_ops.start_vm(vm_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) vm_ops.stop_vm(vm_uuid) migrate_host_uuids = [] if candidate_hosts != None: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #resize root volume vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(vol_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_util.test_logger('resize vm success') #storage migrate #change vm image image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid) image_uuids = [] for image in image_list.inventories: image_uuids.append(image.uuid) vm_ops.change_vm_image(vm_uuid,image_uuids[0]) vm.update() #update vm nic mac nic_uuid = vm.get_vm().vmNics[0].uuid mac = 'fa:4c:ee:9a:76:00' vm_ops.update_vm_nic_mac(nic_uuid,mac) #set/del static ip l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid) vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid, vm.get_vm().vmNics[0].ip) vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vol_ops.use_snapshot(sp.uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm,bss,'stopped') vm.destroy() vm.expunge()
def running_vm_operations(vm, bss): numa = config_ops.get_global_config_value('vm', 'numa') live_migration = config_ops.get_global_config_value( 'localStoragePrimaryStorage', 'liveMigrationWithStorage.allow') ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_uuid = vm.get_vm().uuid #change vm's instanceoffering if numa == 'false': try: vm_ops.update_vm(vm_uuic, 2, 2048 * 1024 * 1024) test_util.test_fail( 'Test Fail.Cannot change instanceoffering of running vm when NUMA is false' ) except: config_ops.change_global_config('vm', 'numa', 'true') vm_ops.reboot_vm(vm_uuid) vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024) #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm_ops.reboot_vm(vm_uuid) vm_ops.suspend_vm(vm_uuid) vm_ops.resume_vm(vm_uuid) vm_ops.stop_vm(vm_uuid, 'cold') vm_ops.start_vm(vm_uuid) #clone vms vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart') #migrate candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) migrate_host_uuids = [] if candidate_hosts == None: pass else: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': if live_migration == 'false': try: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_fail( 'Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' ) except: config_ops.change_global_config( 'localStoragePrimaryStorage', 'liveMigrationWithStorage.allow', 'true') else: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') else: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #change vm's password(qga) try: vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword') test_util.test_fail( 'Test Fail.Cannot change vm password when qga is disabled.') except: vm_ops.set_vm_qga_enable(vm_uuid) vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword') vm_ops.set_vm_qga_disable(vm_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid) sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vm_ops.stop_vm(vm_uuid) vol_ops.use_snapshot(sp.uuid) vm_ops.start_vm(vm_uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm, bss, 'running') vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm.destroy() vm.expunge()
def stopped_vm_operations(vm, bss): vm_uuid = vm.get_vm().uuid ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_ops.stop_vm(vm_uuid) #Change vm's instanceoffering vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024) #Change vm's status ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) if ps.type != 'LocalStorage': target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid if target_host_uuid != None: vm_ops.start_vm_with_target_host(vm_uuid, target_host_uuid) #vm_ops.stop_vm(vm_uuid) vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.reinit_vm(vm_uuid) #clone vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart') #migrate vm_ops.start_vm(vm_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) vm_ops.stop_vm(vm_uuid) migrate_host_uuids = [] if candidate_hosts != None: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #resize root volume vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024 * 1024 * 1024 * 5 vol_ops.resize_volume(vol_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_util.test_logger('resize vm success') #storage migrate #change vm image image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid) image_uuids = [] for image in image_list.inventories: image_uuids.append(image.uuid) vm_ops.change_vm_image(vm_uuid, image_uuids[0]) vm.update() #update vm nic mac nic_uuid = vm.get_vm().vmNics[0].uuid mac = 'fa:4c:ee:9a:76:00' vm_ops.update_vm_nic_mac(nic_uuid, mac) #set/del static ip l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid) vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid, vm.get_vm().vmNics[0].ip) vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vol_ops.use_snapshot(sp.uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm, bss, 'stopped') vm.destroy() vm.expunge()