def test():
    #Enable twofa and check login
    password = '******'
    session_uuid = acc_ops.login_as_admin()
    twofa_enabled = conf_ops.get_global_config_value('twofa', 'twofa.enable')
    if twofa_enabled == 'false':
        conf_ops.change_global_config('twofa', 'twofa.enable', 'true') 
    twofa = acc_ops.get_twofa_auth_secret('admin', password, session_uuid = session_uuid)
    secret = twofa.secret
    twofa_status = twofa.status
    if twofa_status != 'NewCreated':
        test_util.test_fail("The twofa auth secret statue should be 'NewCreated' but it's %s" %twofa_status) 
    security_code = test_stub.get_security_code(secret)
    session1_uuid = acc_ops.login_by_account('admin', password, system_tags=['twofatoken::%s' %security_code]) 
    if session1_uuid != None:
        test_util.test_logger("Enable twofa and login with security code passed")

    twofa_status = acc_ops.get_twofa_auth_secret('admin', password, session_uuid = session_uuid).status
    if twofa_status != 'Logined':
        test_util.test_fail("The twofa auth secret statue should be 'Logined' but it's %s" %twofa_status)

    #Disable twofa and check login again
    conf_ops.change_global_config('twofa', 'twofa.enable', 'false', session_uuid = session_uuid)
    session2_uuid = acc_ops.login_as_admin()
    if session2_uuid != None:
        test_util.test_pass("Disable twofa and login without security code passed")

    test_util.test_fail("Fail to login without security code after twofa disabled")
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_vm', 'imageName_s', 'l3VlanNetwork2')
    vm.check()
    session_uuid = acc_ops.login_as_admin()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid,
                                                  session_uuid)
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_logger('[vm:] %s console on %s:%s is connectable' %
                              (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' %
                            (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    test_stub.migrate_vm_to_random_host(vm)

    vm.check()
    session_uuid = acc_ops.login_as_admin()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid,
                                                  session_uuid)
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_logger('[vm:] %s console on %s:%s is connectable' %
                              (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' %
                            (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    vm.destroy()
    test_util.test_pass('Migrate VM Console Access Test Success')
def test():
    global vm
    vm = test_stub.create_vr_vm('migrate_vm', 'imageName_s', 'l3VlanNetwork2')
    vm.check()
    session_uuid = acc_ops.login_as_admin()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid, session_uuid)
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_logger('[vm:] %s console on %s:%s is connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    test_stub.migrate_vm_to_random_host(vm)

    vm.check()
    session_uuid = acc_ops.login_as_admin()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid, session_uuid)
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_logger('[vm:] %s console on %s:%s is connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    vm.destroy()
    test_util.test_pass('Migrate VM Console Access Test Success')
def add_l3_resource(deploy_config, l3_name, l2_name = None, zone_name = None, \
        session_uuid = None):
    session_uuid_flag = True
    if not session_uuid:
        session_uuid = acc_ops.login_as_admin()
        session_uuid_flag = False
    try:
        dep_ops.add_l3_network(None, None, deploy_config, session_uuid, l3_name = l3_name, \
                l2_name = l2_name, zone_name = zone_name)
        dep_ops.add_virtual_router(None, None, deploy_config, session_uuid, \
                l3_name = l3_name, zone_name = zone_name)
        l3_uuid = res_ops.get_resource(res_ops.L3_NETWORK, session_uuid, \
                name = l3_name)[0].uuid
    except Exception as e:
        test_util.test_logger(
            '[Error] zstack deployment meets exception when adding l3 resource .'
        )
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        if not session_uuid_flag:
            acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add l3 resources for [uuid:] %s' \
            % l3_uuid)
def test():
    global vms
    for i in range(12):
        vms.append(test_stub.create_vm())

    session_uuid = acc_ops.login_as_admin()
    for vm in vms:
        if vm:
            vm.check()
            console = test_lib.lib_get_vm_console_address(
                vm.get_vm().uuid, session_uuid)
            if test_lib.lib_network_check(console.hostIp, console.port):
                test_util.test_logger(
                    '[vm:] %s console on %s:%s is connectable' %
                    (vm.get_vm().uuid, console.hostIp, console.port))
            else:
                test_util.test_fail(
                    '[vm:] %s console on %s:%s is not connectable' %
                    (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    for vm in vms:
        if vm:
            vm.destroy()
            vm.check()
    test_util.test_pass('Request Access Multiple VM Console Test Success')
Example #6
0
def test():
    global session_to
    global session_mc
    global session_uuid
    session_to = con_ops.change_global_config("identity", "session.timeout", "720000", session_uuid)
    session_mc = con_ops.change_global_config("identity", "session.maxConcurrent", "10000", session_uuid)
    session_uuid = acc_ops.login_as_admin()
    num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid)

    if num <= thread_threshold:
        sgs = res_ops.query_resource(res_ops.SECURITY_GROUP, [], session_uuid)
        delete_sgs(sgs)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        sgs = []
        while curr_num < num:
            sgs_tmp = res_ops.query_resource_fields(res_ops.SECURITY_GROUP, [], session_uuid, ["uuid"], start, limit)
            sgs.extend(sgs_tmp)
            curr_num += limit
            start += limit
        delete_sgs(sgs)

    # con_ops.change_global_config('identity', 'session.timeout', session_to)
    # con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    con_ops.change_global_config("identity", "session.timeout", session_to, session_uuid)
    con_ops.change_global_config("identity", "session.maxConcurrent", session_mc, session_uuid)
    left_num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid)
    acc_ops.logout(session_uuid)
    if left_num == 0:
        test_util.test_pass("Delete SG Success. Delete %d SGs." % num)
    else:
        test_util.test_fail("Delete SG Fail. %d SGs are not deleted." % left_num)
def test():
    global session_uuid
    global session_to
    global session_mc
    vm_num = os.environ.get('ZSTACK_TEST_NUM')
    if not vm_num:
        vm_num = 0
    else:
        vm_num = int(vm_num)

    test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold)
    test_util.test_logger('ZSTACK_TEST_NUM is %d' % vm_num)

    org_num = vm_num
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_sim')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_name = os.environ.get('l3VlanNetworkName1')
    conditions = res_ops.gen_query_conditions('name', '=', l3_name)
    l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \
            session_uuid, start = 0, limit = 1)[0].uuid
    vm_creation_option.set_l3_uuids([l3_uuid])
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    session_uuid = acc_ops.login_as_admin()

    #change account session timeout. 
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)

    vm_creation_option.set_session_uuid(session_uuid)

    vm = test_vm_header.ZstackTestVm()
    random_name = random.random()
    vm_name = 'multihost_sim_vm_%s' % str(random_name)
    vm_creation_option.set_name(vm_name)

    while vm_num > 0:
        check_thread_exception()
        vm.set_creation_option(vm_creation_option)
        vm_num -= 1
        thread = threading.Thread(target=create_vm, args=(vm,))
        while threading.active_count() > thread_threshold:
            time.sleep(1)
        thread.start()

    while threading.active_count() > 1:
        time.sleep(0.01)

    cond = res_ops.gen_query_conditions('name', '=', vm_name)
    vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    acc_ops.logout(session_uuid)
    if vms == org_num:
        test_util.test_pass('Create %d VMs Test Success' % org_num)
    else:
        test_util.test_fail('Create %d VMs Test Failed. Only find %d VMs.' % (org_num, vms))
def delete_all_volumes(thread_threshold = 1000):
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000')
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000')
    delete_policy = test_lib.lib_set_delete_policy('volume', 'Direct')
    expunge_time = test_lib.lib_set_expunge_time('volume', 1)
    cond = res_ops.gen_query_conditions('status', '!=', 'Deleted')
    num = res_ops.query_resource_count(res_ops.VOLUME, cond)

    if num <= thread_threshold:
        volumes = res_ops.query_resource(res_ops.VOLUME, cond)
        do_delete_volumes(volumes, thread_threshold)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        volumes = []
        while curr_num < num:
            volumes_temp = res_ops.query_resource_fields(res_ops.VOLUME, \
                    cond, None, ['uuid'], start, limit)
            volumes.extend(volumes_temp)
            curr_num += limit
            start += limit
        do_delete_volumes(volumes, thread_threshold)

    test_lib.lib_set_delete_policy('volume', delete_policy)
    test_lib.lib_set_expunge_time('volume', expunge_time)
    test_util.test_logger('Volumes destroy Success. Destroy %d Volumes.' % num)
def umount_all_primary_storages_violently():
    session_uuid = acc_ops.login_as_admin()
    zones = res_ops.query_resource(res_ops.ZONE)
    for zone in zones:
        conditions = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        conditions = res_ops.gen_query_conditions('state', '=', 'Enabled', conditions)
        pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, conditions, session_uuid)
        conditions = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions)
        conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions)
        conditions = res_ops.gen_query_conditions('hypervisorType', '=', inventory.KVM_HYPERVISOR_TYPE, conditions)
        all_hosts = res_ops.query_resource(res_ops.HOST, conditions, session_uuid)
        for host in all_hosts:
            for ps in pss:
                ps_url = ps.mountPath
                thread = threading.Thread(\
                        target = umount_primary_storage_violently, \
                        args = (host.managementIp, ps_url))
                thread.start()

    while threading.active_count() > 1:
        time.sleep(0.1)

    acc_ops.logout(session_uuid)
    delete_ps_ceph_pools()
