diff --git a/doc/source/roles/role-check_undercloud_conf.rst b/doc/source/roles/role-check_undercloud_conf.rst new file mode 100644 index 000000000..c5018a4aa --- /dev/null +++ b/doc/source/roles/role-check_undercloud_conf.rst @@ -0,0 +1,6 @@ +============================ +Role - check_undercloud_conf +============================ + +.. ansibleautoplugin:: + :role: roles/check_undercloud_conf diff --git a/playbooks/check-undercloud-conf.yaml b/playbooks/check-undercloud-conf.yaml new file mode 100644 index 000000000..de1e059c2 --- /dev/null +++ b/playbooks/check-undercloud-conf.yaml @@ -0,0 +1,15 @@ +--- +- hosts: undercloud + vars: + metadata: + name: Verify undercloud.conf correctness + description: | + This validation verifies that no deprecated, invalid or + incompatible parameters are being passwed in the Undercloud's + undercloud.conf configuration file. + groups: + - prep + - pre-undercloud-upgrade + check_undercloud_conf_debug: false + roles: + - check_undercloud_conf diff --git a/roles/check_undercloud_conf/defaults/main.yml b/roles/check_undercloud_conf/defaults/main.yml new file mode 100644 index 000000000..c50aa69ca --- /dev/null +++ b/roles/check_undercloud_conf/defaults/main.yml @@ -0,0 +1,41 @@ +--- +# 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_undercloud_conf" +check_undercloud_conf_debug: false +required_params: + - container_images_file +deprecated_params: + - masquerade_network + - docker_images_file + - enabled_drivers + - docker_bip + - network_gateway + - network_cidr + - discovery_interface + - discovery_runbench + - docker_insecure_registries + - docker_registry_mirror + - ipxe_enabled +unsupported_drivers: + - pxe_ipmitool + - pxe_drac + - pxe_ilo + - pxe_irmc + - fake_pxe diff --git a/roles/check_undercloud_conf/molecule/config_OK/Dockerfile b/roles/check_undercloud_conf/molecule/config_OK/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/config_OK/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_undercloud_conf/molecule/config_OK/converge.yml b/roles/check_undercloud_conf/molecule/config_OK/converge.yml new file mode 100644 index 000000000..f2e75960f --- /dev/null +++ b/roles/check_undercloud_conf/molecule/config_OK/converge.yml @@ -0,0 +1,45 @@ +--- +# 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. + +# Validate a correct undercloud.conf with content: +# +# [DEFAULT] +# local_interface = em0 +# local_ip = 192.168.24.1/24 +# undercloud_public_host = 192.168.24.2 +# undercloud_admin_host = 192.168.24.3 +# undercloud_nameservers = 172.16.0.1,10.0.0.1 +# undercloud_ntp_servers=clock1.rdu2.redhat.com +# overcloud_domain_name=redhat.local +# undercloud_service_certificate = /undercloud.pem +# hieradata_override = /hiera_override.yaml +# container_images_file= /containers-prepare-parameter.yaml +# enabled_hw_types = ipmi,redfish +# custom_env_files = /skip_rhel_release.yaml +# +# [ctlplane-subnet] +# local_subnet = ctlplane-subnet +# cidr = 192.168.24.0/24 +# dhcp_start = 192.168.24.5 +# dhcp_end = 192.168.24.55 +# gateway = 192.168.24.1 +# inspection_iprange = 192.168.24.100,192.168.24.120 +# +- name: Converge + hosts: all + gather_facts: false + roles: + - role: "check_undercloud_conf" diff --git a/roles/check_undercloud_conf/molecule/config_OK/molecule.yml b/roles/check_undercloud_conf/molecule/config_OK/molecule.yml new file mode 100644 index 000000000..28b449b6d --- /dev/null +++ b/roles/check_undercloud_conf/molecule/config_OK/molecule.yml @@ -0,0 +1,52 @@ +--- +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 + - /etc/pki/rpm-gpg:/etc/pki/rpm-gpg + - /opt/yum.repos.d:/etc/yum.repos.d:rw + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + ulimits: &ulimit + - host + +provisioner: + name: ansible + options: + vvv: true + inventory: + hosts: + all: + hosts: + ubi8: + ansible_python_interpreter: /usr/bin/python3 + vars: + ansible_user: root + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - destroy + +verifier: + name: testinfra diff --git a/roles/check_undercloud_conf/molecule/config_OK/prepare.yml b/roles/check_undercloud_conf/molecule/config_OK/prepare.yml new file mode 100644 index 000000000..97c7df874 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/config_OK/prepare.yml @@ -0,0 +1,65 @@ +--- +# 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: false + tasks: + - name: Ensure we get needed facts + setup: + gather_subset: + - '!all' + - '!any' + - '!min' + - env + + - name: populate undercloud.conf + copy: + dest: "{{ ansible_env.HOME }}/undercloud.conf" + content: | + [DEFAULT] + local_interface = em0 + local_ip = 192.168.24.1/24 + undercloud_public_host = 192.168.24.2 + undercloud_admin_host = 192.168.24.3 + undercloud_nameservers = 172.16.0.1,10.0.0.1 + undercloud_ntp_servers=clock1.rdu2.redhat.com + overcloud_domain_name=redhat.local + undercloud_service_certificate = /undercloud.pem + hieradata_override = /hiera_override.yaml + container_images_file= /containers-prepare-parameter.yaml + enabled_hardware_types = ipmi,redfish + custom_env_files = /skip_rhel_release.yaml + + [ctlplane-subnet] + local_subnet = ctlplane-subnet + cidr = 192.168.24.0/24 + dhcp_start = 192.168.24.5 + dhcp_end = 192.168.24.55 + gateway = 192.168.24.1 + inspection_iprange = 192.168.24.100,192.168.24.120 + + - name: create files with random content + copy: + dest: "/{{ item }}" + content: | + I'm the file {{ item }} + loop: + - 'undercloud.pem' + - 'hiera_override.yaml' + - 'containers-prepare-parameter.yaml' + - 'skip_rhel_release.yaml' diff --git a/roles/check_undercloud_conf/molecule/default/Dockerfile b/roles/check_undercloud_conf/molecule/default/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/check_undercloud_conf/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_undercloud_conf/molecule/default/converge.yml b/roles/check_undercloud_conf/molecule/default/converge.yml new file mode 100644 index 000000000..e00ae6fe5 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/default/converge.yml @@ -0,0 +1,55 @@ +--- +# 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. + +# Validate an undercloud.conf with the following content: +# +# [DEFAULT] +# container_images_file= /home/stack/containers-prepare-parameter.yaml +# +# The validation should fail as the file /home/stack/containers-prepare-parameter.yaml +# does not exist. + +- name: Converge + hosts: all + gather_facts: false + tasks: + - name: detect non existing file assigned to a parameter + block: + - name: run validation check_undercloud_conf + include_role: + name: "check_undercloud_conf" + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Detect right error message + fail: + msg: "Test failed due to wrong error: {{ ansible_failed_result.results.0.msg }}" + when: + - not ansible_failed_result.results.0.msg | + regex_search("^File configured in .* does not exist$") + + - name: Status message + debug: + msg: "Detected undercloud.conf configuration issue!" + + - name: End play + meta: end_play + + - name: Fail the test + fail: + msg: | + A configuration issue should have been detected but it wasn't.. diff --git a/roles/check_undercloud_conf/molecule/default/molecule.yml b/roles/check_undercloud_conf/molecule/default/molecule.yml new file mode 100644 index 000000000..28b449b6d --- /dev/null +++ b/roles/check_undercloud_conf/molecule/default/molecule.yml @@ -0,0 +1,52 @@ +--- +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 + - /etc/pki/rpm-gpg:/etc/pki/rpm-gpg + - /opt/yum.repos.d:/etc/yum.repos.d:rw + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + ulimits: &ulimit + - host + +provisioner: + name: ansible + options: + vvv: true + inventory: + hosts: + all: + hosts: + ubi8: + ansible_python_interpreter: /usr/bin/python3 + vars: + ansible_user: root + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - destroy + +verifier: + name: testinfra diff --git a/roles/check_undercloud_conf/molecule/default/prepare.yml b/roles/check_undercloud_conf/molecule/default/prepare.yml new file mode 100644 index 000000000..72ce14cc0 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/default/prepare.yml @@ -0,0 +1,34 @@ +--- +# 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: false + tasks: + - name: Ensure we get needed facts + setup: + gather_subset: + - '!all' + - '!any' + - '!min' + - env + + - name: populate undercloud.conf + copy: + dest: "{{ ansible_env.HOME }}/undercloud.conf" + content: | + [DEFAULT] + container_images_file= /home/stack/containers-prepare-parameter.yaml diff --git a/roles/check_undercloud_conf/molecule/deprecated_drivers/Dockerfile b/roles/check_undercloud_conf/molecule/deprecated_drivers/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_drivers/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_undercloud_conf/molecule/deprecated_drivers/converge.yml b/roles/check_undercloud_conf/molecule/deprecated_drivers/converge.yml new file mode 100644 index 000000000..e88f6cbe4 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_drivers/converge.yml @@ -0,0 +1,71 @@ +--- +# 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. + +# Validate that the validation fails when the undercloud.conf contains +# deprecated drivers in the enabled_hardware_types: +# +# [DEFAULT] +# local_interface = em0 +# local_ip = 192.168.24.1/24 +# undercloud_public_host = 192.168.24.2 +# undercloud_admin_host = 192.168.24.3 +# undercloud_nameservers = 172.16.0.1,10.0.0.1 +# undercloud_ntp_servers=clock1.rdu2.redhat.com +# overcloud_domain_name=redhat.local +# undercloud_service_certificate = /undercloud.pem +# hieradata_override = /hiera_override.yaml +# container_images_file= /containers-prepare-parameter.yaml +# enabled_hardware_types = pxe_ipmitool,pxe_drac,fake_pxe,ipmi,redfish +# custom_env_files = /skip_rhel_release.yaml +# +# [ctlplane-subnet] +# local_subnet = ctlplane-subnet +# cidr = 192.168.24.0/24 +# dhcp_start = 192.168.24.5 +# dhcp_end = 192.168.24.55 +# gateway = 192.168.24.1 +# inspection_iprange = 192.168.24.100,192.168.24.120 +# +- name: Converge + hosts: all + gather_facts: false + tasks: + - name: detect deprecated parameters in undercloud conf + block: + - name: run validation check_undercloud_conf + include_role: + name: "check_undercloud_conf" + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Detect right error message + fail: + msg: "Test failed due to wrong error: {{ ansible_failed_result.msg }}" + when: + - not ansible_failed_result.msg | regex_search("^Hardware type\\(s\\) .* are not supported any more$") + + - name: Status message + debug: + msg: "Detected undercloud.conf configuration issue!" + + - name: End play + meta: end_play + + - name: Fail the test + fail: + msg: | + A configuration issue should have been detected but it wasn't.. diff --git a/roles/check_undercloud_conf/molecule/deprecated_drivers/molecule.yml b/roles/check_undercloud_conf/molecule/deprecated_drivers/molecule.yml new file mode 100644 index 000000000..28b449b6d --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_drivers/molecule.yml @@ -0,0 +1,52 @@ +--- +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 + - /etc/pki/rpm-gpg:/etc/pki/rpm-gpg + - /opt/yum.repos.d:/etc/yum.repos.d:rw + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + ulimits: &ulimit + - host + +provisioner: + name: ansible + options: + vvv: true + inventory: + hosts: + all: + hosts: + ubi8: + ansible_python_interpreter: /usr/bin/python3 + vars: + ansible_user: root + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - destroy + +verifier: + name: testinfra diff --git a/roles/check_undercloud_conf/molecule/deprecated_drivers/prepare.yml b/roles/check_undercloud_conf/molecule/deprecated_drivers/prepare.yml new file mode 100644 index 000000000..9df3264c7 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_drivers/prepare.yml @@ -0,0 +1,65 @@ +--- +# 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: false + tasks: + - name: Ensure we get needed facts + setup: + gather_subset: + - '!all' + - '!any' + - '!min' + - env + + - name: populate undercloud.conf + copy: + dest: "{{ ansible_env.HOME }}/undercloud.conf" + content: | + [DEFAULT] + local_interface = em0 + local_ip = 192.168.24.1/24 + undercloud_public_host = 192.168.24.2 + undercloud_admin_host = 192.168.24.3 + undercloud_nameservers = 172.16.0.1,10.0.0.1 + undercloud_ntp_servers=clock1.rdu2.redhat.com + overcloud_domain_name=redhat.local + undercloud_service_certificate = /undercloud.pem + hieradata_override = /hiera_override.yaml + container_images_file= /containers-prepare-parameter.yaml + enabled_hardware_types = pxe_ipmitool,pxe_drac,fake_pxe,ipmi,redfish + custom_env_files = /skip_rhel_release.yaml + + [ctlplane-subnet] + local_subnet = ctlplane-subnet + cidr = 192.168.24.0/24 + dhcp_start = 192.168.24.5 + dhcp_end = 192.168.24.55 + gateway = 192.168.24.1 + inspection_iprange = 192.168.24.100,192.168.24.120 + + - name: create files with random content + copy: + dest: "/{{ item }}" + content: | + I'm the file {{ item }} + loop: + - 'undercloud.pem' + - 'hiera_override.yaml' + - 'containers-prepare-parameter.yaml' + - 'skip_rhel_release.yaml' diff --git a/roles/check_undercloud_conf/molecule/deprecated_params/Dockerfile b/roles/check_undercloud_conf/molecule/deprecated_params/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_params/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_undercloud_conf/molecule/deprecated_params/converge.yml b/roles/check_undercloud_conf/molecule/deprecated_params/converge.yml new file mode 100644 index 000000000..8e7583b35 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_params/converge.yml @@ -0,0 +1,61 @@ +--- +# 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. + +# Validate that the validation fails when undercloud.conf contains +# deprecated parameters: +# +# +# [DEFAULT] +# container_images_file= /containers-prepare-parameter.yaml +# enabled_drivers = ipxe +# masquerade_network=192.168.24.0/24 +# ipxe_enabled = true +# docker_insecure_registries = 'docker.io' +# custom_env_files = /skip_rhel_release.yaml +# network_cidr = 192.168.24.0/24 +# network_gateway =192.168.24.1 +# +- name: Converge + hosts: all + gather_facts: false + tasks: + - name: detect deprecated parameters in undercloud conf + block: + - name: run validation check_undercloud_conf + include_role: + name: "check_undercloud_conf" + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Detect right error message + fail: + msg: "Test failed due to wrong error: {{ ansible_failed_result.msg }}" + when: + - not ansible_failed_result.msg | + regex_search("^Parameters .* are deprecated for .*$") + + - name: Status message + debug: + msg: "Detected undercloud.conf configuration issue!" + + - name: End play + meta: end_play + + - name: Fail the test + fail: + msg: | + A configuration issue should have been detected but it wasn't.. diff --git a/roles/check_undercloud_conf/molecule/deprecated_params/molecule.yml b/roles/check_undercloud_conf/molecule/deprecated_params/molecule.yml new file mode 100644 index 000000000..28b449b6d --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_params/molecule.yml @@ -0,0 +1,52 @@ +--- +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 + - /etc/pki/rpm-gpg:/etc/pki/rpm-gpg + - /opt/yum.repos.d:/etc/yum.repos.d:rw + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + ulimits: &ulimit + - host + +provisioner: + name: ansible + options: + vvv: true + inventory: + hosts: + all: + hosts: + ubi8: + ansible_python_interpreter: /usr/bin/python3 + vars: + ansible_user: root + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - destroy + +verifier: + name: testinfra diff --git a/roles/check_undercloud_conf/molecule/deprecated_params/prepare.yml b/roles/check_undercloud_conf/molecule/deprecated_params/prepare.yml new file mode 100644 index 000000000..fdaca9a1c --- /dev/null +++ b/roles/check_undercloud_conf/molecule/deprecated_params/prepare.yml @@ -0,0 +1,51 @@ +--- +# 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: false + tasks: + - name: Ensure we get needed facts + setup: + gather_subset: + - '!all' + - '!any' + - '!min' + - env + + - name: populate undercloud.conf + copy: + dest: "{{ ansible_env.HOME }}/undercloud.conf" + content: | + [DEFAULT] + container_images_file= /containers-prepare-parameter.yaml + enabled_drivers = ipxe + masquerade_network=192.168.24.0/24 + ipxe_enabled = true + docker_insecure_registries = 'docker.io' + custom_env_files = /skip_rhel_release.yaml + network_cidr = 192.168.24.0/24 + network_gateway =192.168.24.1 + + - name: create files with random content + copy: + dest: "/{{ item }}" + content: | + I'm the file {{ item }} + loop: + - 'containers-prepare-parameter.yaml' + - 'skip_rhel_release.yaml' diff --git a/roles/check_undercloud_conf/molecule/required_missing/Dockerfile b/roles/check_undercloud_conf/molecule/required_missing/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/required_missing/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_undercloud_conf/molecule/required_missing/converge.yml b/roles/check_undercloud_conf/molecule/required_missing/converge.yml new file mode 100644 index 000000000..a350d7ccd --- /dev/null +++ b/roles/check_undercloud_conf/molecule/required_missing/converge.yml @@ -0,0 +1,71 @@ +--- +# 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. + +# Validate that the validation fails when the undercloud.conf does not contain +# a required parameter. In this case, container_images_file: +# +# [DEFAULT] +# local_interface = em0 +# local_ip = 192.168.24.1/24 +# undercloud_public_host = 192.168.24.2 +# undercloud_admin_host = 192.168.24.3 +# undercloud_nameservers = 172.16.0.1,10.0.0.1 +# undercloud_ntp_servers=clock1.rdu2.redhat.com +# overcloud_domain_name=redhat.local +# undercloud_service_certificate = /undercloud.pem +# hieradata_override = /hiera_override.yaml +# enabled_hardware_types = ipmi,redfish +# custom_env_files = /skip_rhel_release.yaml +# +# [ctlplane-subnet] +# local_subnet = ctlplane-subnet +# cidr = 192.168.24.0/24 +# dhcp_start = 192.168.24.5 +# dhcp_end = 192.168.24.55 +# gateway = 192.168.24.1 +# inspection_iprange = 192.168.24.100,192.168.24.120 +# +- name: Converge + hosts: all + gather_facts: false + tasks: + - name: detect missing required parameter from conf + block: + - name: run validation check_undercloud_conf + include_role: + name: "check_undercloud_conf" + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Detect right error message + fail: + msg: "Test failed due to wrong error: {{ ansible_failed_result.results.0.msg }}" + when: + - not ansible_failed_result.results.0.msg | + regex_search("^Property .* is required in .*$") + + - name: Status message + debug: + msg: "Detected undercloud.conf configuration issue!" + + - name: End play + meta: end_play + + - name: Fail the test + fail: + msg: | + A configuration issue should have been detected but it wasn't.. diff --git a/roles/check_undercloud_conf/molecule/required_missing/molecule.yml b/roles/check_undercloud_conf/molecule/required_missing/molecule.yml new file mode 100644 index 000000000..28b449b6d --- /dev/null +++ b/roles/check_undercloud_conf/molecule/required_missing/molecule.yml @@ -0,0 +1,52 @@ +--- +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 + - /etc/pki/rpm-gpg:/etc/pki/rpm-gpg + - /opt/yum.repos.d:/etc/yum.repos.d:rw + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + ulimits: &ulimit + - host + +provisioner: + name: ansible + options: + vvv: true + inventory: + hosts: + all: + hosts: + ubi8: + ansible_python_interpreter: /usr/bin/python3 + vars: + ansible_user: root + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - destroy + +verifier: + name: testinfra diff --git a/roles/check_undercloud_conf/molecule/required_missing/prepare.yml b/roles/check_undercloud_conf/molecule/required_missing/prepare.yml new file mode 100644 index 000000000..54951b878 --- /dev/null +++ b/roles/check_undercloud_conf/molecule/required_missing/prepare.yml @@ -0,0 +1,63 @@ +--- +# 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: false + tasks: + - name: Ensure we get needed facts + setup: + gather_subset: + - '!all' + - '!any' + - '!min' + - env + + - name: populate undercloud.conf + copy: + dest: "{{ ansible_env.HOME }}/undercloud.conf" + content: | + [DEFAULT] + local_interface = em0 + local_ip = 192.168.24.1/24 + undercloud_public_host = 192.168.24.2 + undercloud_admin_host = 192.168.24.3 + undercloud_nameservers = 172.16.0.1,10.0.0.1 + undercloud_ntp_servers=clock1.rdu2.redhat.com + overcloud_domain_name=redhat.local + undercloud_service_certificate = /undercloud.pem + hieradata_override = /hiera_override.yaml + enabled_hardware_types = ipmi,redfish + custom_env_files = /skip_rhel_release.yaml + + [ctlplane-subnet] + local_subnet = ctlplane-subnet + cidr = 192.168.24.0/24 + dhcp_start = 192.168.24.5 + dhcp_end = 192.168.24.55 + gateway = 192.168.24.1 + inspection_iprange = 192.168.24.100,192.168.24.120 + + - name: create files with random content + copy: + dest: "/{{ item }}" + content: | + I'm the file {{ item }} + loop: + - 'undercloud.pem' + - 'hiera_override.yaml' + - 'skip_rhel_release.yaml' diff --git a/roles/check_undercloud_conf/tasks/check_syntax.yml b/roles/check_undercloud_conf/tasks/check_syntax.yml new file mode 100644 index 000000000..cd422ad57 --- /dev/null +++ b/roles/check_undercloud_conf/tasks/check_syntax.yml @@ -0,0 +1,46 @@ +--- +- name: Verify required properties + lineinfile: + name: "{{ ansible_env.HOME }}/undercloud.conf" + regexp: "^{{ item }}\\s*=.*$" + state: absent + check_mode: true + register: uc_conf + loop: "{{ required_params }}" + +- name: "Fail if parameter not present in {{ ansible_env.HOME }}/undercloud.conf" + fail: + msg: >- + Property {{ item.item }} is required in + {{ ansible_env.HOME }}/undercloud.conf + failed_when: not item.changed + loop: "{{ uc_conf.results }}" + +- name: Check deprecated parameters + vars: + common_deprecated: "{{ uc_conf_props | intersect(deprecated_params) }}" + fail: + msg: >- + Parameters {{ common_deprecated | join(', ') }} are deprecated for + {{ ansible_env.HOME }}/undercloud.conf + when: + - common_deprecated is defined + - common_deprecated|length > 0 + +- name: Get hw_types from conf file + validations_read_ini: + path: "{{ ansible_env.HOME }}/undercloud.conf" + section: DEFAULT + key: enabled_hardware_types + register: hw_types + +- name: Check deprecated drivers + vars: + hw_types_common: "{{ hw_types.value.split(',')|intersect(unsupported_drivers) }}" + fail: + msg: >- + Hardware type(s) {{ hw_types_common | join(', ') }} + are not supported any more + when: + - "'enabled_hardware_types' in uc_conf_props" + - hw_types_common|length > 0 diff --git a/roles/check_undercloud_conf/tasks/main.yml b/roles/check_undercloud_conf/tasks/main.yml new file mode 100644 index 000000000..e627f8bcb --- /dev/null +++ b/roles/check_undercloud_conf/tasks/main.yml @@ -0,0 +1,69 @@ +--- +# 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: Ensure we get needed facts + setup: + gather_subset: + - '!all' + - '!any' + - '!min' + - env + +# "check_undercloud_conf" tasks +- name: "Retrieve {{ ansible_env.HOME }}/undercloud.conf content" + slurp: + src: "{{ ansible_env.HOME }}/undercloud.conf" + register: uc_conf_content + +- name: Store all properties and file type properties + # b64decode will return all lines delimited by \n character in a + # single string. Therefore, we can really use ^/$. + # Get the string ([a-zA-Z0-9_]) after each \n skipping whitespaces + # until the equals. + # For the file properties, store all properties which after the = + # matches a directory. Being the directory optionally started + # by . or ~, followed by / and anything else until getting to \n. + # Ex: container_images_file= /home/stack/containers-prepare-parameter.yaml + set_fact: + uc_conf_props: "{{ uc_conf_content['content'] | b64decode | + regex_findall('\\\n\\s*(\\w+)\\s*=[^\\\n]') }}" + uc_file_props: "{{ uc_conf_content['content'] | b64decode | + regex_findall('\\\n\\s*(\\w+)\\s*=\\s*[.~]*\\/[^\\\n]') }}" + +- name: Get value from conf file + validations_read_ini: + path: "{{ ansible_env.HOME }}/undercloud.conf" + section: DEFAULT + key: "{{ item }}" + register: conf_values + loop: "{{ uc_file_props }}" + +- name: Check file property point to existing file + stat: + path: "{{ item.value }}" + register: file_prop_stat + loop: "{{ conf_values.results }}" + +- name: fail if location doesn't exist + fail: + msg: >- + File configured in {{ ansible_env.HOME }}/undercloud.conf {{ item.item.item }} + does not exist + when: not item.stat.exists + loop: "{{ file_prop_stat.results }}" + +- include_tasks: check_syntax.yml diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 45cefcef9..a2ebffb71 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -6,6 +6,7 @@ - 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-check_undercloud_conf - tripleo-validations-centos-8-molecule-controller_token - tripleo-validations-centos-8-molecule-controller_ulimits - tripleo-validations-centos-8-molecule-ctlplane_ip_range @@ -26,6 +27,7 @@ - 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-check_undercloud_conf - tripleo-validations-centos-8-molecule-controller_token - tripleo-validations-centos-8-molecule-controller_ulimits - tripleo-validations-centos-8-molecule-ctlplane_ip_range @@ -329,3 +331,10 @@ parent: tripleo-validations-centos-8-base vars: tripleo_validations_role_name: overcloud_service_status +- job: + files: + - ^roles/check_undercloud_conf/.* + name: tripleo-validations-centos-8-molecule-check_undercloud_conf + parent: tripleo-validations-centos-8-base + vars: + tripleo_validations_role_name: check_undercloud_conf