From a249c161587c2d690accd2b8e8cc1e170817d339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Jeanneret?= Date: Fri, 26 Jul 2019 08:47:01 +0200 Subject: [PATCH] Adds molecule testing for undercloud-heat-purge-deleted Change-Id: I24bb60777b685954b7fd369642b59a7f1924ef85 (cherry picked from commit 3ba8931a58d00c8f631ff8a32dd16377748a0fc8) --- .../molecule/default/Dockerfile.j2 | 37 +++++++ .../molecule/default/molecule.yml | 51 ++++++++++ .../molecule/default/playbook.yml | 54 ++++++++++ .../molecule/default/prepare.yml | 98 +++++++++++++++++++ zuul.d/molecule.yaml | 9 ++ 5 files changed, 249 insertions(+) create mode 100644 roles/undercloud-heat-purge-deleted/molecule/default/Dockerfile.j2 create mode 100644 roles/undercloud-heat-purge-deleted/molecule/default/molecule.yml create mode 100644 roles/undercloud-heat-purge-deleted/molecule/default/playbook.yml create mode 100644 roles/undercloud-heat-purge-deleted/molecule/default/prepare.yml diff --git a/roles/undercloud-heat-purge-deleted/molecule/default/Dockerfile.j2 b/roles/undercloud-heat-purge-deleted/molecule/default/Dockerfile.j2 new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/roles/undercloud-heat-purge-deleted/molecule/default/Dockerfile.j2 @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2019 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 if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% 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"] diff --git a/roles/undercloud-heat-purge-deleted/molecule/default/molecule.yml b/roles/undercloud-heat-purge-deleted/molecule/default/molecule.yml new file mode 100644 index 000000000..9de9dea89 --- /dev/null +++ b/roles/undercloud-heat-purge-deleted/molecule/default/molecule.yml @@ -0,0 +1,51 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + override_command: True + command: python -m SimpleHTTPServer 8787 + pkg_extras: python-setuptools python-enum34 python-netaddr epel-release ruby + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + + - name: fedora28 + hostname: fedora28 + image: fedora:28 + override_command: True + command: python3 -m http.server 8787 + pkg_extras: python*-setuptools python*-enum python*-netaddr ruby + environment: + <<: *env + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "../../../../library" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/undercloud-heat-purge-deleted/molecule/default/playbook.yml b/roles/undercloud-heat-purge-deleted/molecule/default/playbook.yml new file mode 100644 index 000000000..aa82c166a --- /dev/null +++ b/roles/undercloud-heat-purge-deleted/molecule/default/playbook.yml @@ -0,0 +1,54 @@ +--- +# Copyright 2019 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 + hosts: all + gather_facts: no + + tasks: + - name: working detection + include_role: + name: undercloud-heat-purge-deleted + + - name: Validate failure + block: + - name: Override container_cli + copy: + dest: /undercloud.conf + content: | + [DEFAULT] + container_cli = docker + + - name: run validation + include_role: + name: undercloud-heat-purge-deleted + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Test output + debug: + msg: The validation works! Ending play. + + - name: End play + meta: end_play + + - name: Fail the validation at this point + fail: + msg: | + The undercloud-heat-purge-deleted validation failed to detect + missing cron job. diff --git a/roles/undercloud-heat-purge-deleted/molecule/default/prepare.yml b/roles/undercloud-heat-purge-deleted/molecule/default/prepare.yml new file mode 100644 index 000000000..ed46780a8 --- /dev/null +++ b/roles/undercloud-heat-purge-deleted/molecule/default/prepare.yml @@ -0,0 +1,98 @@ +--- +# Copyright 2019 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: Prepare + hosts: all + gather_facts: no + + tasks: + - name: install hiera + package: + name: hiera + + - name: create hiera tree + file: + path: /etc/puppet + state: directory + + - name: populate hiera.yaml + copy: + dest: /etc/puppet/hiera.yaml + content: | + :backends: + - yaml + :yaml: + :datadir: "/etc/puppet/" + :hierarchy: + - "common" + + - name: populate hiera content + copy: + dest: /etc/puppet/common.yaml + content: | + tripleo_undercloud_conf_file: /undercloud.conf + + - name: populate undercloud.conf + copy: + dest: /undercloud.conf + content: | + [DEFAULT] + container_cli = podman + + - name: Populate successful podman CLI + copy: + dest: /usr/bin/podman + mode: 0755 + content: | + #!/bin/bash + action="$1" + shift + container="$1" + shift + command="$@" + + case $container in + 'heat_api_cron') + echo '# This is a comment that should be ignored' + echo '0 12 14 2 * heat-manage purge_deleted' + ;; + *) + echo "Unknown container ${container}" + ;; + esac + + - name: Populate buggy docker CLI + copy: + dest: /usr/bin/docker + mode: 0755 + content: | + #!/bin/bash + action="$1" + shift + container="$1" + shift + command="$@" + + case $container in + 'heat_api_cron') + echo '# This is a comment that should be ignored' + echo '0 12 14 2 * some-other command' + ;; + *) + echo "Unknown container ${container}" + ;; + esac diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 0a822535b..9c07d3d56 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -18,6 +18,7 @@ - tripleo-validations-centos-7-molecule-nova-status - tripleo-validations-centos-7-molecule-image-serve - tripleo-validations-centos-7-molecule-check-network-gateway + - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted gate: queue: integrated jobs: @@ -36,6 +37,7 @@ - tripleo-validations-centos-7-molecule-nova-status - tripleo-validations-centos-7-molecule-image-serve - tripleo-validations-centos-7-molecule-check-network-gateway + - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted name: tripleo-validations-molecule-jobs - job: files: @@ -143,3 +145,10 @@ parent: tripleo-validations-centos-7-base vars: tripleo_validations_role_name: check-network-gateway +- job: + files: + - ^roles/undercloud-heat-purge-deleted/.* + name: tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted + parent: tripleo-validations-centos-7-base + vars: + tripleo_validations_role_name: undercloud-heat-purge-deleted