def test():
    global vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" % (root_password))
        vm = test_stub.create_vm(vm_name='c7-vm-32',
                                 image_name="imageName_i_c7_32",
                                 root_password=root_password)

        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
        for bs in backup_storage_list:
            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:
            vm.destroy()
            test_util.test_skip('Not find image store type backup storage.')

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root",
                                              root_password):
            test_util.test_fail("create vm with root password: %s failed",
                                root_password)

        vm.destroy()
        vm.check()

        vm.expunge()
        vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
Beispiel #2
0
def test():
    global vm, test_account_uuid, test_account_session
    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)
    test_account_uuid = test_account.uuid
    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(vm_name='c7-vm-no-sys-tag',
                             image_name="imageName_i_c7_no_tag",
                             session_uuid=test_account_session)
    vm.check()

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    for (usr, passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)

        #When vm is running:
        #res_ops.enable_change_vm_password("true", vm.get_vm().uuid, 'VmInstanceVO', session_uuid = test_account_session)
        vm_ops.set_vm_qga_enable(vm.get_vm().uuid,
                                 session_uuid=test_account_session)
        vm_ops.change_vm_password(vm.get_vm().uuid,
                                  usr,
                                  passwd,
                                  skip_stopped_vm=None,
                                  session_uuid=test_account_session)

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed",
                                usr, passwd)

        vm_ops.change_vm_password(vm.get_vm().uuid,
                                  "root",
                                  test_stub.original_root_password,
                                  session_uuid=test_account_session)
        vm.check()

    vm.destroy(test_account_session)
    vm.check()
    vm.expunge(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass(
        'enable and change vm password by normal user account Success')
def test():
    global vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" % (root_password))
        #vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag", root_password=root_password)
        vm = test_stub.create_vm(vm_name='c7-vm-no-sys-tag',
                                 image_name="imageName_i_c7_no_tag")

        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
        for bs in backup_storage_list:
            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:
            vm.destroy()
            test_util.test_skip('Not find image store type backup storage.')

        #if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root", root_password):
        #    test_util.test_fail("create vm with root password: %s failed", root_password)

        # stop vm && change vm password
        #vm.stop()
        vm.check()
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password)
        except Exception, e:
            test_util.test_pass(
                "negative test of change a no system tag image passed.")
def test():
    global test_obj_dict

    test_util.test_dsc('Create test vm and check')
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)
    for i in bs:
        if i.type == 'AliyunEBS':
            test_util.test_skip('Skip test on AliyunEBS')
    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 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 vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" %(root_password))
        vm = test_stub.create_vm(vm_name = 'u13-vm', image_name = "imageName_i_u13", root_password=root_password)
        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
        for bs in backup_storage_list:
            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:
            vm.destroy()
            test_util.test_skip('Not find image store type backup storage.')

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root", root_password):
            test_util.test_fail("create vm with root password: %s failed", root_password)

        vm.destroy()
        vm.check()

        vm.expunge()
        vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
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 vm
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    test_obj_dict.add_vm(vm)
    vm.check()

    vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
    volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
    set_size = 1024*1024*1024*5
    vol_ops.resize_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)

    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.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_vm = test_stub.create_vm("test_vm_after_resize", 'image_resize_template', l3_name)
    test_obj_dict.add_vm(new_vm)
    new_vm.check()
    new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm())
    vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) 
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Create Template for Resize VM Test Success')
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 test():
    global vm
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" %(root_password))
        #vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag", root_password=root_password)
        vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag")

        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
        for bs in backup_storage_list:
            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:
            vm.destroy()
            test_util.test_skip('Not find image store type backup storage.')

        #if not test_lib.lib_check_login_in_vm(vm.get_vm(), "root", root_password):
        #    test_util.test_fail("create vm with root password: %s failed", root_password)

        # stop vm && change vm password
        #vm.stop()
        vm.check()
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password)
        except Exception, e:
            if "CreateSystemTag" in str(e):
                test_util.test_pass("negative test of change a no system tag image passed.")
            else:
                test_util.test_fail("negative test failed with not expected log: %s", str(e))
Beispiel #11
0
def test():
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    vm.stop()
    r_volume = zstack_volume_header.ZstackTestVolume()
    r_volume.set_volume(test_lib.lib_get_root_volume(vm.get_vm()))
    r_volume.set_state(volume_header.ATTACHED)

    test_util.test_dsc('Create volume template and check')
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    vol_tmpt = r_volume.create_template([bs_list[0].uuid], 'new_data_template')
    test_obj_dict.add_image(vol_tmpt)

    test_util.test_dsc('Try to use data vol_tempt to Create VM. ')
    vm_option = vm.get_creation_option()
    vm_option.set_image_uuid(vol_tmpt.get_image().uuid)
    vm2 = zstack_vm_header.ZstackTestVm()
    vm2.set_creation_option(vm_option)
    try:
        vm2.create()
    except:
        test_util.test_logger('Expected exception, when creating VM by using Data Volume Template as root image')
    else:
        test_util.test_fail('VM can use data volume template to create VM')

    vol_tmpt.delete()
    test_obj_dict.rm_image(vol_tmpt)
    vm.destroy()
    test_util.test_pass('Create VM from Data Volume Template Test Success')
