def test(): global vcenter_uuid, vm_uuid 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'] #ova_image_name = os.environ['vcenter2_template_exist'] vm_name = os.environ['vcenter2_no_nic_vm'] network_pattern1 = os.environ['vcenter2_network_pattern1'] 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_uuid = inv.uuid if vcenter_uuid == None: test_util.test_fail("vcenter_uuid is None") #vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-start-stop-test', image_name = ova_image_name, l3_name = network_pattern1) 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) if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running') vm.stop() if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stopped') elif vm_uuid and vm_state == "running": print "#%s#" % vm_state vm.stop() if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stopped') vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running') vm_ops.destroy_vm(vm_uuid) vm_ops.expunge_vm(vm_uuid) vct_ops.delete_vcenter(vcenter_uuid) test_util.test_pass("vm start and stop of vcenter test passed.")
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.detach(vm.get_vm().uuid) #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) time.sleep(5) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global vm global schd_job global schd_trigger vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) vm.check() start_date = int(time.time()) schd_job = schd_ops.create_scheduler_job('simple_reboot_vm_scheduler', 'simple_reboot_vm_scheduler', vm.get_vm().uuid, 'rebootVm', None) schd_trigger = schd_ops.create_scheduler_trigger('simple_reboot_vm_scheduler', start_date+60, None, 120, 'simple') schd_ops.add_scheduler_job_to_trigger(schd_trigger.uuid, schd_job.uuid) #schd = vm_ops.reboot_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_reboot_vm_scheduler', start_date+60, 120) test_stub.sleep_util(start_date+58) if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 120): test_util.test_fail('VM: %s is not reboot in 120 seconds. Fail to reboot it with scheduler. ' % vm.get_vm().uuid) for i in range(0, 58): if test_lib.lib_find_in_local_management_server_log(start_date+i, '[msg received]: org.zstack.header.vm.RebootVmInstanceMsg {"org.zstack.header.vm.RebootVmInstanceMsg', vm.get_vm().uuid): test_util.test_fail('VM is expected to reboot start from %s' (start_date+60)) test_stub.sleep_util(start_date+59) if not test_lib.lib_find_in_local_management_server_log(start_date+60, '[msg received]: org.zstack.header.vm.RebootVmInstanceMsg {"org.zstack.header.vm.RebootVmInstanceMsg', vm.get_vm().uuid): test_util.test_fail('VM is expected to reboot start from %s' % (start_date+60)) schd_ops.del_scheduler_job(schd_job.uuid) schd_ops.del_scheduler_trigger(schd_trigger.uuid) vm.destroy() test_util.test_pass('Create Simple VM Reboot Scheduler Success')
def test(): global vm global schd vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) vm.check() start_date = int(time.time()) schd = vm_ops.reboot_vm_scheduler(vm.get_vm().uuid, 'simple', 'simple_reboot_vm_scheduler', start_date + 60, 120) test_stub.sleep_util(start_date + 58) for i in range(0, 58): if test_lib.lib_find_in_local_management_server_log( start_date + i, '[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 + 60)) test_stub.sleep_util(start_date + 59) if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 120): test_util.test_fail( 'VM: %s is not reboot in 120 seconds. Fail to reboot it with scheduler. ' % vm.get_vm().uuid) if not test_lib.lib_find_in_local_management_server_log( start_date + 60, '[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 + 60)) schd_ops.delete_scheduler(schd.uuid) vm.destroy() test_util.test_pass('Create Simple VM Reboot Scheduler Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") if bss[0].type != inventory.CEPH_BACKUP_STORAGE_TYPE: test_util.test_skip("not find available imagestore or ceph backup storage. Skip test") l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() test_util.test_pass('PS maintain mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system("echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() vm.check() #vm.expunge() #vm.check() test_util.test_pass('PS maintain mode Test Success')
def test(): global vcenter_uuid, vm_uuid 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'] #ova_image_name = os.environ['vcenter2_template_exist'] vm_name = os.environ['vcenter2_no_nic_vm'] network_pattern1 = os.environ['vcenter2_network_pattern1'] 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_uuid = inv.uuid if vcenter_uuid == None: test_util.test_fail("vcenter_uuid is None") #vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-start-stop-test', image_name = ova_image_name, l3_name = network_pattern1) 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) if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running') vm.stop() if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stopped') elif vm_uuid and vm_state == "running": print "#%s#" % vm_state vm.stop() if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stopped') vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running') vm_ops.destroy_vm(vm_uuid) vm_ops.expunge_vm(vm_uuid) vct_ops.delete_vcenter(vcenter_uuid) test_util.test_pass("vm start and stop of vcenter test passed.")
def test(): global vm global test_host global ps_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') for i in range(0, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0].state == "Running": break time.sleep(1) else: test_util.test_fail( "vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass( 'Test checking VM ha and none status when force stop vm Success.')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.delete() volume.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.recover() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global vm global test_host global ps_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') for i in range(0, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass('Test checking VM ha and none status when force stop vm Success.')
def test(): test_util.test_dsc('Create test vm1 and check') vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm1) test_util.test_dsc('Create test vm2 and check') vm2 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm2) vm1.check() vm2.check() vrs = test_lib.lib_find_vr_by_vm(vm1.vm) if len(vrs) != 1: test_util.test_logger( 'more than 1 VR are found for vm1: %s. Will test the 1st one: %s.' % (vm1.vm.uuid, vr.uuid)) vr = vrs[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) if not test_lib.lib_check_testagent_status(vr_mgmt_ip): test_util.test_fail( 'vr: %s is not reachable, since can not reach its test agent. Give up test and test failure. ' % vr.uuid) test_lib.lib_install_testagent_to_vr_with_vr_vm(vr) #Need to put the vr restart into thread. Since vr reboot API is a sync API. thread = threading.Thread(target=vm_ops.reboot_vm, args=(vr.uuid, )) thread.start() #check vr vr service port if not test_lib.lib_wait_target_down(vr_mgmt_ip, '7272', 120): test_util.test_fail( 'vr: %s is not shutdown in 120 seconds. Fail to reboot it. ' % vr.uuid) if not test_lib.lib_wait_target_up(vr_mgmt_ip, '7272', 120): test_util.test_fail( 'vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr.uuid) #avoid of possible apt conflicting between install testagent and appliancevm #time.sleep(60) vm1.check() vm2.check() test_util.test_dsc('Ping from vm1 to vm2.') test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip) vm1.destroy() vm2.destroy() test_util.test_pass( 'Create vlan VirtualRouter VM (and reboot VR after VM created) Test with snat ping between two VMs Success' )
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) test_stub.ensure_pss_connected() vrs = test_lib.lib_get_all_vrs() for vr in vrs: vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid) vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0] if vr_inv.state == 'Stopped': vm_ops.start_vm(vr.uuid) else: test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360) for _ in xrange(100): if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running': time.sleep(3) else: break vm.start() vm.check() vm.destroy() test_util.test_pass('PS maintain mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm) backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) for bs in backup_storage_list: if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: break else: vm.destroy() test_util.test_skip('Not find ceph type backup storage.') l3_1_name = os.environ.get('l3VlanNetwork3') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to disable state') vm.set_state(vm_header.STOPPED) vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'Enabled') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_util.test_pass('PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm) backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) for bs in backup_storage_list: if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: break else: vm.destroy() test_util.test_skip('Not find ceph type backup storage.') l3_1_name = os.environ.get('l3VlanNetwork3') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to disable state') vm.set_state(vm_header.STOPPED) vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'Enabled') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_util.test_pass('PS disable mode Test Success')
def test(): test_util.test_dsc('Create test vm1 and check') vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm1) test_util.test_dsc('Create test vm2 and check') vm2 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm2) vm1.check() vm2.check() vrs = test_lib.lib_find_vr_by_vm(vm1.vm) if len(vrs) != 1: test_util.test_logger('more than 1 VR are found for vm1: %s. Will test the 1st one: %s.' % (vm1.vm.uuid, vr.uuid)) vr = vrs[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) if not test_lib.lib_check_testagent_status(vr_mgmt_ip): test_util.test_fail('vr: %s is not reachable, since can not reach its test agent. Give up test and test failure. ' % vr.uuid) test_lib.lib_install_testagent_to_vr_with_vr_vm(vr) #Need to put the vr restart into thread. Since vr reboot API is a sync API. thread = threading.Thread(target=vm_ops.reboot_vm, args=(vr.uuid,)) thread.start() #check vr vr service port if not test_lib.lib_wait_target_down(vr_mgmt_ip, '7272', 60): test_util.test_fail('vr: %s is not shutdown in 60 seconds. Fail to reboot it. ' % vr.uuid) if not test_lib.lib_wait_target_up(vr_mgmt_ip, '7272', 120): test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr.uuid) #avoid of possible apt conflicting between install testagent and appliancevm #time.sleep(60) vm1.check() vm2.check() test_util.test_dsc('Ping from vm1 to vm2.') test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip) vm1.destroy() vm2.destroy() test_util.test_pass('Create vlan VirtualRouter VM (and reboot VR after VM created) Test with snat ping between two VMs Success')
def test(): allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) flavor = case_flavor[os.environ.get('CASE_FLAVOR')] test_util.test_dsc('Create original vm') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm1) test_util.test_dsc('Create Sharable Data Volume obj.') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_name('sharable volume') volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.attach(vm) if flavor['vm_running'] == False: vm.stop() test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, 22) if flavor['vm_running'] == True: allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_util.test_dsc('create data volume snapshot') snapshots_data = test_obj_dict.get_volume_snapshot(volume.get_volume().uuid) snapshots_data.set_utility_vm(vm1) snapshots_data.create_snapshot('create_data_snapshot1') snapshots_data.check() snapshot1 = snapshots_data.get_current_snapshot() snapshots_data.create_snapshot('create_data_snapshot2') snapshots_data.check() #check data snapshots if flavor['vm_running'] == True: vm.stop() test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, 22) snapshots_data.use_snapshot(snapshot1) snapshots_data.check() vm.start() test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22) else: snapshots_data.use_snapshot(snapshot1) snapshots_data.check() snapshots_data.create_snapshot('create_snapshot1.1.1') snapshot2 = snapshots_data.get_current_snapshot() snapshots_data.check() snapshots_data.create_snapshot('create_snapshot1.2.1') snapshots_data.check() snapshots_data.delete_snapshot(snapshot2) snapshots_data.check() #check delete snapshot1 sp = snapshots_data.get_current_snapshot() snapshots_data.delete_snapshot(snapshot1) snapshots_data.check() if flavor['vm_running'] == False: vm.start() test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22) import tempfile with tempfile.NamedTemporaryFile() as script: script.write(''' device=/dev/`ls -ltr --file-type /dev | awk '$4~/disk/ {print $NF}' | grep -v '[[:digit:]]' | tail -1`1 mkdir -p %s >/dev/null mount $device %s >/dev/null mkdir -p %s >/dev/null checking_result='' ls %s umount %s >/dev/null ''' % (test_lib.WOODPECKER_MOUNT_POINT, \ test_lib.WOODPECKER_MOUNT_POINT, \ zstack_sp_header.checking_point_folder, \ zstack_sp_header.checking_point_folder, \ test_lib.WOODPECKER_MOUNT_POINT)) script.flush() rsp = test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script.name) if rsp: result_list = rsp.result.split() temp_checking_list = list(result_list) if len(temp_checking_list) == 3: test_util.test_logger('Checker result: snapshot: %s integrity checking pass' % sp.get_snapshot().uuid) else: test_util.test_fail('Checker fail.') else: test_util.test_fail('Cmd fail.') test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test sharable volume snapshot success.')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.delete() volume.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.recover() volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) test_stub.ensure_pss_connected() vrs = test_lib.lib_get_all_vrs() time.sleep(5) for vr in vrs: vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid) vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0] if vr_inv.state == 'Stopped': vm_ops.start_vm(vr.uuid) else: test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360) for _ in xrange(100): if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running': time.sleep(3) else: break vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system( "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Detach ISO to VM') img_ops.detach_iso(vm.vm.uuid) #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() #vm.check() #vm.expunge() vm.check() test_util.test_pass('PS maintain mode Test Success')
def test(): global vr_type test_util.test_dsc('Create test vm1 and check') vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm1) test_util.test_dsc('Create test vm2 and check') vm2 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm2) vm1.check() vm2.check() vr_type = res_ops.query_resource( res_ops.VIRTUALROUTER_VM)[0].applianceVmType test_util.test_logger("vr type is %s" % (vr_type)) #vrs = test_lib.lib_find_vr_by_vm(vm1.vm) vrs = test_lib.lib_find_flat_dhcp_vr_by_vm(vm1.vm) vr = vrs[0] if len(vrs) != 1: test_util.test_logger( 'more than 1 VR are found for vm1: %s. Will test the 1st one: %s.' % (vm1.vm.uuid, vr.uuid)) vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) vr_reboot_record_org = check_vr_reboot_record_line(vr_mgmt_ip) test_lib.lib_install_testagent_to_vr_with_vr_vm(vr) if not test_lib.lib_check_testagent_status(vr_mgmt_ip): test_util.test_fail( 'vr: %s is not reachable, since can not reach its test agent. Give up test and test failure. ' % vr.uuid) #Need to put the vr restart into thread. Since vr reboot API is a sync API. thread = threading.Thread(target=vm_ops.reboot_vm, args=(vr.uuid, )) thread.start() #check vr vr service port cond = res_ops.gen_query_conditions('resourceUuid', '=', vr.uuid) cond = res_ops.gen_query_conditions('tag', '=', "ha::NeverStop", cond) if res_ops.query_resource(res_ops.SYSTEM_TAG, cond) and res_ops.query_resource( res_ops.SYSTEM_TAG, cond)[0]: time.sleep(30) elif not test_lib.lib_wait_target_down(vr_mgmt_ip, '7272', 120): test_util.test_fail( 'vr: %s is not shutdown in 120 seconds. Fail to reboot it. ' % vr.uuid) if not test_lib.lib_wait_target_up(vr_mgmt_ip, '7272', 120): test_util.test_fail( 'vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr.uuid) vr_reboot_record_new = check_vr_reboot_record_line(vr_mgmt_ip) if vr_reboot_record_new == vr_reboot_record_org: test_util.test_fail("not find vr reboot record increased.") #avoid of possible apt conflicting between install testagent and appliancevm #time.sleep(60) vm1.check() vm2.check() test_util.test_dsc('Ping from vm1 to vm2.') test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip) vm1.destroy() vm2.destroy() test_util.test_pass( 'Create vlan VirtualRouter VM (and reboot VR after VM created) Test with snat ping between two VMs Success' )
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) command = "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % os.environ.get('zstackInstallPath') test_lib.lib_execute_ssh_cmd(os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], 'root', 'password', command) img_option.set_url('http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'])) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) test_stub.ensure_hosts_connected(120) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid) vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0] if vr_inv.state == 'Stopped': vm_ops.start_vm(vr.uuid) else: test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360) for _ in xrange(100): if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running': time.sleep(3) else: break vm.start() vm.check() vm.destroy() vm.check() #vm.expunge() #vm.check() test_util.test_pass('PS maintain mode Test Success')