Browse Source

Add validation to verify undercloud.conf content.

This validation checks the correctness of the undercloud.conf
file. The checks run as part of the verification are:
 - All parameters assigned to a file path point to an existing
   file location in the system.
 - No deprecated parameters are included in undercloud.conf
 - All required parameters are present in undercloud.conf
 - No deprecated hw types are included in the enabled_hw_types
   parameters.

Change-Id: Ic543e21c4aa60b05991f0c4866a6408b924304fd
(cherry picked from commit 99fdf8ae6a)
(cherry picked from commit 6b181d8905)
(cherry picked from commit e5df5b3681)
changes/68/775668/6
Jose Luis Franco Arza 6 months ago
committed by Sergii Golovatiuk
parent
commit
5df68a43f0
26 changed files with 1212 additions and 0 deletions
  1. +6
    -0
      doc/source/roles/role-check_undercloud_conf.rst
  2. +15
    -0
      playbooks/check-undercloud-conf.yaml
  3. +41
    -0
      roles/check_undercloud_conf/defaults/main.yml
  4. +37
    -0
      roles/check_undercloud_conf/molecule/config_OK/Dockerfile
  5. +45
    -0
      roles/check_undercloud_conf/molecule/config_OK/converge.yml
  6. +52
    -0
      roles/check_undercloud_conf/molecule/config_OK/molecule.yml
  7. +65
    -0
      roles/check_undercloud_conf/molecule/config_OK/prepare.yml
  8. +37
    -0
      roles/check_undercloud_conf/molecule/default/Dockerfile
  9. +55
    -0
      roles/check_undercloud_conf/molecule/default/converge.yml
  10. +52
    -0
      roles/check_undercloud_conf/molecule/default/molecule.yml
  11. +34
    -0
      roles/check_undercloud_conf/molecule/default/prepare.yml
  12. +37
    -0
      roles/check_undercloud_conf/molecule/deprecated_drivers/Dockerfile
  13. +71
    -0
      roles/check_undercloud_conf/molecule/deprecated_drivers/converge.yml
  14. +52
    -0
      roles/check_undercloud_conf/molecule/deprecated_drivers/molecule.yml
  15. +65
    -0
      roles/check_undercloud_conf/molecule/deprecated_drivers/prepare.yml
  16. +37
    -0
      roles/check_undercloud_conf/molecule/deprecated_params/Dockerfile
  17. +61
    -0
      roles/check_undercloud_conf/molecule/deprecated_params/converge.yml
  18. +52
    -0
      roles/check_undercloud_conf/molecule/deprecated_params/molecule.yml
  19. +51
    -0
      roles/check_undercloud_conf/molecule/deprecated_params/prepare.yml
  20. +37
    -0
      roles/check_undercloud_conf/molecule/required_missing/Dockerfile
  21. +71
    -0
      roles/check_undercloud_conf/molecule/required_missing/converge.yml
  22. +52
    -0
      roles/check_undercloud_conf/molecule/required_missing/molecule.yml
  23. +63
    -0
      roles/check_undercloud_conf/molecule/required_missing/prepare.yml
  24. +46
    -0
      roles/check_undercloud_conf/tasks/check_syntax.yml
  25. +69
    -0
      roles/check_undercloud_conf/tasks/main.yml
  26. +9
    -0
      zuul.d/molecule.yaml

+ 6
- 0
doc/source/roles/role-check_undercloud_conf.rst View File

@ -0,0 +1,6 @@
============================
Role - check_undercloud_conf
============================
.. ansibleautoplugin::
:role: roles/check_undercloud_conf

+ 15
- 0
playbooks/check-undercloud-conf.yaml View File

@ -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

+ 41
- 0
roles/check_undercloud_conf/defaults/main.yml View File

@ -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

+ 37
- 0
roles/check_undercloud_conf/molecule/config_OK/Dockerfile View File

@ -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"]

+ 45
- 0
roles/check_undercloud_conf/molecule/config_OK/converge.yml View File

@ -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"

+ 52
- 0
roles/check_undercloud_conf/molecule/config_OK/molecule.yml View File

@ -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

+ 65
- 0
roles/check_undercloud_conf/molecule/config_OK/prepare.yml View File

@ -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'

+ 37
- 0
roles/check_undercloud_conf/molecule/default/Dockerfile View File

@ -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"]

+ 55
- 0
roles/check_undercloud_conf/molecule/default/converge.yml View File

@ -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..

+ 52
- 0
roles/check_undercloud_conf/molecule/default/molecule.yml View File

@ -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

+ 34
- 0
roles/check_undercloud_conf/molecule/default/prepare.yml View File

@ -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

+ 37
- 0
roles/check_undercloud_conf/molecule/deprecated_drivers/Dockerfile View File

@ -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"]

+ 71
- 0
roles/check_undercloud_conf/molecule/deprecated_drivers/converge.yml View File

@ -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..

+ 52
- 0
roles/check_undercloud_conf/molecule/deprecated_drivers/molecule.yml View File

@ -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

+ 65
- 0
roles/check_undercloud_conf/molecule/deprecated_drivers/prepare.yml View File

@ -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'

+ 37
- 0
roles/check_undercloud_conf/molecule/deprecated_params/Dockerfile View File

@ -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"]

+ 61
- 0
roles/check_undercloud_conf/molecule/deprecated_params/converge.yml View File

@ -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..

+ 52
- 0
roles/check_undercloud_conf/molecule/deprecated_params/molecule.yml View File

@ -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

+ 51
- 0
roles/check_undercloud_conf/molecule/deprecated_params/prepare.yml View File

@ -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'

+ 37
- 0
roles/check_undercloud_conf/molecule/required_missing/Dockerfile View File

@ -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"]

+ 71
- 0
roles/check_undercloud_conf/molecule/required_missing/converge.yml View File

@ -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..

+ 52
- 0
roles/check_undercloud_conf/molecule/required_missing/molecule.yml View File

@ -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

+ 63
- 0
roles/check_undercloud_conf/molecule/required_missing/prepare.yml View File

@ -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'

+ 46
- 0
roles/check_undercloud_conf/tasks/check_syntax.yml View File

@ -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

+ 69
- 0
roles/check_undercloud_conf/tasks/main.yml View File

@ -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

+ 9
- 0
zuul.d/molecule.yaml View File

@ -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
@ -25,6 +26,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
@ -322,3 +324,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

Loading…
Cancel
Save