Example #10
0
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    session_uuid = acc_ops.login_as_admin()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid,
                                                  session_uuid)
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_logger('[vm:] %s console on %s:%s is connectable' %
                              (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_fail('[vm:] %s console on %s:%s is not connectable' %
                            (vm.get_vm().uuid, console.hostIp, console.port))
    vm.destroy()
    vm.check()
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_fail(
            '[vm:] %s console on %s:%s is connectable, while VM is already destroyed'
            % (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_logger('[vm:] %s console on %s:%s is not connectable' %
                              (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    test_util.test_pass('Request Access VM Console Test Success')
Example #11
0
def delete_all_volumes(thread_threshold=1000):
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config("identity", "session.timeout", "720000")
    session_mc = con_ops.change_global_config("identity", "session.maxConcurrent", "10000")
    delete_policy = test_lib.lib_set_delete_policy("volume", "Direct")
    expunge_time = test_lib.lib_set_expunge_time("volume", 1)
    cond = res_ops.gen_query_conditions("status", "!=", "Deleted")
    num = res_ops.query_resource_count(res_ops.VOLUME, cond)

    if num <= thread_threshold:
        volumes = res_ops.query_resource(res_ops.VOLUME, cond)
        do_delete_volumes(volumes, thread_threshold)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        volumes = []
        while curr_num < num:
            volumes_temp = res_ops.query_resource_fields(res_ops.VOLUME, cond, None, ["uuid"], start, limit)
            volumes.extend(volumes_temp)
            curr_num += limit
            start += limit
        do_delete_volumes(volumes, thread_threshold)

    test_lib.lib_set_delete_policy("volume", delete_policy)
    test_lib.lib_set_expunge_time("volume", expunge_time)
    test_util.test_logger("Volumes destroy Success. Destroy %d Volumes." % num)
def add_zone_resource(deploy_config, zone_name):
    session_uuid = acc_ops.login_as_admin()
    try:
        test_util.test_dsc('-------add zone operation-------')
        dep_ops.add_zone(deploy_config, session_uuid, zone_name = zone_name)
        test_util.test_dsc('-------add l2 operation-------')
        dep_ops.add_l2_network(deploy_config, session_uuid, \
                zone_name = zone_name)
        test_util.test_dsc('-------add primary stroage operation-------')
        dep_ops.add_primary_storage(deploy_config, session_uuid, \
                zone_name = zone_name)
        test_util.test_dsc('-------add cluster operation-------')
        dep_ops.add_cluster(deploy_config, session_uuid, \
                zone_name = zone_name)
        test_util.test_dsc('-------add host operation-------')
        dep_ops.add_host(deploy_config, session_uuid, \
                zone_name = zone_name)
        test_util.test_dsc('-------add l3 operation-------')
        dep_ops.add_l3_network(deploy_config, session_uuid, \
                zone_name = zone_name)
        test_util.test_dsc('-------add virtual router offering operation-------')
        dep_ops.add_virtual_router(deploy_config, session_uuid, \
                zone_name = zone_name)
        zone = res_ops.get_resource(res_ops.ZONE, session_uuid, \
                name = zone_name)[0]
    except Exception as e:
        test_util.test_logger('[Error] zstack deployment meets exception when adding zone resource .')
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add zone resources for [uuid:] %s' \
            % zone.uuid)
def test():
    global session_to
    global session_mc
    global session_uuid
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
    session_uuid = acc_ops.login_as_admin()
    cond = res_ops.gen_query_conditions('type', '=', 'Data')
    num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid)

    if num <= thread_threshold:
        volumes = res_ops.query_resource(res_ops.VOLUME, cond, session_uuid)
        delete_volumes(volumes)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        volumes = []
        while curr_num < num:
            volumes_temp = res_ops.query_resource_with_num(res_ops.VOLUME, cond, session_uuid, start, limit)
            volumes.extend(volumes_temp)
            start += limit
            curr_num += limit
        delete_volumes(volumes)

    #con_ops.change_global_config('identity', 'session.timeout', session_to)
    #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    left_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid)
    acc_ops.logout(session_uuid)
    if left_num == 0:
        test_util.test_pass('Delete Data Volume Success. Delete %d Volumes.' % num)
    else:
        test_util.test_fail('Delete Data Volume Fail. %d Volumes are not deleted.' % left_num)
Example #14
0
def add_zone_resource(deploy_config, zone_name):
    session_uuid = acc_ops.login_as_admin()
    try:
        dep_ops.add_zone(deploy_config, session_uuid, zone_name=zone_name)
        dep_ops.add_l2_network(deploy_config, session_uuid, \
                zone_name = zone_name)
        dep_ops.add_primary_storage(deploy_config, session_uuid, \
                zone_name = zone_name)
        dep_ops.add_cluster(deploy_config, session_uuid, \
                zone_name = zone_name)
        dep_ops.add_host(deploy_config, session_uuid, \
                zone_name = zone_name)
        dep_ops.add_l3_network(deploy_config, session_uuid, \
                zone_name = zone_name)
        dep_ops.add_virtual_router(deploy_config, session_uuid, \
                zone_name = zone_name)
        zone = res_ops.get_resource(res_ops.ZONE, session_uuid, \
                name = zone_name)[0]
    except Exception as e:
        test_util.test_logger(
            '[Error] zstack deployment meets exception when adding zone resource .'
        )
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add zone resources for [uuid:] %s' \
            % zone.uuid)
Example #15
0
    def __init__(self, get_vm_con, justify_con=None):
        self.exc_info = []
        self.vms = []
        self.i = 0
        self.session_uuid = None
        self.session_to = None
        self.session_mc = None
        self.vm_num = os.environ.get('ZSTACK_TEST_NUM')
        self.thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD')
        self.get_vm_con = get_vm_con
        self.justify_con = justify_con
        if not self.vm_num:
            self.vm_num = 0
        else:
            self.vm_num = int(self.vm_num)

        if not self.thread_threshold:
            self.thread_threshold = 1000
        else:
            self.thread_threshold = int(self.thread_threshold)

        self.vms = res_ops.query_resource(res_ops.VM_INSTANCE, self.get_vm_con)
        if self.vm_num > len(self.vms):
            self.vm_num = len(self.vms)
            test_util.test_warn('ZSTACK_TEST_NUM is forcibly set as %d\n' %
                                len(self.vms))

        self.session_to = con_ops.change_global_config('identity', 'session.timeout',\
                                                  '720000', self.session_uuid)

        self.session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent',\
                                                  '10000', self.session_uuid)
        self.session_uuid = acc_ops.login_as_admin()
Example #16
0
def test():
    global session_uuid
    global session_to
    global session_mc
    global get_all_host_ip
    session_to = con_ops.change_global_config('identity', 'session.timeout',
                                              '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity',
                                              'session.maxConcurrent', '10000',
                                              session_uuid)
    session_uuid = acc_ops.login_as_admin()
    get_all_host_ip = test_lib.get_ip(start_IP, end_IP)
    host_num = len(get_all_host_ip)
    i = 0
    tmp_host_num = host_num
    while tmp_host_num > 0:
        check_thread_exception()
        tmp_host_num -= 1
        thread = threading.Thread(target=add_host_by_ip,
                                  args=(get_all_host_ip[i], ))
        i += 1
        while threading.active_count() > thread_threshold:
            time.sleep(1)
        thread.start()
    while threading.active_count() > 1:
        time.sleep(0.01)
def dump_zstack_deployment_config(deployConfig=None):
    '''
    deployConfig is the original zstack config. We need this conifg to set 
    username/password, as they are not get from ZStack API

    will return an xmlobject
    '''
    if not deployConfig:
        deployConfig = xmlobject.XmlObject('fake')

    root_xml = etree.Element("deployerConfig")
    session_uuid = account_operations.login_as_admin()
    try:
        add_nodes_config(root_xml, deployConfig.nodes__, session_uuid)
        add_sftp_backup_storage_config(root_xml, \
                deployConfig.backupStorages__, session_uuid)
        add_instance_offering_config(root_xml, session_uuid)
        add_disk_offering_config(root_xml, session_uuid)
        add_image_config(root_xml, deployConfig.images__, session_uuid)
        add_zone_config(root_xml, deployConfig.zones, session_uuid)
    except Exception as e:
        test_util.test_logger(
            '[Error] export zstack deployment configuration meets exception.')
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        account_operations.logout(session_uuid)

    return root_xml
Example #18
0
def cleanup_none_vm_volumes_violently():
    session_uuid = acc_ops.login_as_admin()
    try:
        priSto_host_list = {}
        result = res_ops.get_resource(res_ops.VOLUME, session_uuid)
        for volume in result:
            if not volume.installPath:
                continue
            volume_path = os.path.dirname(volume.installPath)
            #VM volume has been cleanup in destroy_vm_and_storage_violently()
            if not volume.hasattr('vmInstanceUuid'):
                pri_sto_uuid = volume.primaryStorageUuid
                if priSto_host_list.has_key(pri_sto_uuid):
                    host_ip = priSto_host_list[pri_sto_uuid]
                else:
                    #TODO: need to add multi hosts, if primary storage is local storage.
                    host = _get_host_from_primary_storage(
                        pri_sto_uuid, session_uuid)
                    host_ip = host.managementIp
                    priSto_host_list[pri_sto_uuid] = host_ip
                thread = threading.Thread(target = _delete_file, \
                        args = (host_ip, volume_path))
                thread.start()

        while threading.active_count() > 1:
            time.sleep(0.1)

    except Exception as e:
        test_util.test_logger("cleanup volumes violently meet exception")
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        acc_ops.logout(session_uuid)
def test():
    global session_uuid
    global session_to
    global session_mc
    vm_num = os.environ.get('ZSTACK_TEST_NUM')
    if not vm_num:
        vm_num = 0
    else:
        vm_num = int(vm_num)

    test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold)
    test_util.test_logger('ZSTACK_TEST_NUM is %d' % vm_num)

    org_num = vm_num
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_name = os.environ.get('l3VlanNetworkName1')
    conditions = res_ops.gen_query_conditions('name', '=', l3_name)
    l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \
            session_uuid, start = 0, limit = 1)[0].uuid
    vm_creation_option.set_l3_uuids([l3_uuid])
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    session_uuid = acc_ops.login_as_admin()

    #change account session timeout. 
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)

    vm_creation_option.set_session_uuid(session_uuid)

    vm = test_vm_header.ZstackTestVm()
    random_name = random.random()
    vm_name = 'multihost_basic_vm_%s' % str(random_name)
    vm_creation_option.set_name(vm_name)

    while vm_num > 0:
        check_thread_exception()
        vm.set_creation_option(vm_creation_option)
        vm_num -= 1
        thread = threading.Thread(target=create_vm, args=(vm,))
        while threading.active_count() > thread_threshold:
            time.sleep(1)
        thread.start()

    while threading.active_count() > 1:
        time.sleep(0.01)

    cond = res_ops.gen_query_conditions('name', '=', vm_name)
    vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    acc_ops.logout(session_uuid)
    if vms == org_num:
        test_util.test_pass('Create %d VMs Test Success' % org_num)
    else:
        test_util.test_fail('Create %d VMs Test Failed. Only find %d VMs.' % (org_num, vms))
def cleanup_none_vm_volumes_violently():
    session_uuid = acc_ops.login_as_admin()
    try:
        priSto_host_list = {}
        result = res_ops.get_resource(res_ops.VOLUME, session_uuid)
        for volume in result:
            if not volume.installPath:
                continue
            volume_path = os.path.dirname(volume.installPath)
            # VM volume has been cleanup in destroy_vm_and_storage_violently()
            if not volume.hasattr("vmInstanceUuid"):
                pri_sto_uuid = volume.primaryStorageUuid
                if priSto_host_list.has_key(pri_sto_uuid):
                    host_ip = priSto_host_list[pri_sto_uuid]
                else:
                    # TODO: need to add multi hosts, if primary storage is local storage.
                    host = _get_host_from_primary_storage(pri_sto_uuid, session_uuid)
                    host_ip = host.managementIp
                    priSto_host_list[pri_sto_uuid] = host_ip
                thread = threading.Thread(target=_delete_file, args=(host_ip, volume_path))
                thread.start()

        while threading.active_count() > 1:
            time.sleep(0.1)

    except Exception as e:
        test_util.test_logger("cleanup volumes violently meet exception")
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        acc_ops.logout(session_uuid)
def test():
    global session_to
    global session_mc
    global session_uuid
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
    session_uuid = acc_ops.login_as_admin()
    num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid)

    if num <= thread_threshold:
        sgs = res_ops.query_resource(res_ops.SECURITY_GROUP, [], session_uuid)
        delete_sgs(sgs)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        sgs = []
        while curr_num < num:
            sgs_tmp = res_ops.query_resource_fields(res_ops.SECURITY_GROUP, \
                    [], session_uuid, ['uuid'], start, limit)
            sgs.extend(sgs_tmp)
            curr_num += limit
            start += limit
        delete_sgs(sgs)

    #con_ops.change_global_config('identity', 'session.timeout', session_to)
    #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    left_num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid)
    acc_ops.logout(session_uuid)
    if left_num == 0:
        test_util.test_pass('Delete SG Success. Delete %d SGs.' % num)
    else:
        test_util.test_fail('Delete SG Fail. %d SGs are not deleted.' % left_num)
Example #22
0
    def __init__(self, get_host_con = None, justify_con = None):
        self.exc_info = []
        self.hosts = []
        self.i = 0
        self.session_uuid = None
        self.session_to = None
        self.session_mc = None
        self.host_num = os.environ.get('ZSTACK_TEST_NUM')
        self.thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD')
        self.get_host_con = get_host_con
        self.justify_con = justify_con
        if not self.host_num:
            self.host_num = 0
        else:
            self.host_num = int(self.host_num)

        if not self.thread_threshold:
            self.thread_threshold = 1000
        else:
            self.thread_threshold = int(self.thread_threshold)

        self.hosts = res_ops.query_resource(res_ops.HOST, self.get_host_con)
        if self.host_num > len(self.hosts):
            self.host_num = len(self.hosts)
            test_util.test_warn('ZSTACK_TEST_NUM is forcibly set as %d\n' % len(self.hosts))

        self.session_to = con_ops.change_global_config('identity', 'session.timeout',\
                                                  '720000', self.session_uuid)

        self.session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent',\
                                                  '10000', self.session_uuid)
        self.session_uuid = acc_ops.login_as_admin()
Example #23
0
def delete_all_volumes(thread_threshold=1000):
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout',
                                              '720000')
    session_mc = con_ops.change_global_config('identity',
                                              'session.maxConcurrent', '10000')
    delete_policy = test_lib.lib_set_delete_policy('volume', 'Direct')
    expunge_time = test_lib.lib_set_expunge_time('volume', 1)
    cond = res_ops.gen_query_conditions('status', '!=', 'Deleted')
    num = res_ops.query_resource_count(res_ops.VOLUME, cond)

    if num <= thread_threshold:
        volumes = res_ops.query_resource(res_ops.VOLUME, cond)
        do_delete_volumes(volumes, thread_threshold)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        volumes = []
        while curr_num < num:
            volumes_temp = res_ops.query_resource_fields(res_ops.VOLUME, \
                    cond, None, ['uuid'], start, limit)
            volumes.extend(volumes_temp)
            curr_num += limit
            start += limit
        do_delete_volumes(volumes, thread_threshold)

    test_lib.lib_set_delete_policy('volume', delete_policy)
    test_lib.lib_set_expunge_time('volume', expunge_time)
    test_util.test_logger('Volumes destroy Success. Destroy %d Volumes.' % num)