def test():
    vm = test_stub.create_vm(vm_name = vn_prefix)
    test_obj_dict.add_vm(vm)
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
            break
    else:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    vm1 = test_stub.create_vm(vm_name = vn_prefix)
    test_obj_dict.add_vm(vm1)
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    test_util.test_dsc('create snapshot and check')
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm1)
    snapshots.create_snapshot('create_root_snapshot1')
    snapshot1 = snapshots.get_current_snapshot()
    snapshots.create_snapshot('create_root_snapshot2')

    snapshots.delete_snapshot(snapshot1)
    vm.reboot()
    new_vm1 = vm.clone(vm_name1)[0]
    test_obj_dict.add_vm(new_vm1)
    vm.destroy()

    new_vm1.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Clone VM Test with snapshot operations Success')
def test():
    vm = test_stub.create_vm(vm_name = vn_prefix)
    test_obj_dict.add_vm(vm)
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE, inventory.CEPH_BACKUP_STORAGE_TYPE]:
            break
    else:
        vm.destroy()
        test_util.test_skip('Not find image store or ceph type backup storage.')

    vm1 = test_stub.create_vm(vm_name = vn_prefix)
    test_obj_dict.add_vm(vm1)
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    test_util.test_dsc('create snapshot and check')
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm1)
    snapshots.create_snapshot('create_root_snapshot1')
    snapshot1 = snapshots.get_current_snapshot()
    snapshots.create_snapshot('create_root_snapshot2')

    snapshots.delete_snapshot(snapshot1)
    vm.reboot()
    new_vm1 = vm.clone(vm_name1)[0]
    test_obj_dict.add_vm(new_vm1)
    vm.destroy()

    new_vm1.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Clone VM Test with snapshot operations Success')
Beispiel #14
0
def test():
    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_system_tags(
        ['ephemeral::shareable', 'capability::virtio-scsi'])

    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    test_util.test_dsc('Attach volume and check')
    #vm.check()
    volume.attach(vm)
    if flavor['vm_running'] == False:
        vm.stop()
    if flavor['vm_running'] == True:
        allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE]
        test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)
    ps_uuid = volume.get_volume().primaryStorageUuid
    ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid)

    test_util.test_dsc('Create volume template and check')
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    bs_uuid_list = []
    for bs in bs_list:
        bs_uuid_list.append(bs.uuid)
    vol_tmpt = volume.create_template(bs_uuid_list, 'new_data_template')
    test_obj_dict.add_image(vol_tmpt)
    vol_tmpt.check()
    volume.check()
    volume.delete()
    test_obj_dict.rm_volume(volume)

    test_util.test_dsc('Create volume from template and check')
    volume2 = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template')
    test_obj_dict.add_volume(volume2)
    vol_tmpt.delete()
    test_obj_dict.rm_image(vol_tmpt)

    volume2.check()
    volume2.attach(vm)
    vm.check()
    volume2.check()
    volume2.detach()
    volume2.delete()
    test_obj_dict.rm_volume(volume2)

    vm.destroy()
    test_util.test_pass(
        'Create Sharable Data Volume Template from Data Volume Success.')
def test():
    global vm, exist_users
    test_util.test_dsc('Change unexisted user password test')

    vm = test_stub.create_vm(vm_name = 'cknewusrvmpswd-u13-64', image_name = "imageName_i_u13")
    vm.check()

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    for (usr,passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_util.test_logger("un-existed user:%s change vm password" %(usr))
            #if the user is not existed, it should report
            #try:
            #    vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)
            #except Exception,e:
            #    test_util.test_logger("unexisted user change vm password exception is %s" %(str(e)))
            #    normal_failed_string = "not exist"
            #    if normal_failed_string in str(e):
            #        test_util.test_logger("unexisted user return correct, create a the user for it.")
            #else:
            #    test_util.test_fail("user not exist in this OS, it should not raise exception, but return a failure.")

            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)


        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)
        
        #When vm is stopped:
        #vm.stop()
        vm_ops.change_vm_password(vm.get_vm().uuid, "root", test_stub.original_root_password)

        #vm.start()
        vm.check()


    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global origin_interval
    global bs_type

    test_util.test_dsc('Create test vm and check')
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)
    for i in bs:
        if i.type == 'AliyunEBS':
            test_util.test_skip('Skip test on AliyunEBS')
    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')
