Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Add shared configuration for all molecule test
Browse files Browse the repository at this point in the history
This patch adds a molecule configuration file at the repository
level (tripleo-validations/.config/molecule/config.yml) which defines
all the default values for molecule.yml files in all roles.

This patch also introduces a common Dockerfile (UBI8 image) shared
between all the role molecule tests. This Dockerfile will install the
CentOS 8.x Linux Repos and GPG Keys during the image build.

This Dockerfile is located in tripleo-validations/.config/molecule
directory and it is shared through a relative symbolic link between all
the molecule directories.

NOTE: tox-ansible doesn't manage shared molecule configuration at the
project level (see [1]). To be able to use it, we have to explicitly add
the driver name in each molecule.yml file in the roles level. Once [1]
will be fixed, these will be removed.

[1] - ansible/tox-ansible#88).

Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
Change-Id: I4717825e2767dc55016a30fb62aa6a5541f26cfd
(cherry picked from commit 66193a6)
(cherry picked from commit 6a3081b)
(cherry picked from commit 8bd52a2)
(cherry picked from commit f2f322c1ea195905d080b303a0e97c905f9592f3)
  • Loading branch information
strider committed Jul 2, 2021
1 parent ab5dd56 commit 505545a
Show file tree
Hide file tree
Showing 110 changed files with 347 additions and 4,228 deletions.
35 changes: 35 additions & 0 deletions .config/molecule/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Molecule managed
# 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.


{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

RUN dnf makecache && dnf install -y sudo python*-devel python*-dnf bash {{ item.pkg_extras | default('') }}
# TODO(gchamoul): find a better to get always the latest version of those rpms
# below from the centos mirror
RUN dnf install -y http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-2.el8.noarch.rpm
RUN dnf install -y http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-linux-repos-8-2.el8.noarch.rpm && dnf install -y epel-release && dnf clean all

{% for pkg in item.easy_install | default([]) %}
# install pip for centos where there is no python-pip rpm in default repos
RUN easy_install {{ pkg }}
{% endfor %}

CMD ["sh", "-c", "while true; do sleep 10000; done"]
70 changes: 70 additions & 0 deletions .config/molecule/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# Tripleo-validations uses a shared molecule configuration file to avoid
# repetition. That configuration file is located at the repository level
# ({REPO}/.config/molecule/config.yml) and defines all the default values for
# all the molecule.yml files across all the roles. By default, the role-addition
# process will produce an empty molecule.yml inheriting this config.yml file.
#
# Any key defined in the role molecule.yml file will override values from this
# config.yml file.
#
# IMPORTANT: if you want to override the default values set here in this file,
# you will have to redefine them completely in your molecule.yml (at the role
# level) and add your extra configuration!
#
# For instance, if you need to add an extra package in your ubi8 container, you
# will have to add the entire "platforms" key into your molecule.yml file and
# add your package name in the pkg_extras key.
#
# No merge will happen between your molecule.yml and this config.yml
# files. That's why you will have to redefine them completely.

driver:
name: podman

log: true

platforms:
- name: ubi8
hostname: ubi8
image: ubi8/ubi-init
registry:
url: registry.access.redhat.com
dockerfile: Dockerfile
pkg_extras: python*-setuptools python*-pyyaml
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
privileged: true
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
ulimits: &ulimit
- host

provisioner:
name: ansible
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}"

scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy

verifier:
name: testinfra
37 changes: 0 additions & 37 deletions _skeleton_role_/molecule/default/Dockerfile

This file was deleted.

49 changes: 3 additions & 46 deletions _skeleton_role_/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
---
# inherits tripleo-validations/.config/molecule/config.yml
# To override default values, please take a look at the config.yml.

driver:
name: podman

log: true

platforms:
- name: ubi8
hostname: ubi8
image: ubi8/ubi-init
registry:
url: registry.access.redhat.com
dockerfile: Dockerfile
pkg_extras: python*-setuptools
privileged: true
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
- /etc/pki/rpm-gpg:/etc/pki/rpm-gpg
- /opt/yum.repos.d:/etc/yum.repos.d:rw
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
ulimits: &ulimit
- host

provisioner:
name: ansible
inventory:
hosts:
all:
hosts:
ubi8:
ansible_python_interpreter: /usr/bin/python3
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}"

scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy

verifier:
name: testinfra
23 changes: 22 additions & 1 deletion doc/source/_exts/ansible-autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def _run_role(self, role):
os.path.basename(role)
)
)

abspath_role = os.path.dirname(os.path.abspath(role))
molecule_shared_file = os.path.join(os.path.dirname(abspath_role),
".config/molecule/config.yml")

if os.path.exists(molecule_shared_file):
with open(molecule_shared_file) as msf:
molecule_defaults = yaml.safe_load(msf.read())

defaults_file = os.path.join(role, 'defaults', 'main.yml')
if os.path.exists(defaults_file):
with open(defaults_file) as f:
Expand Down Expand Up @@ -226,6 +235,9 @@ def _run_role(self, role):
with open(molecule_file) as f:
molecule_conf = yaml.safe_load(f.read())

if not molecule_conf:
molecule_conf = molecule_defaults

molecule_section.append(
self._yaml_section(
to_yaml_data=molecule_conf,
Expand All @@ -234,7 +246,16 @@ def _run_role(self, role):
)

default_playbook = [molecule_path, test, 'converge.yml']
provisioner_data = molecule_conf.get('provisioner')

provisioner_data = None
# Now that we use a shared molecule configuration file, the
# molecule.yml file in the role scenarios could be empty or
# contains only overriding keys.
if molecule_conf:
provisioner_data = molecule_conf.get('provisioner')
else:
provisioner_data = molecule_defaults.get('provisioner')

if provisioner_data:
inventory = provisioner_data.get('inventory')
if inventory:
Expand Down
6 changes: 6 additions & 0 deletions role-addition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
args:
creates: "tripleo_validations/roles/{{ _role_name }}"

- name: Create link to the common Dockerfile
file:
src: ../../../../.config/molecule/Dockerfile
dest: roles/validation_{{ _role_name }}/molecule/default/Dockerfile
state: link

- name: Read zuul molecule file
slurp:
src: zuul.d/molecule.yaml
Expand Down
48 changes: 3 additions & 45 deletions roles/ceilometerdb_size/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,6 @@
---
# inherits tripleo-validations/.config/molecule/config.yml
# To override default values, please take a look at the config.yml.

driver:
name: podman

log: true

platforms:
- name: ubi8
hostname: ubi8
image: ubi8/ubi-init
registry:
url: registry.access.redhat.com
dockerfile: Dockerfile
pkg_extras: python*-setuptools ruby python*-pyyaml
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
- /etc/pki/rpm-gpg:/etc/pki/rpm-gpg
- /opt/yum.repos.d:/etc/yum.repos.d:rw
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
ulimits: &ulimit
- host

provisioner:
name: ansible
inventory:
hosts:
all:
hosts:
ubi8:
ansible_python_interpreter: /usr/bin/python3
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}"

scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy

verifier:
name: testinfra
37 changes: 0 additions & 37 deletions roles/ceph/molecule/ceph-ansible-installed/Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions roles/ceph/molecule/ceph-ansible-installed/Dockerfile
Loading

0 comments on commit 505545a

Please sign in to comment.