diff --git a/roles/stonith-exists/molecule/default/Dockerfile.j2 b/roles/stonith-exists/molecule/default/Dockerfile.j2 new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/roles/stonith-exists/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/stonith-exists/molecule/default/molecule.yml b/roles/stonith-exists/molecule/default/molecule.yml new file mode 100644 index 000000000..5eb59c254 --- /dev/null +++ b/roles/stonith-exists/molecule/default/molecule.yml @@ -0,0 +1,46 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + pkg_extras: python-setuptools + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + + - name: fedora28 + hostname: fedora28 + image: fedora:28 + pkg_extras: python*-setuptools + environment: + <<: *env + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/stonith-exists/molecule/default/playbook.yml b/roles/stonith-exists/molecule/default/playbook.yml new file mode 100644 index 000000000..91def951d --- /dev/null +++ b/roles/stonith-exists/molecule/default/playbook.yml @@ -0,0 +1,56 @@ +--- +# 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 + + tasks: + - name: Safe run + include_role: + name: stonith-exists + + - name: Fail the validation + block: + - name: Faulty pcs script + copy: + dest: /usr/bin/pcs + mode: 0755 + content: | + #!/bin/sh + echo "NO stonith devices configured" + exit 0 + + - name: Run validation + include_role: + name: stonith-exists + + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Test output + debug: + msg: The validation works! End play + + - name: End play + meta: end_play + + - name: Fail playbook if reached + fail: + msg: | + The stonith-exists validation didn't properly detect failed + stonith config diff --git a/roles/stonith-exists/molecule/default/prepare.yml b/roles/stonith-exists/molecule/default/prepare.yml new file mode 100644 index 000000000..c47fc2079 --- /dev/null +++ b/roles/stonith-exists/molecule/default/prepare.yml @@ -0,0 +1,30 @@ +--- +# 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: Populate successful stonith + copy: + dest: /usr/bin/pcs + mode: 0755 + content: | + #!/bin/sh + echo "Stonith service configured" + exit 0 diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 31c85e0fa..99a0810d5 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -21,6 +21,7 @@ - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted - tripleo-validations-centos-7-molecule-undercloud-tokenflush - tripleo-validations-centos-7-molecule-rabbitmq-limits + - tripleo-validations-centos-7-molecule-stonith-exists gate: queue: integrated jobs: @@ -42,6 +43,7 @@ - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted - tripleo-validations-centos-7-molecule-undercloud-tokenflush - tripleo-validations-centos-7-molecule-rabbitmq-limits + - tripleo-validations-centos-7-molecule-stonith-exists name: tripleo-validations-molecule-jobs - job: files: @@ -170,3 +172,10 @@ parent: tripleo-validations-centos-7-base vars: tripleo_validations_role_name: rabbitmq-limits +- job: + files: + - ^roles/stonith-exists/.* + name: tripleo-validations-centos-7-molecule-stonith-exists + parent: tripleo-validations-centos-7-base + vars: + tripleo_validations_role_name: stonith-exists