Beispiel #17
0
def test():
    global vm, exist_users, cur_usr, cur_passwd
    test_util.test_dsc('change VM with assigned password test')

    vm = test_stub.create_vm(vm_name='ckvmpswd-c6-32',
                             image_name="imageName_i_c6_32")
    vm.check()

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    cur_usr = "******"
    cur_passwd = "password"

    for (usr, passwd) in zip(users, passwds):

        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid,
                                  usr,
                                  passwd,
                                  skip_stopped_vm=None,
                                  session_uuid=None)

        cur_usr = usr
        cur_passwd = passwd

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed",
                                usr, passwd)

        #When vm is stopped:
        #vm.stop()
        vm_ops.change_vm_password(vm.get_vm().uuid, "root",
                                  test_stub.original_root_password)

        cur_usr = "******"
        cur_passwd = "password"

        #vm.start()
        vm.check()

    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
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():
    allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"]
    test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi'])

    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    test_util.test_dsc('Attach volume and check')
    #vm.check()
    volume.attach(vm)
    if flavor['vm_running'] == False:
        vm.stop()
    if flavor['vm_running'] == True:
        allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE]
        test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list)
    ps_uuid = volume.get_volume().primaryStorageUuid
    ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid)
    
    test_util.test_dsc('Create volume template and check')
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    bs_uuid_list = []
    for bs in bs_list:
        bs_uuid_list.append(bs.uuid)
    vol_tmpt = volume.create_template(bs_uuid_list, 'new_data_template')
    test_obj_dict.add_image(vol_tmpt)
    vol_tmpt.check()
    volume.check()
    volume.delete()
    test_obj_dict.rm_volume(volume)

    test_util.test_dsc('Create volume from template and check')
    volume2 = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template')
    test_obj_dict.add_volume(volume2)
    vol_tmpt.delete()
    test_obj_dict.rm_image(vol_tmpt)

    volume2.check()
    volume2.attach(vm)
    vm.check()
    volume2.check()
    volume2.detach()
    volume2.delete()
    test_obj_dict.rm_volume(volume2)

    vm.destroy()
    test_util.test_pass('Create Sharable Data Volume Template from Data Volume Success.')
Beispiel #20
0
def test():
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('rootDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi'])
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.attach(vm)
    vm.stop()
    vm.check()

    new_vms = vm.clone(vm_names)
    for new_vm in new_vms:
        test_obj_dict.add_vm(new_vm)

    if len(new_vms) != len(vm_names):
        test_util.test_fail(
            'only %s VMs have been cloned, which is less than required: %s' %
            (len(new_vms), vm_names))

    for new_vm in new_vms:
        new_vm = new_vm.get_vm()
        try:
            vm_names.remove(new_vm.name)
            test_util.test_logger('VM:%s name: %s is found' %
                                  (new_vm.uuid, new_vm.name))
        except:
            test_util.test_fail('%s vm name: %s is not in list: %s' %
                                (new_vm.uuid, new_vm.name, vm_names))

    if test_lib.lib_get_data_volumes(new_vms[0].vm) != []:
        test_util.test_fail(
            'The cloned vm is still have data volume, the expected behavior is only clone root volume.'
        )

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Clone VM Test Success')
def test():
    global vm, vm2, image_uuid
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" %(root_password))
        vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag")

        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
        for bs in backup_storage_list:
            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:
            vm.destroy()
            test_util.test_skip('Not find image store type backup storage.')

        vm.check()

        #add tag to vm
        tag_ops.create_system_tag('VmInstanceVO', vm.get_vm().uuid, "qemuga")

        vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password)

        #create image by the vm with tag
        vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
        root_volume_uuid = vm_root_volume_inv.uuid

        image_option1 = test_util.ImageOption()
        image_option1.set_root_volume_uuid(root_volume_uuid)
        image_option1.set_name('add_tag_vm_to_image')
        image_option1.set_format('qcow2')
        image_option1.set_backup_storage_uuid_list([bs.uuid])

        vm.stop()
        image = img_ops.create_root_volume_template(image_option1)

        #create vm by new image
        vm2 = test_stub.create_vm(vm_name = 'c7-vm-add-tag-from-previous-vm', image_name = "add_tag_vm_to_image")
        if not test_lib.lib_check_login_in_vm(vm2.get_vm(), "root", root_password):
            test_util.test_fail("create vm with user:%s password: %s failed", "root", root_password)

        vm_ops.change_vm_password(vm2.get_vm().uuid, "root", root_password)

        image_uuid = image.uuid
        if not image_uuid:
            img_ops.delete_image(image_uuid)
            img_ops.expunge_image(image_uuid)
            

    test_util.test_pass('add system tag on a no system tag image test passed')
