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')
Exemplo n.º 2
0
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 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 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')
Exemplo n.º 5
0
def error_cleanup():
    if session_to:
        con_ops.change_global_config("identity", "session.timeout", session_to)
    if session_mc:
        con_ops.change_global_config("identity", "session.maxConcurrent", session_mc)
    if session_uuid:
        acc_ops.logout(session_uuid)
Exemplo n.º 6
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 error_cleanup():
    if session_to:
        con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
    if session_mc:
        con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
    if session_uuid:
        acc_ops.logout(session_uuid)
Exemplo n.º 8
0
def test():
    global ldap_server_uuid
    global new_account_uuid

    system_tag = ["ldapUseAsLoginName::uid"]
    ldap_server = ldp_ops.add_ldap_server('ldap1',
                                          'ldap for test',
                                          os.environ.get('ldapServerUrl'),
                                          os.environ.get('ldapServerBase'),
                                          os.environ.get('ldapServerUsername'),
                                          os.environ.get('ldapServerPassword'),
                                          'TLS',
                                          systemtags=system_tag)
    ldap_server_uuid = ldap_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]

    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapDn'),
                                             new_account.uuid)
    ldap_account_uuid = ldap_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'),
                                         os.environ.get('ldapPassword'))
    acc_ops.logout(session_uuid)

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(
            os.environ.get('ldapUid'),
            os.environ.get('ldapPassword') + '1')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with wrong password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), '')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with blank password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), None)
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login without password')

    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
Exemplo n.º 9
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_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)
Exemplo n.º 11
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 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 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))
Exemplo n.º 14
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()
Exemplo n.º 15
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')
Exemplo n.º 16
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 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
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')
Exemplo n.º 19
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)
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)
Exemplo n.º 21
0
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
Exemplo n.º 22
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 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_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))
Exemplo n.º 25
0
def test():
    iam2_ops.clean_iam2_enviroment()

    # 1 create project
    project_name = 'test_project'
    project = iam2_ops.create_iam2_project(project_name)
    project_name = project.name
    project_uuid = project.uuid

    # 2 create plain user
    plain_user_name = 'username'
    plain_user_password = \
        'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
    plain_user_uuid = iam2_ops.create_iam2_virtual_id(
        plain_user_name, plain_user_password, project_uuid=project_uuid).uuid

    # 3 add virtual id to project
    iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid], project_uuid)

    # 4 login in project by plain user
    plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(
        plain_user_name, plain_user_password)

    # 4 login in project
    # project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid)
    project_session_uuid = iam2_ops.login_iam2_project(
        project_name, plain_user_session_uuid).uuid

    # 5 get iam2 virtual id api permission and project
    iam2_ops.get_iam2_virtual_id_permission(session_uuid=project_session_uuid)
    # time.sleep(20)

    # 6 logout
    acc_ops.logout(project_session_uuid)

    try:
        iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password)
    except:
        test_util.test_dsc("the user [%s] is deleted,can't login" %
                           plain_user_name)

    username = '******' * 85
    password = \
        'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'

    iam2_ops.create_iam2_virtual_id(username, password)
    test_util.test_dsc("success test 255 varchar long username")

    username = '******' * 256
    try:
        iam2_ops.create_iam2_virtual_id(username, password)
        test_util.test_fail(
            "256 varchar long name is bigger than number in database")
    except:
        test_util.test_dsc(
            "can't create username more than 255 varchar ,success!")

    iam2_ops.clean_iam2_enviroment()
    test_util.test_pass('success test iam2 login in by plain user')
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)
def test():
    global ldap_server_uuid
    global new_account_uuid

    ldap_server = ldp_ops.add_ldap_server('ldap1', 'ldap for test', os.environ.get('ldapServerUrl'), os.environ.get('ldapServerBase'), os.environ.get('ldapServerUsername'), os.environ.get('ldapServerPassword'), 'TLS')
    ldap_server_uuid = ldap_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]

    get_expected_exception = False
    try:
        ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapUid'), account.uuid)
    except:
	get_expected_exception = True
    if not get_expected_exception:
        test_util.test_fail('should not be able to bind ldapuid to admin account')

    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapUid'), new_account.uuid)
    ldap_account_uuid = ldap_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
    acc_ops.logout(session_uuid)

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword')+'1')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with wrong password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), '')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with blank password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), None)
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login without password')

    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
