Molecule testing for TripleO Strategy Plugins

For both tripleo_free and tripleo_linear, add molecule tests that will
execute a simple task (for now) and test the max_fail_percentage value
that is defined in the Ansible inventory.

We simulate a failure on one compute node, which shouldn't make the
playbook failing since we tolerate 50% of failure (we have 6 nodes and
one failure).

Change-Id: I97a0171f9e7ba08f020ac7cf224a9ff9f6a34d01
This commit is contained in:
Emilien Macchi 2020-05-29 17:25:21 -04:00
parent 87f9c93548
commit 54ea54c26b
8 changed files with 211 additions and 0 deletions

View File

@ -2,6 +2,7 @@ export TRIPLEO_ANSIBLE_WORKPATH="$(dirname $(readlink -f ${BASH_SOURCE[0]}))"
export ANSIBLE_STDOUT_CALLBACK=debug
export ANSIBLE_ACTION_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/roles.galaxy/config_template/action:${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/action"
export ANSIBLE_CALLBACK_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/callback"
export ANSIBLE_STRATEGY_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/strategy"
export ANSIBLE_FILTER_PLUGINS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/filter"
export ANSIBLE_LIBRARY="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/roles.galaxy/config_template/library:${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/modules"
export ANSIBLE_MODULE_UTILS="${TRIPLEO_ANSIBLE_WORKPATH}/tripleo_ansible/ansible_plugins/module_utils"

View File

@ -0,0 +1 @@
../../../../../ansible-test-env.rc

View File

@ -0,0 +1,59 @@
---
# 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: Run strategy tests
hosts: localhost
connection: local
gather_facts: false
environment:
ANSIBLE_ROLES_PATH: "${ANSIBLE_ROLES_PATH:-/usr/share/ansible/roles}:${HOME}/zuul-jobs/roles"
ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}"
ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-/usr/share/ansible/plugins/filter}"
ANSIBLE_STRATEGY_PLUGINS: "${ANSIBLE_STRATEGY_PLUGINS:-/usr/share/ansible/plugins/strategy}"
tasks:
- name: Run TripleO linear success
shell: |-
. {{ playbook_dir }}/ansible-test-env.rc
ansible-playbook {{ playbook_dir }}/tripleo-linear.yml -i {{ playbook_dir }}/inventory-success | grep "second"
args:
executable: /bin/bash
register: linear_success
- name: Run TripleO linear fail
shell: |-
. {{ playbook_dir }}/ansible-test-env.rc
ansible-playbook {{ playbook_dir }}/tripleo-linear.yml -i {{ playbook_dir }}/inventory-fail | grep "second"
args:
executable: /bin/bash
register: linear_fail
failed_when: linear_fail.rc == 0
- name: Run TripleO free success
shell: |-
. {{ playbook_dir }}/ansible-test-env.rc
ansible-playbook {{ playbook_dir }}/tripleo-free.yml -i {{ playbook_dir }}/inventory-success | grep "second"
args:
executable: /bin/bash
register: free_success
- name: Run TripleO free fail
shell: |-
. {{ playbook_dir }}/ansible-test-env.rc
ansible-playbook {{ playbook_dir }}/tripleo-free.yml -i {{ playbook_dir }}/inventory-fail | grep "second"
args:
executable: /bin/bash
register: free_fail
failed_when: free_fail.rc == 0

View File

@ -0,0 +1,16 @@
[Controller]
instance1 ansible_connection=local
instance2 ansible_connection=local
instance3 ansible_connection=local
[Compute]
instance4 ansible_connection=local
instance5 ansible_connection=local
[Controller:vars]
max_fail_percentage=0
tripleo_role_name=Controller
[Compute:vars]
max_fail_percentage=10
tripleo_role_name=Compute

View File

@ -0,0 +1,16 @@
[Controller]
instance1 ansible_connection=local
instance2 ansible_connection=local
instance3 ansible_connection=local
[Compute]
instance4 ansible_connection=local
instance5 ansible_connection=local
[Controller:vars]
max_fail_percentage=0
tripleo_role_name=Controller
[Compute:vars]
max_fail_percentage=100
tripleo_role_name=Compute

View File

@ -0,0 +1,38 @@
---
driver:
name: delegated
options:
managed: false
login_cmd_template: >-
ssh
-o UserKnownHostsFile=/dev/null
-o StrictHostKeyChecking=no
-o Compression=no
-o TCPKeepAlive=yes
-o VerifyHostKeyDNS=no
-o ForwardX11=no
-o ForwardAgent=no
{instance}
ansible_connection_options:
ansible_connection: ssh
log: true
platforms:
- name: instance1
provisioner:
name: ansible
config_options:
defaults:
fact_caching: jsonfile
fact_caching_connection: /tmp/molecule/facts
log: true
scenario:
test_sequence:
- converge
- verify
verifier:
name: testinfra

View File

@ -0,0 +1,40 @@
---
# 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: Run a first play with tests for the tripleo_linear strategy
hosts: all
any_errors_fatal: true
gather_facts: false
strategy: tripleo_free
tasks:
- name: Run a task that will fail on one host
debug:
msg: "Task running with tripleo_linear strategy with max_fail_percentage set to {{ max_fail_percentage|default('undefined') }}"
failed_when:
- ansible_host in ['instance5']
- name: Run a task after a potential failure on a node
debug:
msg: "Task running on {{ ansible_host }} after a potential failure"
- name: Run a second play with tests for the tripleo_linear strategy
hosts: all
any_errors_fatal: true
gather_facts: false
strategy: tripleo_free
tasks:
- name: Run a task on a node
debug:
msg: "Task running on {{ ansible_host }}"

View File

@ -0,0 +1,40 @@
---
# 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: Run a first play with tests for the tripleo_linear strategy
hosts: all
any_errors_fatal: true
gather_facts: false
strategy: tripleo_linear
tasks:
- name: Run a task that will fail on one host
debug:
msg: "Task running with tripleo_linear strategy with max_fail_percentage set to {{ max_fail_percentage|default('undefined') }}"
failed_when:
- ansible_host in ['instance5']
- name: Run a task after a potential failure on a node
debug:
msg: "Task running on {{ ansible_host }} after a potential failure"
- name: Run a second play with tests for the tripleo_linear strategy
hosts: all
any_errors_fatal: true
gather_facts: false
strategy: tripleo_linear
tasks:
- name: Run a task on a node
debug:
msg: "Task running on {{ ansible_host }}"