def dump_zstack_deployment_config(deployConfig = None):
    '''
    deployConfig is the original zstack config. We need this conifg to set 
    username/password, as they are not get from ZStack API

    will return an xmlobject
    '''
    if not deployConfig:
        deployConfig = xmlobject.XmlObject('fake')

    root_xml = etree.Element("deployerConfig")
    session_uuid = account_operations.login_as_admin()
    try:
        add_nodes_config(root_xml, deployConfig.nodes__, session_uuid)
        add_sftp_backup_stroage_config(root_xml, \
                deployConfig.backupStorages__, session_uuid)
        add_instance_offering_config(root_xml, session_uuid)
        add_disk_offering_config(root_xml, session_uuid)
        add_image_config(root_xml, deployConfig.images__, session_uuid)
        add_zone_config(root_xml, deployConfig.zones, session_uuid)
    except Exception as e:
        test_util.test_logger('[Error] export zstack deployment configuration meets exception.')
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        account_operations.logout(session_uuid)

    return root_xml
def test():
    global session_to
    global session_mc
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
    cond = res_ops.gen_query_conditions('type', '=', inventory.USER_VM_TYPE)
    num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)

    if num <= thread_threshold:
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond, session_uuid)
        destroy_vms(vms)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < num:
            vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \
                    cond, session_uuid, ['uuid'], start, limit)
            vms.extend(vms_temp)
            curr_num += limit
            start += limit
        destroy_vms(vms)

    vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)

    if vip_num <= thread_threshold:
        vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
        destroy_vips(vips)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < vip_num:
            vips_temp = res_ops.query_resource_fields(res_ops.VIP, \
                    [], session_uuid, ['uuid'], start, limit)
            vips.extend(vips_temp)
            curr_num += limit
            start += limit
        destroy_vips(vips)
    #con_ops.change_global_config('identity', 'session.timeout', session_to)
    #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    left_num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
    if left_num == 0:
        test_util.test_pass('None VR VMs destroy Success. Destroy %d VMs.' % num)
    else:
        test_util.test_fail('None VR VMs destroy Fail. %d VMs are not Destroied.' % left_num)

    left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)
    if left_num == 0:
        test_util.test_pass('VIP destroy Success. Destroy %d VIP.' % num)
    else:
        test_util.test_fail('VIP destroy Fail. %d VIP are not Destroied.' % left_num)

    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    acc_ops.logout(session_uuid)
