Beispiel #1
0
def config_compute(config_parser, p_vip, user_name, password, tenant_name,
                   min_compute_nodes):
    session = get_session(p_vip=p_vip,
                          username=user_name,
                          password=password,
                          project_name=tenant_name,
                          domain_name=DEFAULT_DOMAIN_ID)
    nova = nova_client.Client('2', session=session)
    # Create the flavors
    m1 = create_if_not_exist(nova.flavors,
                             'flavor',
                             FLAVOR1_NAME,
                             ram=512,
                             vcpus=1,
                             disk=15,
                             is_public=True)
    config_parser.set('compute', 'flavor_ref', m1.id)
    config_parser.set('orchestration', 'instance_type', FLAVOR1_NAME)
    config_parser.set('heat_plugin', 'instance_type', FLAVOR1_NAME)
    m2 = create_if_not_exist(nova.flavors,
                             'flavor',
                             FLAVOR2_NAME,
                             ram=1024,
                             vcpus=2,
                             disk=15,
                             is_public=True)
    config_parser.set('compute', 'flavor_ref_alt', m2.id)
    config_parser.set('compute', 'min_compute_nodes', min_compute_nodes)
    config_parser.set('heat_plugin', 'minimal_instance_type', FLAVOR2_NAME)
    config_parser.set('compute-feature-enabled', 'pause', 'false')
Beispiel #2
0
def config_compute(config_parser, private_vip, user_name, password,
                   tenant_name, endpoint_type='internalURL',
                   min_compute_nodes=1):
    auth_url = get_auth_url(private_vip)
    nova = nova_client.Client('2', user_name, password, tenant_name, auth_url,
                              insecure=True, endpoint_type=endpoint_type)
    # Get the default image.
    images = nova.images.list()
    if len(images) == 0:
        raise NotSupportedError('At least 1 image in glance is required.')
    default_image = images[0]
    for image in images:
        if image.name == IMAGE_NAME:
            default_image = image
            images.remove(image)
    LOG.info('Use image %s as default image in tempest', default_image.name)
    alt_image = images[0] if len(images) > 0 else default_image
    LOG.info('Use image %s as alter image in tempest', alt_image.name)
    config_parser.set('compute', 'image_ref', default_image.id)
    config_parser.set('compute', 'image_ref_alt', alt_image.id)
    # Create the flavors
    m1 = create_if_not_exist(nova.flavors, 'flavor', FLAVOR1_NAME, ram=512,
                             vcpus=1, disk=10, is_public=True)
    config_parser.set('compute', 'flavor_ref', m1.id)
    config_parser.set('orchestration', 'instance_type', FLAVOR1_NAME)
    m2 = create_if_not_exist(nova.flavors, 'flavor', FLAVOR2_NAME, ram=1024,
                             vcpus=2, disk=10, is_public=True)
    config_parser.set('compute', 'flavor_ref_alt', m2.id)
    config_parser.set('compute', 'min_compute_nodes', min_compute_nodes)
    config_parser.set('compute-feature-enabled', 'pause', 'false')
