示例#1
0
def headers_with_format(step, format):
    """
    Set headers with:
        - Service (Domain) set before
        - Servicepath (Project) set before
        - Token get before
        - format given
    :param step:
    :param format:
    :return:
    """
    try:
        token = IdmUtils.get_token(world.user, world.user, world.domain,
                                   world.ks['platform']['address']['ip'],
                                   world.ks['platform']['address']['port'])
    except ConnectionError as e:
        assert False, 'There was a problem getting the token with the connection with Keystone: Ip: {ip} - Port: {port}'.format(
            ip=world.ks['platform']['address']['ip'],
            port=world.ks['platform']['address']['port'])
    headers = {
        "accept": "application/%s" % format,
        'content-type': 'application/%s' % format,
        'fiware-servicepath': world.project,
        'fiware-service': world.domain,
        'x-auth-token': token
    }
    world.headers = headers
def before_all_scenarios():
    """
    Actions before all scenarios
    Get the initial time at start the tests
    """
    # Remove lettuce log file
    file = open('logs/lettuce.log', 'w')
    file.write('')
    file.close()
    world.log = log
    world.test_time_init = time.strftime("%c")
    log.debug('Starting environment')
    # Start proxys and mocks
    start_environment()

    # At first, there are not configuration for PEP
    world.config_set = ''

    log.debug('Initialize environment')
    initialize_keystone(world.ks['platform'], world.ks['environment_general'])
    initialize_keystone(world.ks['platform'], world.ks['environment_general_ko'])
    initialize_keystone(world.ks['platform'], world.ks['environment_general_no_roles'])
    initialize_keystone(world.ks['platform'], world.ks['environment_domain'])
    initialize_keystone(world.ks['platform'], world.ks['environment_project'])
    initialize_keystone(world.ks['platform'], world.ks['environment_bypass'])
    world.structure = IdmUtils.get_structure(world.ks['platform'])

    # General
    user_roles_general = [(world.ks['user_all'], x['name']) for x in
                          world.ks['environment_general']['domains'][0]['users'][0]['projects'][0]['roles']]
    initialize_ac(user_roles_general,
                  world.ac['ip'], world.ac['port'],
                  world.structure,
                  world.ks['domain_ok'],
                  world.ks['project_ok'],
                  'general')
    # #Domain
    user_roles_domain = [(x['name'], x['roles'][0]['name']) for x in
                         world.ks['environment_domain']['domains'][0]['users']]
    initialize_ac(user_roles_domain,
                  world.ac['ip'], world.ac['port'],
                  world.structure,
                  world.ks['domain_domain_only'],
                  world.ks['project_domain_only'],
                  'domain')
    # Project
    user_roles_project = [(x['name'], x['projects'][0]['roles'][0]['name']) for x in
                          world.ks['environment_project']['domains'][0]['users']]
    initialize_ac(user_roles_project,
                  world.ac['ip'], world.ac['port'],
                  world.structure,
                  world.ks['domain_project_only'],
                  world.ks['project_project_only'],
                  'project')
    reset_test_variables()
    log.debug('Environment ready')