def test():
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)

    #create VRs.
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)
    if not vrs:
        vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
        vm.destroy()
        vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    else:
        vr1 = vrs[0]

    vm_ops.stop_vm(vr1.uuid)
    if test_lib.lib_get_ha_enable() != 'true' or vr1.applianceVmType != "vrouter":
        vm_ops.start_vm(vr1.uuid)

    vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1)
    if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120):
        test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid)

    timeout = time.time() + 60
    while time.time() < timeout:
        cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) 
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
        if vms[0].status == 'Connected':
            test_util.test_pass('Test Reconnect VR VM start VRs success')
        time.sleep(1)

    test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
def test():
    session_uuid = acc_ops.login_as_admin()
    acc_ops.logout(session_uuid)

    image_name = os.environ.get('imageName3')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    try:
        vm = test_stub.create_vm(image_uuid=image_uuid,
                                 session_uuid=session_uuid)
        test_util.test_fail(
            'Expect exception after logout while there is none')
    except:
        pass

    vm = test_stub.create_vm(image_uuid=image_uuid)
    vm_ops.stop_vm(vm.get_vm().uuid)
    vm_ops.start_vm(vm.get_vm().uuid)
    try:
        vm_ops.stop_vm(vm.get_vm().uuid, session_uuid=session_uuid)
        test_util.test_fail(
            'Expect exception after logout while there is none')
    except:
        pass
    vm.destroy()
    vm.expunge()
    test_util.test_pass('Test operations after session logout passed')