Beispiel #3
0
def config_identity(config_parser,
                    p_vip,
                    admin_user_name,
                    admin_pwd,
                    admin_tenant_name,
                    creds_provider,
                    default_user_name=None,
                    default_pwd=None,
                    alt_user_name=None,
                    alt_pwd=None):
    uri_v3 = get_auth_url(p_vip, 'v3')
    uri_v2 = get_auth_url(p_vip)
    keystone = get_keystone_client(p_vip=p_vip,
                                   username=admin_user_name,
                                   password=admin_pwd,
                                   project_name=admin_tenant_name,
                                   domain_name=DEFAULT_DOMAIN_ID)
    config_parser.set('identity', 'uri_v3', uri_v3)
    config_parser.set('identity', 'uri', uri_v2)
    config_parser.set('identity', 'auth_version', 'v3')
    config_parser.set('auth', 'admin_project_name', admin_tenant_name)
    config_parser.set('auth', 'admin_password', admin_pwd)
    config_parser.set('auth', 'admin_username', admin_user_name)
    # config heat_plugin
    auth_url = get_auth_url2(p_vip, 'v3')
    config_parser.set('heat_plugin', 'auth_url', auth_url)
    config_parser.set('heat_plugin', 'auth_version', '3')
    config_parser.set('heat_plugin', 'admin_username', admin_user_name)
    config_parser.set('heat_plugin', 'admin_password', admin_pwd)
    # Create tempest test role
    test_role = create_if_not_exist(keystone.roles, 'role', ROLE_NAME)
    config_parser.set('auth', 'tempest_roles', ROLE_NAME)
    # Both SQL backend and LDAP backend is Default
    config_parser.set('auth', 'admin_domain_name', 'Default')
    default_domain = keystone.domains.get(DEFAULT_DOMAIN_ID)
    default_tenant = create_if_not_exist(keystone.projects,
                                         'project',
                                         TENANT_NAME,
                                         domain=default_domain)
    # config_parser.set('heat_plugin', 'username', 'admin')
    # config_parser.set('heat_plugin', 'password', 'vmware')
    # config_parser.set('heat_plugin', 'project_name', 'admin')
    # config_parser.set('heat_plugin', 'user_domain_name', 'Default')
    # config_parser.set('heat_plugin', 'project_domain_name', 'Default')
    try:
        heat_user = create_if_not_exist(keystone.users,
                                        'user',
                                        'demo',
                                        password='******',
                                        default_project=default_tenant)
        grant_role_on_project(keystone, default_tenant, heat_user, test_role)
        config_parser.set('heat_plugin', 'username', 'admin')
        config_parser.set('heat_plugin', 'password', 'vmware')
        config_parser.set('heat_plugin', 'project_name', 'admin')
        config_parser.set('heat_plugin', 'user_domain_name', 'Default')
        config_parser.set('heat_plugin', 'project_domain_name', 'Default')
    except Exception:
        config_parser.set('heat_plugin', 'username', 'admin')
        config_parser.set('heat_plugin', 'password', 'vmware')
        config_parser.set('heat_plugin', 'project_name', 'admin')
        config_parser.set('heat_plugin', 'user_domain_name', 'local')
        config_parser.set('heat_plugin', 'project_domain_name', 'local')
    if creds_provider in [LEGACY_PROVIDER, PRE_PROVISIONED_PROVIDER]:
        # Create default tenant and user
        default_domain = keystone.domains.get(DEFAULT_DOMAIN_ID)
        default_tenant = create_if_not_exist(keystone.projects,
                                             'project',
                                             TENANT_NAME,
                                             domain=default_domain)
        default_user = create_if_not_exist(keystone.users,
                                           'user',
                                           default_user_name,
                                           password=default_pwd,
                                           tenant_id=default_tenant.id)

        grant_role_on_project(keystone, default_tenant, default_user,
                              test_role)
        # Create alter tenant and user
        alt_tenant = create_if_not_exist(keystone.projects,
                                         'project',
                                         ALT_TENANT_NAME,
                                         domain=default_domain)
        alt_user = create_if_not_exist(keystone.users,
                                       'user',
                                       alt_user_name,
                                       password=alt_pwd,
                                       tenant_id=alt_tenant.id)

        grant_role_on_project(keystone, alt_tenant, alt_user, test_role)
        if LEGACY_PROVIDER == creds_provider:
            # Legacy provider can only be used before Newton release.
            config_parser.set('identity', 'tenant_name', TENANT_NAME)
            config_parser.set('identity', 'username', default_user_name)
            config_parser.set('identity', 'password', default_pwd)
            config_parser.set('identity', 'alt_tenant_name', ALT_TENANT_NAME)
            config_parser.set('identity', 'alt_username', alt_user_name)
            config_parser.set('identity', 'alt_password', alt_pwd)
        elif PRE_PROVISIONED_PROVIDER == creds_provider:
            accounts = list()
            accounts.append(
                add_account(default_user_name,
                            default_pwd,
                            TENANT_NAME,
                            default_tenant.id,
                            roles=[ROLE_NAME]))
            accounts.append(
                add_account(alt_user_name,
                            alt_pwd,
                            ALT_TENANT_NAME,
                            alt_tenant.id,
                            roles=[ROLE_NAME]))
            project_id = None
            for project in keystone.projects.list():
                if project.name == admin_tenant_name \
                        and project.domain_id == DEFAULT_DOMAIN_ID:
                    project_id = project.id
                    break
            if not project_id:
                raise NotFoundError('Project %s not found' % admin_tenant_name)
            accounts.append(
                add_account(admin_user_name,
                            admin_pwd,
                            admin_tenant_name,
                            project_id,
                            roles=['admin']))
            test_accounts_file = os.path.join(os.getcwd(), TEMPEST_DIR,
                                              'etc/accounts.yaml')
            with open(test_accounts_file, 'w') as fh:
                yaml.dump(accounts,
                          fh,
                          default_flow_style=False,
                          default_style=False,
                          indent=2,
                          encoding='utf-8',
                          allow_unicode=True)
            config_parser.set('auth', 'test_accounts_file', test_accounts_file)
        config_parser.set('auth', 'use_dynamic_credentials', 'false')
        config_parser.set('auth', 'create_isolated_networks', 'false')
    elif creds_provider == DYNAMIC_PROVIDER:
        config_parser.set('auth', 'use_dynamic_credentials', 'true')
        config_parser.set('auth', 'create_isolated_networks', 'false')
    else:
        raise NotSupportedError('Not support %s' % creds_provider)
    # Create role for object storage
    create_if_not_exist(keystone.roles, 'role', STORAGE_ROLE_NAME)
    config_parser.set('object-storage', 'operator_role', STORAGE_ROLE_NAME)