def test():
    global vm, test_account_uuid, test_account_session, image_uuid
    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)
    test_account_uuid = test_account.uuid
    test_account_session = acc_ops.login_by_account(account_name, account_pass)
    test_stub.share_admin_resource([test_account_uuid])

    img_cond = res_ops.gen_query_conditions("name", '=', "centos7-installation-no-system-tag")
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, img_cond, None)
    image_uuid = img_inv[0].uuid
    #res_ops.enable_change_vm_password("true", image_uuid, 'ImageVO', session_uuid = test_account_session)
    img_ops.set_image_qga_enable(image_uuid, session_uuid = test_account_session)
    vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag", session_uuid = test_account_session)
    vm.check()

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    for (usr,passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)

        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = test_account_session)

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)

        vm_ops.change_vm_password(vm.get_vm().uuid, "root", test_stub.original_root_password, session_uuid = test_account_session)
        vm.check()

    #res_ops.enable_change_vm_password("false", img_inv[0].uuid, 'ImageVO', session_uuid = test_account_session)
    img_ops.set_image_qga_disable(img_inv[0].uuid, session_uuid = test_account_session)
    vm.destroy(test_account_session)
    vm.check()
    vm.expunge(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass('enable and change vm password by normal user account Success')
Beispiel #23
0
def test():
    global vms
    global images
    global threads
    global checker_threads
    global origin_interval
    global bs_type

    test_util.test_dsc('Create test vm and check')
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('dd if=/dev/zero of=/home/dd bs=1M count=100')
    script_file.close()

    for i in range(0, threads_num):
        vms[i] = test_stub.create_vlan_vm()
        vms[i].check()
        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(
            vms[i].vm)
        if backup_storage_list[0].type != 'ImageStoreBackupStorage':
            test_util.test_skip("Requires imagestore BS to test, skip testing")
        if not test_lib.lib_execute_shell_script_in_vm(vms[i].get_vm(),
                                                       script_file.name):
            test_util.test_fail("fail to create data in [vm:] %s" %
                                (vms[i].get_vm().uuid))
        test_obj_dict.add_vm(vms[i])
        vms[i].stop()

    os.unlink(script_file.name)

    for i in range(0, threads_num):
        threads[i] = threading.Thread(target=create_temp_image, args=(i, ))
        threads[i].start()

    for i in range(0, threads_num):
        checker_threads[i] = threading.Thread(
            target=check_create_temp_image_progress, args=(i, ))
        checker_threads[i].start()

    for i in range(0, threads_num):
        checker_threads[i].join()
        threads[i].join()
        images[i].check()
        vms[i].destroy()
        images[i].delete()

    if bs_type == 'Ceph':
        time.sleep(60)

    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 vm, exist_users, cur_usr, cur_passwd
    test_util.test_dsc('change VM with assigned password test')

    vm = test_stub.create_vm(vm_name = 'ckvmpswd-c7-64', image_name = "imageName_i_c7")
    vm.check()

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    cur_usr = "******"
    cur_passwd = "password"

    for (usr,passwd) in zip(users, passwds):

        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)

        cur_usr = usr
        cur_passwd = passwd

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)
        
        #When vm is stopped:
        #vm.stop()
        vm_ops.change_vm_password(vm.get_vm().uuid, "root", test_stub.original_root_password)

        cur_usr = "******"
        cur_passwd = "password"

        #vm.start()
        vm.check()



    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vms
    global images
    global threads
    global checker_threads
    global origin_interval
    global bs_type

    test_util.test_dsc('Create test vm and check')
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('dd if=/dev/zero of=/home/dd bs=1M count=100')
    script_file.close()

    for i in range(0, threads_num):
        vms[i] = test_stub.create_vlan_vm()
        vms[i].check()
        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vms[i].vm)
	if backup_storage_list[0].type != 'ImageStoreBackupStorage':
            test_util.test_skip("Requires imagestore BS to test, skip testing")
        if not test_lib.lib_execute_shell_script_in_vm(vms[i].get_vm(), script_file.name):
            test_util.test_fail("fail to create data in [vm:] %s" % (vms[i].get_vm().uuid))
        test_obj_dict.add_vm(vms[i])
        vms[i].stop()
        
    os.unlink(script_file.name)

    for i in range(0, threads_num):
        threads[i] = threading.Thread(target=create_temp_image, args=(i, ))
        threads[i].start()

    for i in range(0, threads_num):
        checker_threads[i] = threading.Thread(target=check_create_temp_image_progress, args=(i, ))
        checker_threads[i].start()

    for i in range(0, threads_num):
        checker_threads[i].join()
        threads[i].join()
        images[i].check()
        vms[i].destroy()
        images[i].delete()

    for i in range(0, threads_num):
        if checker_results[i] == None:
            test_util.test_fail("Image checker thread %s fail" % (i))

    if bs_type == 'Ceph':
        time.sleep(60)

    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 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 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():
    global vm, test_account_uuid, test_account_session
    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)
    test_account_uuid = test_account.uuid
    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(vm_name = 'c7-vm', image_name = "imageName_i_c7", session_uuid = test_account_session)
    vm.check()

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    for (usr,passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)

        #When vm is running:
        vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = test_account_session)

        if not test_lib.lib_check_login_in_vm(vm.get_vm(), usr, passwd):
            test_util.test_fail("create vm with user:%s password: %s failed", usr, passwd)

        #When vm is stopped:
        #vm.stop(session_uuid = test_account_session)
        vm_ops.change_vm_password(vm.get_vm().uuid, "root", test_stub.original_root_password, session_uuid = test_account_session)

        #vm.start(session_uuid = test_account_session)
        vm.check()

    vm.destroy(test_account_session)
    vm.check()
    vm.expunge(test_account_session)
    vm.check()
    acc_ops.delete_account(test_account_uuid)
    test_util.test_pass('change vm password by normal user account Success')
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():
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)

    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    test_util.test_dsc('Attach volume and check')
    #vm.check()
    volume.attach(vm)

    test_util.test_dsc('Detach volume and check')
    volume.detach()

    test_util.test_dsc('Create volume template and check')
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    bs_uuid_list = []
    for bs in bs_list:
        bs_uuid_list.append(bs.uuid)
    vol_tmpt = volume.create_template(bs_uuid_list, 'new_data_template')
    test_obj_dict.add_image(vol_tmpt)
    vol_tmpt.check()
    volume.check()
    volume.delete()
    test_obj_dict.rm_volume(volume)

    test_util.test_dsc('Create volume from template and check')
    ps_uuid = vm.get_vm().allVolumes[0].primaryStorageUuid
    volume2 = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template')
    test_obj_dict.add_volume(volume2)
    vol_tmpt.delete()
    test_obj_dict.rm_image(vol_tmpt)

    volume2.check()
    volume2.attach(vm)
    vm.check()
    volume2.check()
    volume2.detach()
    volume2.delete()
    test_obj_dict.rm_volume(volume2)

    vm.destroy()
    test_util.test_pass('Create Data Volume Template from Data Volume Success')
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 create_dvol_image(vm_obj):
    global dvol
    volume_uuid = dvol.volume.uuid
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm_obj.vm)
    image_option = test_util.ImageOption()
    image_option.set_data_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_data_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.delete()
    new_image.expunge()
