def test(): global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(volume_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_stub.migrate_vm_to_random_host(vm) vm.check() target_host = test_lib.lib_find_random_host(vm.get_vm()) vol_ops.migrate_volume(volume_uuid, target_host.uuid) 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) vm.destroy() test_util.test_pass('Resize VM and Migrate Test Success')
def test(): global test_obj_dict #volume_creation_option = test_util.VolumeOption() #test_util.test_dsc('Create volume and check') #disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) #volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume = test_stub.create_volume(volume_creation_option) bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") volume_creation_option = test_util.VolumeOption() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume_uuid = volume1.volume.uuid test_util.test_dsc('Create vm and check') vm = test_stub.create_vr_vm('migrate_volume_vm', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.vm.uuid volume1.attach(vm) volume1.detach(vm_uuid) vm.stop() image_obj = volume1.create_template([bss[0].uuid]) vm.start() host_uuid = vm.vm.hostUuid ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) volume2 = image_obj.create_data_volume(ps.uuid, 'volumeName', host_uuid) test_obj_dict.add_volume(volume2) volume2.check() volume_uuid = volume2.volume.uuid ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') snapshots = test_obj_dict.get_volume_snapshot(volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() snapshots.create_snapshot('create_snapshot2') snapshots.check() target_host = test_lib.lib_find_random_host_by_volume_uuid(volume_uuid) target_host_uuid = target_host.uuid vol_ops.migrate_volume(volume_uuid, target_host_uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Cold migrate Data Volume from Template with Snapshot Test Success')
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] global agent_url global vm imagestore = test_lib.lib_get_image_store_backup_storage() if imagestore == None: test_util.test_skip('Required imagestore to test') image_uuid = test_stub.get_image_by_bs(imagestore.uuid) cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage') local_pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(local_pss) == 0: test_util.test_skip('Required ceph ps to test') ps_uuid = local_pss[0].uuid vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid) vm.stop() target_host = test_lib.lib_find_random_host(vm.vm) agent_url = flavor['agent_url'] agent_action = flavor['agent_action'] if agent_action == 1: agent_time = (24*60*60-60)*1000 elif agent_action == 2: agent_time = 360 * 1000 rsp = dep_ops.json_post("http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({"key": vm.get_vm().rootVolumeUuid, "value": '{"%s":%s}' % (agent_url, agent_action)})) start = time.time() vol_ops.migrate_volume(vm.get_vm().rootVolumeUuid, target_host.uuid) end = time.time() if end - start < agent_time / 2 / 1000: test_util.test_fail('execution time too short %s' % (end - start))
def test(): global test_obj_dict pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE) if pss[0].type != "LocalStorage": test_util.test_skip( "this test is designed to run on localstorage, skip on other ps type." ) vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm) vm.check() vm_nic_uuid = vm.vm.vmNics[0].uuid net_ops.detach_l3(vm_nic_uuid) vm.stop() vm.check() #test_stub.migrate_vm_to_random_host(vm) target_host = test_lib.lib_find_random_host(vm.vm) vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) l3_name = os.environ.get('l3VlanNetwork3') l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid net_ops.attach_l3(l3_uuid, vm.vm.uuid) vm.start() vm.check() test_util.test_pass('test detach l3, migrate and attaching passed.')
def test(): global test_obj_dict volume_creation_option = test_util.VolumeOption() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) 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.check() volume_uuid = volume.volume.uuid test_util.test_dsc('Create vm and check') vm = test_stub.create_vr_vm('migrate_volume_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.vm.uuid ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') test_util.test_dsc('Attach data volume to vm and check') volume.attach(vm) target_host = test_lib.lib_find_random_host_by_volume_uuid(volume_uuid) target_host_uuid = target_host.uuid test_util.test_dsc('Detach data volume from vm and check') volume.detach(vm_uuid) vol_ops.migrate_volume(volume_uuid, target_host_uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Cold migrate Data Volume Test Success')
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] global agent_url global vm imagestore = test_lib.lib_get_image_store_backup_storage() if imagestore == None: test_util.test_skip('Required imagestore to test') image_uuid = test_stub.get_image_by_bs(imagestore.uuid) cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage') local_pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(local_pss) == 0: test_util.test_skip('Required ceph ps to test') ps_uuid = local_pss[0].uuid vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid) vm.stop() target_host = test_lib.lib_find_random_host(vm.vm) agent_url = flavor['agent_url'] agent_action = flavor['agent_action'] if agent_action == 1: agent_time = (24 * 60 * 60 - 60) * 1000 elif agent_action == 2: agent_time = 360 * 1000 rsp = dep_ops.json_post( "http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({ "key": vm.get_vm().rootVolumeUuid, "value": '{"%s":%s}' % (agent_url, agent_action) })) start = time.time() vol_ops.migrate_volume(vm.get_vm().rootVolumeUuid, target_host.uuid) end = time.time() if end - start < agent_time / 2 / 1000: test_util.test_fail('execution time too short %s' % (end - start))
def test(): global vm, kvm_host ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == inventory.LOCAL_STORAGE_TYPE: break else: test_util.test_skip('Skip test on non-localstoreate PS') #ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0] #if ps.type != inventory.LOCAL_STORAGE_TYPE: # test_util.test_skip('Skip test on non-localstorage') #if "test-config-local-ps.xml" != os.path.basename(os.environ.get('WOODPECKER_TEST_CONFIG_FILE')).strip(): # test_util.test_skip('Skip test on non-localstoreage') #query all hosts and change password conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') if res_ops.query_resource(res_ops.HOST, conditions): kvm_host = res_ops.query_resource(res_ops.HOST, conditions) for i in kvm_host: host_ops.update_kvm_host(i.uuid, 'password', 'password*()') cmd = 'echo "password*()"| passwd --stdin root' test_lib.lib_execute_ssh_cmd(i.managementIp, "root", "password", cmd) host_ops.reconnect_host(i.uuid) else: test_util.test_skip("There is no host. Skip test") test_util.test_dsc('Test KVM Host Infomation: password') #create vm and stop and migrate vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() vm.destroy() vm.expunge() ################################# recover KVM HOST Password ################################# conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') if res_ops.query_resource(res_ops.HOST, conditions): kvm_host = res_ops.query_resource(res_ops.HOST, conditions) for i in kvm_host: host_ops.update_kvm_host(i.uuid, 'password', 'password') cmd = 'echo "password"| passwd --stdin root' test_lib.lib_execute_ssh_cmd(i.managementIp, "root", "password*()", cmd) host_ops.reconnect_host(i.uuid) else: test_util.test_skip("There is no host. Skip test") test_util.test_dsc('Test KVM Host Infomation: password') test_util.test_pass( 'Migrate Stopped VM with special_password Test Success')
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) mn = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0] cmd = "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % (os.environ.get('zstackInstallPath')) if os.system("ip r | grep %s" % (mn.hostName)) == 0: os.system(cmd) else: for host in test_lib.lib_get_all_hosts_from_plan(): test_util.test_logger("host.managementIp_: %s" %(host.managementIp_)) test_util.test_logger("mn.hostName: %s" %(mn.hostName)) test_util.test_logger("anotherIp: %s" %(test_stub.get_another_ip_of_host(host.managementIp_, host.username_, host.password_))) if host.managementIp_ == mn.hostName or test_stub.get_another_ip_of_host(host.managementIp_, host.username_, host.password_) == mn.hostName: out = test_lib.lib_execute_ssh_cmd(host.managementIp_, host.username_, host.password_, cmd, timeout=30) img_option.set_url('http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (mn.hostName)) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def test(): global vm, kvm_host ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == inventory.LOCAL_STORAGE_TYPE: break else: test_util.test_skip('Skip test on non-localstoreate PS') #ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0] #if ps.type != inventory.LOCAL_STORAGE_TYPE: # test_util.test_skip('Skip test on non-localstorage') #if "test-config-local-ps.xml" != os.path.basename(os.environ.get('WOODPECKER_TEST_CONFIG_FILE')).strip(): # test_util.test_skip('Skip test on non-localstoreage') #query all hosts and change password conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') if res_ops.query_resource(res_ops.HOST, conditions): kvm_host = res_ops.query_resource(res_ops.HOST, conditions) for i in kvm_host: host_ops.update_kvm_host(i.uuid, 'password', 'password*()') cmd = 'echo "password*()"| passwd --stdin root' test_lib.lib_execute_ssh_cmd(i.managementIp,"root","password",cmd) host_ops.reconnect_host(i.uuid) else: test_util.test_skip("There is no host. Skip test") test_util.test_dsc('Test KVM Host Infomation: password') #create vm and stop and migrate vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() vm.destroy() vm.expunge() ################################# recover KVM HOST Password ################################# conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') if res_ops.query_resource(res_ops.HOST, conditions): kvm_host = res_ops.query_resource(res_ops.HOST, conditions) for i in kvm_host: host_ops.update_kvm_host(i.uuid, 'password', 'password') cmd = 'echo "password"| passwd --stdin root' test_lib.lib_execute_ssh_cmd(i.managementIp,"root","password*()",cmd) host_ops.reconnect_host(i.uuid) else: test_util.test_skip("There is no host. Skip test") test_util.test_dsc('Test KVM Host Infomation: password') test_util.test_pass('Migrate Stopped VM with special_password Test 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) vol_ops.migrate_volume(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid) threads_result[index] = "Done"
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system( "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def migrate(vm_obj): ps = test_lib.lib_get_primary_storage_by_vm(vm_obj.get_vm()) if vm_obj.vm.state == "Running" and ps.type in [inventory.CEPH_PRIMARY_STORAGE_TYPE, 'SharedMountPoint', inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedBlock', inventory.LOCAL_STORAGE_TYPE]: target_host = test_lib.lib_find_random_host(vm_obj.vm) vm_obj.migrate(target_host.uuid) elif ps.type in [inventory.LOCAL_STORAGE_TYPE]: vm_obj.check() target_host = test_lib.lib_find_random_host(vm_obj.vm) vol_ops.migrate_volume(vm_obj.get_vm().allVolumes[0].uuid, target_host.uuid) vm_obj.start() test_lib.lib_wait_target_up(vm_obj.get_vm().vmNics[0].ip, 22, 300) else: test_util.test_fail("FOUND NEW STORAGTE TYPE. FAILED")
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success')
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system("echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def migrate(vm_obj): ps = test_lib.lib_get_primary_storage_by_vm(vm_obj.get_vm()) if vm_obj.vm.state == "Running" and ps.type in [ inventory.CEPH_PRIMARY_STORAGE_TYPE, 'SharedMountPoint', inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedBlock', inventory.LOCAL_STORAGE_TYPE ]: target_host = test_lib.lib_find_random_host(vm_obj.vm) vm_obj.migrate(target_host.uuid) elif ps.type in [inventory.LOCAL_STORAGE_TYPE]: vm_obj.check() target_host = test_lib.lib_find_random_host(vm_obj.vm) vol_ops.migrate_volume(vm_obj.get_vm().allVolumes[0].uuid, target_host.uuid) vm_obj.start() test_lib.lib_wait_target_up(vm_obj.get_vm().vmNics[0].ip, 22, 300) else: test_util.test_fail("FOUND NEW STORAGTE TYPE. FAILED")
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success')
def test(): global test_obj_dict test_util.test_dsc('Create vm and check') vm = test_stub.create_vr_vm('migrate_volume_vm', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.vm.uuid root_vol_uuid = vm.vm.rootVolumeUuid ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') snapshots = test_obj_dict.get_volume_snapshot(root_vol_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('snapshot_for_volume') snapshots.check() snapshot = snapshots.get_current_snapshot() snapshot_uuid = snapshot.snapshot.uuid volume = snapshot.create_data_volume() test_obj_dict.add_volume(volume) volume.check() volume_uuid = volume.volume.uuid snapshots = test_obj_dict.get_volume_snapshot(volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() snapshots.create_snapshot('create_snapshot2') snapshots.check() target_host = test_lib.lib_find_random_host_by_volume_uuid(volume_uuid) target_host_uuid = target_host.uuid vol_ops.migrate_volume(volume_uuid, target_host_uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass( 'Cold migrate Data Volume from Snapshot with Snapshot Test Success')
def test(): global test_obj_dict volume_creation_option = test_util.VolumeOption() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) 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.check() volume_uuid = volume.volume.uuid vol_size = volume.volume.size image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) vm.check() test_obj_dict.add_vm(vm) volume.attach(vm) vm.stop() vm.check() set_size = 1024 * 1024 * 1024 * 5 vol_ops.resize_data_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size if set_size != vol_size_after: test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after) volume.detach() vm.update() target_host = test_lib.lib_find_random_host(vm.get_vm()) vol_ops.migrate_volume(volume_uuid, target_host.uuid) cond = res_ops.gen_query_conditions('uuid', '=', volume_uuid) data_volume = res_ops.query_resource(res_ops.VOLUME, cond) vol_size_after = data_volume[0].size if set_size != vol_size_after: test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Resize Data Volume Test Success')
def test(): global test_obj_dict test_util.test_dsc('Create vm and check') vm = test_stub.create_vr_vm('migrate_volume_vm', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.vm.uuid root_vol_uuid = vm.vm.rootVolumeUuid ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') snapshots = test_obj_dict.get_volume_snapshot(root_vol_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('snapshot_for_volume') snapshots.check() snapshot = snapshots.get_current_snapshot() snapshot_uuid = snapshot.snapshot.uuid volume = snapshot.create_data_volume() test_obj_dict.add_volume(volume) volume.check() volume_uuid = volume.volume.uuid snapshots = test_obj_dict.get_volume_snapshot(volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() snapshots.create_snapshot('create_snapshot2') snapshots.check() target_host = test_lib.lib_find_random_host_by_volume_uuid(volume_uuid) target_host_uuid = target_host.uuid vol_ops.migrate_volume(volume_uuid, target_host_uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Cold migrate Data Volume from Snapshot with Snapshot Test Success')
def test(): global test_obj_dict pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE) if pss[0].type != "LocalStorage": test_util.test_skip("this test is designed to run on localstorage, skip on other ps type.") l3_name = os.environ.get('l3VlanNetwork3') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l2_net_uuid = test_lib.lib_get_l3_by_name(l3_name).l2NetworkUuid l2_net_type = res_ops.get_resource(res_ops.L2_NETWORK, uuid=l2_net_uuid)[0].type test_util.test_logger("l2_network.type@@:%s" %(l2_net_type)) if l2_net_type == "VxlanNetwork": test_util.test_skip("Vxlan network not support detach l2 network, therefore, skip the test") vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm) vm.check() vm_nic_uuid = vm.vm.vmNics[0].uuid net_ops.detach_l3(vm_nic_uuid) vm.stop() vm.check() #test_stub.migrate_vm_to_random_host(vm) target_host = test_lib.lib_find_random_host(vm.vm) vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) l3_name = os.environ.get('l3VlanNetwork3') l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid net_ops.attach_l3(l3_uuid, vm.vm.uuid) vm.start() vm.check() test_util.test_pass('test detach l3, migrate and attaching passed.')
def test(): global test_obj_dict volume_creation_option = test_util.VolumeOption() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) 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.check() volume_uuid = volume.volume.uuid vol_size = volume.volume.size image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) vm.check() test_obj_dict.add_vm(vm) volume.attach(vm) vm.stop() vm.check() set_size = 1024*1024*1024*5 vol_ops.resize_data_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size if set_size != vol_size_after: test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after) volume.detach() vm.update() target_host = test_lib.lib_find_random_host(vm.get_vm()) vol_ops.migrate_volume(volume_uuid, target_host.uuid) cond = res_ops.gen_query_conditions('uuid', '=', volume_uuid) data_volume = res_ops.query_resource(res_ops.VOLUME, cond) vol_size_after = data_volume[0].size if set_size != vol_size_after: test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Resize Data Volume Test Success')
def test(): ps_env = test_stub.PSEnvChecker() local_nfs_env = ps_env.is_local_nfs_env local_smp_env = ps_env.is_local_smp_env local_ps, another_ps = ps_env.get_two_ps() vm = test_stub.create_multi_vms(name_prefix='test-', count=1)[0] test_obj_dict.add_vm(vm) volume_in_local = [] if not local_nfs_env: volume_in_local = test_stub.create_multi_volumes(count=VOLUME_NUMBER, ps=local_ps, host_uuid=test_lib.lib_get_vm_host(vm.get_vm()).uuid) volume_in_another = test_stub.create_multi_volumes(count=VOLUME_NUMBER, ps=another_ps, host_uuid=None if local_nfs_env else test_lib.lib_get_vm_host(vm.get_vm()).uuid) for volume in volume_in_local + volume_in_another: test_obj_dict.add_volume(volume) for volume in volume_in_local + volume_in_another: volume.attach(vm) volume.check() vm.check() for volume in volume_in_local + volume_in_another: volume.detach() volume.check() vm.check() target_host = test_lib.lib_find_random_host(vm.get_vm()) vm.stop() vm.check() vol_ops.migrate_volume(test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid) for volume in volume_in_local: vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) if not (local_nfs_env or local_smp_env): for volume in volume_in_another: vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) for volume in volume_in_local + volume_in_another: volume.attach(vm) volume.check() vm.start() vm.check() for volume in volume_in_local + volume_in_another: assert volume.get_volume().vmInstanceUuid == vm.get_vm().uuid test_util.test_pass('Multi PrimaryStorage Test Pass')
def test(): global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) vm.check() vm.stop() vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(volume_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) vm.start() vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() vm.stop() vm.check() target_host = test_lib.lib_find_random_host(vm.get_vm()) vol_ops.migrate_volume(volume_uuid, target_host.uuid) vm.start() 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) vm.destroy() test_util.test_pass('Resize VM and Migrate Test Success')
def test(): ps_env = test_stub.PSEnvChecker() local_nfs_env = ps_env.is_local_nfs_env local_smp_env = ps_env.is_local_smp_env local_ps, another_ps = ps_env.get_two_ps() vm = test_stub.create_multi_vms(name_prefix='test-', count=1)[0] test_obj_dict.add_vm(vm) volume_in_local = [] if not local_nfs_env: volume_in_local = test_stub.create_multi_volumes( count=VOLUME_NUMBER, ps=local_ps, host_uuid=test_lib.lib_get_vm_host(vm.get_vm()).uuid) volume_in_another = test_stub.create_multi_volumes( count=VOLUME_NUMBER, ps=another_ps, host_uuid=None if local_nfs_env else test_lib.lib_get_vm_host(vm.get_vm()).uuid) for volume in volume_in_local + volume_in_another: test_obj_dict.add_volume(volume) for volume in volume_in_local + volume_in_another: volume.attach(vm) volume.check() vm.check() for volume in volume_in_local + volume_in_another: volume.detach() volume.check() vm.check() target_host = test_lib.lib_find_random_host(vm.get_vm()) vm.stop() vm.check() vol_ops.migrate_volume( test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid) for volume in volume_in_local: vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) if not (local_nfs_env or local_smp_env): for volume in volume_in_another: vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) for volume in volume_in_local + volume_in_another: volume.attach(vm) volume.check() vm.start() vm.check() for volume in volume_in_local + volume_in_another: assert volume.get_volume().vmInstanceUuid == vm.get_vm().uuid test_util.test_pass('Multi PrimaryStorage Test Pass')
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) mn = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0] cmd = "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % ( os.environ.get('zstackInstallPath')) if os.system("ip r | grep %s" % (mn.hostName)) == 0: os.system(cmd) else: for host in test_lib.lib_get_all_hosts_from_plan(): test_util.test_logger("host.managementIp_: %s" % (host.managementIp_)) test_util.test_logger("mn.hostName: %s" % (mn.hostName)) test_util.test_logger( "anotherIp: %s" % (test_stub.get_another_ip_of_host( host.managementIp_, host.username_, host.password_))) if host.managementIp_ == mn.hostName or test_stub.get_another_ip_of_host( host.managementIp_, host.username_, host.password_) == mn.hostName: out = test_lib.lib_execute_ssh_cmd(host.managementIp_, host.username_, host.password_, cmd, timeout=30) img_option.set_url( 'http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (mn.hostName)) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] ps_env = test_stub.PSEnvChecker() local_ps, shared_ps = ps_env.get_two_ps() test_util.test_dsc("Create VM: {}".format(os.environ.get('CASE_FLAVOR'))) vm = test_stub.create_vm_with_random_offering(vm_name='test_vm', ps_uuid=local_ps.uuid if flavor["root_vol"] is LOCAL else shared_ps.uuid, l3_name='l3VlanNetworkName1', image_name='imageName_net') test_obj_dict.add_vm(vm) if flavor['data_vol'] in (LOCAL, MIXED): local_vol = test_stub.create_multi_volumes(count=1,host_uuid=vm.get_vm().hostUuid, ps=local_ps)[0] test_obj_dict.add_volume(local_vol) local_vol.attach(vm) else: local_vol = None if flavor['data_vol'] in (SHARED, MIXED): shared_vol = test_stub.create_multi_volumes(count=1, ps=shared_ps)[0] test_obj_dict.add_volume(shared_vol) shared_vol.attach(vm) else: shared_vol = None vm.check() test_util.test_dsc("Try to perform live migration") if flavor['root_vol'] is SHARED and flavor['data_vol'] in (None, SHARED): test_stub.migrate_vm_to_random_host(vm) elif flavor['root_vol'] is LOCAL and flavor['data_vol'] is None: test_util.test_dsc("Try to perform local vm live migration") test_stub.migrate_vm_to_random_host(vm) else: with test_lib.expected_failure("live migration will fail if have local volumes", Exception): test_stub.migrate_vm_to_random_host(vm) vm.check() test_util.test_dsc("Try to perform cold migration") if local_vol: local_vol.detach() if shared_vol: shared_vol.detach() vm.stop() vm.check() if flavor['root_vol'] is LOCAL: target_host = test_lib.lib_find_random_host(vm.get_vm()) vol_ops.migrate_volume(test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid) if local_vol: vol_ops.migrate_volume(local_vol.get_volume().uuid, target_host.uuid) if shared_vol: with test_lib.expected_failure('cold migrate volume in shared ps', Exception): vol_ops.migrate_volume(shared_vol.get_volume().uuid, target_host.uuid) if local_vol: local_vol.attach(vm) if shared_vol: shared_vol.attach(vm) vm.start() vm.check() test_util.test_dsc("Try to perform detached VM hot migration") if flavor['root_vol'] is SHARED and flavor['data_vol'] in (LOCAL, MIXED): if local_vol: local_vol.detach() if shared_vol: shared_vol.detach() test_stub.migrate_vm_to_random_host(vm) if local_vol: vol_ops.migrate_volume(local_vol.get_volume().uuid, vm.get_vm().hostUuid) if local_vol: local_vol.attach(vm) if shared_vol: shared_vol.attach(vm) vm.check() test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Multi PrimaryStorage Test Pass')
def test(): if test_lib.lib_get_active_host_number() < 2: test_util.test_fail('Not available host to do maintenance, since there are not 2 hosts') vm = test_stub.create_vm(vm_name = 'migrate_stopped_vm_with_snapshot') host_uuid = vm.get_vm().hostUuid root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_obj_dict.add_vm(vm) test_util.test_dsc('Create volume for snapshot testing') 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 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) #make sure utility vm is starting and running vm.check() volume.attach(vm) volume.detach() test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(volume.get_volume().uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() vm.stop() conditions = res_ops.gen_query_conditions('uuid', '!=', host_uuid) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) rest_hosts = res_ops.query_resource(res_ops.HOST, conditions) target_host = random.choice(rest_hosts) test_util.test_dsc('migrate vm and volumes') vol_ops.migrate_volume(root_volume_uuid, target_host.uuid) vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) vm.start() vm.check() snapshots.check() snapshot1 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot2') snapshots.check() snapshots.use_snapshot(snapshot1) snapshots.create_snapshot('create_snapshot1.1.1') snapshots.check() snapshots.use_snapshot(snapshot1) snapshots.create_snapshot('create_snapshot1.2.1') snapshots.check() snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) volume.check() volume.delete() test_obj_dict.rm_volume(volume) vm.destroy() test_util.test_pass('Create Snapshot with VM migration test Success')
def test(): global vm bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") image_option = test_util.ImageOption() image_option.set_name('test_image_cache_cleanup') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(new_image.image.uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('test_image_cache_cleanup_vm1') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') test_obj_dict.add_vm(vm) vm.check() host = test_lib.lib_find_host_by_vm(vm.get_vm()) target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() new_image.delete() new_image.expunge() ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if test_lib.lib_check_file_exist(host, image_cache_path): test_util.test_fail('image cache is expected to be deleted') # elif ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE: # elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: # elif ps.type == 'SharedMountPoint': vm.destroy() test_util.test_pass('Migrate VM Test Success')
def test(): global test_obj_dict #volume_creation_option = test_util.VolumeOption() #test_util.test_dsc('Create volume and check') #disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) #volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume = test_stub.create_volume(volume_creation_option) bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") volume_creation_option = test_util.VolumeOption() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume_uuid = volume1.volume.uuid test_util.test_dsc('Create vm and check') vm = test_stub.create_vr_vm('migrate_volume_vm', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.vm.uuid volume1.attach(vm) volume1.detach(vm_uuid) vm.stop() image_obj = volume1.create_template([bss[0].uuid]) vm.start() host_uuid = vm.vm.hostUuid ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) volume2 = image_obj.create_data_volume(ps.uuid, 'volumeName', host_uuid) test_obj_dict.add_volume(volume2) volume2.check() volume_uuid = volume2.volume.uuid ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') snapshots = test_obj_dict.get_volume_snapshot(volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() snapshots.create_snapshot('create_snapshot2') snapshots.check() target_host = test_lib.lib_find_random_host_by_volume_uuid(volume_uuid) target_host_uuid = target_host.uuid vol_ops.migrate_volume(volume_uuid, target_host_uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass( 'Cold migrate Data Volume from Template with Snapshot Test Success')
def test(): global vm bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") image_option = test_util.ImageOption() image_option.set_name('test_image_cache_cleanup') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(new_image.image.uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('test_image_cache_cleanup_vm1') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') test_obj_dict.add_vm(vm) vm.check() host = test_lib.lib_find_host_by_vm(vm.get_vm()) target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() new_image.delete() new_image.expunge() ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) count = 0 while True: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 count = 0 while True: image_cache_path = "%s/zstore-cache/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 vm.destroy() test_util.test_pass('Migrate VM Test Success')
def migrate_local_storage_volume(volume_uuid, host_uuid): vol_ops.migrate_volume(volume_uuid, host_uuid)
def migrate_volume(volume_uuid, target_host_uuid): vol_ops.migrate_volume(volume_uuid, target_host_uuid)
def test(): ps_env = test_stub.PSEnvChecker() local_nfs_env = ps_env.is_local_nfs_env local_ps, another_ps = ps_env.get_two_ps() vm = test_stub.create_multi_vms(name_prefix='test-', count=1)[0] test_obj_dict.add_vm(vm) vm.check() volume_in_local = test_stub.create_multi_volumes( count=VOLUME_NUMBER, ps=local_ps, host_uuid=test_lib.lib_get_vm_host(vm.get_vm()).uuid) volume_in_another = test_stub.create_multi_volumes( count=VOLUME_NUMBER, ps=another_ps, host_uuid=None if local_nfs_env else test_lib.lib_get_vm_host(vm.get_vm()).uuid) for volume in volume_in_local + volume_in_another: test_obj_dict.add_volume(volume) for volume in volume_in_local + volume_in_another: volume.attach(vm) volume.check() vm.check() vm.update() snapshots_list = [] for volume in vm.get_vm().allVolumes: snapshots = test_obj_dict.get_volume_snapshot(volume.uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_volume_snapshot') snapshots_list.append(snapshots) for volume in volume_in_local + volume_in_another: volume.detach() volume.check() vm.check() target_host = test_lib.lib_find_random_host(vm.get_vm()) vm.stop() vm.check() vol_ops.migrate_volume( test_lib.lib_get_root_volume(vm.get_vm()).uuid, target_host.uuid) for volume in volume_in_local: vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) if not local_nfs_env: for volume in volume_in_another: vol_ops.migrate_volume(volume.get_volume().uuid, target_host.uuid) for volume in volume_in_local + volume_in_another: volume.attach(vm) volume.check() for snapshots in snapshots_list: snapshot = snapshots.get_current_snapshot() snapshots.use_snapshot(snapshot) vm.start() vm.check() for volume in volume_in_local + volume_in_another: assert volume.get_volume().vmInstanceUuid == vm.get_vm().uuid test_util.test_pass('Multi PrimaryStorage Test Pass')
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 migrate_volume(index): target_host = test_lib.lib_find_random_host(vms[index].get_vm()) vms[index].stop() vol_ops.migrate_volume(vms[index].get_vm().allVolumes[0].uuid, target_host.uuid) threads_result[index] = "Done"
def test(): global host if test_lib.lib_get_active_host_number() < 2: test_util.test_fail('Not available host to do maintenance, since there are not 2 hosts') vm1 = test_stub.create_vm(vm_name = 'maintain_host_vm1') test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vm(vm_name = 'maintain_host_vm2') test_obj_dict.add_vm(vm2) #vm1.check() #vm2.check() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) test_util.test_dsc('Attach volume and check') volume.attach(vm1) volume.check() current_host1 = test_lib.lib_get_vm_host(vm1.vm) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) all_hosts = res_ops.query_resource(res_ops.HOST, conditions) target_host = random.choice(all_hosts) if current_host1.uuid != target_host.uuid: vm1.migrate(target_host.uuid) current_host2 = test_lib.lib_get_vm_host(vm2.vm) if current_host2.uuid != target_host.uuid: vm2.migrate(target_host.uuid) new_host = test_lib.lib_get_vm_host(vm1.vm) if new_host.uuid != target_host.uuid: test_util.test_fail('VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host.uuid)) volume.check() host = test_kvm_host.ZstackTestKvmHost() host.set_host(target_host) host.maintain() #need to update vm's inventory, since they will be changed by maintenace mode vm1.update() vm2.update() vm1.set_state(vm_header.STOPPED) vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() volume.check() host.change_state(test_kvm_host.ENABLE_EVENT) if not linux.wait_callback_success(is_host_connected, host.get_host().uuid, 120): test_util.test_fail('host status is not changed to connected, after changing its state to Enable') volume.detach() vm1_root_volume = test_lib.lib_get_root_volume(vm1.get_vm()) vm2_root_volume = test_lib.lib_get_root_volume(vm2.get_vm()) conditions = res_ops.gen_query_conditions('uuid', '!=', target_host.uuid, conditions) rest_hosts = res_ops.query_resource(res_ops.HOST, conditions) new_target_host = random.choice(rest_hosts) vol_ops.migrate_volume(vm1_root_volume.uuid, new_target_host.uuid) vol_ops.migrate_volume(vm2_root_volume.uuid, new_target_host.uuid) vol_ops.migrate_volume(volume.get_volume().uuid, new_target_host.uuid) volume.attach(vm1) vm1.start() vm2.start() vm1.check() vm2.check() volume.check() vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) volume.delete() test_obj_dict.rm_volume(volume) test_util.test_pass('Maintain Host Test Success')
def migrate(self, host_uuid, session_uuid = None): ''' Only valid when volume is in local storage ''' vol_ops.migrate_volume(self.get_volume().uuid, host_uuid, session_uuid)
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 migrate(self, host_uuid, session_uuid=None): ''' Only valid when volume is in local storage ''' vol_ops.migrate_volume(self.get_volume().uuid, host_uuid, session_uuid)
def test(): global host if test_lib.lib_get_active_host_number() < 2: test_util.test_fail( 'Not available host to do maintenance, since there are not 2 hosts' ) vm1 = test_stub.create_vm(vm_name='maintain_host_vm1') test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vm(vm_name='maintain_host_vm2') test_obj_dict.add_vm(vm2) #vm1.check() #vm2.check() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) test_util.test_dsc('Attach volume and check') volume.attach(vm1) volume.check() current_host1 = test_lib.lib_get_vm_host(vm1.vm) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) all_hosts = res_ops.query_resource(res_ops.HOST, conditions) target_host = random.choice(all_hosts) if current_host1.uuid != target_host.uuid: vm1.migrate(target_host.uuid) current_host2 = test_lib.lib_get_vm_host(vm2.vm) if current_host2.uuid != target_host.uuid: vm2.migrate(target_host.uuid) new_host = test_lib.lib_get_vm_host(vm1.vm) if new_host.uuid != target_host.uuid: test_util.test_fail( 'VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host.uuid)) volume.check() host = test_kvm_host.ZstackTestKvmHost() host.set_host(target_host) host.maintain() #need to update vm's inventory, since they will be changed by maintenace mode vm1.update() vm2.update() vm1.set_state(vm_header.STOPPED) vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() volume.check() host.change_state(test_kvm_host.ENABLE_EVENT) if not linux.wait_callback_success(is_host_connected, host.get_host().uuid, 120): test_util.test_fail( 'host status is not changed to connected, after changing its state to Enable' ) volume.detach() vm1_root_volume = test_lib.lib_get_root_volume(vm1.get_vm()) vm2_root_volume = test_lib.lib_get_root_volume(vm2.get_vm()) conditions = res_ops.gen_query_conditions('uuid', '!=', target_host.uuid, conditions) rest_hosts = res_ops.query_resource(res_ops.HOST, conditions) new_target_host = random.choice(rest_hosts) vol_ops.migrate_volume(vm1_root_volume.uuid, new_target_host.uuid) vol_ops.migrate_volume(vm2_root_volume.uuid, new_target_host.uuid) vol_ops.migrate_volume(volume.get_volume().uuid, new_target_host.uuid) volume.attach(vm1) vm1.start() vm2.start() vm1.check() vm2.check() volume.check() vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) volume.delete() test_obj_dict.rm_volume(volume) test_util.test_pass('Maintain Host Test Success')