commit be28ef7187a83342877b20bda48911c7d52b4097 Author: Owen McGonagle Date: Sun Sep 27 18:34:34 2020 -0400 After leapp has been run, verify that the kernel has been upgraded. This is a new validation to verify the kernel has been upgraded by checking the kernel version (uname -r) and making sure "el8" appears in it. Instead of running 'uname -r' - this validation uses the "kernel" variable from ansible_facts - and checks to see if "el8" is contained in it. Change-Id: I3a3c98788a2dfff16412eecaff09f28f7cdef0a6 diff --git a/doc/source/roles/role-check_kernel_version.rst b/doc/source/roles/role-check_kernel_version.rst new file mode 100644 index 0000000..b95743a --- /dev/null +++ b/doc/source/roles/role-check_kernel_version.rst @@ -0,0 +1,6 @@ +=========================== +Role - check_kernel_version +=========================== + +.. ansibleautoplugin:: + :role: roles/check_kernel_version diff --git a/playbooks/check-kernel-version.yaml b/playbooks/check-kernel-version.yaml new file mode 100644 index 0000000..7b808be --- /dev/null +++ b/playbooks/check-kernel-version.yaml @@ -0,0 +1,13 @@ +--- +- hosts: all + gather_facts: true + vars: + metadata: + name: Verify the kernel version contains el8 in its name + description: > + This validation checks the kernel has been upgaded by checking + el8 is in kernel (uname -r) version string + groups: + - post-deployment + roles: + - check_kernel_version diff --git a/roles/check_kernel_version/defaults/main.yml b/roles/check_kernel_version/defaults/main.yml new file mode 100644 index 0000000..e1f54eb --- /dev/null +++ b/roles/check_kernel_version/defaults/main.yml @@ -0,0 +1,3 @@ +--- +check_kernel_version_fact: "{{ ansible_facts.kernel }}" +check_kernel_version_expected: "el8" diff --git a/roles/check_kernel_version/molecule/default/Dockerfile.j2 b/roles/check_kernel_version/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..e0534b4 --- /dev/null +++ b/roles/check_kernel_version/molecule/default/Dockerfile.j2 @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install sudo python*-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + + +CMD ["sh", "-c", "while true; do sleep 10000; done"] diff --git a/roles/check_kernel_version/molecule/default/converge.yml b/roles/check_kernel_version/molecule/default/converge.yml new file mode 100644 index 0000000..0c98b46 --- /dev/null +++ b/roles/check_kernel_version/molecule/default/converge.yml @@ -0,0 +1,47 @@ +--- +# Copyright 2020 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Converge + hosts: all + gather_facts: true + + tasks: + - name: validate correct kernel version + include_role: + name: "check_kernel_version" + + - name: detect wrong kernel version + block: + - name: run validation against wrong kernel version + include_role: + name: "check_kernel_version" + vars: + check_kernel_version_fact: "4.18.0-193.14.2.el7_2.x86_64" + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Status message + debug: + msg: "Detected kernel version mismatch!" + + - name: End play + meta: end_play + + - name: Fail the test + fail: + msg: | + The kernel version mismatch should have been detected but it wasn't. diff --git a/roles/check_kernel_version/molecule/default/molecule.yml b/roles/check_kernel_version/molecule/default/molecule.yml new file mode 100644 index 0000000..4d067a4 --- /dev/null +++ b/roles/check_kernel_version/molecule/default/molecule.yml @@ -0,0 +1,36 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos8 + hostname: centos8 + image: centos:8 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + environment: + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_LIBRARY: "../../../../library" + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +verifier: + name: testinfra diff --git a/roles/check_kernel_version/tasks/main.yml b/roles/check_kernel_version/tasks/main.yml new file mode 100644 index 0000000..8f7127e --- /dev/null +++ b/roles/check_kernel_version/tasks/main.yml @@ -0,0 +1,20 @@ +--- +# 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: Check kernel version + fail: + msg: '{{ check_kernel_version_expected }} does not match configured kernel_version {{ check_kernel_version_fact }}' + when: check_kernel_version_expected not in check_kernel_version_fact diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 9850aaf..d43d6b8 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -20,6 +20,7 @@ - tripleo-validations-centos-8-molecule-undercloud_debug - tripleo-validations-centos-8-molecule-undercloud_heat_purge_deleted - tripleo-validations-centos-8-molecule-undercloud_tokenflush + - tripleo-validations-centos-8-molecule-check_kernel_version gate: jobs: - tripleo-validations-centos-8-molecule-ceph @@ -42,6 +43,7 @@ - tripleo-validations-centos-8-molecule-undercloud_debug - tripleo-validations-centos-8-molecule-undercloud_heat_purge_deleted - tripleo-validations-centos-8-molecule-undercloud_tokenflush + - tripleo-validations-centos-8-molecule-check_kernel_version name: tripleo-validations-molecule-jobs - job: files: @@ -316,3 +318,10 @@ parent: tripleo-validations-centos-8-base vars: tripleo_validations_role_name: package_version +- job: + files: + - ^roles/check_kernel_version/.* + name: tripleo-validations-centos-8-molecule-check_kernel_version + parent: tripleo-validations-centos-8-base + vars: + tripleo_validations_role_name: check_kernel_version