[validation_init] Add ability to create new validation w/o molecule test

This patch adds a new variable called `validation_init_molecule` to the
`validation_init` role in order to create a new validation with or
without Molecule test.

If sets to `false` (by default `true`), the molecule directory for the
new role will be removed and no CI Job will be added into the
zuul.d/molecule.yaml file.

Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
Change-Id: Ia068957eed5e868b40c2386e3844d7a51bf61bb6
This commit is contained in:
Gael Chamoulaud (Strider) 2021-07-20 22:32:35 +02:00
parent 78d9f5b00a
commit 8f43cce4ee
No known key found for this signature in database
GPG Key ID: 4119D0305C651D66
9 changed files with 166 additions and 15 deletions

View File

@ -505,6 +505,16 @@ of the `molecule.yaml` file.
jobs:
- tripleo-validations-centos-8-molecule-${NEWROLENAME}
.. note::
Adding `Molecule` test is highly recommended but remains **optional**. Some
validations might require a real OpenStack Infrastructure in order to run
them and this, by definition, will make the `Molecule` test very complex to
implement.
If you are in this case when creating a new validation, please
add `-e validation_init_molecule=false` to the above `ansible-playbook`
command. No molecule directory and no CI Job will be created.
Finally it will add a role documentation file at
`doc/source/roles/role-${NEWROLENAME}.rst`. This file will need to contain

View File

@ -45,3 +45,9 @@ validation_init_roles_doc_dir: "doc/source/roles"
# If 'true', the documentation and CI configuration will be created, otherwise not.
# Will be used to create new custom validation through the CLI.
validation_init_enabling_ci: true
# If sets to 'true', the molecule directory created from the skeleton won't be deleted
# from the role and a CI job will be added in zuul.d/molecule.yaml file.
# If sets to 'false', the molecule directory will be deleted after the creation
# of the new role and no ci job will be added in zuul.d/molecule.yaml file.
validation_init_molecule: true

View File

@ -1,15 +0,0 @@
---
# Copyright 2021 Red Hat, Inc.
# All Rights Reserved.
#
# 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.

View File

@ -1,3 +1,21 @@
---
# inherits tripleo-validations/.config/molecule/config.yml
# To override default values, please take a look at the config.yml.
provisioner:
name: ansible
playbooks:
prepare: ../../resources/playbooks/prepare.yml
inventory:
hosts:
all:
hosts:
ubi8:
ansible_python_interpreter: /usr/bin/python3
log: true
options:
vvv: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
ANSIBLE_ROLES_PATH: "${ANSIBLE_ROLES_PATH}:${HOME}/zuul-jobs/roles"
ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}"

View File

@ -0,0 +1,32 @@
---
# Copyright 2021 Red Hat, Inc.
# All Rights Reserved.
#
# 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: Converge - Role without molecule tests
hosts: all
gather_facts: false
tasks:
- name: Create new role
include_role:
name: validation_init
vars:
validation_init_role_name: skeleton_test_no_molecule
validation_init_prefix: "tripleo"
validation_init_skeleton_role_dir: "/tmp"
validation_init_roles_dir: "/tmp/roles"
validation_init_zuuld_molecule: "/tmp/zuul.d/molecule.yaml"
validation_init_playbooks_dir: "/tmp/playbooks"
validation_init_roles_doc_dir: "/tmp/doc/source/roles"
validation_init_molecule: false

View File

@ -0,0 +1,21 @@
---
# inherits tripleo-validations/.config/molecule/config.yml
# To override default values, please take a look at the config.yml.
provisioner:
name: ansible
playbooks:
prepare: ../../resources/playbooks/prepare.yml
inventory:
hosts:
all:
hosts:
ubi8:
ansible_python_interpreter: /usr/bin/python3
log: true
options:
vvv: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
ANSIBLE_ROLES_PATH: "${ANSIBLE_ROLES_PATH}:${HOME}/zuul-jobs/roles"
ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}"

View File

@ -0,0 +1,72 @@
---
# Copyright 2021 Red Hat, Inc.
# All Rights Reserved.
#
# 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: Verify with no molecule tests
hosts: all
gather_facts: false
vars:
new_role_path: "/tmp/roles/tripleo_skeleton_test_no_molecule"
new_role_name: "tripleo_skeleton_test_no_molecule"
new_zmol_path: "/tmp/zuul.d/molecule.yaml"
tasks:
- name: Check new role directory is present
stat:
path: "{{ new_role_path }}"
register: roles_name_dir
- assert:
that:
- roles_name_dir.stat.exists | bool
- roles_name_dir.stat.isdir | bool
fail_msg: |
{{ new_role_path }} role directory doesn't exist.
success_msg: |
{{ new_role_path }} role directory does exist.
- name: Check the molecule directory presence/absence
stat:
path: "{{ new_role_path }}/molecule"
register: roles_molecule_dir
- name: Fail if the molecule directory if present
fail:
msg: |
{{ new_role_path }}/molecule directory has not been removed.
when: roles_molecule_dir.stat.exists | bool
- name: Read zuul molecule file
slurp:
src: "{{ new_zmol_path }}"
register: molecule_yaml
- name: Print returned information
debug:
msg: "{{ molecule_yaml['content'] | b64decode }}"
- name: Check no molecule job has been added
command: >-
grep {{ new_role_name }} {{ new_zmol_path }}
changed_when: false
ignore_errors: true
register: is_molecule_ci_job_definition
- assert:
that:
- "{{ is_molecule_ci_job_definition.rc | int }} > 0"
fail_msg: |
CI Job definition has been added!
success_msg: |
CI Job definition not found as expected!

View File

@ -62,6 +62,12 @@
args:
creates: "{{ validation_init_roles_dir }}/{{ validation_init_prefix }}_{{ _role_name }}"
- name: Remove molecule directory if not needed
file:
path: "{{ validation_init_roles_dir }}/{{ validation_init_prefix }}_{{ _role_name }}/molecule"
state: absent
when: not validation_init_molecule | default(true) | bool
- name: Create the playbook
copy:
content: |
@ -164,6 +170,7 @@
{% set _ = sorted_jobs.insert(0, project) %}
{{ sorted_jobs | to_nice_yaml(indent=2, width=1337) }}
dest: "{{ validation_init_zuuld_molecule }}"
when: validation_init_molecule | default(true) | bool
- name: Create role documentation
copy: