def test(): img_option = test_util.ImageOption() UEFI_image_url = os.environ.get('imageUrl_linux_UEFI') image_name = os.environ.get('imageName_linux_UEFI') 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('qcow2') img_option.set_url(UEFI_image_url) img_option.set_system_tags("bootMode::UEFI") 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) image_uuid = test_lib.lib_get_image_by_name(image_name).uuid test_obj_dict.add_image(image) vm = test_stub.create_vm(image_name = os.environ.get('imageName_linux_UEFI')) test_obj_dict.add_vm(vm) vm.check() vm_ip = vm.get_vm().vmNics[0].ip retcode = subprocess.call(["ping", "-c","4",vm_ip]) if retcode != 0: test_util.test_fail('Create VM Test linux UEFI failed.') else: test_util.test_pass('Create VM Test linux UEFI Success.') vm.destroy() test_util.test_pass('Create VM Test linux UEFI Success')
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(): 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(): 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(): 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(): bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] if bs.type == "Ceph": test_util.test_skip('bs: %s is ceph backup storage. Will skip test.' % bs.uuid) command = 'dd if=/dev/zero of=%s bs=1M count=1 seek=300' % test_image test_lib.lib_execute_ssh_cmd(bs.hostname, 'root', 'password', command) 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) 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() command = 'ls %s' % test_image if not test_lib.lib_execute_ssh_cmd(bs.hostname, 'root', 'password', command): test_util.test_fail('test image disappeared, after add image.') command = 'rm -f %s' % test_image result = test_lib.lib_execute_ssh_cmd(bs.hostname, 'root', 'password', command) test_util.test_pass('Test adding image from local storage pass.')
def test(): img_option = test_util.ImageOption() ipv6_image_url = os.environ.get('ipv6ImageUrl') image_name = os.environ.get('ipv6ImageName') 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('qcow2') img_option.set_url(ipv6_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) vm1 = test_stub.create_vm(l3_name = "%s,%s" %(os.environ.get('l3PublicNetworkName1'), os.environ.get('l3PublicNetworkName')), vm_name = 'IPv6 2 stack test ipv4 and ipv6', image_name = image_name) vm2 = test_stub.create_vm(l3_name = os.environ.get('l3PublicNetworkName1'), vm_name = 'IPv6 2 stack test ipv6', image_name = image_name) time.sleep(90) #waiting for vm bootup vm1_nic1 = vm1.get_vm().vmNics[0].ip vm1_nic2 = vm1.get_vm().vmNics[1].ip vm2_nic1 = vm2.get_vm().vmNics[0].ip for ip in (vm1_nic1, vm1_nic2): if "." in ip: ipv4 = ip print "vm1_nic1 : %s, vm1_nic2: %s, vm2_nic1 :%s, ipv4 :%s." %(vm1_nic1, vm1_nic2, vm2_nic1,ipv4) cmd = "ping6 -c 4 %s" %(vm2_nic1) (retcode, output, erroutput) = ssh.execute(cmd, ipv4, "root", "password", True, 22) print "retcode is: %s; output is : %s.; erroutput is: %s" %(retcode, output , erroutput) if retcode != 0: test_util.test_fail('Test Create IPv6 VM Failed.')
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) l3_name = os.environ.get('l3VlanNetworkName5') l3_net = test_lib.lib_get_l3_by_name(l3_name) l3_net_uuid = l3_net.uuid if 'DHCP' not in test_lib.lib_get_l3_service_type(l3_net_uuid): test_util.test_skip('Only DHCP support userdata') for ns in l3_net.networkServices: if ns.networkServiceType == 'DHCP': sp_uuid = ns.networkServiceProviderUuid sp = test_lib.lib_get_network_service_provider_by_uuid(sp_uuid) if sp.type != 'Flat': test_util.test_skip('Only Flat DHCP support userdata') vm = test_stub.create_vm(l3_uuid_list = [l3_net_uuid], vm_name = 'userdata-vm',image_uuid = image.get_image().uuid,system_tags = ["userdata::%s" % os.environ.get('userdata_systemTags')]) test_obj_dict.add_vm(vm) time.sleep(60) try: vm.check() except: test_util.test_logger("expected failure to connect VM") 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) cmd = '%s cat /tmp/helloworld_config' % ssh_cmd process_result = test_stub.execute_shell_in_process(cmd, tmp_file) if process_result != 0: test_util.test_fail("fail to cat /tmp/helloworld_config") cmd = '%s find /tmp/temp' % ssh_cmd process_result = test_stub.execute_shell_in_process(cmd, tmp_file) if process_result != 0: test_util.test_fail("fail to find /tmp/temp") vm.destroy() test_obj_dict.rm_vm(vm) image.delete() if test_lib.lib_get_image_delete_policy() != 'Direct': image.expunge() test_obj_dict.rm_image(image) test_util.test_pass('Create VM with userdata Success')
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(): global delete_policy delete_policy = test_lib.lib_set_delete_policy('image', 'Direct') os.system('dd if=/dev/zero of=%s bs=1M count=300' % test_image) time.sleep(1) bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] img_ops.reconnect_sftp_backup_storage(bs.uuid) time.sleep(1) 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] avail_cap = bs.availableCapacity total_cap = bs.totalCapacity 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) bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] avail_cap1 = bs.availableCapacity total_cap1 = bs.totalCapacity if total_cap != total_cap1: test_util.test_fail('Backup storage total capacity is not same, after adding new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, total_cap, total_cap1)) if avail_cap <= avail_cap1 : test_util.test_fail('Backup storage available capacity is not correct, after adding new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, avail_cap, avail_cap1)) image.delete() bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] avail_cap2 = bs.availableCapacity total_cap2 = bs.totalCapacity if total_cap != total_cap2 : test_util.test_fail('Backup storage total capacity is not same, after deleting new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, total_cap, total_cap2)) if avail_cap > (avail_cap2 + 1024000) or avail_cap < avail_cap2: test_util.test_fail('Backup storage available capacity is not correct, after adding and deleting new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, avail_cap, avail_cap2)) os.system('rm -f %s' % test_image) test_lib.lib_set_delete_policy('image', delete_policy) test_util.test_pass('Test backup storage capacity for adding/deleting image 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 test(): bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] if bs.type == "Ceph": test_util.test_skip('bs: %s is ceph backup storage. Will skip test.' % bs.uuid) command = 'dd if=/dev/zero of=%s bs=1M count=1 seek=300' % test_image test_lib.lib_execute_ssh_cmd(bs.hostname, 'root', 'password', command) 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) 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() command = 'ls %s' % test_image if not test_lib.lib_execute_ssh_cmd(bs.hostname, 'root', 'password', command): test_util.test_fail('test image disappeared, after add image.') command = 'rm -f %s' % test_image result = test_lib.lib_execute_ssh_cmd(bs.hostname, 'root', 'password', command) test_util.test_pass('Test adding image from local storage pass.')
def add_root_volume_template(self): self.set_image(img_ops.add_root_volume_template(self.get_creation_option())) return self
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) l3_name = os.environ.get('l3VlanNetworkName5') l3_net = test_lib.lib_get_l3_by_name(l3_name) l3_net_uuid = l3_net.uuid if 'DHCP' not in test_lib.lib_get_l3_service_type(l3_net_uuid): test_util.test_skip('Only DHCP support userdata') for ns in l3_net.networkServices: if ns.networkServiceType == 'DHCP': sp_uuid = ns.networkServiceProviderUuid sp = test_lib.lib_get_network_service_provider_by_uuid(sp_uuid) if sp.type != 'Flat': test_util.test_skip('Only Flat DHCP support userdata') vm = test_stub.create_vm( l3_uuid_list=[l3_net_uuid], vm_name='userdata-vm', image_uuid=image.get_image().uuid, system_tags=["userdata::%s" % os.environ.get('userdata_systemTags')]) test_obj_dict.add_vm(vm) time.sleep(60) try: vm.check() except: test_util.test_logger("expected failure to connect VM") 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) cmd = '%s cat /tmp/helloworld_config' % ssh_cmd process_result = test_stub.execute_shell_in_process(cmd, tmp_file) if process_result != 0: test_util.test_fail("fail to cat /tmp/helloworld_config") cmd = '%s find /tmp/temp' % ssh_cmd process_result = test_stub.execute_shell_in_process(cmd, tmp_file) if process_result != 0: test_util.test_fail("fail to find /tmp/temp") vm.destroy() test_obj_dict.rm_vm(vm) image.delete() if test_lib.lib_get_image_delete_policy() != 'Direct': image.expunge() test_obj_dict.rm_image(image) test_util.test_pass('Create VM with userdata Success')
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) instance_offering_name = os.environ.get('instanceOfferingName_m') instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(instance_offering_name).uuid vm_1 = test_stub.create_vm(image_name = os.environ.get('sshkeyImageName'),instance_offering_uuid = instance_offering_uuid) test_obj_dict.add_vm(vm_1) time.sleep(90) vm_1_ip = vm_1.get_vm().vmNics[0].ip vm_2 = test_stub.create_vm(vm_name = 'userdata-and-sshkey-vm',image_name = image_name,system_tags = ["userdata::%s" % os.environ.get('userdata_systemTags'),"%s::%s" % (vm_header.SSHKEY, os.environ.get('sshkeyPubKey'))], instance_offering_uuid = instance_offering_uuid) test_obj_dict.add_vm(vm_2) time.sleep(90) vm_2_ip = vm_2.get_vm().vmNics[0].ip for i in range(5): ssh_cmd = 'timeout 5 ssh -i %s -oPasswordAuthentication=no -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s echo pass' % (os.environ.get('sshkeyPriKey_file'), vm_2_ip) process_result = test_stub.execute_shell_in_process(ssh_cmd, tmp_file) if process_result == 0: break else: time.sleep(10) else: test_util.test_fail("fail to use ssh key connect to VM") ssh_cmd = 'ssh -i %s -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null test@%s' % (os.environ.get('sshkeyPriKey_file'), vm_2_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_1.destroy() test_obj_dict.rm_vm(vm_1) vm_2.destroy() test_obj_dict.rm_vm(vm_2) image.delete() image.expunge() test_obj_dict.rm_image(image) test_util.test_pass('Create VM with userdata Success')
def test(): global delete_policy delete_policy = test_lib.lib_set_delete_policy('image', 'Direct') os.system('dd if=/dev/zero of=%s bs=1M count=300' % test_image) time.sleep(1) bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] img_ops.reconnect_sftp_backup_storage(bs.uuid) time.sleep(1) 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] avail_cap = bs.availableCapacity total_cap = bs.totalCapacity 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) bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] avail_cap1 = bs.availableCapacity total_cap1 = bs.totalCapacity if total_cap != total_cap1: test_util.test_fail( 'Backup storage total capacity is not same, after adding new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, total_cap, total_cap1)) if avail_cap <= avail_cap1: test_util.test_fail( 'Backup storage available capacity is not correct, after adding new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, avail_cap, avail_cap1)) image.delete() bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] avail_cap2 = bs.availableCapacity total_cap2 = bs.totalCapacity if total_cap != total_cap2: test_util.test_fail( 'Backup storage total capacity is not same, after deleting new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, total_cap, total_cap2)) if avail_cap > (avail_cap2 + 1024000) or avail_cap < avail_cap2: test_util.test_fail( 'Backup storage available capacity is not correct, after adding and deleting new image: %s. The previous value: %s, the current value: %s' % (image_inv.uuid, avail_cap, avail_cap2)) os.system('rm -f %s' % test_image) test_lib.lib_set_delete_policy('image', delete_policy) test_util.test_pass( 'Test backup storage capacity for adding/deleting image pass.')