def test():
    global session_to
    global session_mc
    global session_uuid
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
    session_uuid = acc_ops.login_as_admin()
    num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)

    if num <= thread_threshold:
        vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
        delete_vips(vips)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vips = []
        while curr_num < num:
            vips_temp = res_ops.query_resource_fields(res_ops.VIP, [], \
                    session_uuid, ['uuid'], start, limit)
            vips.extend(vips_temp)
            curr_num += limit
            start += limit
            
        delete_vips(vips)

    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)
    acc_ops.logout(session_uuid)
    if left_num == 0:
        test_util.test_pass('Delete VIP Success. Delete %d VIPs.' % num)
    else:
        test_util.test_fail('Delete VIP Fail. %d VIPs are not deleted.' % left_num)
Example #29
0
def umount_all_primary_storages_violently():
    session_uuid = acc_ops.login_as_admin()
    zones = res_ops.query_resource(res_ops.ZONE)
    for zone in zones:
        conditions = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        conditions = res_ops.gen_query_conditions('state', '=', 'Enabled',
                                                  conditions)
        pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, conditions,
                                     session_uuid)
        conditions = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
        conditions = res_ops.gen_query_conditions('state', '=',
                                                  host_header.ENABLED,
                                                  conditions)
        conditions = res_ops.gen_query_conditions('status', '=',
                                                  host_header.CONNECTED,
                                                  conditions)
        conditions = res_ops.gen_query_conditions(
            'hypervisorType', '=', inventory.KVM_HYPERVISOR_TYPE, conditions)
        all_hosts = res_ops.query_resource(res_ops.HOST, conditions,
                                           session_uuid)
        for host in all_hosts:
            for ps in pss:
                ps_url = ps.mountPath
                thread = threading.Thread(\
                        target = umount_primary_storage_violently, \
                        args = (host.managementIp, ps_url))
                thread.start()

    while threading.active_count() > 1:
        time.sleep(0.1)

    acc_ops.logout(session_uuid)
    delete_ps_ceph_pools()
def Create(vm_name_prefix):
    global session_uuid
    global session_to
    global session_mc

    session_uuid = None
    session_to = None
    session_mc = None

    vm_num = os.environ.get('ZSTACK_TEST_NUM')
    if not vm_num:
       vm_num = 1000
    else:
       vm_num = int(vm_num)

    test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold)
    test_util.test_logger('ZSTACK_TEST_NUM is %d' % vm_num)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid

    cond = res_ops.gen_query_conditions('category', '=', 'Private')
    l3net_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond, session_uuid)[0].uuid
    l3s = test_lib.lib_get_l3s()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    #change account session timeout. 
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)

    session_uuid = acc_ops.login_as_admin()

    vm_creation_option.set_session_uuid(session_uuid)

    vm = test_vm_header.ZstackTestVm()
    vm_creation_option.set_l3_uuids([l3net_uuid])
          
    while vm_num > 0:
        check_thread_exception()
        vm_name = '%s_%s' % (vm_name_prefix, str(vm_num))
        vm_creation_option.set_name(vm_name)
        vm.set_creation_option(vm_creation_option)
        vm_num -= 1
        thread = threading.Thread(target=create_vm, args=(vm,))
        while threading.active_count() > thread_threshold:
            time.sleep(1)
        thread.start()

    while threading.active_count() > 1:
        time.sleep(0.05)

    cond = res_ops.gen_query_conditions('name', '=', vm_name)
    vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    acc_ops.logout(session_uuid)
Example #31
0
def test():
    global session_uuid
    global session_to
    global session_mc
    vm_num = os.environ.get('ZSTACK_VM_NUM')
    if not vm_num:
        vm_num = 0
    else:
        vm_num = int(vm_num)

    org_num = vm_num
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_name = os.environ.get('l3PublicNetworkName')

    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout',
                                              '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity',
                                              'session.maxConcurrent', '10000',
                                              session_uuid)
    l3s = test_lib.lib_get_l3s()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_session_uuid(session_uuid)

    vm = test_vm_header.ZstackTestVm()
    random_name = random.random()
    vm_name = 'multihost_basic_vm_%s' % str(random_name)
    vm_creation_option.set_name(vm_name)

    while vm_num > 0:
        vm_creation_option.set_l3_uuids([random.choice(l3s).uuid])
        vm.set_creation_option(vm_creation_option)
        vm_num -= 1
        thread = threading.Thread(target=vm.create)
        thread.start()

    while threading.active_count() > 1:
        time.sleep(0.01)

    cond = res_ops.gen_query_conditions('name', '=', vm_name)
    vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
    con_ops.change_global_config('identity', 'session.timeout', session_to,
                                 session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent',
                                 session_mc, session_uuid)
    if vms == org_num:
        test_util.test_pass('Create %d VMs Test Success' % org_num)
    else:
        test_util.test_fail('Create %d VMs Test Failed. Only find %d VMs.' %
                            (org_num, vms))
Example #32
0
def Create():
    global session_uuid
    global session_to
    global session_mc
    vm_num = os.environ.get('ZSTACK_TEST_NUM')
    if not vm_num:
       vm_num = 1000
    else:
       vm_num = int(vm_num)

    test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold)
    test_util.test_logger('ZSTACK_TEST_NUM is %d' % vm_num)

    org_num = vm_num
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_name = os.environ.get('l3PublicNetworkName')

    l3 = test_lib.lib_get_l3_by_name(l3_name)
    l3s = test_lib.lib_get_l3s()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    #change account session timeout. 
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)

    session_uuid = acc_ops.login_as_admin()

    vm_creation_option.set_session_uuid(session_uuid)

    vm = test_vm_header.ZstackTestVm()
    vm_creation_option.set_l3_uuids([l3.uuid])

    while vm_num > 0:
        check_thread_exception()
        vm_name = 'multihost_basic_vm_%s' % str(vm_num)
        vm_creation_option.set_name(vm_name)
        vm.set_creation_option(vm_creation_option)
        vm_num -= 1
        thread = threading.Thread(target=create_vm, args=(vm,))
        while threading.active_count() > thread_threshold:
            time.sleep(1)
        thread.start()

    while threading.active_count() > 1:
        time.sleep(0.05)

    cond = res_ops.gen_query_conditions('name', '=', vm_name)
    vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    acc_ops.logout(session_uuid)
def error_cleanup():
    global deploy_conf
    global vm_inv
    global vm

    cond = res_ops.gen_query_conditions('zone.vmInstance.uuid', '=', vm_inv.uuid)
    if len(res_ops.query_resource(res_ops.VR_OFFERING, cond)) == 0:
        session_uuid = acc_ops.login_as_admin()
        dep_ops.add_virtual_router(deploy_conf, session_uuid)
        vm.reboot()

    test_lib.lib_error_cleanup(test_obj_dict)