def test():
    vm = test_stub.create_vlan_vm()
    #test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.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:
        vm.destroy()
        vm.expunge()
        test_util.test_skip('Not find image store type backup storage.')

    new_vms = vm.clone(vm_names)
    for new_vm in new_vms:
        test_obj_dict.add_vm(new_vm)

    if len(new_vms) != len(vm_names):
        test_util.test_fail('only %s VMs have been cloned, which is less than required: %s' % (len(new_vms), vm_names))

    for new_vm in new_vms:
        new_vm = new_vm.get_vm()
        try:
            vm_names.remove(new_vm.name)
            test_util.test_logger('VM:%s name: %s is found' % (new_vm.uuid, new_vm.name))
        except:
            test_util.test_fail('%s vm name: %s is not in list: %s' % (new_vm.uuid, new_vm.name, vm_names))
    
    vm.destroy()
    check_imf2_cmd = "find /|grep imf|grep %s" % (test_lib.lib_get_root_volume_uuid(vm.get_vm()))
    host = test_lib.lib_find_host_by_vm(vm.get_vm()) 
    ret, output, stderr = ssh.execute(check_imf2_cmd, host.managementIp, "root", "password", False, 22)
    test_util.test_logger('expect imf2 exist: %s,%s' % (output, ret))
    if ret != 0:
        test_util.test_fail('imf2 is expected to exist')

    vm.expunge()
    ret, output, stderr = ssh.execute(check_imf2_cmd, host.managementIp, "root", "password", False, 22)
    test_util.test_logger('expect imf2 not exist: %s,%s' % (output, ret))
    if ret == 0:
        test_util.test_fail('imf2 is expected to be deleted')

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Clone VM Test Success')
Beispiel #34
0
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():
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi'])
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume.attach(vm)
    vm.stop()
    vm.check()

    new_vms = vm.clone(vm_names)
    for new_vm in new_vms:
        test_obj_dict.add_vm(new_vm)

    if len(new_vms) != len(vm_names):
        test_util.test_fail('only %s VMs have been cloned, which is less than required: %s' % (len(new_vms), vm_names))

    for new_vm in new_vms:
        new_vm = new_vm.get_vm()
        try:
            vm_names.remove(new_vm.name)
            test_util.test_logger('VM:%s name: %s is found' % (new_vm.uuid, new_vm.name))
        except:
            test_util.test_fail('%s vm name: %s is not in list: %s' % (new_vm.uuid, new_vm.name, vm_names))
    
    if test_lib.lib_get_data_volumes(new_vms[0].vm) != []:
        test_util.test_fail('The cloned vm is still have data volume, the expected behavior is only clone root volume.')
    

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Clone VM Test Success')
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)
    images[index].create()
    test_obj_dict.add_image(images[index])
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():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    vm.check()
    test_obj_dict.add_vm(vm)
    volume.attach(vm)
    vm.stop()
    vm.check()

    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' %
                            vol_size_after)

    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    image_option = test_util.ImageOption()
    image_option.set_data_volume_uuid(volume_uuid)
    image_option.set_name('data_resize_template')
    image_option.set_backup_storage_uuid_list([bs_list[0].uuid])
    data_image = img_ops.create_data_volume_template(image_option)
    target_host = test_lib.lib_find_random_host(vm.get_vm())

    new_data = vol_ops.create_volume_from_template(
        data_image.uuid,
        volume.volume.primaryStorageUuid,
        host_uuid=target_host.uuid)
    if set_size != new_data.size:
        test_util.test_fail('Resize Data Volume failed, size = %s' %
                            new_data.size)

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test Success')
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])
Beispiel #40
0
def create_temp_image():
    global vm1
    global image
    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_progress')
    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)
Beispiel #41
0
def test():
    global test_obj_dict
    global vm
    import signal

    def handler(signum, frame):
        raise Exception()

    signal.signal(signal.SIGALRM, handler)
    signal.alarm(300)
    test_util.test_dsc('Create test clone windows vm boot option')

    image_name = os.environ.get('imageName_windows')
    vm = test_stub.create_vm(image_name=image_name)
    test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type in [
                inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE,
                inventory.CEPH_BACKUP_STORAGE_TYPE
        ]:
            break
    else:
        vm.destroy()
        test_util.test_skip(
            'Not find image store or ceph type backup storage.')

    new_vm = vm.clone(vm_name)[0]
    test_obj_dict.add_vm(new_vm)
    console = test_lib.lib_get_vm_console_address(new_vm.get_vm().uuid)
    test_util.test_logger('[vm:] %s console is on %s:%s' %
                          (new_vm.get_vm().uuid, console.hostIp, console.port))
    display = str(int(console.port) - 5900)

    client = api.connect(console.hostIp + ":" + display)
    client.keyPress('esc')
    time.sleep(2)
    client.expectRegion(boot_option_picture, 0, 100)

    vm.destroy()
    new_vm.destroy()

    test_util.test_pass('VM With Volumes Boot Option Test Success')
