def test(): #vm1 = test_stub.create_vm(vm_name = 'basic-test-vm', image_name = 'test-sft') vm1 = test_stub.create_vm(vm_name='basic-test-vm') test_obj_dict.add_vm(vm1) #vm1.check() image_creation_option = test_util.ImageOption() backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.vm) for bs in backup_storage_list: if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: image_creation_option.set_backup_storage_uuid_list( [backup_storage_list[0].uuid]) break else: test_util.test_skip('Not find image store type backup storage.') image_creation_option.set_root_volume_uuid(vm1.vm.rootVolumeUuid) image_creation_option.set_name(image1_name) #image_creation_option.set_platform('Linux') bs_type = backup_storage_list[0].type if bs_type == 'Ceph': origin_interval = conf_ops.change_global_config( 'ceph', 'imageCache.cleanup.interval', '1') image1 = test_image.ZstackTestImage() image1.set_creation_option(image_creation_option) #vm1.stop() image1.create() image1.check() test_obj_dict.add_image(image1) vm2 = test_stub.create_vm(image_name=image1_name) test_obj_dict.add_vm(vm2) image_creation_option.set_root_volume_uuid(vm2.vm.rootVolumeUuid) image_creation_option.set_name(image2_name) image2 = test_image.ZstackTestImage() image2.set_creation_option(image_creation_option) #vm2.stop() image2.create() test_obj_dict.add_image(image2) image2.check() vm3 = test_stub.create_vm(image_name=image2_name) test_obj_dict.add_vm(vm3) vm2.check() vm3.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): vm1 = test_stub.create_vm(vm_name='basic-test-vm') test_obj_dict.add_vm(vm1) #vm1.check() image_creation_option = test_util.ImageOption() backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.vm) for bs in backup_storage_list: if bs.type in [ inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE, inventory.CEPH_BACKUP_STORAGE_TYPE ]: image_creation_option.set_backup_storage_uuid_list( [backup_storage_list[0].uuid]) break else: vm1.destroy() test_util.test_skip( 'Not find image store or ceph type backup storage.') vm2 = test_stub.create_vm(vm_name='basic-test-vm') test_obj_dict.add_vm(vm2) image_creation_option.set_root_volume_uuid(vm1.vm.rootVolumeUuid) image_creation_option.set_name('test_create_vm_images_with_same_name') #image_creation_option.set_platform('Linux') image1 = test_image.ZstackTestImage() image1.set_creation_option(image_creation_option) image1.create() test_obj_dict.add_image(image1) image1.check() vm1.destroy() image_creation_option.set_root_volume_uuid(vm2.vm.rootVolumeUuid) image_creation_option.set_name('test_create_vm_images_with_same_name') image2 = test_image.ZstackTestImage() image2.set_creation_option(image_creation_option) image2.create() test_obj_dict.add_image(image2) image2.check() vm3 = test_stub.create_vm( image_name='test_create_vm_images_with_same_name') test_obj_dict.add_vm(vm3) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass( 'Create 2 VM images from same origin Image Successfully')
def test(): vm1 = test_stub.create_vm(vm_name='basic-test-vm') test_obj_dict.add_vm(vm1) vm1.check() image_creation_option = test_util.ImageOption() backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.vm) for bs in backup_storage_list: if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: image_creation_option.set_backup_storage_uuid_list( [backup_storage_list[0].uuid]) break else: test_util.test_skip('Not find image store type backup storage.') global default_snapshot_depth default_snapshot_depth = conf_ops.change_global_config('volumeSnapshot', \ 'incrementalSnapshot.maxNum', test_depth) image_creation_option.set_root_volume_uuid(vm1.vm.rootVolumeUuid) test_img_num = 1 while (test_img_num < 101): image_creation_option.set_name('test_create_img_store_img_vm%d' % test_img_num) #image_creation_option.set_platform('Linux') image = test_image.ZstackTestImage() image.set_creation_option(image_creation_option) image.create() image.check() test_obj_dict.add_image(image) test_img_num += 1 vm2 = test_stub.create_vm(image_name='test_create_img_store_img_vm100') test_obj_dict.add_vm(vm2) vm2.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create 100 images Success')
def test(): global new_image 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") for bs in bss: if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: break if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE: break if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: break else: test_util.test_skip('Not find image store type backup storage.') image_option = test_util.ImageOption() image_option.set_format('qcow2') image_option.set_name('test_file_url_image') image_option.set_system_tags('qemuga') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url("file:///etc/issue") image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(60000) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() new_image.delete() test_util.test_pass('test add file:///image.qcow2 passed.')
def test(): bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") image_option = test_util.ImageOption() image_option.set_name('test_150min_downloading_image') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('timeout150MinImageUrl')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(12000 * 1000) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) time1 = time.time() new_image.add_root_volume_template() time2 = time.time() cost_time = time2 - time1 if cost_time < 7200: test_util.test_fail('The test image is added less than 2 hours: \ %s, which does not meet the test criterial.' % cost_time) new_image.delete() #new_image.expunge([bss[0].uuid]) test_util.test_pass('Add Image with 150 mins Pass.')
def test(): global test_obj_dict test_util.test_dsc('Create test vm and check') vm1 = test_stub.create_vlan_vm() #Without this checking, the image (created later) might be not able to get a DHCP IP, when using to create a new vm. vm1.check() test_obj_dict.add_vm(vm1) vm1.stop() image_creation_option = test_util.ImageOption() backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.vm) image_creation_option.set_backup_storage_uuid_list( [backup_storage_list[0].uuid]) image_creation_option.set_root_volume_uuid(vm1.vm.rootVolumeUuid) image_creation_option.set_name('test_create_image_template') image = test_image.ZstackTestImage() image.set_creation_option(image_creation_option) image.create() test_obj_dict.add_image(image) image.delete() image.check() test_util.test_pass('Delete Image Template Test Success')
def create_image_template(self): ''' @return: zstack_test_image() object ''' import zstackwoodpecker.zstack_test.zstack_test_image as \ zstack_image_header if self.state == sp_header.DELETED: test_util.test_fail(\ 'Should not be called, as snapshot volume:%s has been deleted. Snapshot can \ not be created to a new template' % \ self.target_volume.get_volume().uuid) if not self.image_option.get_root_volume_uuid(): self.image_option.set_root_volume_uuid(self.snapshot.uuid) if not self.image_option.get_backup_storage_uuid_list(): bs_uuid = res_ops.get_resource(res_ops.BACKUP_STORAGE)[0].uuid self.image_option.set_backup_storage_uuid_list([bs_uuid]) img_inv = img_ops.create_template_from_snapshot(self.image_option) super(ZstackTestSnapshot, self).create_image_template() img_obj = zstack_image_header.ZstackTestImage() img_obj.set_image(img_inv) img_obj.set_state(image_header.CREATED) #ROOT Volume won't create checking point. So skip. if self.get_volume_type() != volume_header.ROOT_VOLUME: img_obj.set_original_checking_points(self.get_checking_points()) return img_obj
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 test(): has_iamgestore = False bs_lst = res_ops.query_resource(res_ops.BACKUP_STORAGE) for _bs in bs_lst: if _bs.type == "ImageStoreBackupStorage": has_iamgestore = True bs = _bs if has_iamgestore == False: test_util.test_skip( 'Here does not have ImageStore backup storage. Will skip test.') ca_str = os.environ.get('zstore_ca').replace('\\n', '\n') zstore_url = os.environ.get('zstore_url') image_name = 'test-image-%s' % time.time() image_option = test_util.ImageOption() image_option.set_name(image_name) image_option.set_description('test image from remote imageStore') image_option.set_url(zstore_url) image_option.set_backup_storage_uuid_list([bs.uuid]) image_option.set_format('qcow2') image_option.set_system_tags("image::cert::%s" % ca_str) image_option.set_mediaType('RootVolumeTemplate') image_inv = img_ops.add_root_volume_template(image_option) time.sleep(10) image = zstack_image_header.ZstackTestImage() image.set_creation_option(image_option) image.set_image(image_inv) test_obj_dict.add_image(image) image.check() vm = test_stub.create_vm(image_name=image_name) vm.destroy() image.delete() test_util.test_pass('Test adding image from remote imageStorage pass.')
def test(): os.system('dd if=/dev/zero of=%s bs=1M count=1 seek=300' % test_image) time.sleep(10) image_name = 'test-image-%s' % time.time() image_option = test_util.ImageOption() image_option.set_name(image_name) image_option.set_description('test image which is upload from local filesystem.') image_option.set_url('file://%s' % test_image) bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] image_option.set_backup_storage_uuid_list([bs.uuid]) image_option.set_format('raw') image_option.set_mediaType('RootVolumeTemplate') image_inv = img_ops.add_root_volume_template(image_option) time.sleep(10) image = zstack_image_header.ZstackTestImage() image.set_creation_option(image_option) image.set_image(image_inv) test_obj_dict.add_image(image) image.check() vm = test_stub.create_vm(image_name = image_name) vm.destroy() image.delete() if not os.path.exists(test_image): test_util.test_fail('test image disappeared, after add image.') os.system('rm -f %s' % test_image) test_util.test_pass('Test adding image from local stroage pass.')
def test(): allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) img_option = test_util.ImageOption() image_name = 'userdata-image' image_url = os.environ.get('userdataImageUrl') img_option.set_name(image_name) 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_format('raw') img_option.set_url(image_url) image_inv = img_ops.add_root_volume_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) vm = test_stub.create_vm(vm_name='userdata-vm', image_name=image_name, system_tags=[ "userdata::%s" % os.environ.get('long_userdata_systemTags') ]) test_obj_dict.add_vm(vm) time.sleep(90) vm_ip = vm.get_vm().vmNics[0].ip ssh_cmd = 'ssh -i %s -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null test@%s' % ( os.environ.get('sshkeyPriKey_file'), vm_ip) for i in range(5): cmd = '%s cat /tmp/helloworld_config' % ssh_cmd process_result = test_stub.execute_shell_in_process(cmd, tmp_file) if process_result == 0: break else: time.sleep(10) else: test_util.test_fail("fail to cat /tmp/helloworld_config") for i in range(5): cmd = '%s find /tmp/temp' % ssh_cmd process_result = test_stub.execute_shell_in_process(cmd, tmp_file) if process_result == 0: break else: time.sleep(10) else: test_util.test_fail("fail to find /tmp/temp") vm.destroy() test_obj_dict.rm_vm(vm) image.delete() image.expunge() test_obj_dict.rm_image(image) test_util.test_pass('Create VM with long userdata string Success')
def test(): bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") image_option = test_util.ImageOption() image_option.set_name('test_image_cache_cleanup') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vm = test_stub.create_vm([l3_net_uuid], new_image.image.uuid, 'imagecache_vm', \ default_l3_uuid = l3_net_uuid) test_obj_dict.add_vm(vm) vm.check() host = test_lib.lib_find_host_by_vm(vm.get_vm()) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm.destroy() if test_lib.lib_get_vm_delete_policy() != 'Direct': vm.expunge() new_image.delete() if test_lib.lib_get_image_delete_policy() != 'Direct': new_image.expunge() if ps.type == 'SharedMountPoint': test_util.test_skip( 'CleanUpImageCacheOnPrimaryStorage not supported on SMP storage, skip test.' ) elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: test_util.test_skip( 'ceph is not directly using image cache, skip test.') ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if test_lib.lib_check_file_exist(host, image_cache_path): test_util.test_fail('image cache is expected to be deleted') elif ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if test_lib.lib_check_file_exist(host, image_cache_path): test_util.test_fail('image cache is expected to be deleted') # elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: # elif ps.type == 'SharedMountPoint': test_util.test_pass('imagecache cleanup Pass.')
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 create_template(self, backup_storage_uuid_list, name=None): image_inv = vol_ops.create_volume_template(self.get_volume().uuid, \ backup_storage_uuid_list, name) image = zstack_image_header.ZstackTestImage() image.set_image(image_inv) image.set_state(image_header.CREATED) super(ZstackTestVolume, self).create_template() return image
def test(): global image1 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']) image_name1 = 'image1_a' image_option = test_util.ImageOption() image_option.set_format('qcow2') image_option.set_name(image_name1) #image_option.set_system_tags('qemuga') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(3600 * 1000) image1 = zstack_image_header.ZstackTestImage() image1.set_creation_option(image_option) image1.add_root_volume_template() image1.check() #export image if bss[0].type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE]: image1.export() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm('test-vm', image_name, l3_name) test_obj_dict.add_vm(vm) # clone vm cloned_vm_name = ['cloned_vm'] cloned_vm_obj = vm.clone(cloned_vm_name)[0] test_obj_dict.add_vm(cloned_vm_obj) # delete image image1.delete() # vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_MIGRATE") # expunge image image1.expunge() # vm ops test test_stub.vm_ops_test(cloned_vm_obj, "VM_TEST_ATTACH") test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Cloned VM ops for BS Success')
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(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] global agent_url global vm global image imagestore = test_lib.lib_get_image_store_backup_storage() if imagestore == None: test_util.test_skip('Required imagestore to test') image_uuid = test_stub.get_image_by_bs(imagestore.uuid) cond = res_ops.gen_query_conditions('type', '=', 'SharedMountPoint') local_pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(local_pss) == 0: test_util.test_skip('Required smp ps to test') ps_uuid = local_pss[0].uuid vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid) agent_url = flavor['agent_url'] agent_action = flavor['agent_action'] if agent_action == 1: agent_time = (24 * 60 * 60 - 60) * 1000 elif agent_action == 2: agent_time = 360 * 1000 image_uuid = str(uuid.uuid4()).replace('-', '') if agent_url == CREATE_TEMPLATE_FROM_VOLUME_PATH: rsp = dep_ops.json_post( "http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({ "key": vm.get_vm().rootVolumeUuid, "value": '{"%s":%s}' % (agent_url, agent_action) })) else: rsp = dep_ops.json_post( "http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({ "key": image_uuid, "value": '{"%s":%s}' % (agent_url, agent_action) })) image_creation_option = test_util.ImageOption() bss = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE, []) if len(bss) == 0: test_util.test_skip('Required sftp bs to test') bs_uuid = bss[0].uuid image_creation_option.set_uuid(image_uuid) image_creation_option.set_backup_storage_uuid_list([bs_uuid]) image_creation_option.set_root_volume_uuid(vm.vm.rootVolumeUuid) image_creation_option.set_name('test_create_root_volume_template_timeout') image_creation_option.set_timeout(24 * 60 * 60 * 1000) image = zstack_image_header.ZstackTestImage() image.set_creation_option(image_creation_option) start = time.time() image.create() end = time.time() if end - start < agent_time / 2 / 1000: test_util.test_fail('execution time too short %s' % (end - start))
def test(): global origin_interval global bs_type test_util.test_dsc('Create test vm and check') vm1 = test_stub.create_vlan_vm() #Without this checking, the image (created later) might be not able to get a DHCP IP, when using to create a new vm. vm1.check() test_obj_dict.add_vm(vm1) vm1.stop() image_creation_option = test_util.ImageOption() backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.vm) image_creation_option.set_backup_storage_uuid_list( [backup_storage_list[0].uuid]) image_creation_option.set_root_volume_uuid(vm1.vm.rootVolumeUuid) image_creation_option.set_name('test_create_image_template') bs_type = backup_storage_list[0].type if bs_type == 'Ceph': origin_interval = conf_ops.change_global_config( 'ceph', 'imageCache.cleanup.interval', '1') image = test_image.ZstackTestImage() image.set_creation_option(image_creation_option) image.create() test_obj_dict.add_image(image) image.check() test_util.test_dsc('Use new created Image to create a VM') new_img_uuid = image.image.uuid vm_creation_option = vm1.get_creation_option() vm_creation_option.set_image_uuid(new_img_uuid) vm2 = test_vm.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() test_obj_dict.add_vm(vm2) vm2.check() vm1.start() vm1.check() vm2.destroy() vm1.destroy() image.delete() if bs_type == 'Ceph': time.sleep(60) image.check() if bs_type == 'Ceph': conf_ops.change_global_config('ceph', 'imageCache.cleanup.interval', origin_interval) test_util.test_pass('Create Image Template Test Success')
def test(): global image1 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) 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']) image_name1 = 'image1_a' image_option = test_util.ImageOption() image_option.set_format('qcow2') image_option.set_name(image_name1) #image_option.set_system_tags('qemuga') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(3600 * 1000) image1 = zstack_image_header.ZstackTestImage() image1.set_creation_option(image_option) image1.add_root_volume_template() image1.check() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm1 = test_stub.create_vm(image_name1, image_name, l3_name) test_obj_dict.add_vm(vm1) image1.delete() image1.expunge() #target_host = test_lib.lib_find_random_host(vm1.vm) #vm1.migrate(target_host.uuid) test_stub.vm_ops_test(vm1, "VM_TEST_MIGRATE") test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create VM Image in Image Store Success')
def test(): global vm bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected') bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) if not bss: test_util.test_skip("not find availbale backup storage.Skip test") #add iso image_option_iso = test_util.ImageOption() image_option_iso.set_name('vm-iso') image_option_iso.set_format('iso') image_option_iso.set_mediaType('RootVolumeTemplate') image_option_iso.set_url("http://iso/CentOS-x86_64-7.2-Minimal.iso") image_option_iso.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option_iso) new_image.add_root_volume_template() #add sshkeyimage image_option_sshkey = test_util.ImageOption() image_option_sshkey.set_name('sshkeyimage') image_option_sshkey.set_format('qcow2') image_option_sshkey.set_mediaType('RootVolumeTemplate') image_option_sshkey.set_url("http://zstack-cloudinit.img") image_option_sshkey.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option_sshkey) new_image.add_root_volume_template() image_name = os.environ.get('imageName3') centosimage_uuid = test_lib.lib_get_image_by_name(image_name).uuid running_vm = test_stub.create_vm(image_uuid=centosimage_uuid) stopped_vm = test_stub.create_vm(image_uuid=centosimage_uuid) scheduler_vm = test_stub.create_vm(image_uuid=centosimage_uuid) running_vm_operations(running_vm, bss) stopped_vm_operations(stopped_vm, bss) scheduler_vm_operations(scheduler_vm, bss)
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 add_image(bs_uuid): global new_image image_option = test_util.ImageOption() image_option.set_name('test_add_image_progress') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_net')) image_option.set_backup_storage_uuid_list([bs_uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template()
def create_image(vm_obj): volume_uuid = test_lib.lib_get_root_volume(vm_obj.get_vm()).uuid bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm_obj.vm) image_option = test_util.ImageOption() image_option.set_root_volume_uuid(volume_uuid) image_option.set_name('image_resize_template') image_option.set_backup_storage_uuid_list([bs_list[0].uuid]) image = img_ops.create_root_volume_template(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) new_image.check() new_image.clean()
def test(): vm1 = test_stub.create_vr_vm('vm_imagecache', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm1) vm1.check() vm1.stop() image_creation_option = test_util.ImageOption() backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm( vm1.get_vm()) image_creation_option.set_backup_storage_uuid_list( [backup_storage_list[0].uuid]) image_creation_option.set_root_volume_uuid(vm1.get_vm().rootVolumeUuid) image_creation_option.set_name('test_create_image_template_imagecache') image = test_image.ZstackTestImage() image.set_creation_option(image_creation_option) image.create() test_obj_dict.add_image(image) image.check() vm2 = test_stub.create_vm('vm_imagecache2', 'test_create_image_template_imagecache', os.environ.get('l3VlanNetwork3')) test_obj_dict.add_vm(vm2) host = test_lib.lib_find_host_by_vm(vm2.get_vm()) ps = test_lib.lib_get_primary_storage_by_vm(vm2.get_vm()) image = test_lib.lib_get_image_by_name( 'test_create_image_template_imagecache') img_ops.sync_image_size(image.uuid) image = test_lib.lib_get_image_by_name( 'test_create_image_template_imagecache') img_ops.delete_image(image.uuid) if ps.type == inventory.LOCAL_STORAGE_TYPE or ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == 'SharedMountPoint': image_cache_path = "%s/imagecache/template/%s/" % (ps.mountPath, image.uuid) imagecache_file_size = int( test_lib.lib_get_file_size(host, image_cache_path)) image_actual_size = int(image.actualSize) if imagecache_file_size < image.actualSize * 0.99 or imagecache_file_size > image.actualSize * 1.01: test_util.test_fail( 'image cache size (%s) not match image actual size(%s)' % (imagecache_file_size, image_actual_size)) else: test_util.test_skip( "Skip test when primary storage is not local or NFS") # elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('imagecache cleanup Pass.')
def test(): img_option = test_util.ImageOption() image_name = 'userdata-image' image_url = os.environ.get('userdataImageUrl') img_option.set_name(image_name) 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_format('raw') img_option.set_url(image_url) image_inv = img_ops.add_root_volume_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) vm = test_stub.create_vm( vm_name='userdata-vm', image_name=image_name, system_tags=["userdata::%s" % os.environ.get('userdata_systemTags')]) test_obj_dict.add_vm(vm) time.sleep(60) cond = res_ops.gen_query_conditions('resourceUuid', '=', vm.vm.uuid) system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) if system_tag != []: test_util.test_logger('Success get system tags.') else: test_util.test_fail('Failed to get system tags.') sys_tags = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) system_tag_uuid = [tag.uuid for tag in sys_tags if 'userdata' in tag.tag][0] # system_tag_uuid = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0].uuid tag_ops.delete_tag(system_tag_uuid) # system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) system_tag_after = res_ops.query_resource(res_ops.SYSTEM_TAG, cond) system_tag = [tag for tag in system_tag_after if 'userdata' in tag.tag] if system_tag == []: test_util.test_logger('Success delete system tags.') else: test_util.test_fail('Failed to delete system tags.') vm.destroy() test_obj_dict.rm_vm(vm) image.delete() image.expunge() test_obj_dict.rm_image(image) test_util.test_pass('Delete userdata Success')
def add_image(bs_uuid, index): global images image_option = test_util.ImageOption() image_option.set_name('test_add_image_progress%s' % (index)) image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_net')) image_option.set_backup_storage_uuid_list([bs_uuid]) images[index] = zstack_image_header.ZstackTestImage() images[index].set_creation_option(image_option) images[index].add_root_volume_template() test_obj_dict.add_image(images[index])
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(): import uuid account_name = uuid.uuid1().get_hex() account_pass = uuid.uuid1().get_hex() account_pass = hashlib.sha512(account_name).hexdigest() test_account = acc_ops.create_normal_account(account_name, account_pass) global vm bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") test_util.test_dsc('Test change vm image with quota limited') test_account_uuid = test_account.uuid #set normal account's storage capacity as 4G acc_ops.update_quota(test_account.uuid, "volume.capacity", "4294967296") test_account_session = acc_ops.login_by_account(account_name, account_pass) test_stub.share_admin_resource([test_account_uuid]) vm = test_stub.create_vm(session_uuid=test_account_session) vm.check() image_option = test_util.ImageOption() image_option.set_name('8G') image_option.set_format('qcow2') image_option.set_url( "http://172.20.1.15:7480/diskimages/CentOS-7-x86_64-Cloudinit-8G-official.qcow2" ) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() test_stub.share_admin_resource([test_account_uuid]) vm.stop(session_uuid=test_account_session) image_uuid = test_lib.lib_get_image_by_name("8G").uuid try: vm_ops.change_vm_image(vm.get_vm().uuid, image_uuid, session_uuid=test_account_session) except: acc_ops.delete_account(test_account_uuid) img_ops.delete_image(test_lib.lib_get_image_by_name('8G').uuid) test_util.test_pass( 'Change Vm Image With Limited Storage Quota Test Success ') test_util.test_fail('Overstep the limit of storage capacity')
def create_image(self): bs = self.get_bs_candidate() self._image_name = 'vm-created-image-%s' % time.strftime( '%y%m%d-%H%M%S', time.localtime()) image_creation_option = test_util.ImageOption() image_creation_option.set_backup_storage_uuid_list([bs.uuid]) image_creation_option.set_root_volume_uuid(self.vm.vm.rootVolumeUuid) image_creation_option.set_name(self._image_name) self._image = test_image.ZstackTestImage() self._image.set_creation_option(image_creation_option) self._image.create() if bs.type.lower() == 'ceph': bs_mon_ip = bs.mons[0].monAddr os.environ[ 'cephBackupStorageMonUrls'] = 'root:password@%s' % bs_mon_ip self._image.check()
def create_temp_image(index): global vms global images image_creation_option = test_util.ImageOption() backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vms[index].vm) image_creation_option.set_backup_storage_uuid_list([backup_storage_list[0].uuid]) image_creation_option.set_root_volume_uuid(vms[index].vm.rootVolumeUuid) image_creation_option.set_name('test_create_image_template_progress%s' % (index)) bs_type = backup_storage_list[0].type if bs_type == 'Ceph': origin_interval = conf_ops.change_global_config('ceph', 'imageCache.cleanup.interval', '1') images[index] = test_image.ZstackTestImage() images[index].set_creation_option(image_creation_option) image_jobs[index] = str(uuid.uuid4()).replace('-', '') images[index].create(image_jobs[index]) test_obj_dict.add_image(images[index])