Example #34
0
def cleanup_all_vms_violently():
    session_uuid = account_operations.login_as_admin()
    result = res_ops.get_resource(res_ops.VM_INSTANCE, session_uuid)
    for vm in result:
        thread = threading.Thread(target = destroy_vm_and_storage_violently\
                , args = (vm, session_uuid, ))
        thread.start()

    while threading.active_count() > 1:
        time.sleep(0.1)

    account_operations.logout(session_uuid)
Example #35
0
def test():
    global session_to
    global session_mc
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000')
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000')
    clean_util.delete_accounts()
    test_util.test_pass('Accounts Delete Success.')
    con_ops.change_global_config('identity', 'session.timeout', session_to)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    acc_ops.logout(session_uuid)
def cleanup_all_vms_violently():
    destroy_all_vm_and_vips()
    session_uuid = acc_ops.login_as_admin()
    result = res_ops.get_resource(res_ops.VM_INSTANCE, session_uuid)
    for vm in result:
        thread = threading.Thread(target=destroy_vm_and_storage_violently, args=(vm, session_uuid))
        thread.start()

    while threading.active_count() > 1:
        time.sleep(0.1)

    acc_ops.logout(session_uuid)
Example #37
0
def test():
    global session_to
    global session_mc
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000')
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000')
    clean_util.destroy_all_vm_and_vips()
    test_util.test_pass('vms destroy Success.')
    con_ops.change_global_config('identity', 'session.timeout', session_to)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    acc_ops.logout(session_uuid)
Example #38
0
def error_cleanup():
    global deploy_conf
    global vm_inv
    global vm

    cond = res_ops.gen_query_conditions('zone.vmInstance.uuid', '=',
                                        vm_inv.uuid)
    if len(res_ops.query_resource(res_ops.VR_OFFERING, cond)) == 0:
        session_uuid = acc_ops.login_as_admin()
        dep_ops.add_virtual_router(deploy_conf, session_uuid)
        vm.reboot()

    test_lib.lib_error_cleanup(test_obj_dict)
Example #39
0
def exercise_connection(ops_num=120, thread_threshold=10):
    session_uuid = acc_ops.login_as_admin()
    for ops_id in range(ops_num):
        thread = threading.Thread(target=create_delete_account, args=(ops_id, session_uuid, ))
        while threading.active_count() > thread_threshold:
            time.sleep(0.5)
        exc = sys.exc_info()
        thread.start()

    while threading.activeCount() > 1:
        exc = sys.exc_info()
        time.sleep(0.1)
    acc_ops.logout(session_uuid)
Example #40
0
def exercise_connection(ops_num=120, thread_threshold=10):
    session_uuid = acc_ops.login_as_admin()
    for ops_id in range(ops_num):
        thread = threading.Thread(target=create_delete_account, args=(ops_id, session_uuid, ))
        while threading.active_count() > thread_threshold:
            time.sleep(0.5)
        exc = sys.exc_info()
        thread.start()

    while threading.activeCount() > 1:
        exc = sys.exc_info()
        time.sleep(0.1)
    acc_ops.logout(session_uuid)
Example #41
0
def test():
    global session_to
    global session_mc
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout',
                                              '720000')
    session_mc = con_ops.change_global_config('identity',
                                              'session.maxConcurrent', '10000')
    cond = []
    num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond)

    if num <= thread_threshold:
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
        destroy_vms(vms)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < num:
            vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \
                    cond, None, ['uuid'], start, limit)
            vms.extend(vms_temp)
            curr_num += limit
            start += limit
        destroy_vms(vms)

    vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)

    if vip_num <= thread_threshold:
        vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
        destroy_vips(vips)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < vip_num:
            vips_temp = res_ops.query_resource_fields(res_ops.VIP, \
                    [], session_uuid, ['uuid'], start, limit)
            vips.extend(vips_temp)
            curr_num += limit
            start += limit
        destroy_vips(vips)

    test_util.test_pass('vms destroy Success. Destroy %d VMs.' % num)
    con_ops.change_global_config('identity', 'session.timeout', session_to)
    con_ops.change_global_config('identity', 'session.maxConcurrent',
                                 session_mc)
    acc_ops.logout(session_uuid)
def test():
    global session_uuid
    global session_to
    global session_mc
    vm_num = os.environ.get('ZSTACK_VM_NUM')
    if not vm_num:
        vm_num = 0
    else:
        vm_num = int(vm_num)

    org_num = vm_num
    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
    l3_name = os.environ.get('l3PublicNetworkName')

    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
    l3s = test_lib.lib_get_l3s()
    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_session_uuid(session_uuid)

    vm = test_vm_header.ZstackTestVm()
    random_name = random.random()
    vm_name = 'multihost_basic_vm_%s' % str(random_name)
    vm_creation_option.set_name(vm_name)

    while vm_num > 0:
        vm_creation_option.set_l3_uuids([random.choice(l3s).uuid])
        vm.set_creation_option(vm_creation_option)
        vm_num -= 1
        thread = threading.Thread(target=vm.create)
        thread.start()


    while threading.active_count() > 1:
        time.sleep(0.01)

    cond = res_ops.gen_query_conditions('name', '=', vm_name)
    vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
    con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    if vms == org_num:
        test_util.test_pass('Create %d VMs Test Success' % org_num)
    else:
        test_util.test_fail('Create %d VMs Test Failed. Only find %d VMs.' % (org_num, vms))
def test():
    global session_to
    global session_mc
    global session_uuid
    session_to = con_ops.change_global_config('identity', \
            'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', \
            'session.maxConcurrent', '10000', session_uuid)
    session_uuid = acc_ops.login_as_admin()
    num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT_TREE, [], \
            session_uuid)

    sps_del = []
    if num <= thread_threshold:
        sps = res_ops.query_resource_with_num(res_ops.VOLUME_SNAPSHOT_TREE,\
                [], session_uuid, start = 0, limit = num)
        for sp in sps:
            sps_del.append(sp.tree.inventory.uuid)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        while curr_num < num:
            sps_temp = res_ops.query_resource_with_num(\
                    res_ops.VOLUME_SNAPSHOT_TREE, \
                    [], session_uuid, start, limit)
            for sp in sps_temp:
                sps_del.append(sp.tree.inventory.uuid)
            start += limit
            curr_num += limit
    delete_sps(sps_del)

    #con_ops.change_global_config('identity', 'session.timeout', session_to)
    #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    con_ops.change_global_config('identity', 'session.timeout', session_to,
                                 session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent',
                                 session_mc, session_uuid)
    left_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, [], \
            session_uuid)
    acc_ops.logout(session_uuid)
    if left_num == 0:
        test_util.test_pass(
            'Delete Volume Snapshot Success. Delete %d Volume Snapshots.' %
            num)
    else:
        test_util.test_fail(
            'Delete Data Volume Snapshot Fail. %d Volume Snapshots are not deleted.'
            % left_num)
