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)
This commit is contained in:
Jose Luis Franco Arza 2020-11-03 15:05:53 +01:00 committed by Sergii Golovatiuk
parent 1a737336c5
commit 5df68a43f0
26 changed files with 1212 additions and 0 deletions

View File

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

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

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

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

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"

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

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'

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

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

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

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

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

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

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

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'

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

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

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

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'

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

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

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

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'

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

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

View File

@ -6,6 +6,7 @@
- tripleo-validations-centos-8-molecule-ceph - tripleo-validations-centos-8-molecule-ceph
- tripleo-validations-centos-8-molecule-check_network_gateway - tripleo-validations-centos-8-molecule-check_network_gateway
- tripleo-validations-centos-8-molecule-check_rhsm_version - 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_token
- tripleo-validations-centos-8-molecule-controller_ulimits - tripleo-validations-centos-8-molecule-controller_ulimits
- tripleo-validations-centos-8-molecule-ctlplane_ip_range - tripleo-validations-centos-8-molecule-ctlplane_ip_range
@ -25,6 +26,7 @@
- tripleo-validations-centos-8-molecule-ceph - tripleo-validations-centos-8-molecule-ceph
- tripleo-validations-centos-8-molecule-check_network_gateway - tripleo-validations-centos-8-molecule-check_network_gateway
- tripleo-validations-centos-8-molecule-check_rhsm_version - 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_token
- tripleo-validations-centos-8-molecule-controller_ulimits - tripleo-validations-centos-8-molecule-controller_ulimits
- tripleo-validations-centos-8-molecule-ctlplane_ip_range - tripleo-validations-centos-8-molecule-ctlplane_ip_range
@ -322,3 +324,10 @@
parent: tripleo-validations-centos-8-base parent: tripleo-validations-centos-8-base
vars: vars:
tripleo_validations_role_name: overcloud_service_status 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