Пример #1
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, 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 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, 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():
    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 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 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.')