def test():
    test_util.test_dsc("Create test vm and check")
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    test_util.test_dsc("Create volume and check")
    print os.environ.get("smallDiskOfferingName")
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get("smallDiskOfferingName"))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)

    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    test_util.test_dsc("Attach volume and check")
    # vm.check()
    volume.attach(vm)

    test_util.test_dsc("Detach volume and check")
    volume.detach()

    test_util.test_dsc("Create volume template and check")
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    bs_uuid_list = []
    for bs in bs_list:
        bs_uuid_list.append(bs.uuid)
    vol_tmpt1 = volume.create_template(bs_uuid_list, "new_data_template1")
    test_obj_dict.add_image(vol_tmpt1)
    vol_tmpt2 = volume.create_template(bs_uuid_list, "new_data_template2")
    test_obj_dict.add_image(vol_tmpt2)
    vol_tmpt1.check()
    vol_tmpt2.check()

    vol_tmpt1.delete()
    test_obj_dict.rm_image(vol_tmpt1)
    vol_tmpt1.check()
    vol_tmpt2.check()
    vol_tmpt2.delete()
    test_obj_dict.rm_image(vol_tmpt2)

    volume.delete()
    test_obj_dict.rm_volume(volume)
    vm.destroy()
    test_util.test_pass("Create Duplicated Data Volume Template from Same Data Volume Success")
def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid

    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
            break
    else:
        vm.destroy()
        test_util.test_skip('Not find ceph type backup storage.')

    l3_1_name = os.environ.get('l3VlanNetwork3')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    vr_uuid = vr.uuid

    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    ps_uuid = ps.uuid
    ps_ops.change_primary_storage_state(ps_uuid, 'disable')
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail(
            'VM is expected to stop when PS change to disable state')

    vm.set_state(vm_header.STOPPED)
    vm.check()
    test_stub.migrate_vm_to_random_host(vm)
    vm.check()
    volume.check()

    ps_ops.change_primary_storage_state(ps_uuid, 'Enabled')
    host_ops.reconnect_host(host_uuid)
    vm_ops.reconnect_vr(vr_uuid)
    test_util.test_pass('PS disable mode Test Success')
def test():
    global test_obj_dict
    global ps_uuid
    global host_uuid
    global vr_uuid

    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
            break
    else:
        vm.destroy()
        test_util.test_skip('Not find ceph type backup storage.')

    l3_1_name = os.environ.get('l3VlanNetwork3')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
    vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    vr_uuid = vr.uuid
    
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    test_obj_dict.add_vm(vm)
    vm.check()
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    ps_uuid = ps.uuid
    ps_ops.change_primary_storage_state(ps_uuid, 'disable')
    if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90):
        test_util.test_fail('VM is expected to stop when PS change to disable state')

    vm.set_state(vm_header.STOPPED)
    vm.check()
    test_stub.migrate_vm_to_random_host(vm)
    vm.check()
    volume.check()

    ps_ops.change_primary_storage_state(ps_uuid, 'Enabled')
    host_ops.reconnect_host(host_uuid)
    vm_ops.reconnect_vr(vr_uuid)
    test_util.test_pass('PS disable mode Test Success')
Beispiel #45
0
def test():
    global test_obj_dict

    test_util.test_dsc('Create test vm and check')
    vm1 = test_stub.create_vm()
    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.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()
    image.check()

    test_util.test_pass('Create Image Template Test Success')
def test():
    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 = 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()
    image.check()

    test_util.test_pass('Create Image Template Test Success')
def test():
    global test_obj_dict

    test_util.test_dsc('Create test vm and check')
    vm1 = test_stub.create_vm()
    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.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()
    image.check()

    test_util.test_pass('Create Image Template Test Success')
def test():
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    vm.stop()
    r_volume = zstack_volume_header.ZstackTestVolume()
    r_volume.set_volume(test_lib.lib_get_root_volume(vm.get_vm()))
    r_volume.set_state(volume_header.ATTACHED)

    test_util.test_dsc('Create volume template and check')
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    vol_tmpt = r_volume.create_template([bs_list[0].uuid], 'new_data_template')
    test_obj_dict.add_image(vol_tmpt)
    vol_tmpt.check()

    test_util.test_dsc('Create volume from template and check')
    ps_uuid = vm.get_vm().allVolumes[0].primaryStorageUuid
    volume = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template1')
    test_obj_dict.add_volume(volume)

    volume2 = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template2')
    test_obj_dict.add_volume(volume2)
    volume2.check()
    volume.attach(vm)
    vm.start()
    volume2.attach(vm)
    vm.check()
    volume.check()
    volume2.check()
    volume.detach()
    volume.delete()
    test_obj_dict.rm_volume(volume)
    volume2.detach()
    volume2.delete()
    test_obj_dict.rm_volume(volume2)

    vol_tmpt.delete()
    test_obj_dict.rm_image(vol_tmpt)
    vm.destroy()
    test_util.test_pass('Create Data Volume Template from Data Volume Success')
