blob: d00b060143ea4764b81f99030fd105498b13de49 [file] [log] [blame]
{%- from "runtest/map.jinja" import tempest with context %}
{%- from "keystone/map.jinja" import client as kclient with context %}
{%- if tempest.get('test_accounts', {}).get('enabled', False) %}
{% set prefix = tempest.get('test_accounts', {}).get('prefix', 'Test') %}
{% set identity_name = tempest.get('keystone_profile_admin', 'admin_identity') %}
{%- macro load_accounts_file() %}{% include 'runtest/files/test_accounts.yml' %}{% endmacro %}
{%- set accounts_yaml = load_accounts_file()|load_yaml %}
{%- set count = 1 %}
{%- for account in accounts_yaml %}
{% set project_name = account['project_name'] %}
{% set user_name = account['username'] %}
{% set roles = account['roles'] %}
{% set network_name = account.get('resources', {}).get('network', '') %}
{% set router_name = account.get('resources', {}).get('router', '') %}
{% set admin_project = kclient.get('os_client_config',{}).get('cfgs', {}).get('root', {}).get('content',{}).get('clouds',{}).get(identity_name, {}).get('auth', {}).get('project_name', 'admin') %}
{%- if project_name != admin_project %}
keystone_project_{{ project_name }}:
keystonev3.project_present:
- cloud_name: {{ identity_name }}
- name: {{ project_name }}
- description: {{ project_name }} for Openstack Testing
- enabled: True
- domain_id: 'default'
{% endif %}
keystone_user_{{ user_name }}:
keystonev3.user_present:
- cloud_name: {{ identity_name }}
- name: {{ user_name }}
- default_project_id: {{ project_name }}
- enabled: true
- password: {{ account['password'] }}
- email: {{ user_name }}@test.tst
{%- for role_name in roles %}
keystone_user_{{ user_name }}_role_{{ role_name }}_assigned:
keystonev3.user_role_assigned:
- name: {{ user_name }}
- role_id: {{ role_name }}
- cloud_name: {{ identity_name }}
- project_id: {{ project_name }}
{%- endfor %}
{% if network_name %}
{% set subnet_name = network_name + '_subnet' %}
{% set subnet_prefix = '10.199.' + count|string %}
{% set count = count + 1 %}
neutron_openstack_network_{{ network_name }}:
neutronng.network_present:
- name: {{ network_name }}
- profile: {{ identity_name }}
- tenant: {{ project_name }}
- router_external: False
- admin_state_up: True
- shared: False
neutron_openstack_subnet_{{ subnet_name }}:
neutronng.subnet_present:
- name: {{ subnet_name }}
- network_name: {{ network_name }}
- profile: {{ identity_name }}
- tenant: {{ project_name }}
- cidr: {{ subnet_prefix + '.0/24' }}
- enable_dhcp: True
- allocation_pools:
- start: {{ subnet_prefix + '.10' }}
end: {{ subnet_prefix + '.254' }}
- gateway_ip: {{ subnet_prefix + '.1' }}
- require:
- neutronng: neutron_openstack_network_{{ network_name }}
{% endif %}
{% if router_name %}
neutron_openstack_router_{{ router_name }}:
neutronng.router_present:
- name: {{ router_name }}
- interfaces:
- {{ subnet_name }}
- gateway_network: {{ tempest.get('network', {}).get('floating_network_name', 'public') }}
- profile: {{ identity_name }}
- tenant: {{ project_name }}
- admin_state_up: True
- require:
- neutronng: neutron_openstack_subnet_{{ subnet_name }}
{% endif %}
{%- endfor %}
generate_test_accounts_file:
file.managed:
- name: {{ tempest.test_accounts.cfg_path }}
- contents: |
{{ accounts_yaml |yaml(False)|indent(8) }}
{%- if tempest.test_target is defined %}
copy_test_accounts_file:
cmd.run:
- name: salt-cp {{ tempest.test_target }} {{ tempest.test_accounts.cfg_path}} {{ tempest.test_accounts.cfg_path }}
- require:
- file: generate_test_accounts_file
{%- endif %}
{%- endif %}