diff --git a/doc/source/roles/role-check_rhsm_version.rst b/doc/source/roles/role-check_rhsm_version.rst new file mode 100644 index 000000000..b5ef8cbd9 --- /dev/null +++ b/doc/source/roles/role-check_rhsm_version.rst @@ -0,0 +1,6 @@ +========================= +Role - check_rhsm_version +========================= + +.. ansibleautoplugin:: + :role: roles/check_rhsm_version diff --git a/playbooks/check-rhsm-version.yaml b/playbooks/check-rhsm-version.yaml new file mode 100644 index 000000000..1f8005fe7 --- /dev/null +++ b/playbooks/check-rhsm-version.yaml @@ -0,0 +1,16 @@ +--- +- hosts: all + gather_facts: false + vars: + metadata: + name: Verify that the RSHM version configured is the right one + description: | + This validation checks the RHSM version of the target node via + subscription-manager release --show and makes sure that the + release matches the value set in check_rhsm_version_expected. + groups: + - pre-undercloud-upgrade + - pre-overcloud-upgrade + check_rhsm_version_debug: false + roles: + - check_rhsm_version diff --git a/roles/check_rhsm_version/defaults/main.yml b/roles/check_rhsm_version/defaults/main.yml new file mode 100644 index 000000000..845ef8b1a --- /dev/null +++ b/roles/check_rhsm_version/defaults/main.yml @@ -0,0 +1,29 @@ +--- +# Copyright 2020 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. + + +# All variables intended for modification should place placed in this file. + +# All variables within this role should have a prefix of "check_rhsm_version" +check_rhsm_version_debug: false + +# subscription manager command used to retrieve the +# rhsm release. Parametrized mostly for testing +check_rhsm_version_command: "subscription-manager release --show" + +# Version expected by the validation, if the configured RHSM version +# does not match the validation will fail. +check_rhsm_version_expected: "8.2" diff --git a/roles/check_rhsm_version/molecule/default/Dockerfile b/roles/check_rhsm_version/molecule/default/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/check_rhsm_version/molecule/default/Dockerfile @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2020 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 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"] \ No newline at end of file diff --git a/roles/check_rhsm_version/molecule/default/converge.yml b/roles/check_rhsm_version/molecule/default/converge.yml new file mode 100644 index 000000000..9e6aba82c --- /dev/null +++ b/roles/check_rhsm_version/molecule/default/converge.yml @@ -0,0 +1,24 @@ +--- +# Copyright 2020 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 + roles: + - role: "check_rhsm_version" + vars: + check_rhsm_version_command: "echo 'Release: 8.2'" + check_rhsm_version_expected: "8.2" diff --git a/roles/check_rhsm_version/molecule/default/molecule.yml b/roles/check_rhsm_version/molecule/default/molecule.yml new file mode 100644 index 000000000..646914aa8 --- /dev/null +++ b/roles/check_rhsm_version/molecule/default/molecule.yml @@ -0,0 +1,38 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos8 + hostname: centos8 + image: centos:8 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + environment: + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + +provisioner: + name: ansible + options: + vvv: true + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "../../../../library" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +verifier: + name: testinfra diff --git a/roles/check_rhsm_version/molecule/rhsm_mismatch/Dockerfile b/roles/check_rhsm_version/molecule/rhsm_mismatch/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/check_rhsm_version/molecule/rhsm_mismatch/Dockerfile @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2020 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 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"] \ No newline at end of file diff --git a/roles/check_rhsm_version/molecule/rhsm_mismatch/converge.yml b/roles/check_rhsm_version/molecule/rhsm_mismatch/converge.yml new file mode 100644 index 000000000..6af3dba30 --- /dev/null +++ b/roles/check_rhsm_version/molecule/rhsm_mismatch/converge.yml @@ -0,0 +1,43 @@ +--- +# Copyright 2020 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: detect wrong rhsm version + block: + - name: run validation with wrong rhsm version + include_role: + name: "check_rhsm_version" + vars: + check_rhsm_version_command: "echo 'Release: 8.4'" + check_rhsm_version_expected: "8.2" + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Status message + debug: + msg: "Detected RHSM version mismatch!" + + - name: End play + meta: end_play + + - name: Fail the test + fail: + msg: | + The rhsm version mismatch should have detected but it wasn't.. diff --git a/roles/check_rhsm_version/molecule/rhsm_mismatch/molecule.yml b/roles/check_rhsm_version/molecule/rhsm_mismatch/molecule.yml new file mode 100644 index 000000000..646914aa8 --- /dev/null +++ b/roles/check_rhsm_version/molecule/rhsm_mismatch/molecule.yml @@ -0,0 +1,38 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos8 + hostname: centos8 + image: centos:8 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + environment: + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + +provisioner: + name: ansible + options: + vvv: true + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "../../../../library" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +verifier: + name: testinfra diff --git a/roles/check_rhsm_version/tasks/main.yml b/roles/check_rhsm_version/tasks/main.yml new file mode 100644 index 000000000..95b8cf913 --- /dev/null +++ b/roles/check_rhsm_version/tasks/main.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2020 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. + + +# "check_rhsm_version" tasks +- name: Retrieve RHSM version + become: true + command: "{{ check_rhsm_version_command }}" + register: rhsm_version_ret + +- name: Check RHSM version + fail: + msg: '{{ check_rhsm_version_expected }} does not match configured rhsm_version {{ rhsm_version_ret.stdout }}' + when: "check_rhsm_version_expected not in rhsm_version_ret.stdout" diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 4fdd66223..4a5a94ac4 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -4,6 +4,7 @@ jobs: - tripleo-validations-centos-8-molecule-ceph - tripleo-validations-centos-8-molecule-check_network_gateway + - tripleo-validations-centos-8-molecule-check_rhsm_version - tripleo-validations-centos-8-molecule-controller_token - tripleo-validations-centos-8-molecule-controller_ulimits - tripleo-validations-centos-8-molecule-ctlplane_ip_range @@ -23,6 +24,7 @@ jobs: - tripleo-validations-centos-8-molecule-ceph - tripleo-validations-centos-8-molecule-check_network_gateway + - tripleo-validations-centos-8-molecule-check_rhsm_version - tripleo-validations-centos-8-molecule-controller_token - tripleo-validations-centos-8-molecule-controller_ulimits - tripleo-validations-centos-8-molecule-ctlplane_ip_range @@ -305,3 +307,10 @@ parent: tripleo-validations-centos-8-base vars: tripleo_validations_role_name: package_version +- job: + files: + - ^roles/check_rhsm_version/.* + name: tripleo-validations-centos-8-molecule-check_rhsm_version + parent: tripleo-validations-centos-8-base + vars: + tripleo_validations_role_name: check_rhsm_version