Adds molecule tests for the nova-status validation

Change-Id: Iee2f85b05ab6f36dfae8844c44f436ea3ac69274
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
(cherry picked from commit b0ee177f0a)
This commit is contained in:
Gael Chamoulaud 2019-08-03 15:04:58 +02:00
parent 95fbe0b62d
commit a522405617
6 changed files with 224 additions and 1 deletions

View File

@ -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 python 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,47 @@
---
driver:
name: docker
log: true
platforms:
- name: centos7
hostname: centos7
image: centos:7
pkg_extras: python-setuptools python-enum34
easy_install:
- pip
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
- name: fedora28
hostname: fedora28
image: fedora:28
pkg_extras: python*-setuptools python*-enum
environment:
<<: *env
provisioner:
name: ansible
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
ANSIBLE_LIBRARY: "../../../../library"
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy
lint:
enabled: false
verifier:
name: testinfra
lint:
name: flake8

View File

@ -0,0 +1,50 @@
---
# 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: Converge
hosts: all
gather_facts: no
tasks:
- name: working detection
include_role:
name: nova-status
- name: make validation fail
block:
- name: run validation
include_role:
name: nova-status
vars:
container_cli: docker
rescue:
- name: Clear host errors
meta: clear_host_errors
- name: Test output
debug:
msg: The validation works! End play
- name: End play
meta: end_play
- name: Fail playbook if reached
fail:
msg: |
The nova-status validation didn't properly detect bad upgrade
status check!

View File

@ -0,0 +1,79 @@
---
# 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: no
tasks:
- name: Populate successful podman CLI
copy:
dest: /usr/bin/podman
mode: 0755
content: |
#!/bin/bash
action="$1"
shift
container="$3"
shift
command="$@"
case $container in
'heat_api_cron')
echo '# This is a comment that should be ignored'
echo '0 12 14 2 * heat-manage purge_deleted'
;;
'keystone_cron')
echo '# This is a comment that should be ignored'
echo '0 12 14 2 * keystone-manage token_flush'
;;
'nova_api')
exit 0
;;
*)
echo "Unknown container ${container}"
;;
esac
- name: Populate buggy docker CLI
copy:
dest: /usr/bin/docker
mode: 0755
content: |
#!/bin/bash
action="$1"
shift
container="$3"
shift
command="$@"
case $container in
'heat_api_cron')
echo '# This is a comment that should be ignored'
echo '0 12 14 2 * some-other command'
;;
'keystone_cron')
echo '# This is a comment that should be ignored'
echo '0 12 14 2 * some-other command'
;;
'nova_api')
exit 2
;;
*)
echo "Unknown container ${container}"
;;
esac

View File

@ -1,7 +1,8 @@
---
- name: Set container_cli fact from the inventory
set_fact:
container_cli: "{{ hostvars[inventory_hostname].container_cli }}"
container_cli: "{{ hostvars[inventory_hostname].container_cli | default('podman', true) }}"
when: container_cli is not defined
- name: Check nova upgrade status
become: true

View File

@ -15,6 +15,7 @@
- tripleo-validations-centos-7-molecule-undercloud-disk-space
- tripleo-validations-centos-7-molecule-xfs-check-ftype
- tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
- tripleo-validations-centos-7-molecule-nova-status
gate:
queue: integrated
jobs:
@ -30,6 +31,7 @@
- tripleo-validations-centos-7-molecule-undercloud-disk-space
- tripleo-validations-centos-7-molecule-xfs-check-ftype
- tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
- tripleo-validations-centos-7-molecule-nova-status
name: tripleo-validations-molecule-jobs
- job:
files:
@ -116,3 +118,10 @@
parent: tripleo-validations-centos-7-base
vars:
tripleo_validations_role_name: no-op-firewall-nova-driver
- job:
files:
- ^roles/nova-status/.*
name: tripleo-validations-centos-7-molecule-nova-status
parent: tripleo-validations-centos-7-base
vars:
tripleo_validations_role_name: nova-status