def test():
    global test_obj_dict
    volume_creation_option = test_util.VolumeOption()
    test_util.test_dsc('Create volume and check')
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)
    volume.check()
    volume_uuid = volume.volume.uuid
    vol_size = volume.volume.size
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    vm.check()
    test_obj_dict.add_vm(vm)
    volume.attach(vm)
    vm.stop()
    vm.check()

    set_size = 1024*1024*1024*5
    vol_ops.resize_data_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after)

    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    image_option = test_util.ImageOption()
    image_option.set_data_volume_uuid(volume_uuid)
    image_option.set_name('data_resize_template')
    image_option.set_backup_storage_uuid_list([bs_list[0].uuid])
    data_image = img_ops.create_data_volume_template(image_option)
    target_host = test_lib.lib_find_random_host(vm.get_vm())

    new_data = vol_ops.create_volume_from_template(data_image.uuid, volume.volume.primaryStorageUuid, host_uuid = target_host.uuid)
    if set_size != new_data.size:
        test_util.test_fail('Resize Data Volume failed, size = %s' % new_data.size)

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Resize Data Volume Test 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')
Beispiel #51
0
def test():
    global vm
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm = test_stub.create_vm("test_resize_vm", image_name, l3_name)
    test_obj_dict.add_vm(vm)
    vm.check()
    vm.stop()
    vm.check()

    vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
    volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_volume(volume_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' %
                            vol_size_after)

    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.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_vm = test_stub.create_vm("test_vm_after_resize",
                                 'image_resize_template', l3_name)
    test_obj_dict.add_vm(new_vm)
    new_vm.check()
    new_vm.stop()
    new_vm.check()
    new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm())
    vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' %
                            vol_size_after)
    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('Create Template for Resize VM Test Success')
def test():
    test_util.test_dsc('Create test vm and check')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)

    vm.stop()
    r_volume = zstack_volume_header.ZstackTestVolume()
    r_volume.set_volume(test_lib.lib_get_root_volume(vm.get_vm()))
    r_volume.set_state(volume_header.ATTACHED)

    test_util.test_dsc('Create volume template and check')
    bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm())
    vol_tmpt = r_volume.create_template([bs_list[0].uuid], 'new_data_template')
    test_obj_dict.add_image(vol_tmpt)
    vol_tmpt.check()

    test_util.test_dsc('Create volume from template and check')
    ps_uuid = vm.get_vm().allVolumes[0].primaryStorageUuid
    volume = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template1')
    test_obj_dict.add_volume(volume)

    volume2 = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template2')
    test_obj_dict.add_volume(volume2)
    volume2.check()
    volume.attach(vm)
    vm.start()
    volume2.attach(vm)
    vm.check()
    volume.check()
    volume2.check()
    volume.detach()
    volume.delete()
    test_obj_dict.rm_volume(volume)
    volume2.detach()
    volume2.delete()
    test_obj_dict.rm_volume(volume2)

    vol_tmpt.delete()
    test_obj_dict.rm_image(vol_tmpt)
    vm.destroy()
    test_util.test_pass('Create Data Volume Template from Data Volume Success')
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():
    global vm, exist_users
    test_util.test_dsc('cloned vm change password test')

    vm = test_stub.create_vm(vm_name='1st-created-vm-u12',
                             image_name="imageName_i_u12")
    test_obj_dict.add_vm(vm)
    vm.check()

    force_vm_auto_boot(vm)

    test_util.test_logger("change vm password for initial created vm")
    vm_ops.change_vm_password(vm.get_vm().uuid,
                              "root",
                              "password",
                              skip_stopped_vm=None,
                              session_uuid=None)
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    for (usr, passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_util.test_logger("find new account: <%s:%s>" % (usr, passwd))
            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd)
            exist_users.append(usr)

        #new vm->cloned new_vm1/new_vm2
        test_util.test_logger("1st clone")
        new_vms = vm.clone(vm_names)

        if len(new_vms) != len(vm_names):
            test_util.test_fail(
                'only %s VMs have been cloned, which is less than required: %s'
                % (len(new_vms), vm_names))

        for new_vm in new_vms:
            new_vm.update()
            #new_vm.check()
            test_obj_dict.add_vm(new_vm)

            #When vm is running:
            test_util.test_logger(
                "vm running && change 1st cloned vm password:<%s:%s:%s>" %
                (new_vm, usr, passwd))
            vm_ops.change_vm_password(new_vm.get_vm().uuid,
                                      usr,
                                      passwd,
                                      skip_stopped_vm=None,
                                      session_uuid=None)

            if not test_lib.lib_check_login_in_vm(new_vm.get_vm(), usr,
                                                  passwd):
                test_util.test_fail(
                    "check login cloned vm with user:%s password: %s failed",
                    usr, passwd)

            #When vm is stopped:
            #new_vm.stop()
            test_util.test_logger(
                "vm stopped && change 1st cloned vm password:<%s:%s:%s>" %
                (new_vm, usr, passwd))
            vm_ops.change_vm_password(new_vm.get_vm().uuid, "root",
                                      test_stub.original_root_password)

            #new_vm.start()
            new_vm.check()

            #test use the cloned vm change password to clone new vm and then change password
            test_util.test_logger("2nd cloned")
            in_new_vms = new_vm.clone(in_vm_names)

            new_vm.destroy()
            new_vm.check()
            new_vm.expunge()
            new_vm.check()

            for in_new_vm in in_new_vms:
                in_new_vm.update()
                test_obj_dict.add_vm(in_new_vm)

                test_util.test_logger(
                    "vm running && change 2nd cloned vm password:<%s:%s:%s>" %
                    (new_vm, usr, passwd))
                vm_ops.change_vm_password(in_new_vm.get_vm().uuid,
                                          usr,
                                          passwd,
                                          skip_stopped_vm=None,
                                          session_uuid=None)

                if not test_lib.lib_check_login_in_vm(in_new_vm.get_vm(), usr,
                                                      passwd):
                    test_util.test_fail(
                        "check login cloned in_vm with user:%s password: %s failed",
                        usr, passwd)

                #When vm is stopped:
                #in_new_vm.stop()
                test_util.test_logger(
                    "vm stopped && change 2nd cloned vm password:<%s:%s:%s>" %
                    (new_vm, usr, passwd))
                vm_ops.change_vm_password(in_new_vm.get_vm().uuid, "root",
                                          test_stub.original_root_password)

                #in_new_vm.start()
                in_new_vm.check()
                in_new_vm.destroy()
                in_new_vm.check()
                in_new_vm.expunge()
                in_new_vm.check()

    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')
