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 operate_vm_parall(self, vm_uuid): try: #test_lib.lib_get_root_volume_uuid(rebootvms.vms[0]) vm=test_lib.lib_get_vm_by_uuid(vm_uuid) root_volume_uuid=test_lib.lib_get_root_volume_uuid(vm) sp_option = test_util.SnapshotOption() sp_option.set_name('simple_schduler_snapshot') sp_option.set_volume_uuid(root_volume_uuid) schd = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler', 0, 1, 1) except: self.exc_info.append(sys.exc_info())
def __init__(self): self.snapshot_option = test_util.SnapshotOption() self.parent = None self.child_list = [] self.checking_point = uuid.uuid1().get_hex() #utility_vm is mostly like a VR vm, which could be connected by ssh. self.utility_vm = None self.image_option = None #all checking points files including parents checking points. self.checking_points = [] super(ZstackTestSnapshot, self).__init__()
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 test(): global vm global schd vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_name('volume for snapshot scheduler testing') volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.attach(vm) volume.detach() test_util.test_dsc('create snapshot and check') start_date = int(time.time()) sp_option = test_util.SnapshotOption() sp_option.set_name('simple_schduler_snapshot') sp_option.set_volume_uuid(volume.get_volume().uuid) schd = vol_ops.create_snapshot_scheduler( sp_option, 'simple', 'simple_create_snapshot_scheduler', start_date + 60, 120) snapshot_num = 0 for i in range(0, 3): test_util.test_logger('round %s' % (i)) test_stub.sleep_util(start_date + 60 + 120 * i - 2) test_util.test_logger( 'check volume snapshot number at %s, there should be %s' % (start_date + 60 + 120 * i - 2, snapshot_num)) new_snapshot_num = query_snapshot_number('simple_schduler_snapshot') if snapshot_num != new_snapshot_num: test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num)) snapshot_num += 1 test_stub.sleep_util(start_date + 60 + 120 * i + 60) test_util.test_logger( 'check volume snapshot number at %s, there should be %s' % (start_date + 60 + 120 * i + 65, snapshot_num + 1)) new_snapshot_num = query_snapshot_number('simple_schduler_snapshot') if snapshot_num != new_snapshot_num: test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num)) schd_ops.delete_scheduler(schd.uuid) vm.destroy() test_util.test_pass('Create Simple VM Stop Start Scheduler Success')
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=None): 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.') sp_option = test_util.SnapshotOption() sp_option.set_name(name) sp_option.set_volume_uuid(self.target_volume.get_volume().uuid) snapshot = ZstackTestSnapshot() snapshot.set_snapshot_creation_option(sp_option) snapshot.set_utility_vm(self.utility_vm) snapshot.set_target_volume(self.target_volume) snapshot.create() self.add_snapshot(snapshot) 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 test(): global vm global schd global new_account vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_name('volume for snapshot scheduler testing') volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.attach(vm) volume.detach() test_util.test_dsc('create snapshot scheduler') start_date = int(time.time()) sp_option = test_util.SnapshotOption() sp_option.set_name('simple_schduler_snapshot') sp_option.set_volume_uuid(volume.get_volume().uuid) schd = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler', start_date+60, 120) check_scheduler_state(schd, 'Enabled') snapshot_num = 0 for i in range(0, 3): test_util.test_logger('round %s' % (i)) test_stub.sleep_util(start_date + 60 + 120*i - 2) test_util.test_logger('check volume snapshot number at %s, there should be %s' % (start_date + 60 + 120*i - 2, snapshot_num)) new_snapshot_num = query_snapshot_number('simple_schduler_snapshot') if snapshot_num != new_snapshot_num: test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num)) snapshot_num += 1 test_stub.sleep_util(start_date + 60 + 120*i + 60) test_util.test_logger('check volume snapshot number at %s, there should be %s' % (start_date + 60 + 120*i + 65, snapshot_num+1)) new_snapshot_num = query_snapshot_number('simple_schduler_snapshot') if snapshot_num != new_snapshot_num: test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num)) new_account = account_operations.create_account('new_account', 'password', 'Normal') res_ops.change_recource_owner(new_account.uuid, volume.get_volume().uuid) test_util.test_dsc('check scheduler state after changing the owner of volume') check_scheduler_state(schd, 'Disabled') current_time = int(time.time()) except_start_time = start_date + 120 * (((current_time - start_date) % 120) + 1) for i in range(0, 3): test_util.test_logger('round %s' % (i)) test_stub.sleep_util(except_start_time + 60 + 120*i - 2) test_util.test_logger('check volume snapshot number at %s, there should be %s' % (except_start_time + 60 + 120*i - 2, snapshot_num)) new_snapshot_num = query_snapshot_number('simple_schduler_snapshot') if snapshot_num != new_snapshot_num: test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num)) test_stub.sleep_util(except_start_time + 60 + 120*i + 60) test_util.test_logger('check volume snapshot number at %s, there should be %s' % (except_start_time + 60 + 120*i + 65, snapshot_num+1)) new_snapshot_num = query_snapshot_number('simple_schduler_snapshot') if snapshot_num != new_snapshot_num: test_util.test_fail('there sholuld be %s snapshots' % (snapshot_num)) schd_ops.delete_scheduler(schd.uuid) vm.destroy() account_operations.delete_account(new_account.uuid) test_util.test_pass('Check Scheduler State after Changing Volume Owner Success')