Beispiel #4
0
def config_identity(config_parser, private_vip, admin_user_name, admin_pwd,
                    admin_tenant_name, creds_provider, default_user_name=None,
                    default_pwd=None, alt_user_name=None, alt_pwd=None):
    uri_v3 = get_auth_url(private_vip, 'v3')
    uri_v2 = get_auth_url(private_vip)
    keystone = get_keystone_client(private_vip=private_vip,
                                   username=admin_user_name,
                                   password=admin_pwd,
                                   project_name=admin_tenant_name,
                                   domain_name=DEFAULT_DOMAIN_ID)
    admin_tenant = get_entity(keystone.projects, 'project', admin_tenant_name)
    config_parser.set('identity', 'uri_v3', uri_v3)
    config_parser.set('identity', 'uri', uri_v2)
    config_parser.set('identity', 'auth_version', 'v2')
    config_parser.set('auth', 'admin_tenant_name', admin_tenant_name)
    config_parser.set('auth', 'admin_password', admin_pwd)
    config_parser.set('auth', 'admin_username', admin_user_name)
    # Create tempest test role
    test_role = create_if_not_exist(keystone.roles, 'role', ROLE_NAME)
    config_parser.set('auth', 'tempest_roles', ROLE_NAME)
    # Both SQL backend and LDAP backend is Default
    config_parser.set('auth', 'admin_domain_name', 'Default')
    if creds_provider in [LEGACY_PROVIDER, PRE_PROVISIONED_PROVIDER]:
        # Create default tenant and user
        default_domain = keystone.domains.get(DEFAULT_DOMAIN_ID)
        default_tenant = create_if_not_exist(keystone.projects, 'project',
                                             TENANT_NAME,
                                             domain=default_domain)
        default_user = create_if_not_exist(keystone.users, 'user',
                                           default_user_name,
                                           password=default_pwd,
                                           tenant_id=default_tenant.id)

        grant_role_on_project(keystone, default_tenant, default_user,
                              test_role)
        # Create alter tenant and user
        alt_tenant = create_if_not_exist(keystone.projects, 'project',
                                         ALT_TENANT_NAME,
                                         domain=default_domain)
        alt_user = create_if_not_exist(keystone.users, 'user', alt_user_name,
                                       password=alt_pwd,
                                       tenant_id=alt_tenant.id)

        grant_role_on_project(keystone, alt_tenant, alt_user, test_role)
        if LEGACY_PROVIDER == creds_provider:
            # Legacy provider can only be used before Newton release.
            config_parser.set('identity', 'tenant_name', TENANT_NAME)
            config_parser.set('identity', 'username', default_user_name)
            config_parser.set('identity', 'password', default_pwd)
            config_parser.set('identity', 'alt_tenant_name', ALT_TENANT_NAME)
            config_parser.set('identity', 'alt_username', alt_user_name)
            config_parser.set('identity', 'alt_password', alt_pwd)
        elif PRE_PROVISIONED_PROVIDER == creds_provider:
            accounts = list()
            accounts.append(add_account(default_user_name, default_pwd,
                                        TENANT_NAME, roles=[ROLE_NAME]))
            accounts.append(add_account(alt_user_name, alt_pwd,
                                        ALT_TENANT_NAME, roles=[ROLE_NAME]))
            accounts.append(add_account(admin_user_name, admin_pwd,
                                        admin_tenant_name, roles=['admin']))
            test_accounts_file = os.path.join(os.getcwd(), TEMPEST_DIR,
                                              'etc/accounts.yaml')
            with open(test_accounts_file, 'w') as fh:
                yaml.dump(accounts, fh, default_flow_style=False,
                          default_style=False, indent=2, encoding='utf-8',
                          allow_unicode=True)
            config_parser.set('auth', 'test_accounts_file', test_accounts_file)
        config_parser.set('auth', 'use_dynamic_credentials', 'false')
        config_parser.set('auth', 'create_isolated_networks', 'false')
    elif creds_provider == DYNAMIC_PROVIDER:
        config_parser.set('auth', 'use_dynamic_credentials', 'true')
        config_parser.set('auth', 'create_isolated_networks', 'false')
    else:
        raise NotSupportedError('Not support %s' % creds_provider)
    # Create role for object storage
    create_if_not_exist(keystone.roles, 'role', STORAGE_ROLE_NAME)
    config_parser.set('object-storage', 'operator_role', STORAGE_ROLE_NAME)
    # Create role and add it to admin user for heat tempest tests.
    heat_role = get_entity(keystone.roles, 'role', 'heat_stack_owner')
    if not heat_role:
        LOG.info("Create role heat_stack_owner")
        heat_role = keystone.roles.create('heat_stack_owner')
        admin_user = get_entity(keystone.users, 'user', admin_user_name)
        grant_role_on_project(keystone, admin_tenant, admin_user, heat_role)