def test():
    global vm, exist_users
    test_util.test_dsc('cloned vm change password test')

    vm = test_stub.create_vm(vm_name = '1st-created-vm-u13', image_name = "imageName_i_u13")
    test_obj_dict.add_vm(vm)
    vm.check()

    force_vm_auto_boot(vm)

    test_util.test_logger("change vm password for initial created vm")
    vm_ops.change_vm_password(vm.get_vm().uuid, "root", "password", skip_stopped_vm = None, session_uuid = None)
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        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:
        vm.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    for (usr,passwd) in zip(users, passwds):
        if usr not in exist_users:
            test_util.test_logger("find new account: <%s:%s>" %(usr, passwd))
            test_stub.create_user_in_vm(vm.get_vm(), usr, passwd) 
            exist_users.append(usr)

        #new vm->cloned new_vm1/new_vm2
        test_util.test_logger("1st clone")
        new_vms = vm.clone(vm_names)

        if len(new_vms) != len(vm_names):
            test_util.test_fail('only %s VMs have been cloned, which is less than required: %s' % (len(new_vms), vm_names))

        for new_vm in new_vms:
            new_vm.update()
            #new_vm.check()
            test_obj_dict.add_vm(new_vm)

            #When vm is running:
            test_util.test_logger("vm running && change 1st cloned vm password:<%s:%s:%s>" %(new_vm, usr, passwd))
            vm_ops.change_vm_password(new_vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)

            if not test_lib.lib_check_login_in_vm(new_vm.get_vm(), usr, passwd):
                test_util.test_fail("check login cloned vm with user:%s password: %s failed", usr, passwd)

            #When vm is stopped:
            #new_vm.stop()
            test_util.test_logger("vm stopped && change 1st cloned vm password:<%s:%s:%s>" %(new_vm, usr, passwd))
            vm_ops.change_vm_password(new_vm.get_vm().uuid, "root", test_stub.original_root_password)

            #new_vm.start()
            new_vm.check()
            
            #test use the cloned vm change password to clone new vm and then change password
            test_util.test_logger("2nd cloned")
            in_new_vms = new_vm.clone(in_vm_names)

            new_vm.destroy()
            new_vm.check()
            new_vm.expunge()
            new_vm.check()

            for in_new_vm in in_new_vms:
                in_new_vm.update()
                test_obj_dict.add_vm(in_new_vm)

                test_util.test_logger("vm running && change 2nd cloned vm password:<%s:%s:%s>" %(new_vm, usr, passwd))
                vm_ops.change_vm_password(in_new_vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)

                if not test_lib.lib_check_login_in_vm(in_new_vm.get_vm(), usr, passwd):
                    test_util.test_fail("check login cloned in_vm with user:%s password: %s failed", usr, passwd)

                #When vm is stopped:
                #in_new_vm.stop()
                test_util.test_logger("vm stopped && change 2nd cloned vm password:<%s:%s:%s>" %(new_vm, usr, passwd))
                vm_ops.change_vm_password(in_new_vm.get_vm().uuid, "root", test_stub.original_root_password)

                #in_new_vm.start()
                in_new_vm.check()
                in_new_vm.destroy()
                in_new_vm.check()
                in_new_vm.expunge()
                in_new_vm.check()

    vm.destroy()
    vm.check()

    vm.expunge()
    vm.check()

    test_util.test_pass('Set password when VM is creating is successful.')