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))
Пример #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 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.')
Пример #5
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 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')
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 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')
Пример #10
0
def change_vm_password_wrapper(vm_uuid,
                               usr,
                               passwd,
                               skip_stopped_vm=None,
                               session_uuid=None):
    global invs

    inv = vm_ops.change_vm_password(vm_uuid, usr, passwd, skip_stopped_vm,
                                    session_uuid)
    if inv:
        invs.append(inv)
def running_vm_operations(vm, bss):

    numa = config_ops.get_global_config_value('vm', 'numa')
    live_migration = config_ops.get_global_config_value(
        'localStoragePrimaryStorage', 'liveMigrationWithStorage.allow')
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    vm_uuid = vm.get_vm().uuid
    #change vm's instanceoffering
    if numa == 'false':
        try:
            vm_ops.update_vm(vm_uuic, 2, 2048 * 1024 * 1024)
            test_util.test_fail(
                'Test Fail.Cannot change instanceoffering of running vm when NUMA is false'
            )
        except:
            config_ops.change_global_config('vm', 'numa', 'true')

    vm_ops.reboot_vm(vm_uuid)
    vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024)

    #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop
    ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop')
    vm_ops.stop_vm(vm_uuid)
    ha_ops.del_vm_instance_ha_level(vm_uuid)
    vm_ops.stop_vm(vm_uuid)
    vm_ops.start_vm(vm_uuid)
    vm_ops.reboot_vm(vm_uuid)
    vm_ops.suspend_vm(vm_uuid)
    vm_ops.resume_vm(vm_uuid)
    vm_ops.stop_vm(vm_uuid, 'cold')
    vm_ops.start_vm(vm_uuid)

    #clone vms
    vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart')

    #migrate
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
    migrate_host_uuids = []
    if candidate_hosts == None:
        pass
    else:
        for host in candidate_hosts.inventories:
            migrate_host_uuids.append(host.uuid)
        if ps.type == 'LocalStorage':
            if live_migration == 'false':
                try:
                    vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0])
                    test_util.test_fail(
                        'Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.'
                    )
                except:
                    config_ops.change_global_config(
                        'localStoragePrimaryStorage',
                        'liveMigrationWithStorage.allow', 'true')
            else:
                vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0])
                test_util.test_logger('migrate vm success')
        else:
            vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0])
            test_util.test_logger('migrate vm success')

    #change vm's password(qga)
    try:
        vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword')
        test_util.test_fail(
            'Test Fail.Cannot change vm password when qga is disabled.')
    except:
        vm_ops.set_vm_qga_enable(vm_uuid)

    vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword')
    vm_ops.set_vm_qga_disable(vm_uuid)

    #snapshot operations
    sp_option = test_util.SnapshotOption()
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    root_volume_uuid = vm_root_volume_inv.uuid
    test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid)
    sp_option.set_volume_uuid(root_volume_uuid)
    sp = vol_ops.create_snapshot(sp_option)
    vm_ops.stop_vm(vm_uuid)
    vol_ops.use_snapshot(sp.uuid)
    vm_ops.start_vm(vm_uuid)
    vol_ops.delete_snapshot(sp.uuid)

    common_operations(vm, bss, 'running')

    vm_ops.destroy_vm(vm_uuid)
    vm_ops.recover_vm(vm_uuid)
    vm_ops.start_vm(vm_uuid)
    vm.destroy()
    vm.expunge()
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.')
def change_vm_password_wrapper(vm_uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None):
    global invs

    inv = vm_ops.change_vm_password(vm_uuid, usr, passwd, skip_stopped_vm, session_uuid)
    if inv:
        invs.append(inv)
def test():
    global vm, exist_users
    test_util.test_dsc('change VM with assigned password test')


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

        test_util.test_dsc("username:%s, password: \"%s\"" %(usr, passwd))

        #Create VM API
        if usr == "root":
            try:
                vm = test_stub.create_vm(vm_name = 'c7-vm', image_name = "imageName_i_c7", root_password=passwd)
            except:
                pass
            else:
                test_util.test_fail("create vm && the invaild password: %s successfully be set" % (passwd))

        #Check bs type
        vm = test_stub.create_vm(vm_name = 'c7-vm', 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:
            test_util.test_skip('Not find image store type backup storage.')

        #inject normal account username/password
        if usr not in exist_users:
            test_stub.create_user_in_vm(vm.get_vm(), usr, "password") 
            exist_users.append(usr)


        #Change VM API && Running
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)
        except:
            pass
        else:
            test_util.test_fail("vm running && the invaild password: %s successfully be set" %(passwd))

        #Change VM API && Stopped
        #vm.stop()
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid, usr, passwd, skip_stopped_vm = None, session_uuid = None)
        except:
            pass
        else:
            test_util.test_fail("vm stopped && the invaild password: %s successfully be set" %(passwd))

        #vm.start()
        vm.check()

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

        vm.destroy()
        vm.expunge()
        vm.check()

    test_util.test_pass('Invalid password test is passed.')