示例#3
0
def before_all_scenarios():
    """
    Actions before all scenarios
    Get the initial time at start the tests
    """
    # Remove lettuce log file
    file = open('logs/lettuce.log', 'w')
    file.write('')
    file.close()
    world.log = log
    world.test_time_init = time.strftime("%c")
    log.debug('Starting environment')
    # Start proxys and mocks
    start_environment()

    # At first, there are not configuration for PEP
    world.config_set = ''

    log.debug('Initialize environment')
    initialize_keystone(world.ks['platform'], world.ks['environment_general'])
    initialize_keystone(world.ks['platform'],
                        world.ks['environment_general_ko'])
    initialize_keystone(world.ks['platform'],
                        world.ks['environment_general_no_roles'])
    initialize_keystone(world.ks['platform'], world.ks['environment_domain'])
    initialize_keystone(world.ks['platform'], world.ks['environment_project'])
    initialize_keystone(world.ks['platform'], world.ks['environment_bypass'])
    world.structure = IdmUtils.get_structure(world.ks['platform'])

    # General
    user_roles_general = [(world.ks['user_all'], x['name'])
                          for x in world.ks['environment_general']['domains']
                          [0]['users'][0]['projects'][0]['roles']]
    initialize_ac(user_roles_general, world.ac['ip'], world.ac['port'],
                  world.structure, world.ks['domain_ok'],
                  world.ks['project_ok'], 'general')
    # #Domain
    user_roles_domain = [
        (x['name'], x['roles'][0]['name'])
        for x in world.ks['environment_domain']['domains'][0]['users']
    ]
    initialize_ac(user_roles_domain, world.ac['ip'], world.ac['port'],
                  world.structure, world.ks['domain_domain_only'],
                  world.ks['project_domain_only'], 'domain')
    # Project
    user_roles_project = [
        (x['name'], x['projects'][0]['roles'][0]['name'])
        for x in world.ks['environment_project']['domains'][0]['users']
    ]
    initialize_ac(user_roles_project, world.ac['ip'], world.ac['port'],
                  world.structure, world.ks['domain_project_only'],
                  world.ks['project_project_only'], 'project')
    reset_test_variables()
    log.debug('Environment ready')
def initialize_keystone(platform, environment):
    """
    Initialize the keystone environment needed to the tests
    :param platform:
    :param environment:
    :return:
    """
    try:
        IdmUtils.prepare_environment(platform, environment)
    except Exception as e:
        for domain in environment['domains']:
            IdmUtils.clean_service(platform, domain['name'])
        IdmUtils.prepare_environment(platform, environment)
def initialize_keystone(platform, environment):
    """
    Initialize the keystone environment needed to the tests
    :param platform:
    :param environment:
    :return:
    """
    try:
        IdmUtils.prepare_environment(platform, environment)
    except Exception as e:
        for domain in environment['domains']:
            IdmUtils.clean_service(platform, domain['name'])
        IdmUtils.prepare_environment(platform, environment)
示例#6
0
def headers_with_format(step, format):
    """
    Set headers with:
        - Service (Domain) set before
        - Servicepath (Project) set before
        - Token get before
        - format given
    :param step:
    :param format:
    :return:
    """
    try:
        token = IdmUtils.get_token(world.user, world.user, world.domain, world.ks['platform']['address']['ip'], world.ks['platform']['address']['port'])
    except ConnectionError as e:
        assert False, 'There was a problem getting the token with the connection with Keystone: Ip: {ip} - Port: {port}'.format(ip=world.ks['platform']['address']['ip'], port=world.ks['platform']['address']['port'])
    headers = {
        "accept": "application/%s" % format,
        'content-type': 'application/%s' % format,
        'fiware-servicepath': world.project,
        'fiware-service': world.domain,
        'x-auth-token': token
    }
    world.headers = headers
示例#7
0
def after_all_scenarios(scenario):
    """
    Actions after all scenarios
    Show the initial and final time of the tests completed
    :param scenario:
    """
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_ok'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_ko'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_no_roles'])
    IdmUtils.clean_service(world.ks['platform'],
                           world.ks['domain_project_only'])
    IdmUtils.clean_service(world.ks['platform'],
                           world.ks['domain_domain_only'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_bypass'])
    ac_utils = AC(world.ac['ip'], port=world.ac['port'])
    ac_utils.delete_tenant_policies(world.ks['domain_ok'])
    ac_utils.delete_tenant_policies(world.ks['domain_project_only'])
    ac_utils.delete_tenant_policies(world.ks['domain_domain_only'])
    stop_environment()
    show_times(world.test_time_init)
def after_all_scenarios(scenario):
    """
    Actions after all scenarios
    Show the initial and final time of the tests completed
    :param scenario:
    """
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_ok'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_ko'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_no_roles'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_project_only'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_domain_only'])
    IdmUtils.clean_service(world.ks['platform'], world.ks['domain_bypass'])
    ac_utils = AC(world.ac['ip'], port=world.ac['port'])
    ac_utils.delete_tenant_policies(world.ks['domain_ok'])
    ac_utils.delete_tenant_policies(world.ks['domain_project_only'])
    ac_utils.delete_tenant_policies(world.ks['domain_domain_only'])
    stop_environment()
    show_times(world.test_time_init)