openstack-ansible-os_tempest/tasks/tempest_resources.yml

292 lines
10 KiB
YAML

---
# Copyright 2014, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# We set the python interpreter to the ansible runtime venv if
# the delegation is to localhost so that we get access to the
# appropriate python libraries in that venv. If the delegation
# is to another host, we assume that it is accessible by the
# system python instead.
- name: Ensure that all required variables are set when tempest_public_net_create is enabled
assert:
that:
- tempest_public_net_name is defined
- tempest_public_net_provider_type is defined
- tempest_public_net_physical_name is defined
- tempest_public_subnet_name is defined
- tempest_public_subnet_cidr is defined
- tempest_public_net_physical_name is defined
- tempest_public_router_external is defined
when:
- tempest_public_net_create
- name: Ensure that all required variables are set when tempest_public_net_create is disabled
assert:
that:
- tempest_neutron_public_network_id is defined
when:
- not tempest_public_net_create
- name: Ensure that all required variables are set when tempest_private_net_create is enabled
assert:
that:
- tempest_private_net_name is defined
- tempest_private_subnet_name is defined
- tempest_private_subnet_cidr is defined
- tempest_private_net_provider_type is defined
when:
- tempest_private_net_create
- name: Ensure that all required variables are set when tempest_router_create is enabled
assert:
that:
- (tempest_public_net_create or tempest_neutron_public_network_id is defined)
- tempest_private_net_create
when:
- tempest_router_create
- name: Ensure that all required variables are set when tempest_images_create is disabled
assert:
that:
- tempest_glance_image_id_1 is defined
- tempest_glance_image_id_2 is defined
when:
- not tempest_images_create
- name: Ensure that all required variables are set when tempest_flavors_create is enabled
assert:
that:
- "tempest_flavors | length > 0"
when:
- tempest_flavors_create
- name: Ensure that all required variables are set when tempest_flavors_create is disabled
assert:
that:
- tempest_nova_flavor_id_1 is defined
when:
- not tempest_flavors_create
- name: Ensures you have at least one image to upload
assert:
that:
- "tempest_images | length > 0"
when:
- tempest_service_available_glance | bool
- tempest_images_create | bool
- name: Creating OpenStack Projects
ansible.builtin.include_role:
name: openstack.osa.openstack_resources
vars:
openstack_resources_identity:
domains:
- name: "{{ tempest_domain_name }}"
projects: |-
{% set projects = [] %}
{% for project in tempest_projects %}
{% set _ = projects.append({
'name': project,
'description': project ~ ' project',
'domain': tempest_domain_name
}) %}
{% endfor %}
{{ projects }}
when:
- tempest_projects_create | bool
- name: Get tempest tenant data
delegate_to: "{{ tempest_service_setup_host }}"
run_once: true
vars:
ansible_python_interpreter: "{{ tempest_service_setup_host_python_interpreter }}"
block:
- name: Get tempest tenant UUID
openstack.cloud.project_info:
cloud: "{{ tempest_cloud_name }}"
interface: "{{ tempest_interface_name }}"
domain: "{{ tempest_domain_name }}"
name: "{{ project }}"
loop: "{{ tempest_projects }}"
loop_control:
loop_var: project
label: "{{ project }}"
register: tempest_project_details
- name: Get demo tenant id
set_fact:
keystone_demo_tenant_id: >-
{{ (tempest_project_details.results | map(attribute='projects') | list | flatten | map(attribute='id') | list)[0] }}
- name: Creating OpenStack resources
ansible.builtin.include_role:
name: openstack.osa.openstack_resources
vars:
_private_network:
name: "{{ tempest_private_net_name }}"
network_type: "{{ tempest_private_net_provider_type }}"
physical_network: "{{ tempest_private_net_physical_name | default(omit) }}"
segmentation_id: "{{ tempest_private_net_seg_id | default(omit) }}"
mtu: "{{ tempest_private_net_mtu | default(omit) }}"
project: "{{ keystone_demo_tenant_id }}"
subnets:
- name: "{{ tempest_private_subnet_name }}"
cidr: "{{ tempest_private_subnet_cidr }}"
dhcp: false
_public_network:
name: "{{ tempest_public_net_name }}"
network_type: "{{ tempest_public_net_provider_type }}"
physical_network: "{{ tempest_public_net_physical_name | default(omit) }}"
segmentation_id: "{{ tempest_public_net_seg_id | default(omit) }}"
external: "{{ tempest_public_router_external }}"
project: "{{ keystone_demo_tenant_id }}"
subnets:
- name: "{{ tempest_public_subnet_name }}"
cidr: "{{ tempest_public_subnet_cidr }}"
allocation_start: "{{ tempest_public_subnet_allocation_pools.split('-')[0] | default(omit) }}"
allocation_end: "{{ tempest_public_subnet_allocation_pools.split('-')[1] | default(omit) }}"
gateway: "{{ tempest_public_subnet_gateway_ip | default(omit) }}"
_router:
name: router
network: "{{ tempest_public_net_name }}"
interfaces:
- "{{ tempest_private_subnet_name }}"
project: "{{ keystone_demo_tenant_id }}"
_compute_resources:
flavors:
- specs: "{{ tempest_flavors }}"
_image_resources:
images: "{{ tempest_images | default([]) }}"
_network_resources: |-
{% set resources = {'networks': [], 'routers': [], 'security_groups': []} %}
{% if tempest_private_net_create | bool %}
{% set _ = resources['networks'].append(_private_network) %}
{% endif %}
{% if tempest_public_net_create | bool %}
{% set _ = resources['networks'].append(_public_network) %}
{% endif %}
{% if tempest_router_create | bool %}
{% set _ = resources['routers'].append(_router) %}
{% endif %}
{{ resources }}
openstack_resources_setup_host: "{{ tempest_service_setup_host }}"
openstack_resources_python_interpreter: "{{ tempest_service_setup_host_python_interpreter }}"
openstack_resources_cloud_name: "{{ tempest_cloud_name }}"
openstack_resources_interface: "{{ tempest_interface_name }}"
openstack_resources_network: "{{ tempest_service_available_neutron | ternary(_network_resources, {}) }}"
openstack_resources_image: "{{ (tempest_service_available_glance and tempest_images_create) | ternary(_image_resources, {}) }}"
openstack_resources_compute: "{{ (tempest_service_available_nova and tempest_flavors_create) | ternary(_compute_resources, {}) }}"
- name: Get tempest resources data
delegate_to: "{{ tempest_service_setup_host }}"
run_once: true
vars:
ansible_python_interpreter: "{{ tempest_service_setup_host_python_interpreter }}"
block:
- name: Get tempest images
openstack.cloud.image_info:
cloud: "{{ tempest_cloud_name }}"
interface: "{{ tempest_interface_name }}"
filters:
'name': "{{ image['name'] }}"
'tags':
- 'managed_by_tempest'
loop: "{{ tempest_images }}"
loop_control:
loop_var: image
label: "{{ image['name'] }}"
register: tempest_image_details
when:
- tempest_service_available_glance | bool
- tempest_images_create | bool
- name: Get tempest public network UUID
openstack.cloud.networks_info:
cloud: "{{ tempest_cloud_name }}"
interface: "{{ tempest_interface_name }}"
name: "{{ tempest_public_net_name }}"
filters:
project_id: "{{ keystone_demo_tenant_id }}"
register: tempest_public_network_details
when:
- tempest_service_available_neutron | bool
- tempest_public_net_create | bool
- name: Get tempest router details
openstack.cloud.routers_info:
cloud: "{{ tempest_cloud_name }}"
interface: "{{ tempest_interface_name }}"
name: router
filters:
project_id: "{{ keystone_demo_tenant_id }}"
when:
- tempest_service_available_neutron | bool
- tempest_router_create | bool
# These facts are used in tempest.conf.j2; we set an empty string if it is not
# set above to ensure the template will parse correctly.
- name: Store first tempest image id
vars:
res: "{{ tempest_image_details['results'] | map(attribute='images') | flatten }}"
set_fact:
tempest_glance_image_id_1: "{{ res[0]['id'] | default('') }}"
tempest_glance_image_id_2: "{{ res[-1]['id'] | default('') }}"
when:
- tempest_service_available_glance | bool
- tempest_images_create | bool
- name: Store tempest flavor id
set_fact:
tempest_nova_flavor_id_1: "{{ tempest_service_available_nova | ternary(tempest_flavors[0]['id'], '1') }}"
tempest_nova_flavor_id_2: "{{ tempest_service_available_nova | ternary(tempest_flavors[-1]['id'], '2') }}"
when:
- tempest_service_available_nova | bool
- tempest_flavors_create | bool
- name: Store neutron public network id
set_fact:
tempest_neutron_public_network_id: "{{ tempest_service_available_neutron | ternary(tempest_public_network_details['networks'][0]['id'], '') }}"
when:
- tempest_service_available_neutron | bool
- tempest_public_net_create | bool
- name: Get router admin state and ip address
set_fact:
router_admin_state: "{{ _add_router['routers'][0]['is_admin_state_up'] }}"
router_ip: "{{ _add_router['routers'][0]['external_gateway_info']['external_fixed_ips'][0]['ip_address'] }}"
when:
- tempest_service_available_neutron | bool
- tempest_router_create | bool
- name: Ping router ip address
shell: |
set -e
ping -c2 "{{ router_ip }}"
register: _ping_router
changed_when: false
until: _ping_router is success
retries: 5
delay: 10
when:
- tempest_router_create | bool
- tempest_service_available_neutron | bool
- router_admin_state | bool
- tempest_network_ping_gateway | bool
- tempest_public_net_provider_type not in ['local']