def test():
    global session_to
    global session_mc
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000')
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000')
    cond = []
    num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond)

    if num <= thread_threshold:
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
        destroy_vms(vms)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < num:
            vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \
                    cond, None, ['uuid'], start, limit)
            vms.extend(vms_temp)
            curr_num += limit
            start += limit
        destroy_vms(vms)

    vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)

    if vip_num <= thread_threshold:
        vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
        destroy_vips(vips)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < vip_num:
            vips_temp = res_ops.query_resource_fields(res_ops.VIP, \
                    [], session_uuid, ['uuid'], start, limit)
            vips.extend(vips_temp)
            curr_num += limit
            start += limit
        destroy_vips(vips)

    test_util.test_pass('vms destroy Success. Destroy %d VMs.' % num)
    con_ops.change_global_config('identity', 'session.timeout', session_to)
    con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    acc_ops.logout(session_uuid)
def test():
    global vm
    vm = test_stub.create_vm()
    vm.check()
    session_uuid = acc_ops.login_as_admin()
    console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid, session_uuid)
    acc_ops.logout(session_uuid)
    time.sleep(5)
    if test_lib.lib_network_check(console.hostIp, console.port):
        test_util.test_fail('[vm:] %s console on %s:%s is connectable, while already logout' % (vm.get_vm().uuid, console.hostIp, console.port))
    else:
        test_util.test_logger('[vm:] %s console on %s:%s is not connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
    vm.destroy()
    vm.check()

    test_util.test_pass('Request Access VM Console after logout Test Success')
def test():
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    l3_name = os.environ.get('l3VlanDNATNetworkName')
    vm1 = test_stub.create_vlan_vm(l3_name=l3_name)
    test_obj_dict.add_vm(vm1)
    vm2 = test_stub.create_vlan_vm(l3_name=l3_name)
    test_obj_dict.add_vm(vm2)
    vm3 = test_stub.create_vlan_vm(l3_name=l3_name)
    test_obj_dict.add_vm(vm3)
    vm4 = test_stub.create_vlan_vm(l3_name=l3_name)
    test_obj_dict.add_vm(vm4)

    vms = [vm1, vm2, vm3, vm4]

    for vm in vms:
        thread = threading.Thread(target=vm_ops.stop_vm,
                                  args=(
                                      vm.get_vm().uuid,
                                      None,
                                      session_uuid,
                                  ))
        thread.start()

    while threading.activeCount() > 1:
        time.sleep(0.1)

    for vm in vms:
        thread = threading.Thread(target=vm_ops.start_vm,
                                  args=(
                                      vm.get_vm().uuid,
                                      session_uuid,
                                  ))
        thread.start()

    vm1.check()
    vm2.check()
    vm3.check()
    vm4.check()

    time.sleep(1)
    acc_ops.logout(session_uuid)
    while threading.activeCount() > 1:
        time.sleep(0.1)
    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Test start VRs simultaneously success')
def add_cluster_resource(deploy_config, cluster_name, zone_name = None):
    session_uuid = acc_ops.login_as_admin()
    try:
        dep_ops.add_cluster(deploy_config, session_uuid, \
                zone_name = zone_name, cluster_name = cluster_name)
        dep_ops.add_host(deploy_config, session_uuid, \
                zone_name = zone_name, cluster_name = cluster_name)
        cluster = res_ops.get_resource(res_ops.CLUSTER, session_uuid, \
                name = cluster_name)[0]
    except Exception as e:
        test_util.test_logger('[Error] zstack deployment meets exception when adding cluster resource .')
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add cluster resources for [uuid:] %s' \
            % cluster.uuid)
def add_l2_resource(deploy_config, l2_name, zone_name = None, \
        session_uuid = None):
    session_uuid_flag = True
    if not session_uuid:
        session_uuid = acc_ops.login_as_admin()
        session_uuid_flag = False
    try:
        dep_ops.add_l2_network(deploy_config, session_uuid, l2_name, \
                zone_name = zone_name)
        l2_uuid = res_ops.get_resource(res_ops.L2_NETWORK, session_uuid, \
                name = l2_name)[0].uuid

        for zone in xmlobject.safe_list(deploy_config.zones.zone):
            if zone_name and zone_name != zone.name_:
                continue
            for cluster in xmlobject.safe_list(zone.clusters.cluster):
                if xmlobject.has_element(cluster, 'l2NetworkRef'):
                    for l2ref in xmlobject.safe_list(cluster.l2NetworkRef):
                        if l2_name != l2ref.text_:
                            continue

                        cluster_uuid = res_ops.get_resource(res_ops.CLUSTER, \
                                session_uuid, name=cluster.name_)[0].uuid
                        attach_l2(l2_uuid, cluster_uuid, session_uuid)

        dep_ops.add_l3_network(None, None, deploy_config, session_uuid, l2_name = l2_name, \
                zone_name = zone_name)
        cond = res_ops.gen_query_conditions('l2NetworkUuid', '=', l2_uuid)
        l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond, \
                session_uuid)[0].name
        dep_ops.add_virtual_router(None, None, deploy_config, session_uuid, \
                l3_name = l3_name, zone_name = zone_name)
    except Exception as e:
        test_util.test_logger(
            '[Error] zstack deployment meets exception when adding l2 resource .'
        )
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        if not session_uuid_flag:
            acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add l2 resources for [uuid:] %s' \
            % l2_uuid)
Example #49
0
def test():
    global session_to
    global session_mc
    global session_uuid
    session_to = con_ops.change_global_config('identity', 'session.timeout',
                                              '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity',
                                              'session.maxConcurrent', '10000',
                                              session_uuid)
    session_uuid = acc_ops.login_as_admin()
    cond = res_ops.gen_query_conditions('type', '=', 'Data')
    num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid)

    if num <= thread_threshold:
        volumes = res_ops.query_resource(res_ops.VOLUME, cond, session_uuid)
        delete_volumes(volumes)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        volumes = []
        while curr_num < num:
            volumes_temp = res_ops.query_resource_with_num(
                res_ops.VOLUME, cond, session_uuid, start, limit)
            volumes.extend(volumes_temp)
            start += limit
            curr_num += limit
        delete_volumes(volumes)

    #con_ops.change_global_config('identity', 'session.timeout', session_to)
    #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    con_ops.change_global_config('identity', 'session.timeout', session_to,
                                 session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent',
                                 session_mc, session_uuid)
    left_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid)
    acc_ops.logout(session_uuid)
    if left_num == 0:
        test_util.test_pass('Delete Data Volume Success. Delete %d Volumes.' %
                            num)
    else:
        test_util.test_fail(
            'Delete Data Volume Fail. %d Volumes are not deleted.' % left_num)
