def test(): vm = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(vm) vm.check() out = test_lib.lib_execute_command_in_vm(vm.get_vm(), 'ps -ef |grep qemu-ga | grep -v grep') if not out.find('qemu-ga'): test_util.test_skip('qemu-ga not running on VM, skip testing') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid) if time.time()-current_time >= 10: test_util.test_fail("VM should shutdown with default grace method in %s seconds" % (time.time()-current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid, force='cold') if time.time()-current_time >= 5: test_util.test_fail("VM should shutdown immediately with cold method, while it taks %s seconds" % (time.time()-current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.destroy() test_util.test_pass('Stop VM with qemu-guest-agent Test Success')
def test(): session_uuid = acc_ops.login_as_admin() acc_ops.logout(session_uuid) image_name = os.environ.get('imageName3') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid try: vm = test_stub.create_vm(image_uuid=image_uuid, session_uuid=session_uuid) test_util.test_fail( 'Expect exception after logout while there is none') except: pass vm = test_stub.create_vm(image_uuid=image_uuid) vm_ops.stop_vm(vm.get_vm().uuid) vm_ops.start_vm(vm.get_vm().uuid) try: vm_ops.stop_vm(vm.get_vm().uuid, session_uuid=session_uuid) test_util.test_fail( 'Expect exception after logout while there is none') except: pass vm.destroy() vm.expunge() test_util.test_pass('Test operations after session logout passed')
def query_autoscaling_vm_instance(imageUuid): Result = autoscaling.query_vm_install([{'name': 'uuid', 'op': '!=', 'value': 'NULL'}]) for evt in Result: if evt.imageUuid == imageUuid: test_util.test_logger("%s" %(evt.imageUuid)) vm_ops.stop_vm(evt.uuid, None, None) test_util.test_logger("stop autoscaling vmm instance")
def test(): vm = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(vm) vm.check() test_lib.lib_execute_command_in_vm(vm.get_vm(), 'systemctl stop qemu-guest-agent') test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid) if time.time()-current_time <= 10: test_util.test_fail("VM should not shutdown with default grace method in %s seconds" % (time.time()-current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid, force='cold') if time.time()-current_time >= 5: test_util.test_fail("VM should shutdown immediately with cold method, while it taks %s seconds" % (time.time()-current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.destroy() test_util.test_pass('Force Stop VM Test Success')
def test(): vm = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(vm) vm.check() out = test_lib.lib_execute_command_in_vm(vm.get_vm(), 'ps -ef |grep qemu-ga | grep -v grep') if not out.find('qemu-ga'): test_util.test_skip('qemu-ga not running on VM, skip testing') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid) if time.time()-current_time >= 20: test_util.test_fail("VM should shutdown with default grace method in %s seconds" % (time.time()-current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() test_lib.lib_execute_command_in_vm(vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid, force='cold') if time.time()-current_time >= 5: test_util.test_fail("VM should shutdown immediately with cold method, while it taks %s seconds" % (time.time()-current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.destroy() test_util.test_pass('Stop VM with qemu-guest-agent Test Success')
def test(): vm = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(vm) vm.check() test_lib.lib_execute_command_in_vm( vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid) if time.time() - current_time <= 10: test_util.test_fail( "VM should not shutdown with default grace method in %s seconds" % (time.time() - current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() test_lib.lib_execute_command_in_vm( vm.get_vm(), 'nohup systemd-inhibit sleep 60 >/dev/null 2>/dev/null </dev/null &') current_time = time.time() vm_ops.stop_vm(vm.get_vm().uuid, force='cold') if time.time() - current_time >= 5: test_util.test_fail( "VM should shutdown immediately with cold method, while it taks %s seconds" % (time.time() - current_time)) vm.set_state(vm_header.STOPPED) vm.check() vm.destroy() test_util.test_pass('Force Stop VM Test Success')
def test(): test_util.test_dsc('Test Change VM Image In Multihosts Env') global vm image = test_lib.lib_get_image_by_name("centos") vm = test_stub.create_vm(image_uuid=image.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid last_host_uuid = test_lib.lib_get_vm_last_host(vm.get_vm()).uuid image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_uuid = vm.get_vm().uuid host_ops.change_host_state(host_uuid = last_host_uuid, state = 'disable') vm_ops.stop_vm(vm_uuid) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #Disable vm's host.If ps is shared storage,the vm will be started on another host that meets the conditions and the operation of changing vm image will success. if ps.type != 'LocalStorage': vm_ops.change_vm_image(vm_uuid,image_uuid) vm_ops.start_vm(vm_uuid) #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') vm.destroy() test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success') #Disable vm's host.If ps is local storage,the operation of changing vm image will fail. else: try: vm_ops.change_vm_image(vm_uuid, image_uuid) except: test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success') test_util.test_fail('Test Change VM Image In Multihosts Env Success Failed')
def test(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.stop_vm(vr1.uuid) if test_lib.lib_get_ha_enable() != 'true' or vr1.applianceVmType != "vrouter": vm_ops.start_vm(vr1.uuid) vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1) if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120): test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid) timeout = time.time() + 60 while time.time() < timeout: cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if vms[0].status == 'Connected': test_util.test_pass('Test Reconnect VR VM start VRs success') time.sleep(1) test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
def check_resource(): hosts = res_ops.query_resource(res_ops.HOST, [], None) for host in hosts: if host.status != "Connected": host_ops.reconnect_host(host.uuid) return False pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None) for ps in pss: if ps.status != "Connected": ps_ops.reconnect_primary_storage(ps.uuid) return False bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None) for bs in bss: if bs.status != "Connected": bs_ops.reconnect_backup_storage(bs.uuid) return False if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get( 'WOODPECKER_PARALLEL') == '0': vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None) for vm in vms: if vm.type == 'UserVm': try: vm_ops.destroy_vm(vm.uuid) except: test_util.test_logger('ignore exception try to destroy vm') try: vm_ops.expunge_vm(vm.uuid) except: test_util.test_logger('ignore exception try to expunge vm') vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None) for vr in vrs: if vr.status != "Connected" or vr.state != "Running": if vr.applianceVmType != "vrouter": try: vm_ops.stop_vm(vr.uuid, force='cold') vm_ops.start_vm(vr.uuid) except: test_util.test_logger('Exception when reboot vr vm') else: try: vm_ops.stop_vm(vr.uuid, force='cold') except: test_util.test_logger('Exception when reboot vr vm') return False return True
def check_resource(): hosts = res_ops.query_resource(res_ops.HOST, [], None) for host in hosts: if host.status != "Connected": host_ops.reconnect_host(host.uuid) return False pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None) for ps in pss: if ps.status != "Connected": ps_ops.reconnect_primary_storage(ps.uuid) return False bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None) for bs in bss: if bs.status != "Connected": bs_ops.reconnect_backup_storage(bs.uuid) return False if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get('WOODPECKER_PARALLEL') == '0': vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None) for vm in vms: if vm.type == 'UserVm': try: vm_ops.destroy_vm(vm.uuid) except: test_util.test_logger('ignore exception try to destroy vm') try: vm_ops.expunge_vm(vm.uuid) except: test_util.test_logger('ignore exception try to expunge vm') vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None) for vr in vrs: if vr.status != "Connected" or vr.state != "Running": if vr.applianceVmType != "vrouter": try: vm_ops.stop_vm(vr.uuid, force='cold') vm_ops.start_vm(vr.uuid) except: test_util.test_logger('Exception when reboot vr vm') else: try: vm_ops.stop_vm(vr.uuid, force='cold') except: test_util.test_logger('Exception when reboot vr vm') return False return True
def test(): new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\ cpuSpeed = 111, memorySize = 1024 * 1024 * 1024) test_obj_dict.add_instance_offering(new_offering) vm = test_stub.create_vm(vm_name='ckvmoffering-c7-64', image_name="imageName_i_c7", instance_offering_uuid=new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() (available_cpu_before, available_memory_before, vm_outer_cpu_before, vm_outer_mem_before, vm_interal_cpu_before, vm_interal_mem_before) = test_stub.check_cpu_mem(vm, shutdown=True) vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid( vm.get_vm().instanceOfferingUuid) MEMchange = 126 * 1024 * 1024 AlignedMemChange = 128 * 1024 * 1024 vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, vm_instance_offering.memorySize + MEMchange) vm.update() time.sleep(10) vm.check() vm_ops.stop_vm(vm.get_vm().uuid) test_stub.wait_for_certain_vm_state(vm, 'stopped') vm_ops.start_vm(vm.get_vm().uuid) test_stub.wait_for_certain_vm_state(vm, 'running') vm.check() (available_cpu_after, available_memory_after, vm_outer_cpu_after, vm_outer_mem_after, vm_interal_cpu_after, vm_internal_mem_after) = test_stub.check_cpu_mem(vm, shutdown=True) assert available_cpu_before == available_cpu_after + 1 assert available_memory_after + AlignedMemChange / int( test_lib.lib_get_provision_memory_rate()) in range( available_memory_before - 1, available_memory_before + 1) assert vm_outer_cpu_before == vm_outer_cpu_after - 1 assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange assert vm_interal_cpu_before == vm_interal_cpu_after - 1 assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange / 1024 / 1024 test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('VM online change instance offering Test Pass')
def stop(self, session_uuid = None): self.vm = vm_ops.stop_vm(self.vm.uuid, None, session_uuid) super(ZstackTestVm, self).stop() if ha_ops.get_vm_instance_ha_level(self.vm.uuid): status = self.vm.state while status != 'Running': vm_inv = test_lib.lib_get_vm_by_uuid(self.vm.uuid) status = vm_inv.state self.set_state(vm_header.RUNNING)
def test(): test_util.test_dsc('Test Change VM Image In Multihosts Env') global vm image = test_lib.lib_get_image_by_name("centos") vm = test_stub.create_vm(image_uuid=image.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid last_host_uuid = test_lib.lib_get_vm_last_host(vm.get_vm()).uuid image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_uuid = vm.get_vm().uuid host_ops.change_host_state(host_uuid=last_host_uuid, state='disable') vm_ops.stop_vm(vm_uuid) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #Disable vm's host.If ps is shared storage,the vm will be started on another host that meets the conditions and the operation of changing vm image will success. if ps.type != 'LocalStorage': vm_ops.change_vm_image(vm_uuid, image_uuid) vm_ops.start_vm(vm_uuid) #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') vm.destroy() test_util.test_pass( 'Change Vm Image Test Success In Multihosts Env Success') #Disable vm's host.If ps is local storage,the operation of changing vm image will fail. else: try: vm_ops.change_vm_image(vm_uuid, image_uuid) except: test_util.test_pass( 'Change Vm Image Test Success In Multihosts Env Success') test_util.test_fail( 'Test Change VM Image In Multihosts Env Success Failed')
def test(): session_uuid = acc_ops.login_as_admin() acc_ops.logout(session_uuid) image_name = os.environ.get('imageName3') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid try: vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=session_uuid) test_util.test_fail('Expect exception after logout while there is none') except: pass vm = test_stub.create_vm(image_uuid = image_uuid) vm_ops.stop_vm(vm.get_vm().uuid) vm_ops.start_vm(vm.get_vm().uuid) try: vm_ops.stop_vm(vm.get_vm().uuid, session_uuid=session_uuid) test_util.test_fail('Expect exception after logout while there is none') except: pass vm.destroy() vm.expunge() test_util.test_pass('Test operations after session logout passed')
def test(): new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\ memorySize = 1024 * 1024 * 1024) test_obj_dict.add_instance_offering(new_offering) vm = test_stub.create_vm(vm_name = 'ckvmoffering-c7-64', image_name = "imageName_i_c7", instance_offering_uuid=new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() (available_cpu_before, available_memory_before, vm_outer_cpu_before, vm_outer_mem_before, vm_interal_cpu_before, vm_interal_mem_before) = test_stub.check_cpu_mem(vm, shutdown=True) vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid) MEMchange = 126*1024*1024 AlignedMemChange = 128*1024*1024 vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, vm_instance_offering.memorySize + MEMchange) vm.update() time.sleep(10) vm.check() vm_ops.stop_vm(vm.get_vm().uuid) test_stub.wait_for_certain_vm_state(vm, 'stopped') vm_ops.start_vm(vm.get_vm().uuid) test_stub.wait_for_certain_vm_state(vm, 'running') vm.check() (available_cpu_after, available_memory_after, vm_outer_cpu_after, vm_outer_mem_after, vm_interal_cpu_after, vm_internal_mem_after) = test_stub.check_cpu_mem(vm, shutdown=True) assert available_cpu_before == available_cpu_after + 1 assert available_memory_after + AlignedMemChange / int(test_lib.lib_get_provision_memory_rate()) in range(available_memory_before-1, available_memory_before+1) assert vm_outer_cpu_before == vm_outer_cpu_after - 1 assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange assert vm_interal_cpu_before == vm_interal_cpu_after - 1 assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange/1024/1024 test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('VM online change instance offering Test Pass')
def test(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.stop_vm(vr1.uuid) if test_lib.lib_get_ha_enable( ) != 'true' or vr1.applianceVmType != "vrouter": vm_ops.start_vm(vr1.uuid) vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1) if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120): test_util.test_fail( 'vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid) timeout = time.time() + 60 while time.time() < timeout: cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if vms[0].status == 'Connected': test_util.test_pass('Test Reconnect VR VM start VRs success') time.sleep(1) test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
def test(): test_util.test_dsc('Test Change VM Image Function') global vm #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork1").uuid image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-vm",disk_offering_uuids = disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) #stop vm's vr vm_ops.stop_vm(vr.uuid) #change vm image image_uuid = test_lib.lib_get_image_by_name("windows").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the windows vm is running successfully vm_ip = vm.get_vm().vmNics[0].ip if not test_lib.lib_wait_target_up(vm_ip,'23',1200): test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully vm_ops.stop_vm(vm_uuid) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip,'22',120): test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after_linux != primarystorage_uuid_after: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) test_util.test_pass('Change Vm Image Test Success')
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 test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) 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") test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] #create vm with 3 data volumes vm = test_stub.create_vm(image_name = "ttylinux",vm_name="test-vm",disk_offering_uuids = disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) image_option = test_util.ImageOption() image_option.set_name('windows_for_test') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_platform('windows') #image_option.set_url('http://172.20.1.16:7480/diskimages/windows-telnet.qcow2') image_option.set_url(os.environ.get('windowsImageUrl')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(1800*1000) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() image_windows_uuid = test_lib.lib_get_image_by_name("windows_for_test").uuid vm_ops.change_vm_image(vm_uuid,image_windows_uuid) vm_ops.start_vm(vm_uuid) vm.update() vm_ip = vm.get_vm().vmNics[0].ip #check whether the windows vm is running successfully if not test_lib.lib_wait_target_up(vm_ip,'23',1200): test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.stop_vm(vm_uuid) vm_ops.change_vm_image(vm_uuid,image_linux_uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip,'22',180): test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != primarystorage_uuid_after_linux: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) vm.expunge() img_ops.delete_image(image_windows_uuid) img_ops.expunge_image(image_windows_uuid) test_util.test_pass('Change Vm Image Test Success')
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id( project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid], project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # 4 login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id( project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project( project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] image_option = test_util.ImageOption() image_option.set_name('fake_image') image_option.set_description('fake image') image_option.set_format('raw') image_option.set_mediaType('RootVolumeTemplate') image_option.set_backup_storage_uuid_list([bs.uuid]) image_option.url = "http://fake/fake.raw" image_option.set_session_uuid(project_login_uuid) image_uuid = img_ops.add_image(image_option).uuid img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'disable', session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'enable', session_uuid=project_login_uuid) if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: img_ops.export_image_from_backup_storage( image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.delete_exported_image_from_backup_storage( image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid) img_ops.delete_image(image_uuid, session_uuid=project_login_uuid) img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid) # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid acc_ops.share_resources([project_linked_account_uuid], [disk_offering_uuid]) volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_name('data_volume_project_management') volume_option.set_session_uuid(project_login_uuid) data_volume = vol_ops.create_volume_from_offering(volume_option) vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name( os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid=image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid vol_ops.attach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.detach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid) # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap( vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # L2 related ops: create, delete zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid try: l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid) test_util.test_fail( "Expect exception: project admin not allowed to create Novlan L2 except vxlan" ) except: pass try: l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid) test_util.test_fail( "Expect exception: project admin not allowed to create vlan L2 except vxlan" ) except: pass #net_ops.delete_l2(l2.uuid, session_uuid=project_login_uuid) # L3 related ops: # network service ops: # zwatch ops: # scheduler ops: # certificate # 11 delete acc_ops.logout(project_login_uuid) iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) iam2_ops.delete_iam2_virtual_id(project_admin_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def scheduler_vm_operations(vm, bss): vm_ops.stop_vm(vm.get_vm().uuid) volume = vm.get_vm().allVolumes[0] start_date = int(time.time()) schd_job1 = schd_ops.create_scheduler_job('simple_start_vm_scheduler', 'simple_start_vm_scheduler', vm.get_vm().uuid, 'startVm', None) schd_trigger1 = schd_ops.create_scheduler_trigger( 'simple_start_vm_scheduler', start_date + 5, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger1.uuid, schd_job1.uuid) schd_job2 = schd_ops.create_scheduler_job('simple_stop_vm_scheduler', 'simple_stop_vm_scheduler', vm.get_vm().uuid, 'stopVm', None) schd_trigger2 = schd_ops.create_scheduler_trigger( 'simple_stop_vm_scheduler', start_date + 15, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger2.uuid, schd_job2.uuid) schd_job3 = schd_ops.create_scheduler_job('simple_reboot_vm_scheduler', 'simple_reboot_vm_scheduler', vm.get_vm().uuid, 'rebootVm', None) schd_trigger3 = schd_ops.create_scheduler_trigger( 'simple_reboot_vm_scheduler', start_date + 10, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger3.uuid, schd_job3.uuid) schd_job4 = schd_ops.create_scheduler_job( 'simple_create_snapshot_scheduler', 'simple_create_snapshot_scheduler', volume.uuid, 'volumeSnapshot', None) schd_trigger4 = schd_ops.create_scheduler_trigger( 'simple_create_snapshot_scheduler', start_date + 12, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger4.uuid, schd_job4.uuid) snapshot_num = 0 for i in range(0, 3): test_util.test_logger('round %s' % (i)) test_stub.sleep_util(start_date + 5 + 15 * i + 1) #test_util.test_logger('check volume snapshot number at %s, there should be %s' % (start_date + 5 +15*i, snapshot_num)) test_util.test_logger( 'check VM status at %s, VM is expected to start' % (start_date + 15 + 15 * i)) vm.update() if vm.get_vm().state != 'Starting' and vm.get_vm().state != 'Running': test_util.test_fail('VM is expected to start') test_stub.sleep_util(start_date + 10 + 15 * i + 1) test_util.test_logger( 'check VM status at %s, VM is expected to reboot' % (start_date + 10 + 15 * i)) vm.update() if not test_lib.lib_find_in_local_management_server_log( start_date + 10, '[msg received]: {"org.zstack.header.vm.RebootVmInstanceMsg', vm.get_vm().uuid): test_util.test_fail('VM is expected to reboot start from %s' % (start_date + 10 + 15 * i)) test_stub.sleep_util(start_date + 12 + 15 * i + 1) snapshot_num += 1 new_snapshot_num = query_snapshot_number(volume.uuid) if snapshot_num != new_snapshot_num: test_util.test_fail('there should be %s snapshots' % (snapshot_num)) #snapshot_num +=1 test_util.test_logger( 'check volume snapshot number at %s, there should be %s' % (start_date + 5 + 15 * i, snapshot_num)) #test_util.test_logger('check VM status at %s, VM is expected to stop' % (start_date + 6 + 15*i +1)) test_stub.sleep_util(start_date + 15 + 15 * i + 1) test_util.test_logger('check VM status at %s, VM is expected to stop' % (start_date + 15 + 15 * i)) vm.update() if vm.get_vm().state != 'Stopping' and vm.get_vm().state != 'Stopped': test_util.test_fail('VM is expected to stop') schd_ops.del_scheduler_job(schd_job1.uuid) schd_ops.del_scheduler_trigger(schd_trigger1.uuid) schd_ops.del_scheduler_job(schd_job2.uuid) schd_ops.del_scheduler_trigger(schd_trigger2.uuid) schd_ops.del_scheduler_job(schd_job3.uuid) schd_ops.del_scheduler_trigger(schd_trigger3.uuid) schd_ops.del_scheduler_job(schd_job4.uuid) schd_ops.del_scheduler_trigger(schd_trigger4.uuid) vm.update() vm_state = vm.get_vm().state snapshot_num_after = query_snapshot_number(volume.uuid) test_util.test_logger('snapshotnumber:%s' % snapshot_num_after) for i in range(3, 5): test_util.test_logger('round %s' % (i)) test_stub.sleep_util(start_date + 1 + 15 * i) vm.update() test_util.test_logger( 'check vm status at %s, vm is expected to stay in state %s' % (start_date + 5 + 15 * i, vm_state)) if vm.get_vm().state != vm_state: test_util.test_fail('vm is expected to stay in state %s' % (vm_state)) if snapshot_num_after != snapshot_num: test_util.test_fail( 'the number of snapshots is expected to stay in %s' % (snapshot_num)) vm.destroy() vm.expunge()
def scheduler_vm_operations(vm,bss): vm_ops.stop_vm(vm.get_vm().uuid) volume = vm.get_vm().allVolumes[0] start_date = int(time.time()) schd_job1 = schd_ops.create_scheduler_job('simple_start_vm_scheduler', 'simple_start_vm_scheduler', vm.get_vm().uuid, 'startVm', None) schd_trigger1 = schd_ops.create_scheduler_trigger('simple_start_vm_scheduler', start_date+5, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger1.uuid, schd_job1.uuid) schd_job2 = schd_ops.create_scheduler_job('simple_stop_vm_scheduler', 'simple_stop_vm_scheduler', vm.get_vm().uuid, 'stopVm', None) schd_trigger2 = schd_ops.create_scheduler_trigger('simple_stop_vm_scheduler', start_date+15, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger2.uuid, schd_job2.uuid) schd_job3 = schd_ops.create_scheduler_job('simple_reboot_vm_scheduler', 'simple_reboot_vm_scheduler', vm.get_vm().uuid, 'rebootVm', None) schd_trigger3 = schd_ops.create_scheduler_trigger('simple_reboot_vm_scheduler', start_date+10, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger3.uuid, schd_job3.uuid) schd_job4 = schd_ops.create_scheduler_job('simple_create_snapshot_scheduler', 'simple_create_snapshot_scheduler', volume.uuid, 'volumeSnapshot', None) schd_trigger4 = schd_ops.create_scheduler_trigger('simple_create_snapshot_scheduler', start_date+12, None, 15, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger4.uuid, schd_job4.uuid) snapshot_num = 0 for i in range(0,3): test_util.test_logger('round %s' % (i)) test_stub.sleep_util(start_date + 5 + 15*i + 1) #test_util.test_logger('check volume snapshot number at %s, there should be %s' % (start_date + 5 +15*i, snapshot_num)) test_util.test_logger('check VM status at %s, VM is expected to start' % (start_date + 15 + 15*i)) vm.update() if vm.get_vm().state != 'Starting' and vm.get_vm().state != 'Running': test_util.test_fail('VM is expected to start') test_stub.sleep_util(start_date +10 +15*i + 1) test_util.test_logger('check VM status at %s, VM is expected to reboot' % (start_date + 10 + 15*i)) vm.update() if not test_lib.lib_find_in_local_management_server_log(start_date+10, '[msg received]: {"org.zstack.header.vm.RebootVmInstanceMsg', vm.get_vm().uuid): test_util.test_fail('VM is expected to reboot start from %s' % (start_date+ 10 + 15*i)) test_stub.sleep_util(start_date + 12 + 15*i + 1) snapshot_num +=1 new_snapshot_num = query_snapshot_number(volume.uuid) if snapshot_num != new_snapshot_num: test_util.test_fail('there should be %s snapshots' % (snapshot_num)) #snapshot_num +=1 test_util.test_logger('check volume snapshot number at %s, there should be %s' % (start_date + 5 +15*i, snapshot_num)) #test_util.test_logger('check VM status at %s, VM is expected to stop' % (start_date + 6 + 15*i +1)) test_stub.sleep_util(start_date +15 +15*i + 1) test_util.test_logger('check VM status at %s, VM is expected to stop' % (start_date + 15 + 15*i)) vm.update() if vm.get_vm().state != 'Stopping' and vm.get_vm().state != 'Stopped': test_util.test_fail('VM is expected to stop') schd_ops.del_scheduler_job(schd_job1.uuid) schd_ops.del_scheduler_trigger(schd_trigger1.uuid) schd_ops.del_scheduler_job(schd_job2.uuid) schd_ops.del_scheduler_trigger(schd_trigger2.uuid) schd_ops.del_scheduler_job(schd_job3.uuid) schd_ops.del_scheduler_trigger(schd_trigger3.uuid) schd_ops.del_scheduler_job(schd_job4.uuid) schd_ops.del_scheduler_trigger(schd_trigger4.uuid) vm.update() vm_state = vm.get_vm().state snapshot_num_after = query_snapshot_number(volume.uuid) test_util.test_logger('snapshotnumber:%s' % snapshot_num_after) for i in range(3,5): test_util.test_logger('round %s' % (i)) test_stub.sleep_util(start_date + 1 +15*i) vm.update() test_util.test_logger('check vm status at %s, vm is expected to stay in state %s' % (start_date + 5 + 15*i, vm_state)) if vm.get_vm().state != vm_state: test_util.test_fail('vm is expected to stay in state %s' % (vm_state)) if snapshot_num_after != snapshot_num: test_util.test_fail('the number of snapshots is expected to stay in %s' % (snapshot_num)) vm.destroy() vm.expunge()
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid flavor = case_flavor[os.environ.get('CASE_FLAVOR')] # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid if flavor['target_role'] == 'project_admin': # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) elif flavor['target_role'] == 'project_operator': project_operator_name = 'username2' project_operator_password = '******' attributes = [{"name": "__ProjectOperator__", "value": project_uuid}] project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernamethree','password').uuid # login in project by project operator iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid) project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password) project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid elif flavor['target_role'] == 'project_member': plain_user_name = 'username' plain_user_password = '******' plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password, project_uuid=project_uuid).uuid # 3 add virtual id to project iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],project_uuid) # 4 login in project by plain user plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password) # 4 login in project #project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid) project_login_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge if flavor['target_role'] == 'project_member': statements = [{"effect": "Allow", "actions": ["org.zstack.header.vm.**"]}] role_uuid = iam2_ops.create_role('test_role', statements).uuid iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # 11 delete acc_ops.logout(project_login_uuid) if virtual_id_uuid != None: iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) if project_admin_uuid != None: iam2_ops.delete_iam2_virtual_id(project_admin_uuid) if project_operator_uuid != None: iam2_ops.delete_iam2_virtual_id(project_operator_uuid) if plain_user_uuid != None: iam2_ops.delete_iam2_virtual_id(plain_user_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def operate_vm_parall(self, vm_uuid): try: #should be defined by case vm_ops.stop_vm(vm_uuid, None, self.session_uuid) except: self.exc_info.append(sys.exc_info())
def test(): test_util.test_dsc('Test Change VM Image Function') primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for ps in primary_storage_list: if ps.type == "SharedBlock": test_util.test_skip('SharedBlock primary storage does not support overProvision') global vm #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork1").uuid image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] #choose the ps which availableCapacity >= 105G cond = res_ops.gen_query_conditions('availableCapacity', '>=', '112742891520') ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0].uuid system_tag = "primaryStorageUuidForDataVolume::%s" % ps_uuid vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-vm",disk_offering_uuids = disk_offering_uuids,system_tags=[system_tag]) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) #stop vm's vr vm_ops.stop_vm(vr.uuid) #change vm image image_uuid = test_lib.lib_get_image_by_name("windows").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the windows vm is running successfully vm_ip = vm.get_vm().vmNics[0].ip if not test_lib.lib_wait_target_up(vm_ip,'23',1200): test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully vm_ops.stop_vm(vm_uuid) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip,'22',180): test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after_linux != primarystorage_uuid_after: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) test_util.test_pass('Change Vm Image Test Success')
def test(): global vcenter_uuid1 global vcenter_uuid2 global mevoco1_ip global mevoco2_ip vcenter1_name = os.environ['vcenter2_name'] vcenter1_domain_name = os.environ['vcenter2_ip'] vcenter1_username = os.environ['vcenter2_domain_name'] vcenter1_password = os.environ['vcenter2_password'] vm_name = os.environ['vcenter2_sync_vm_start_stop'] mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['serverIp2'] os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid) vcenter_uuid1 = inv.uuid if vcenter_uuid1 == None: test_util.test_fail("vcenter_uuid is None") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid) vcenter_uuid2 = inv.uuid if vcenter_uuid2 == None: test_util.test_fail("vcenter_uuid is None") #start vm in remote and check test_util.test_logger("start vm for sync test") vm_cond = res_ops.gen_query_conditions("name", '=', vm_name) vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("remote woodpecker vm uuid is null") elif vm_uuid and vm_state != "running": print "#%s#" % vm_state vm_ops.start_vm(vm_uuid) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("local woodpecker vm uuid is null") elif vm_state != "running": test_util.test_fail("vcenter sync vm start failed.") #stop vm in remote and check test_util.test_logger("stop vm for sync test") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("remote woodpecker vm uuid is null") elif vm_uuid and vm_state != "stopped": vm_ops.stop_vm(vm_uuid) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("local woodpecker vm uuid is null") elif vm_state != "stopped": test_util.test_fail("vcenter sync vm stop failed.") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if vcenter_uuid2: vct_ops.delete_vcenter(vcenter_uuid2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if vcenter_uuid1: vct_ops.delete_vcenter(vcenter_uuid1) test_util.test_pass("vcenter sync start and stop vm test passed.")
def test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco', 'overProvisioning.primaryStorage', 10) global vm test_lib.lib_create_disk_offering(diskSize=1099511627776, name="1T") disk_offering_uuids = [ test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid, test_lib.lib_get_disk_offering_by_name("root-disk").uuid, test_lib.lib_get_disk_offering_by_name("1T").uuid ] vm = test_stub.create_vm(image_name="ttylinux", vm_name="test-vm", disk_offering_uuids=disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid) avail_cap = ps.availableCapacity total_cap = ps.totalCapacity vm_ops.stop_vm(vm_uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid, image_uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 120): test_util.test_fail( 'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after) avail_cap1 = ps.availableCapacity total_cap1 = ps.totalCapacity if total_cap != total_cap1: test_util.test_fail( 'Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid, total_cap, total_cap1)) if avail_cap <= avail_cap1: test_util.test_fail( 'Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s' % (image_uuid, avail_cap, avail_cap1)) vm_ops.stop_vm(vm_uuid) image_tiny_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid vm_ops.change_vm_image(vm_uuid, image_tiny_uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 120): test_util.test_fail( 'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_tiny = [] data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_tiny: data_volumes_after_uuids_tiny.append(data_volume.uuid) if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after_tiny != l3network_uuid_after: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after_tiny != primarystorage_uuid_after: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid( primarystorage_uuid_after_tiny) avail_cap2 = ps.availableCapacity total_cap2 = ps.totalCapacity if total_cap2 != total_cap1: test_util.test_fail( 'Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid, total_cap1, total_cap2)) if avail_cap2 <= avail_cap1: test_util.test_fail( 'Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s' % (image_uuid, avail_cap1, avail_cap2)) test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) vm.expunge() test_util.test_pass('Change Vm Image Test Success')
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # 4 login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] image_option = test_util.ImageOption() image_option.set_name('fake_image') image_option.set_description('fake image') image_option.set_format('raw') image_option.set_mediaType('RootVolumeTemplate') image_option.set_backup_storage_uuid_list([bs.uuid]) image_option.url = "http://fake/fake.raw" image_option.set_session_uuid(project_login_uuid) image_uuid = img_ops.add_image(image_option).uuid img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'disable', session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'enable', session_uuid=project_login_uuid) if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: img_ops.export_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.delete_exported_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid) img_ops.delete_image(image_uuid, session_uuid=project_login_uuid) img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid) # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid acc_ops.share_resources([project_linked_account_uuid], [disk_offering_uuid]) volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_name('data_volume_project_management') volume_option.set_session_uuid(project_login_uuid) data_volume = vol_ops.create_volume_from_offering(volume_option) vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid vol_ops.attach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.detach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid) # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # L2 related ops: create, delete zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid try: l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid) test_util.test_fail("Expect exception: project admin not allowed to create Novlan L2 except vxlan") except: pass try: l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid) test_util.test_fail("Expect exception: project admin not allowed to create vlan L2 except vxlan") except: pass #net_ops.delete_l2(l2.uuid, session_uuid=project_login_uuid) # L3 related ops: # network service ops: # zwatch ops: # scheduler ops: # certificate # 11 delete acc_ops.logout(project_login_uuid) iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) iam2_ops.delete_iam2_virtual_id(project_admin_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def stop(self, session_uuid = None): self.vm = vm_ops.stop_vm(self.vm.uuid, session_uuid) super(ZstackTestVm, self).stop()
def stop(self): self.vm = vm_ops.stop_vm(self.vm.uuid) super(ZstackTestVm, self).stop()
def test(): global vcenter_uuid1 global vcenter_uuid2 global mevoco1_ip global mevoco2_ip vcenter1_name = os.environ['vcenter2_name'] vcenter1_domain_name = os.environ['vcenter2_ip'] vcenter1_username = os.environ['vcenter2_domain_name'] vcenter1_password = os.environ['vcenter2_password'] vm_name = os.environ['vcenter2_sync_vm_start_stop'] mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['serverIp2'] os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid) vcenter_uuid1 = inv.uuid if vcenter_uuid1 == None: test_util.test_fail("vcenter_uuid is None") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid) vcenter_uuid2 = inv.uuid if vcenter_uuid2 == None: test_util.test_fail("vcenter_uuid is None") #start vm in remote and check test_util.test_logger("start vm for sync test") vm_cond = res_ops.gen_query_conditions("name", '=', vm_name) vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("remote woodpecker vm uuid is null") elif vm_uuid and vm_state != "running": print "#%s#" % vm_state vm_ops.start_vm(vm_uuid) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("local woodpecker vm uuid is null") elif vm_state != "running": test_util.test_fail("vcenter sync vm start failed.") #stop vm in remote and check test_util.test_logger("stop vm for sync test") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("remote woodpecker vm uuid is null") elif vm_uuid and vm_state != "stopped": vm_ops.stop_vm(vm_uuid) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("local woodpecker vm uuid is null") elif vm_state != "stopped": test_util.test_fail("vcenter sync vm stop failed.") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if vcenter_uuid2: vct_ops.delete_vcenter(vcenter_uuid2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if vcenter_uuid1: vct_ops.delete_vcenter(vcenter_uuid1) test_util.test_pass("vcenter sync start and stop vm test passed.")
def test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) global vm test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] vm = test_stub.create_vm(image_name = "ttylinux",vm_name="test-vm",disk_offering_uuids = disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid) avail_cap = ps.availableCapacity total_cap = ps.totalCapacity vm_ops.stop_vm(vm_uuid) image = test_lib.lib_get_image_by_name("image_for_sg_test") image_uuid = image.uuid image_tiny = test_lib.lib_get_image_by_name("ttylinux") image_tiny_uuid = image_tiny.uuid change_size = (image.size-image_tiny.size)/10 vm_ops.change_vm_image(vm_uuid,image_uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',180): test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after) avail_cap1 = ps.availableCapacity total_cap1 = ps.totalCapacity if total_cap != total_cap1: test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap,total_cap1)) if not (avail_cap1-1) <= (avail_cap - change_size) <= (avail_cap1+1): test_util.test_fail('Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap,avail_cap1)) vm_ops.stop_vm(vm_uuid) image_tiny_uuid = image_tiny.uuid vm_ops.change_vm_image(vm_uuid,image_tiny_uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',180): test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_tiny = [] data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_tiny: data_volumes_after_uuids_tiny.append(data_volume.uuid) if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after_tiny != l3network_uuid_after: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after_tiny != primarystorage_uuid_after: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after_tiny) avail_cap2 = ps.availableCapacity total_cap2 = ps.totalCapacity if total_cap2 != total_cap1: test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_tiny_uuid,total_cap1,total_cap2)) if not (change_size-1)<=(avail_cap2 - avail_cap1)<= (change_size+1): test_util.test_fail('Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s' % (image_tiny_uuid,avail_cap1,avail_cap2)) test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) vm.expunge() test_util.test_pass('Change Vm Image Test Success')
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(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for ps in primary_storage_list: if ps.type == "SharedBlock": test_util.test_skip('SharedBlock primary storage does not support overProvision') con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) global vm test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork3").uuid image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-nxs",disk_offering_uuids = disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid) avail_cap = ps.availableCapacity total_cap = ps.totalCapacity vm_ops.stop_vm(vm_uuid) vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) #if vr.state == 'Stopped': else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',120): test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if set(l3network_uuid_after) != set(last_l3network_uuid): test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after) avail_cap1 = ps.availableCapacity total_cap1 = ps.totalCapacity if total_cap != total_cap1: test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap,total_cap1)) if avail_cap <= avail_cap1: test_util.test_fail('Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap,avail_cap1)) vm_ops.stop_vm(vm_uuid) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_tiny_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid vm_ops.change_vm_image(vm_uuid,image_tiny_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) #if vr.state == 'Stopped': else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',120): test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_tiny = [] data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_tiny: data_volumes_after_uuids_tiny.append(data_volume.uuid) if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if set(l3network_uuid_after_tiny) != set(l3network_uuid_after_tiny): test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != primarystorage_uuid_after_tiny: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after_tiny) avail_cap2 = ps.availableCapacity total_cap2 = ps.totalCapacity if total_cap2 != total_cap1: test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap1,total_cap2)) if avail_cap2 <= avail_cap1: test_util.test_fail('Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap1,avail_cap2)) test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) test_util.test_pass('Change Vm Image Test Success')
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 stop_vm(vm_uuid): try: vm_ops.stop_vm(vm_uuid, None, session_uuid) except: exc_info.append(sys.exc_info())
def test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco', 'overProvisioning.primaryStorage', 10) 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") test_lib.lib_create_disk_offering(diskSize=1099511627776, name="1T") disk_offering_uuids = [ test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid, test_lib.lib_get_disk_offering_by_name("root-disk").uuid, test_lib.lib_get_disk_offering_by_name("1T").uuid ] #create vm with 3 data volumes vm = test_stub.create_vm(image_name="ttylinux", vm_name="test-vm", disk_offering_uuids=disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) image_option = test_util.ImageOption() image_option.set_name('windows_for_test') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_platform('windows') image_option.set_url( 'http://172.20.1.16:7480/diskimages/windows-telnet.qcow2') image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(1800 * 1000) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() image_windows_uuid = test_lib.lib_get_image_by_name( "windows_for_test").uuid vm_ops.change_vm_image(vm_uuid, image_windows_uuid) vm_ops.start_vm(vm_uuid) vm.update() vm_ip = vm.get_vm().vmNics[0].ip #check whether the windows vm is running successfully if not test_lib.lib_wait_target_up(vm_ip, '23', 1200): test_util.test_fail( 'vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.stop_vm(vm_uuid) vm_ops.change_vm_image(vm_uuid, image_linux_uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip, '22', 120): test_util.test_fail( 'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != primarystorage_uuid_after_linux: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) vm.expunge() img_ops.delete_image(image_windows_uuid) img_ops.expunge_image(image_windows_uuid) test_util.test_pass('Change Vm Image Test Success')
def stop_vm(vm_uuid): try: vm_ops.stop_vm(vm_uuid, None, session_uuid) except: exc_info.append(sys.exc_info())
def stop(self): self.vm = vm_ops.stop_vm(self.vm.uuid) super(ZstackTestVm, self).stop()