Exemplo n.º 28
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 test():
    iam2_ops.clean_iam2_enviroment()

    # 1 create project
    project_name = 'test_project'
    project = iam2_ops.create_iam2_project(project_name)
    project_name = project.name
    project_uuid = project.uuid

    # 2 create plain user
    plain_user_name = 'username'
    plain_user_password = \
        'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
    plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password,
                                                      project_uuid=project_uuid).uuid

    # 3 add virtual id to project
    iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid], project_uuid)

    # 4 login in project by plain user
    plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password)

    # 4 login in project
    # project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid)
    project_session_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid

    # 5 get iam2 virtual id api permission and project
    iam2_ops.get_iam2_virtual_id_permission(session_uuid=project_session_uuid)
    # time.sleep(20)

    # 6 logout
    acc_ops.logout(project_session_uuid)

    try:
        iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password)
    except:
        test_util.test_dsc("the user [%s] is deleted,can't login" % plain_user_name)

    username = '******' * 85
    password = \
        'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'

    iam2_ops.create_iam2_virtual_id(username, password)
    test_util.test_dsc("success test 255 varchar long username")

    username = '******' * 256
    try:
        iam2_ops.create_iam2_virtual_id(username, password)
        test_util.test_fail("256 varchar long name is bigger than number in database")
    except:
        test_util.test_dsc("can't create username more than 255 varchar ,success!")

    iam2_ops.clean_iam2_enviroment()
    test_util.test_pass('success test iam2 login in by plain user')
Exemplo n.º 30
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)
def error_cleanup():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
def error_cleanup():
    global ldap_server_uuid
    global new_account_uuid
    if ldap_server_uuid:
        ldp_ops.delete_ldap_server(ldap_server_uuid)
    if new_account_uuid:
        acc_ops.delete_account(new_account_uuid)
    ldp_ops.unbind_ldap_account(ldap_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ldap_server_uuid)
    test_util.test_pass('Create VM by normal user account Success')
    acc_ops.logout(session_uuid)
Exemplo n.º 33
0
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)
Exemplo n.º 34
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)
Exemplo n.º 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.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)
Exemplo n.º 36
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)
Exemplo n.º 37
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)
def test():
    global ad_server_uuid
    global new_account_uuid

    system_tag = ["ldapUseAsLoginName::cn"]
    ad_server = ldp_ops.add_ldap_server('ad1', 'ad for test', os.environ.get('adServerUrl'), os.environ.get('adServerBase'), os.environ.get('adServerUsername'), os.environ.get('adServerPassword'), systemtags=system_tag)
    ad_server_uuid = ad_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]
    account_uuid = account.uuid
    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ad_account = ldp_ops.bind_ldap_account(os.environ.get('adUserDn'), account.uuid)
    ad_account_uuid = ad_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), os.environ.get('adPassword'))
    new_account2 = acc_ops.create_account('new_account2', 'password', 'Normal', session_uuid)
    acc_ops.delete_account(new_account2.uuid)
    acc_ops.logout(session_uuid)
    
    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), os.environ.get('adPassword')+'1')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with wrong password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), '')
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with blank password')

    get_expected_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('adUserCn'), None)
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True
    if not get_excepted_exception:
        test_util.test_fail('should not be able to login without password')

    ldp_ops.unbind_ldap_account(ad_account_uuid)
    acc_ops.delete_account(new_account.uuid)
    ldp_ops.delete_ldap_server(ad_server_uuid)
    test_util.test_pass('Login zstack admin by AD Success')
    acc_ops.logout(session_uuid)
Exemplo n.º 39
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)
Exemplo n.º 40
0
def test():

    iam2_ops.clean_iam2_enviroment()

    # 1 create project
    project_name = 'test_project'
    project_uuid = iam2_ops.create_iam2_project(project_name).uuid

    # 2 create project operator and virtual id
    project_operator_name = 'username'
    project_operator_password = '******'
    password='******'
    attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
    project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid
    virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo',password).uuid

    # 3 login in project by project operator
    iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid)
    project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password)
    project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid

    # 4 create virtual id group
    virtual_id_group_uuid = iam2_ops.create_iam2_virtual_id_group(project_uuid,'test_virtual_id_group',session_uuid=project_login_uuid).uuid

    # 5 add virtual id into project and group
    iam2_ops.add_iam2_virtual_ids_to_project([virtual_id_uuid], project_uuid, session_uuid=project_login_uuid)
    iam2_ops.add_iam2_virtual_ids_to_group([virtual_id_uuid],virtual_id_group_uuid,session_uuid=project_login_uuid)

    # 6 remove virtual id from project and group
    iam2_ops.remove_iam2_virtual_ids_from_group([virtual_id_uuid],virtual_id_group_uuid,session_uuid=project_login_uuid)
    iam2_ops.remove_iam2_virtual_ids_from_project([virtual_id_uuid], project_uuid, session_uuid=project_login_uuid)

    # 7 create role
    statements = [{"effect": "Allow", "actions": ["org.zstack.header.vm.**"]}]
    role_uuid = iam2_ops.create_role('role1', statements,session_uuid=project_login_uuid).uuid

    # 8 add/remove roles to/from virtual id(group)
    iam2_ops.add_roles_to_iam2_virtual_id_group([role_uuid],virtual_id_group_uuid,session_uuid=project_login_uuid)
    iam2_ops.remove_roles_from_iam2_virtual_idgroup([role_uuid],virtual_id_group_uuid,session_uuid=project_login_uuid)
    iam2_ops.add_roles_to_iam2_virtual_id([role_uuid],virtual_id_uuid,session_uuid=project_login_uuid)
    iam2_ops.remove_roles_from_iam2_virtual_id([role_uuid],virtual_id_uuid,session_uuid=project_login_uuid)

    # 9 delete
    iam2_ops.delete_role(role_uuid,session_uuid=project_login_uuid)
    iam2_ops.delete_iam2_virtual_id_group(virtual_id_group_uuid,session_uuid=project_login_uuid)
    acc_ops.logout(project_login_uuid)

    iam2_ops.clean_iam2_enviroment()

    test_util.test_pass('success test iam2 login by project operator')
