def test(): imagestore_backup_storage = test_lib.lib_get_image_store_backup_storage() if not imagestore_backup_storage: test_util.test_skip('Not find image store type backup storage.') img_option = test_util.ImageOption() img_option.set_name('iso') root_disk_uuid = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')).uuid bs_uuid = imagestore_backup_storage.uuid img_option.set_backup_storage_uuid_list([bs_uuid]) command = "command -v genisoimage" result = test_lib.lib_execute_ssh_cmd(os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], 'root', 'password', command) if not result: command = "yum -y install genisoimage --disablerepo=* --enablerepo=zstack-local" test_lib.lib_execute_ssh_cmd(os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], 'root', 'password', command) command = "genisoimage -o %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso /tmp/" % 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) image_url = image.export() image.delete_exported_image() test_lib.lib_robot_cleanup(test_obj_dict) if image_url.endswith('.iso'): test_util.test_pass('Export ISO Image Test Success') else: test_util.test_fail('Export ISO Image Test Fail, exported ISO image ends with %s' % (image_url.split('.')[-1]))
def test(): imagestore_backup_storage = test_lib.lib_get_image_store_backup_storage() if not imagestore_backup_storage: test_util.test_skip('Not find image store type backup storage.') img_option = test_util.ImageOption() img_option.set_name('iso') root_disk_uuid = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')).uuid bs_uuid = imagestore_backup_storage.uuid img_option.set_backup_storage_uuid_list([bs_uuid]) os.system("genisoimage -o %s/apache-tomcat/webapps/zstack/static/test.iso /tmp/" % (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) image_url = image.export() image.delete_exported_image() test_lib.lib_robot_cleanup(test_obj_dict) if image_url.endswith('.iso'): test_util.test_pass('Export ISO Image Test Success') else: test_util.test_fail('Export ISO Image Test Fail, exported ISO image ends with %s' % (image_url.split('.')[-1]))
def create_vm_with_iso(vm_creation_option=None, session_uuid=None): img_option = test_util.ImageOption() img_option.set_name('iso') root_disk_uuid = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')).uuid bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], session_uuid)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) if os.path.exists("%s/apache-tomcat/webapps/zstack/static/zstack-repo/" % (os.environ.get('zstackInstallPath'))): os.system( "genisoimage -o %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso /tmp/" % (os.environ.get('zstackInstallPath'))) img_option.set_url( 'http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (os.environ.get('node1Ip'))) else: os.system( "genisoimage -o %s/apache-tomcat/webapps/zstack/static/test.iso /tmp/" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_uuid = img_ops.add_iso_template(img_option).uuid return create_vm(vm_creation_option, None, root_disk_uuid, image_uuid, session_uuid=session_uuid)
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 create_vm_with_iso(vm_name, l3_name, session_uuid=None): img_option = test_util.ImageOption() img_option.set_name('fake_iso') root_disk_uuid = test_lib.lib_get_disk_offering_by_name( os.environ.get('mediumDiskOfferingName')).uuid bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], \ session_uuid)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName img_option.set_url('http://%s:8080/zstack/static/zstack-dvd/ks.cfg' % (mn_ip)) image_uuid = img_ops.add_iso_template(img_option).uuid vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_root_disk_uuid(root_disk_uuid) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name(vm_name) vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() return vm
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, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) 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') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() vm.check() #vm.expunge() vm.check() test_util.test_pass('PS disable mode Test Success')
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) mn = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0] cmd = "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % (os.environ.get('zstackInstallPath')) if os.system("ip r | grep %s" % (mn.hostName)) == 0: os.system(cmd) else: for host in test_lib.lib_get_all_hosts_from_plan(): test_util.test_logger("host.managementIp_: %s" %(host.managementIp_)) test_util.test_logger("mn.hostName: %s" %(mn.hostName)) test_util.test_logger("anotherIp: %s" %(test_stub.get_another_ip_of_host(host.managementIp_, host.username_, host.password_))) if host.managementIp_ == mn.hostName or test_stub.get_another_ip_of_host(host.managementIp_, host.username_, host.password_) == mn.hostName: out = test_lib.lib_execute_ssh_cmd(host.managementIp_, host.username_, host.password_, cmd, timeout=30) img_option.set_url('http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (mn.hostName)) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def test(): global vm vm = test_stub.create_vr_vm('migrate_vm', 'imageName_net', 'l3VlanNetwork2') vm.check() vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') #cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) testIsoUrl = os.environ.get('testIsoUrl') img_option.set_url(testIsoUrl) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) time.sleep(5) cmd = "mount /dev/sr0 /mnt" exec_cmd_in_vm(vm, cmd, "Failed to mount /dev/sr0 /mnt.") test_util.test_dsc('Migrate VM') test_stub.migrate_vm_to_random_host(vm) vm.check() cmd = "umount /mnt" exec_cmd_in_vm(vm, cmd, "Failed to umount /mnt.") img_ops.detach_iso(vm_uuid) img_ops.attach_iso(iso_uuid, vm_uuid) time.sleep(5) cmd = "mount /dev/sr0 /mnt" exec_cmd_in_vm(vm, cmd, "Failed to mount /dev/sr0 /mnt.") cmd = "cat /mnt/Licenses.txt" exec_cmd_in_vm(vm, cmd, "Licenses.txt doesn't exist.") img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate VM Test Success When Attach ISO')
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system( "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def test(): #skip ceph in c74 cmd = "cat /etc/redhat-release | grep '7.4'" mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName rsp = test_lib.lib_execute_ssh_cmd(mn_ip, 'root', 'password', cmd, 180) if rsp != False: ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == 'Ceph': test_util.test_skip('cannot hotplug iso to the vm in ceph,it is a libvirt bug:https://bugzilla.redhat.com/show_bug.cgi?id=1541702.') global vm vm = test_stub.create_vr_vm('migrate_vm', 'imageName_s', 'l3VlanNetwork2') vm.check() ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on localstorage PS') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') #cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) testIsoUrl = os.environ.get('testIsoUrl') img_option.set_url(testIsoUrl) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') test_stub.migrate_vm_to_random_host(vm) vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate VM Test Success When Attach ISO')
def create_vm_with_iso(vm_creation_option = None, session_uuid = None): img_option = test_util.ImageOption() img_option.set_name('iso') root_disk_uuid = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')).uuid bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], \ session_uuid)[0].uuid 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_uuid = img_ops.add_iso_template(img_option).uuid return create_vm(vm_creation_option, None, root_disk_uuid, image_uuid, \ session_uuid = session_uuid)
def add_iso_image(self): bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0].uuid images = res_ops.query_resource(res_ops.IMAGE) image_names = [i.name for i in images] if self.iso[-1]['name'] not in image_names: for iso in self.iso: img_option = test_util.ImageOption() img_option.set_name(iso['name']) img_option.set_backup_storage_uuid_list([bs_uuid]) testIsoUrl = iso['url'] img_option.set_url(testIsoUrl) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option)
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system("echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def test(): imagestore_backup_storage = test_lib.lib_get_image_store_backup_storage() if not imagestore_backup_storage: test_util.test_skip('Not find image store type backup storage.') img_option = test_util.ImageOption() img_option.set_name('iso') root_disk_uuid = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')).uuid bs_uuid = imagestore_backup_storage.uuid img_option.set_backup_storage_uuid_list([bs_uuid]) command = "command -v genisoimage" result = test_lib.lib_execute_ssh_cmd( os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], 'root', 'password', command) if not result: command = "yum -y install genisoimage" test_lib.lib_execute_ssh_cmd( os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], 'root', 'password', command) command = "genisoimage -o %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso /tmp/" % 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) image_url = image.export() image.delete_exported_image() test_lib.lib_robot_cleanup(test_obj_dict) if image_url.endswith('.iso'): test_util.test_pass('Export ISO Image Test Success') else: test_util.test_fail( 'Export ISO Image Test Fail, exported ISO image ends with %s' % (image_url.split('.')[-1]))
def test(): global vm vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') vm_inv = vm.get_vm() vm_uuid = vm_inv.uuid test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions('name', '=', 'sftp') bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) mn = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0] cmd = "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % ( os.environ.get('zstackInstallPath')) if os.system("ip r | grep %s" % (mn.hostName)) == 0: os.system(cmd) else: for host in test_lib.lib_get_all_hosts_from_plan(): test_util.test_logger("host.managementIp_: %s" % (host.managementIp_)) test_util.test_logger("mn.hostName: %s" % (mn.hostName)) test_util.test_logger( "anotherIp: %s" % (test_stub.get_another_ip_of_host( host.managementIp_, host.username_, host.password_))) if host.managementIp_ == mn.hostName or test_stub.get_another_ip_of_host( host.managementIp_, host.username_, host.password_) == mn.hostName: out = test_lib.lib_execute_ssh_cmd(host.managementIp_, host.username_, host.password_, cmd, timeout=30) img_option.set_url( 'http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (mn.hostName)) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm_uuid) test_util.test_dsc('Migrate VM') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() img_ops.detach_iso(vm_uuid) image.delete() image.expunge() test_obj_dict.rm_image(image) vm.destroy() test_util.test_pass('Migrate Stopped VM Test Success When Attach ISO')
def test(): global ssh_timeout data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url('http://172.20.1.15:7480/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #test_lib.lib_wait_target_up(vm_ip, '22', 2400) #vm.check() #cmd ='[ -e /root ] && echo yes || echo no' cmd ='[ -e /root ]' #ssh_num = 0 #ssh_ok = 0 #while ssh_num <= 5 and ssh_ok == 0 : # rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) # if rsp == False: # time.sleep(30) # else: # ssh_ok = 1 # break # ssh_num = ssh_num + 1 #if ssh_ok == 0: # test_util.test_fail('fail to ssh to VM') ssh_timeout = test_lib.SSH_TIMEOUT test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("iso has not been failed to installed.") test_lib.SSH_TIMEOUT = ssh_timeout vm.destroy() test_obj_dict.rm_vm(vm) image.delete() test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation Test Success')
def test(): global image global test_obj_dict #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip("skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 1024*1024*1024 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('isoForVmUrl')) image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #delete iso image.delete() test_obj_dict.rm_image(image) #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(vm, "VM_TEST_STATE") vm.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): #skip ceph in c74 cmd = "cat /etc/redhat-release | grep '7.4'" mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName rsp = test_lib.lib_execute_ssh_cmd(mn_ip, 'root', 'password', cmd, 180) if rsp != False: ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == 'Ceph': test_util.test_skip('cannot hotplug iso to the vm in ceph,it is a libvirt bug:https://bugzilla.redhat.com/show_bug.cgi?id=1541702.') 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) 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) img_ops.detach_iso(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, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() 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) vm_ops.reconnect_vr(vr_uuid) vm.destroy() #vm.check() #vm.expunge() vm.check() test_util.test_pass('PS disable mode Test Success')
def test(): data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 cpuSpeed = 16 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_cpuSpeed(cpuSpeed) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url('http://172.20.1.15:7480/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) l3_name = os.environ.get('l3PublicNetworkName') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid) test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip test_lib.lib_wait_target_up(vm_ip, '22', 2400) cmd ='[ -e /root ] && echo yes || echo no' ssh_num = 0 ssh_ok = 0 while ssh_num <= 5 and ssh_ok == 0 : rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: time.sleep(30) else: ssh_ok = 1 break ssh_num = ssh_num + 1 if ssh_ok == 0: test_util.test_fail('fail to ssh to VM') vm.check() vm.destroy() test_obj_dict.rm_vm(vm) image.delete() test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation Test Success')
def test(): #skip ceph in c74 cmd = "cat /etc/redhat-release | grep '7.4'" mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName rsp = test_lib.lib_execute_ssh_cmd(mn_ip, 'root', 'password', cmd, 180) if rsp != False: ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == 'Ceph': test_util.test_skip('cannot hotplug iso to the vm in ceph,it is a libvirt bug:https://bugzilla.redhat.com/show_bug.cgi?id=1541702.') global image global test_obj_dict allow_bs_list = [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE, inventory.CEPH_BACKUP_STORAGE_TYPE] test_lib.skip_test_when_bs_type_not_in_list(allow_bs_list) allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint'] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip("skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 1024*1024*1024 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('isoForVmUrl')) image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #clone vm cloned_vm_name = ['cloned_vm_name'] cloned_vm_obj = vm.clone(cloned_vm_name)[0] test_obj_dict.add_vm(cloned_vm_obj) #delete iso image.delete() test_obj_dict.rm_image(image) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #create image by vm root volume cloned_vm_img_name = "cloned_vm_image1" img_option2 = test_util.ImageOption() img_option2.set_backup_storage_uuid_list([bs_uuid]) img_option2.set_root_volume_uuid(cloned_vm_obj.vm.rootVolumeUuid) img_option2.set_name(cloned_vm_img_name) image1 = test_image.ZstackTestImage() image1.set_creation_option(img_option2) image1.create() image1.check() test_obj_dict.add_image(image1) bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE) if inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE == bs_list[0] and len(bs_list) == 1 : #export image image1.export() #create vm vm2 = test_stub.create_vm('image-vm', cloned_vm_img_name, l3_name) #delete image image1.delete() test_obj_dict.rm_image(image1) #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") #expunge image image1.expunge() #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") vm.destroy() vm2.destroy() cloned_vm_obj.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): global ssh_timeout data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) cond = res_ops.gen_query_conditions('name', '=', 'image-iso') iso_image = res_ops.query_resource(res_ops.IMAGE, cond) if not iso_image: img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('imageServer')+'/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) else: image_uuid = iso_image[0].uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid, system_tags=["cdroms::%s::Empty::Empty" % (image_uuid)]) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #test_lib.lib_wait_target_up(vm_ip, '22', 2400) #vm.check() #cmd ='[ -e /root ] && echo yes || echo no' cmd ='[ -e /root ]' #ssh_num = 0 #ssh_ok = 0 #while ssh_num <= 5 and ssh_ok == 0 : # rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) # if rsp == False: # time.sleep(30) # else: # ssh_ok = 1 # break # ssh_num = ssh_num + 1 #if ssh_ok == 0: # test_util.test_fail('fail to ssh to VM') ssh_timeout = test_lib.SSH_TIMEOUT test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("iso has not been failed to installed.") cmd_cdrom = 'ls /dev/ | grep sr | wc -l' cdroms = test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd_cdrom) assert str(cdroms).strip() == '3' test_lib.SSH_TIMEOUT = ssh_timeout vm.destroy() test_obj_dict.rm_vm(vm) # image.delete() # test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation Test Success')
def test(): global image global test_obj_dict #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip( "skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 1024 * 1024 * 1024 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url(os.environ.get('isoForVmUrl')) image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #delete iso image.delete() test_obj_dict.rm_image(image) #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(vm, "VM_TEST_REIMAGE") vm.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): global image global test_obj_dict allow_bs_list = [ inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE, inventory.CEPH_BACKUP_STORAGE_TYPE, inventory.SFTP_BACKUP_STORAGE_TYPE ] test_lib.skip_test_when_bs_type_not_in_list(allow_bs_list) allow_ps_list = [ inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint' ] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) #run condition hosts = res_ops.query_resource(res_ops.HOST) if len(hosts) <= 1: test_util.test_skip( "skip for host_num is not satisfy condition host_num>1") bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) #create disk offering data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) #create instance offering cpuNum = 2 memorySize = 2147483648 name = 'iso-vm-offering' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) #add iso img_option = test_util.ImageOption() img_option.set_name('iso1') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url( 'http://172.20.1.15:7480/iso/CentOS-x86_64-7.2-Minimal.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #create vm by iso l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'iso-vm', root_disk_uuid, new_offering.uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_obj_dict.add_vm(vm) #check vm vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip #cmd ='[ -e /root ]' #ssh_timeout = test_lib.SSH_TIMEOUT #test_lib.SSH_TIMEOUT = 3600 test_lib.lib_set_vm_host_l2_ip(vm_inv) test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800) #if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(host_ip, vm_ip, 'root', 'password', cmd): # test_lib.SSH_TIMEOUT = ssh_timeout # test_util.test_fail("iso has been failed to installed.") #test_lib.SSH_TIMEOUT = ssh_timeout #clone vm cloned_vm_name = ['cloned_vm_name'] cloned_vm_obj = vm.clone(cloned_vm_name)[0] test_obj_dict.add_vm(cloned_vm_obj) #delete iso image.delete() test_obj_dict.rm_image(image) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #expunge iso image.expunge() #detach iso img_ops.detach_iso(vm.vm.uuid) #vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ALL") #create image by vm root volume cloned_vm_img_name = "cloned_vm_image1" img_option2 = test_util.ImageOption() img_option2.set_backup_storage_uuid_list([bs_uuid]) img_option2.set_root_volume_uuid(cloned_vm_obj.vm.rootVolumeUuid) img_option2.set_name(cloned_vm_img_name) image1 = test_image.ZstackTestImage() image1.set_creation_option(img_option2) image1.create() image1.check() test_obj_dict.add_image(image1) #export image image1.export() #create vm vm2 = test_stub.create_vm('image-vm', cloned_vm_img_name, l3_name) #delete image image1.delete() test_obj_dict.rm_image(image1) #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") #expunge image image1.expunge() #vm ops test test_stub.vm_ops_test(vm2, "VM_TEST_ALL") vm.destroy() vm2.destroy() cloned_vm_obj.destroy() vol_ops.delete_disk_offering(root_disk_uuid) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_vm(vm) test_obj_dict.rm_disk_offering(data_volume_offering) test_obj_dict.rm_instance_offering(new_offering) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): data_volume_size = 10737418240 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('root-disk-iso') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) cpuNum = 1 cpuSpeed = 16 memorySize = 536870912 name = 'vm-offering-iso' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_cpuSpeed(cpuSpeed) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) img_option = test_util.ImageOption() img_option.set_name('image-iso') bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid img_option.set_backup_storage_uuid_list([bs_uuid]) img_option.set_url( 'http://172.20.1.15:7480/iso/iso_for_install_vm_test.iso') image_inv = img_ops.add_iso_template(img_option) image_uuid = image_inv.uuid image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) l3_name = os.environ.get('l3PublicNetworkName') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid root_disk_uuid = data_volume_offering.uuid vm = test_stub.create_vm_with_iso([l3_net_uuid], image_uuid, 'vm-iso', root_disk_uuid, new_offering.uuid) test_obj_dict.add_vm(vm) test_util.test_dsc('wait for iso installation') vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip test_lib.lib_wait_target_up(vm_ip, '22', 2400) cmd = '[ -e /root ] && echo yes || echo no' ssh_num = 0 ssh_ok = 0 while ssh_num <= 5 and ssh_ok == 0: rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) if rsp == False: time.sleep(30) else: ssh_ok = 1 break ssh_num = ssh_num + 1 if ssh_ok == 0: test_util.test_fail('fail to ssh to VM') vm.check() vm.destroy() test_obj_dict.rm_vm(vm) image.delete() test_obj_dict.rm_image(image) vol_ops.delete_disk_offering(root_disk_uuid) test_obj_dict.rm_disk_offering(data_volume_offering) vm_ops.delete_instance_offering(new_offering.uuid) test_obj_dict.rm_instance_offering(new_offering) test_util.test_pass('Create VM with ISO Installation 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')
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) 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')