From 97b87ad323eb796b01f37977d34ee5c3fcc70a07 Mon Sep 17 00:00:00 2001 From: Logan V Date: Sun, 12 May 2019 00:57:07 -0500 Subject: [PATCH] Store gate scenario configuration on Zuul executor Playbooks other than the run playbook will require access to the gate check scenario vars, which are computed dynamically. Add a pre-playbook implementing the dynamic behavior and store a vars file in the Zuul executor workspace that can be used as an ansible "vars_file" in other Zuul playbooks. Change-Id: I5723aef8c1123b2ce60140041fee78720f67e0af --- zuul.d/jobs.yaml | 5 +- zuul.d/playbooks/pre-gate-scenario.yml | 89 +++++++++++++++++++ zuul.d/playbooks/run.yml | 68 +------------- .../templates/osa-gate-scenario.yml.j2 | 5 ++ 4 files changed, 101 insertions(+), 66 deletions(-) create mode 100644 zuul.d/playbooks/pre-gate-scenario.yml create mode 100644 zuul.d/playbooks/templates/osa-gate-scenario.yml.j2 diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 0c81a956d8..8641b3cbc0 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -22,8 +22,11 @@ aio deploy. required-projects: - name: openstack/openstack-ansible + pre-run: + - zuul.d/playbooks/pre-gate-scenario.yml run: zuul.d/playbooks/run.yml - post-run: zuul.d/playbooks/post.yml + post-run: + - zuul.d/playbooks/post.yml timeout: 10800 irrelevant-files: - ^\.git.* diff --git a/zuul.d/playbooks/pre-gate-scenario.yml b/zuul.d/playbooks/pre-gate-scenario.yml new file mode 100644 index 0000000000..ed7051aa38 --- /dev/null +++ b/zuul.d/playbooks/pre-gate-scenario.yml @@ -0,0 +1,89 @@ +--- +# Copyright 2019, Logan Vig +# +# 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: + scenario_map: + aodh: telemetry + ceilometer: telemetry + gnocchi: telemetry + horizon: lxc + install_methods: + - distro + - source + 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-([^-]+)-.*$') %} + {% set _ = _scenario.extend( + (zuul.job | + regex_replace('^openstack-ansible-deploy-([^-]+)-.*$', '\\1')).split('_') + ) + %} + {% endif %} + {# 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') + %} + {% set _ = _scenario.append(role_service_name) %} + {# Add special scenarios based on the project name #} + {% if role_service_name in scenario_map %} + {% set _ = _scenario.extend(scenario_map[service_name].split('_')) %} + {% 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 }} + + # 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 diff --git a/zuul.d/playbooks/run.yml b/zuul.d/playbooks/run.yml index 1df45a0a99..918624f470 100644 --- a/zuul.d/playbooks/run.yml +++ b/zuul.d/playbooks/run.yml @@ -1,69 +1,7 @@ -- hosts: all - vars: - scenario_map: - aodh: telemetry - ceilometer: telemetry - gnocchi: telemetry - horizon: lxc - install_methods: - - distro - - source +- hosts: all[0] + vars_files: + - "{{ zuul.executor.work_root }}/osa-gate-scenario.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-([^-]+)-.*$') %} - {% set _ = _scenario.extend( - (zuul.job | - regex_replace('^openstack-ansible-deploy-([^-]+)-.*$', '\\1')).split('_') - ) - %} - {% endif %} - {# 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') - %} - {% set _ = _scenario.append(role_service_name) %} - {# Add special scenarios based on the project name #} - {% if role_service_name in scenario_map %} - {% set _ = _scenario.extend(scenario_map[service_name].split('_')) %} - {% 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 }} - - name: Run gate-check-commit.sh script become: yes become_user: root diff --git a/zuul.d/playbooks/templates/osa-gate-scenario.yml.j2 b/zuul.d/playbooks/templates/osa-gate-scenario.yml.j2 new file mode 100644 index 0000000000..77420b3594 --- /dev/null +++ b/zuul.d/playbooks/templates/osa-gate-scenario.yml.j2 @@ -0,0 +1,5 @@ +--- + +scenario: {{ scenario | to_json }} +action: {{ action | to_json }} +install_method: {{ install_method | to_json }}