def add_l2_resource(deploy_config, l2_name, zone_name = None, \
        session_uuid = None):
    session_uuid_flag = True
    if not session_uuid:
        session_uuid = acc_ops.login_as_admin()
        session_uuid_flag = False
    try:
        dep_ops.add_l2_network(deploy_config, session_uuid, l2_name, \
                zone_name = zone_name)
        l2_uuid = res_ops.get_resource(res_ops.L2_NETWORK, session_uuid, \
                name = l2_name)[0].uuid
        
        for zone in xmlobject.safe_list(deploy_config.zones.zone):
            if zone_name and zone_name != zone.name_:
                continue
            for cluster in xmlobject.safe_list(zone.clusters.cluster):
                if xmlobject.has_element(cluster, 'l2NetworkRef'):
                    for l2ref in xmlobject.safe_list(cluster.l2NetworkRef):
                        if l2_name != l2ref.text_:
                            continue

                        cluster_uuid = res_ops.get_resource(res_ops.CLUSTER, \
                                session_uuid, name=cluster.name_)[0].uuid
                        attach_l2(l2_uuid, cluster_uuid, session_uuid)

        dep_ops.add_l3_network(None, None, deploy_config, session_uuid, l2_name = l2_name, \
                zone_name = zone_name)
        cond = res_ops.gen_query_conditions('l2NetworkUuid', '=', l2_uuid)
        l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond, \
                session_uuid)[0].name
        dep_ops.add_virtual_router(None, None, deploy_config, session_uuid, \
                l3_name = l3_name, zone_name = zone_name)
    except Exception as e:
        test_util.test_logger('[Error] zstack deployment meets exception when adding l2 resource .')
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        if not session_uuid_flag:
            acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add l2 resources for [uuid:] %s' \
            % l2_uuid)
def test():
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    l3_1_name = os.environ.get('l3VlanNetworkName1')
    l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)

    #create VRs.
    vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)
    if not vrs:
        vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
        vm.destroy()
        vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
    else:
        vr1 = vrs[0]

    vm_ops.destroy_vm(vr1.uuid)
    vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
    vm.destroy()

    test_util.test_pass('destroy VR VM success')
Example #52
0
def add_cluster_resource(deploy_config, cluster_name, zone_name=None):
    session_uuid = acc_ops.login_as_admin()
    try:
        dep_ops.add_cluster(deploy_config, session_uuid, \
                zone_name = zone_name, cluster_name = cluster_name)
        dep_ops.add_host(deploy_config, session_uuid, \
                zone_name = zone_name, cluster_name = cluster_name)
        cluster = res_ops.get_resource(res_ops.CLUSTER, session_uuid, \
                name = cluster_name)[0]
    except Exception as e:
        test_util.test_logger(
            '[Error] zstack deployment meets exception when adding cluster resource .'
        )
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add cluster resources for [uuid:] %s' \
            % cluster.uuid)
def test():
    global session_to
    global session_mc
    global session_uuid
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout',
                                              '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity',
                                              'session.maxConcurrent', '10000',
                                              session_uuid)
    num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)

    if num <= thread_threshold:
        vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
        destroy_vips(vips)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < num:
            vips_temp = res_ops.query_resource_fields(res_ops.VIP, \
                    [], session_uuid, ['uuid'], start, limit)
            vips.extend(vips_temp)
            curr_num += limit
            start += limit
        destroy_vips(vips)

    #con_ops.change_global_config('identity', 'session.timeout', session_to)
    #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
    con_ops.change_global_config('identity', 'session.timeout', session_to,
                                 session_uuid)
    con_ops.change_global_config('identity', 'session.maxConcurrent',
                                 session_mc, session_uuid)
    left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)
    acc_ops.logout(session_uuid)
    if left_num == 0:
        test_util.test_pass('VIP destroy Success. Destroy %d VIP.' % num)
    else:
        test_util.test_fail('VIP destroy Fail. %d VIP are not Destroied.' %
                            left_num)
Example #54
0
def delete_accounts(thread_threshold=1000):
    def do_delete_accounts(accounts, session_uuid):
        for account in accounts:
            thread = threading.Thread(target=acc_ops.delete_account, \
                    args=(account.uuid, session_uuid))
            while threading.active_count() > thread_threshold:
                time.sleep(0.5)
            exc = sys.exc_info()
            if exc[0]:
                raise info1, None, info2
            thread.start()

        while threading.activeCount() > 1:
            exc = sys.exc_info()
            if exc[0]:
                raise info1, None, info2
            time.sleep(0.1)

    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config('identity', 'session.timeout',
                                              '720000')
    session_mc = con_ops.change_global_config('identity',
                                              'session.maxConcurrent', '10000')
    cond = []
    cond = res_ops.gen_query_conditions('name', '!=', 'admin', cond)
    num = res_ops.query_resource_count(res_ops.ACCOUNT, cond)
    if num <= thread_threshold:
        accounts = res_ops.query_resource(res_ops.ACCOUNT, cond)
        do_delete_accounts(accounts, session_uuid)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        accs = []
        while curr_num < num:
            acc_tmp= res_ops.query_resource_fields(res_ops.ACCOUNT, \
                    [], session_uuid, ['uuid'], start, limit)
            accs.extend(acc_temp)
            curr_num += limit
            start += limit
        do_delete_accounts(accs, thread_threshold)
def test():
    global vms
    for i in range(12):
        vms.append(test_stub.create_vm())

    session_uuid = acc_ops.login_as_admin()
    for vm in vms:
        if vm:
            vm.check()
            console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid, session_uuid)
            if test_lib.lib_network_check(console.hostIp, console.port):
                test_util.test_logger('[vm:] %s console on %s:%s is connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
            else:
                test_util.test_fail('[vm:] %s console on %s:%s is not connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
    acc_ops.logout(session_uuid)

    for vm in vms:
        if vm:
            vm.destroy()
            vm.check()
    test_util.test_pass('Request Access Multiple VM Console Test Success')
def destroy_all_vm_and_vips(thread_threshold=1000):
    session_uuid = acc_ops.login_as_admin()
    session_to = con_ops.change_global_config("identity", "session.timeout", "720000")
    session_mc = con_ops.change_global_config("identity", "session.maxConcurrent", "10000")
    cond = []
    num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond)

    if num <= thread_threshold:
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
        do_destroy_vms(vms, thread_threshold)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < num:
            vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, cond, None, ["uuid"], start, limit)
            vms.extend(vms_temp)
            curr_num += limit
            start += limit
        do_destroy_vms(vms, thread_threshold)

    vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)

    if vip_num <= thread_threshold:
        vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
        do_destroy_vips(vips, thread_threshold)
    else:
        start = 0
        limit = thread_threshold - 1
        curr_num = start
        vms = []
        while curr_num < vip_num:
            vips_temp = res_ops.query_resource_fields(res_ops.VIP, [], session_uuid, ["uuid"], start, limit)
            vips.extend(vips_temp)
            curr_num += limit
            start += limit
        do_destroy_vips(vips, thread_threshold)

    test_util.test_logger("vms destroy Success. Destroy %d VMs." % num)
def test():
    global session_uuid
    global session_to
    global session_mc
    global get_all_host_ip 
    session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
    session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
    session_uuid = acc_ops.login_as_admin()
    get_all_host_ip = test_lib.get_ip(start_IP, end_IP)
    host_num = len(get_all_host_ip)
    i = 0
    tmp_host_num = host_num
    while tmp_host_num > 0:
        check_thread_exception()
        tmp_host_num -= 1
        thread = threading.Thread(target=add_host_by_ip, args=(get_all_host_ip[i],))
        i += 1
        while threading.active_count() > thread_threshold:
            time.sleep(1)
        thread.start()
    while threading.active_count() > 1:
        time.sleep(0.01)