def test():
    iam2_ops.clean_iam2_enviroment()
    # 1 create platformAdmin
    username = '******'
    password = '******'
    platform_admin_uuid = iam2_ops.create_iam2_virtual_id(username,
                                                          password).uuid
    attributes = [{"name": "__PlatformAdmin__"}]
    iam2_ops.add_attributes_to_iam2_virtual_id(platform_admin_uuid, attributes)
    platform_admin_session_uuid = iam2_ops.login_iam2_virtual_id(
        username, password)

    # 2 create platformAdmin by platformAdmin
    username_02 = 'username_02'
    password_02 = 'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
    virtual_id_uuid = iam2_ops.create_iam2_virtual_id(
        username_02, password_02,
        session_uuid=platform_admin_session_uuid).uuid
    try:
        iam2_ops.add_attributes_to_iam2_virtual_id(
            virtual_id_uuid,
            attributes,
            session_uuid=platform_admin_session_uuid)
        test_util.test_fail("platformAdmin can't create platformAdmin")
    except:
        pass

    # 3 delete platformAdmin by platformAdmin
    iam2_ops.add_attributes_to_iam2_virtual_id(virtual_id_uuid, attributes)
    try:
        iam2_ops.remove_attributes_from_iam2_virtual_id(
            virtual_id_uuid,
            attributes,
            session_uuid=platform_admin_session_uuid)
        test_util.test_fail("platformAdmin can't cancel platformAdmin")
    except:
        pass
    acc_ops.logout(platform_admin_session_uuid)
    iam2_ops.delete_iam2_virtual_id(platform_admin_uuid)

    try:
        iam2_ops.login_iam2_virtual_id(username, password)
        test_util.test_fail(
            "the platform admin is Deleted,can't login,but now login success,test fail"
        )
    except:
        pass

    iam2_ops.clean_iam2_enviroment()
    test_util.test_pass("success test platform admin negtive operations")
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)
Exemplo n.º 43
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 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)
Exemplo n.º 47
0
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 cert

    iam2_ops.clean_iam2_enviroment()
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid

    # 1 create project
    project_name = 'test_project'
    password = \
        'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    linked_account_uuid = project.linkedAccountUuid
    attributes = [{"name": "__ProjectRelatedZone__", "value": zone_uuid}]
    iam2_ops.add_attributes_to_iam2_project(project_uuid, attributes)
    test_stub.share_admin_resource_include_vxlan_pool([linked_account_uuid])

    # 2 create projectAdmin  into project
    project_admin_name = 'projectadmin'
    project_admin_uuid = iam2_ops.create_iam2_virtual_id(
        project_admin_name, password).uuid
    iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],
                                             project_uuid)
    attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}]
    iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes)
    project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(
        project_admin_name, password)
    project_admin_session_uuid = iam2_ops.login_iam2_project(
        project_name, project_admin_session_uuid).uuid

    cert = net_ops.create_certificate('certificate_for_pm',
                                      'fake certificate',
                                      session_uuid=project_admin_session_uuid)
    acc_ops.logout(project_admin_session_uuid)

    # 4 delete project
    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)

    # 5 check for cascade delete
    test_stub.check_resource_not_exist(cert.uuid, res_ops.CERTIFICATE)

    iam2_ops.clean_iam2_enviroment()
    test_util.test_pass('Create Simple VM Stop Start Scheduler Success')