def running_vm_operations(vm,bss):
      
   numa = config_ops.get_global_config_value('vm', 'numa')
   live_migration = config_ops.get_global_config_value('localStoragePrimaryStorage','liveMigrationWithStorage.allow')
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   vm_uuid = vm.get_vm().uuid
   #change vm's instanceoffering
   if numa == 'false':
      try:
         vm_ops.update_vm(vm_uuic,2,2048*1024*1024)
         test_util.test_fail('Test Fail.Cannot change instanceoffering of running vm when NUMA is false')
      except:
         config_ops.change_global_config('vm','numa','true')
   
   vm_ops.reboot_vm(vm_uuid)
   vm_ops.update_vm(vm_uuid,2,2048*1024*1024)

   #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop
   ha_ops.set_vm_instance_ha_level(vm_uuid,'NeverStop')
   vm_ops.stop_vm(vm_uuid)
   ha_ops.del_vm_instance_ha_level(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   vm_ops.start_vm(vm_uuid)
   vm_ops.reboot_vm(vm_uuid)
   vm_ops.suspend_vm(vm_uuid)
   vm_ops.resume_vm(vm_uuid)
   vm_ops.stop_vm(vm_uuid,'cold')
   vm_ops.start_vm(vm_uuid)

   #clone vms
   vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart')

   #migrate
   candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
   migrate_host_uuids = []
   if candidate_hosts == None:
      pass
   else:
      for host in candidate_hosts.inventories:
         migrate_host_uuids.append(host.uuid)
      if ps.type == 'LocalStorage':
         if live_migration == 'false':
       	   try:
       	      vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
       	      test_util.test_fail('Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' )
       	   except:
       	      config_ops.change_global_config('localStoragePrimaryStorage','liveMigrationWithStorage.allow','true')
       	 else:
       	    vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
       	    test_util.test_logger('migrate vm success')
      else:
         vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
         test_util.test_logger('migrate vm success')

   #change vm's password(qga)
   try:
      vm_ops.change_vm_password(vm_uuid,'root','testpassword')
      test_util.test_fail('Test Fail.Cannot change vm password when qga is disabled.')
   except:
      vm_ops.set_vm_qga_enable(vm_uuid)
     
   vm_ops.change_vm_password(vm_uuid,'root','testpassword')
   vm_ops.set_vm_qga_disable(vm_uuid)

   #snapshot operations
   sp_option = test_util.SnapshotOption()
   vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
   root_volume_uuid = vm_root_volume_inv.uuid
   test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid)
   sp_option.set_volume_uuid(root_volume_uuid)
   sp = vol_ops.create_snapshot(sp_option)
   vm_ops.stop_vm(vm_uuid)
   vol_ops.use_snapshot(sp.uuid)
   vm_ops.start_vm(vm_uuid)
   vol_ops.delete_snapshot(sp.uuid)
   
   common_operations(vm,bss,'running')

   vm_ops.destroy_vm(vm_uuid)
   vm_ops.recover_vm(vm_uuid)
   vm_ops.start_vm(vm_uuid)
   vm.destroy()
   vm.expunge()
def test():
    global vm, exist_users
    test_util.test_dsc('change VM with assigned password test')

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

        test_util.test_dsc("username:%s, password: \"%s\"" % (usr, passwd))

        #Create VM API
        if usr == "root":
            try:
                vm = test_stub.create_vm(vm_name='c7-vm',
                                         image_name="imageName_i_c7",
                                         root_password=passwd)
            except:
                pass
            else:
                test_util.test_fail(
                    "create vm && the invaild password: %s successfully be set"
                    % (passwd))

        #Check bs type
        vm = test_stub.create_vm(vm_name='c7-vm', 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:
            test_util.test_skip('Not find image store type backup storage.')

        #inject normal account username/password
        if usr not in exist_users:
            test_stub.create_user_in_vm(vm.get_vm(), usr, "password")
            exist_users.append(usr)

        #Change VM API && Running
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid,
                                      usr,
                                      passwd,
                                      skip_stopped_vm=None,
                                      session_uuid=None)
        except:
            pass
        else:
            test_util.test_fail(
                "vm running && the invaild password: %s successfully be set" %
                (passwd))

        #Change VM API && Stopped
        #vm.stop()
        try:
            vm_ops.change_vm_password(vm.get_vm().uuid,
                                      usr,
                                      passwd,
                                      skip_stopped_vm=None,
                                      session_uuid=None)
        except:
            pass
        else:
            test_util.test_fail(
                "vm stopped && the invaild password: %s successfully be set" %
                (passwd))

        #vm.start()
        vm.check()

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

        vm.destroy()
        vm.expunge()
        vm.check()

    test_util.test_pass('Invalid password test is passed.')