openstack-ansible/zuul.d/playbooks/pre-gate-scenario.yml
Jonathan Rosser a0714bf9a9 Simplify handling of 'telemetry' scenario in CI tests
Reduce the amount of logic in the pre-gate-scenario playbook and
keep it all together in the bootstrap-host role.

Change-Id: I83fda9cfceabb14c2fb471059a76a8add6714b72
2024-08-13 14:16:00 +01:00

125 lines
5.3 KiB
YAML

---
# Copyright 2019, Logan Vig <logan2211@gmail.com>
#
# 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.
- name: Calculate the dynamic OSA gate scenario
hosts: all[0]
vars:
install_methods:
- distro
- source
zuul_user_vars_file: "{{ ansible_env.HOME }}/osa-job-vars.yml"
tasks:
- name: Dynamically create scenario if not set
set_fact:
scenario: |-
{% set _scenario = [] %}
{# Add the scenarios based on the job name #}
{# ex. openstack-ansible-deploy-$scenario1_$scenario2-$os #}
{% if zuul.job is match('^openstack-ansible-(deploy|upgrade_?[a-z,0-9,.]*)-([^-]+)-.*$') %}
{% set _ = _scenario.extend(
(zuul.job |
regex_replace('^openstack-ansible-[a-z,0-9,.,_]*-([^-]+)-.*$', '\\1')).split('_')
)
%}
{# If testing a role, add the role service name to the scenario list #}
{% if zuul.project.short_name is match('^openstack-ansible-os_(.*)$') %}
{% set role_service_name = zuul.project.short_name |
regex_replace('^openstack-ansible-os_(.*)$', '\\1')
%}
{% elif zuul.project.short_name is match('^ansible-role-(.*)$') %}
{% set role_service_name = zuul.project.short_name |
regex_replace('^ansible-role-(.*)$', '\\1')
%}
{% elif zuul.project.short_name == 'ansible-hardening' %}
{% set role_service_name = 'hardening' %}
{% elif zuul.project.short_name == 'openstack-ansible' %}
{% set role_service_name = 'integrated' %}
{% elif zuul.project.short_name == 'openstack-ansible-plugins' %}
{% set role_service_name = 'plugins' %}
{% endif %}
{% if role_service_name is defined %}
{% set _ = _scenario.append(role_service_name) %}
{% endif %}
{% endif %}
{% if zuul.job is match('^openstack-ansible-(deploy|upgrade)-([^-]+)-validate') %}
{% set _ = _scenario.append('validate') %}
{% endif %}
{# If running linters we need to provide name of the role as a scenario w/o splitting #}
{% if zuul.job is match('^openstack-ansible-linters-.*$') %}
{% for prefix in ['openstack-ansible', 'ansible-role'] %}
{% if zuul.project.short_name is match('^' ~ prefix ~ '-([^-]+)$') %}
{% set _ = _scenario.append(
zuul.project.short_name | regex_replace('^' ~ prefix ~'-([^-]+)$', '\\1')
)
%}
{% endif%}
{% endfor %}
{# Hardening role is special as our regular filters don't work for it #}
{% if zuul.project.short_name == 'ansible-hardening' %}
{% set _ = _scenario.append('hardening') %}
{% endif %}
{% endif %}
{{ _scenario | join('_') }}
when:
- scenario is not defined
- name: Dynamically set action if not set
set_fact:
action: "{{ zuul.job | regex_replace('^openstack-ansible-([^-]+)-.*$', '\\1') }}"
when:
- action is not defined
- name: Dynamically set install method if not set
set_fact:
install_method: "{{ (scenario.split('_') | intersect(install_methods))[0] }}"
when:
- install_method is not defined
- scenario.split('_') | intersect(install_methods) | length > 0
- name: Set install method to source as a baseline default
set_fact:
install_method: source
when:
- install_method is not defined
- name: Print gate check configuration
debug:
msg: |-
Running gate-check-commit with the following arguments:
Scenario: {{ scenario }}
Action: {{ action }}
Install Method: {{ install_method }}
Zuul project name: {{ zuul.project.short_name }}
# Other playbooks can consume this vars file as shown in run.yml
# This file is stored in work/osa-gate-scenario.yml on the Zuul executor
- name: Log the gate check configuration to a vars file
template:
src: osa-gate-scenario.yml.j2
dest: "{{ zuul.executor.work_root }}/osa-gate-scenario.yml"
delegate_to: localhost
# Other playbooks can consume this vars file to access the
# Zuul job variables, see https://zuul-ci.org/docs/zuul/reference/jobs.html#user-jobs-job-variables
- name: Record the zuul user job variables for future use by embedded ansible
vars:
zuul_helper_var:
zuul: "{{ zuul }}"
zuul_site_mirror_info_helper_var:
zuul_site_mirror_info: "{{ zuul_site_mirror_info | default({}) }}"
template:
src: osa-job-vars.yml.j2
dest: "{{ zuul_user_vars_file }}"