Exemplo n.º 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)
Exemplo n.º 50
0
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)
Exemplo n.º 51
0
    def parall_test_run(self):
        test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % self.thread_threshold)
        test_util.test_logger('ZSTACK_TEST_NUM is %d' % self.host_num)
        tmp_host_num = self.host_num

        while tmp_host_num > 0:
            self.check_thread_exception()
            tmp_host_num -= 1
            thread = threading.Thread(target=self.operate_host_parall, args=(self.hosts[self.i].uuid,))
            self.i += 1
            while threading.active_count() > self.thread_threshold:
                time.sleep(1)
            thread.start()

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

        con_ops.change_global_config('identity', 'session.timeout', self.session_to, self.session_uuid)
        con_ops.change_global_config('identity', 'session.maxConcurrent', self.session_mc, self.session_uuid)
        acc_ops.logout(self.session_uuid)
Exemplo n.º 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():
    iam2_ops.clean_iam2_enviroment()
    # 1 create platformAdmin
    username = '******'
    password = '******'
    platform_admin_uuid = iam2_ops.create_iam2_virtual_id(username, password).uuid
    attributes = [{"name": "__PlatformAdmin__"}]
    iam2_ops.add_attributes_to_iam2_virtual_id(platform_admin_uuid, attributes)
    platform_admin_session_uuid = iam2_ops.login_iam2_virtual_id(username, password)

    # 2 create platformAdmin by platformAdmin
    username_02 = 'username_02'
    password_02 = 'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
    virtual_id_uuid = iam2_ops.create_iam2_virtual_id(username_02, password_02,
                                                      session_uuid=platform_admin_session_uuid).uuid
    try:
        iam2_ops.add_attributes_to_iam2_virtual_id(virtual_id_uuid, attributes,
                                                   session_uuid=platform_admin_session_uuid)
        test_util.test_fail("platformAdmin can't create platformAdmin")
    except:
        pass

    # 3 delete platformAdmin by platformAdmin
    iam2_ops.add_attributes_to_iam2_virtual_id(virtual_id_uuid, attributes)
    try:
        iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes,
                                                        session_uuid=platform_admin_session_uuid)
        test_util.test_fail("platformAdmin can't cancel platformAdmin")
    except:
        pass
    acc_ops.logout(platform_admin_session_uuid)
    iam2_ops.delete_iam2_virtual_id(platform_admin_uuid)

    try:
        iam2_ops.login_iam2_virtual_id(username,password)
        test_util.test_fail("the platform admin is Deleted,can't login,but now login success,test fail")
    except:
        pass

    iam2_ops.clean_iam2_enviroment()
    test_util.test_pass("success test platform admin negtive operations")
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)
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')
Exemplo n.º 56
0
def test():
    global ldap_server_uuid
    global new_account_uuid
    global new_account_uuid2
    system_tags = ["ldapCleanBindingFilter::(uidNumber=1002)", "ldapUseAsLoginName::uid"]
    ldap_server = ldp_ops.add_ldap_server('ldap1', 'ldap for test', os.environ.get('ldapServerUrl'), os.environ.get('ldapServerBase'), os.environ.get('ldapServerUsername'), os.environ.get('ldapServerPassword'), 'None', system_tags)
    ldap_server_uuid = ldap_server.inventory.uuid
    conditions = res_ops.gen_query_conditions('type', '=', 'SystemAdmin')
    account = res_ops.query_resource(res_ops.ACCOUNT, conditions)[0]

    new_account = acc_ops.create_account('new_account', 'password', 'Normal')
    new_account_uuid = new_account.uuid
    ldap_account = ldp_ops.bind_ldap_account(os.environ.get('ldapDn'), new_account.uuid)
    ldap_account_uuid = ldap_account.inventory.uuid
    session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
    acc_ops.logout(session_uuid)

    ldp_ops.clean_invalid_ldap_binding()
    get_excepted_exception = False
    try:
        session_uuid = acc_ops.login_by_ldap(os.environ.get('ldapUid'), os.environ.get('ldapPassword'))
        acc_ops.logout(session_uuid)
    except:
        get_excepted_exception = True

    if not get_excepted_exception:
        test_util.test_fail('should not be able to login with filter account')

    new_account2 = acc_ops.create_account('new_account2', 'password', 'Normal')
    new_account_uuid2 = new_account2.uuid
    ldap_account2 = ldp_ops.bind_ldap_account('uid=ldapuser3,ou=People,dc=mevoco,dc=com', new_account2.uuid)
    ldap_account_uuid2 = ldap_account2.inventory.uuid
    session_uuid2 = acc_ops.login_by_ldap('ldapuser3', 'password')
    acc_ops.logout(session_uuid)
    '''