Replace functional tests with molecule

As effort to sunset tests repo, we replace functional test that were
running for the role with a molecule.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/938220
Change-Id: I2c11008541775e035256489383aa9db31a098635
This commit is contained in:
Jonathan Rosser 2025-01-06 18:18:34 +00:00
parent 9ef744f2c4
commit 43942efb5d
13 changed files with 163 additions and 348 deletions

46
Vagrantfile vendored
View File

@ -1,46 +0,0 @@
# Note:
# This file is maintained in the openstack-ansible-tests repository.
# https://opendev.org/openstack/openstack-ansible-tests/src/Vagrantfile
#
# If you need to perform any change on it, you should modify the central file,
# then, an OpenStack CI job will propagate your changes to every OSA repository
# since every repo uses the same Vagrantfile
# Verify whether required plugins are installed.
required_plugins = [ "vagrant-disksize" ]
required_plugins.each do |plugin|
if not Vagrant.has_plugin?(plugin)
raise "The vagrant plugin #{plugin} is required. Please run `vagrant plugin install #{plugin}`"
end
end
Vagrant.configure(2) do |config|
config.vm.provider "virtualbox" do |v|
v.memory = 6144
v.cpus = 2
# https://github.com/hashicorp/vagrant/issues/9524
v.customize ["modifyvm", :id, "--audio", "none"]
end
config.vm.synced_folder ".", "/vagrant", type: "rsync"
config.vm.provision "shell",
privileged: false,
inline: <<-SHELL
cd /vagrant
./run_tests.sh
SHELL
config.vm.define "centos8" do |centos8|
centos8.vm.box = "centos/8"
end
config.vm.define "debian10" do |debian10|
debian10.vm.box = "debian/buster64"
end
config.vm.define "ubuntu2004" do |focal|
focal.disksize.size = "40GB"
focal.vm.box = "ubuntu/focal64"
end
end

View File

@ -1,33 +0,0 @@
export VIRTUAL_ENV=$(pwd)
export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_SSH_CONTROL_PATH=/tmp/%%h-%%r
# TODO (odyssey4me) These are only here as they are non-standard folder
# names for Ansible 1.9.x. We are using the standard folder names for
# Ansible v2.x. We can remove this when we move to Ansible 2.x.
export ANSIBLE_ACTION_PLUGINS=${HOME}/.ansible/plugins/action
export ANSIBLE_CALLBACK_PLUGINS=${HOME}/.ansible/plugins/callback
export ANSIBLE_FILTER_PLUGINS=${HOME}/.ansible/plugins/filter
export ANSIBLE_LOOKUP_PLUGINS=${HOME}/.ansible/plugins/lookup
# This is required as the default is the current path or a path specified
# in ansible.cfg
export ANSIBLE_LIBRARY=${HOME}/.ansible/plugins/library
# This is required as the default is '/etc/ansible/roles' or a path
# specified in ansible.cfg
export ANSIBLE_ROLES_PATH=${HOME}/.ansible/roles:$(pwd)/..
export ANSIBLE_SSH_ARGS="-o ControlMaster=no \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-o ServerAliveInterval=64 \
-o ServerAliveCountMax=1024 \
-o Compression=no \
-o TCPKeepAlive=yes \
-o VerifyHostKeyDNS=no \
-o ForwardX11=no \
-o ForwardAgent=yes"
echo "Run manual functional tests by executing the following:"
echo "# ./.tox/functional/bin/ansible-playbook -i tests/inventory tests/test.yml"

View File

@ -0,0 +1,34 @@
---
dependency:
name: galaxy
options:
requirements-file: requirements.yml
force: true
driver:
name: docker
platforms:
- name: "config-template-${MOLECULE_SCENARIO_NAME}"
image: "${DOCKER_REGISTRY:-quay.io/gotmax23}/${DOCKER_IMAGE_TAG:-debian-systemd:bookworm}"
command: ${DOCKER_COMMAND:-""}
pre_build_image: true
privileged: true
systemd: true
groups:
- config_template
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ../../tests/test.yml
config_options:
defaults:
inject_facts_as_vars: false
options:
diff: True
scenario:
name: default

2
requirements.yml Normal file
View File

@ -0,0 +1,2 @@
collections:
- name: community.general

View File

@ -1,88 +0,0 @@
#!/usr/bin/env bash
# Copyright 2015, Rackspace US, Inc.
#
# 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.
# PURPOSE:
# This script clones the openstack-ansible-tests repository to the
# tests/common folder in order to be able to re-use test components
# for role testing. This is intended to be the thinnest possible
# shim for test execution outside of OpenStack CI.
# WARNING:
# This file is maintained in the openstack-ansible-tests repository.
# https://opendev.org/openstack/openstack-ansible-tests/src/run_tests.sh
# If you need to modify this file, update the one in the openstack-ansible-tests
# repository and then update this file as well. The purpose of this file is to
# prepare the host and then execute all the tox tests.
#
## Shell Opts ----------------------------------------------------------------
set -xeu
## Vars ----------------------------------------------------------------------
WORKING_DIR="$(readlink -f $(dirname $0))"
OSA_PROJECT_NAME="$(sed -n 's|^project=openstack/\(.*\).git$|\1|p' $(pwd)/.gitreview)"
COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
TESTING_HOME=${TESTING_HOME:-$HOME}
ZUUL_TESTS_CLONE_LOCATION="/home/zuul/src/opendev.org/openstack/openstack-ansible-tests"
# Use .gitreview as the key to determine the appropriate
# branch to clone for tests.
TESTING_BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' "${WORKING_DIR}/.gitreview")
if [[ "${TESTING_BRANCH}" == "" ]]; then
TESTING_BRANCH="master"
fi
## Main ----------------------------------------------------------------------
# Source distribution information
source /etc/os-release || source /usr/lib/os-release
# Figure out the appropriate package install command
case ${ID,,} in
centos|rhel|fedora|rocky) pkg_mgr_cmd="dnf install -y" ;;
ubuntu|debian) pkg_mgr_cmd="apt-get install -y" ;;
*) echo "unsupported distribution: ${ID,,}"; exit 1 ;;
esac
# Install git so that we can clone the tests repo if git is not available
which git &>/dev/null || eval sudo "${pkg_mgr_cmd}" git
# Clone the tests repo for access to the common test script
if [[ ! -d "${COMMON_TESTS_PATH}" ]]; then
# The tests repo doesn't need a clone, we can just
# symlink it.
if [[ "${OSA_PROJECT_NAME}" == "openstack-ansible-tests" ]]; then
ln -s "${WORKING_DIR}" "${COMMON_TESTS_PATH}"
# In zuul v3 any dependent repository is placed into
# /home/zuul/src/opendev.org, so we check to see
# if there is a tests checkout there already. If so, we
# symlink that and use it.
elif [[ -d "${ZUUL_TESTS_CLONE_LOCATION}" ]]; then
ln -s "${ZUUL_TESTS_CLONE_LOCATION}" "${COMMON_TESTS_PATH}"
# Otherwise we're clearly not in zuul or using a previously setup
# repo in some way, so just clone it from upstream.
else
git clone -b "${TESTING_BRANCH}" \
https://opendev.org/openstack/openstack-ansible-tests \
"${COMMON_TESTS_PATH}"
fi
fi
# Execute the common test script
source tests/common/run_tests_common.sh

View File

@ -1,29 +0,0 @@
---
- name: apt_package_pinning
src: https://opendev.org/openstack/openstack-ansible-apt_package_pinning
scm: git
version: master
- name: pip_install
src: https://opendev.org/openstack/openstack-ansible-pip_install
scm: git
version: master
- name: openstack_hosts
src: https://opendev.org/openstack/openstack-ansible-openstack_hosts
scm: git
version: master
- name: lxc_hosts
src: https://opendev.org/openstack/openstack-ansible-lxc_hosts
scm: git
version: master
- name: lxc_container_create
src: https://opendev.org/openstack/openstack-ansible-lxc_container_create
scm: git
version: master
- name: openstack_openrc
src: https://opendev.org/openstack/openstack-ansible-openstack_openrc
scm: git
version: master
- name: pki
src: https://opendev.org/openstack/ansible-role-pki
scm: git
version: master

View File

@ -1,9 +0,0 @@
[all]
localhost
container1
[hosts]
localhost
[all_containers]
container1

View File

@ -22,21 +22,30 @@
dest: "/tmp/test.ini"
config_overrides: "{{ test_config_ini_overrides }}"
config_type: "ini"
# NOTE(jrosser) the input template has an empty [bar] section which is removed in the output, failing idempotency
diff: false
- name: Read test.ini
slurp:
src: /tmp/test.ini
register: ini_file
- name: Set content fact
set_fact:
_ini_file: "{{ ini_file.content | b64decode | community.general.from_ini }}"
- debug:
msg: "ini - {{ ini_file.content | b64decode }}"
msg: "ini - {{ _ini_file }}"
- name: Validate output
assert:
that:
- "(lookup('ini', 'new_key section=DEFAULT file=/tmp/test.ini')) == 'new_value'"
- "(lookup('ini', 'baz section=foo file=/tmp/test.ini')) == 'bar'"
- _ini_file['DEFAULT'] is defined
- _ini_file['DEFAULT']['new_key'] is defined
- _ini_file['DEFAULT']['new_key'] == 'new_value'
- _ini_file['foo'] is defined
- _ini_file['foo']['baz'] is defined
- _ini_file['foo']['baz'] == 'bar'
# Test basic function of config_template with content instead of src
- name: Template test INI template
@ -45,21 +54,30 @@
dest: "/tmp/test_with_content.ini"
config_overrides: "{{ test_config_ini_overrides }}"
config_type: "ini"
# NOTE(jrosser) the input template has an empty [bar] section which is removed in the output, failing idempotency
diff: false
- name: Read test.ini
- name: Read test_with_content.ini
slurp:
src: /tmp/test_with_content.ini
register: ini_file_with_content
- name: Set content fact
set_fact:
_ini_file_with_content: "{{ ini_file_with_content.content | b64decode | community.general.from_ini }}"
- debug:
msg: "ini - {{ ini_file_with_content.content | b64decode }}"
msg: "ini_file_with_content - {{ _ini_file_with_content }}"
- name: Validate output
assert:
that:
- "(lookup('ini', 'new_key section=DEFAULT file=/tmp/test_with_content.ini')) == 'new_value'"
- "(lookup('ini', 'baz section=foo file=/tmp/test_with_content.ini')) == 'bar'"
- _ini_file['DEFAULT'] is defined
- _ini_file['DEFAULT']['new_key'] is defined
- _ini_file['DEFAULT']['new_key'] == 'new_value'
- _ini_file['foo'] is defined
- _ini_file['foo']['baz'] is defined
- _ini_file['foo']['baz'] == 'bar'
# Test multistropt ordering
- name: Template MultiStrOpts using overrides
@ -258,32 +276,35 @@
that:
- _test_default_section_file == _test_default_section_expected_file
- name: Block for tasks which cannot be idempotent
tags:
- molecule-idempotence-notest
block:
# Check output diff
- name: Write ini for testing diff output
config_template:
src: "{{ playbook_dir }}/templates/test_diff.ini"
dest: "/tmp/test_diff.ini"
config_type: "ini"
config_overrides: {}
# Check output diff
- name: Write ini for testing diff output
config_template:
src: "{{ playbook_dir }}/templates/test_diff.ini"
dest: "/tmp/test_diff.ini"
config_type: "ini"
config_overrides: {}
- name: Test ini with additions and changed
config_template:
src: "{{ playbook_dir }}/templates/test_diff.ini"
dest: "/tmp/test_diff.ini"
config_type: "ini"
config_overrides: "{{ test_diff_overrides }}"
register: test_diff_ini
notify: test_diff_ini check diff
- name: Test ini with additions and changed
config_template:
src: "{{ playbook_dir }}/templates/test_diff.ini"
dest: "/tmp/test_diff.ini"
config_type: "ini"
config_overrides: "{{ test_diff_overrides }}"
register: test_diff_ini
notify: test_diff_ini check diff
- name: Test ini with removes
config_template:
src: "{{ playbook_dir }}/templates/test_diff_remove.ini"
dest: "/tmp/test_diff.ini"
config_type: "ini"
config_overrides: "{{ test_diff_overrides }}"
register: test_diff_remove_ini
notify: test_diff_remove_ini check diff
- name: Test ini with removes
config_template:
src: "{{ playbook_dir }}/templates/test_diff_remove.ini"
dest: "/tmp/test_diff.ini"
config_type: "ini"
config_overrides: "{{ test_diff_overrides }}"
register: test_diff_remove_ini
notify: test_diff_remove_ini check diff
# Check if {% raw %} is working
- name: Test template with jinja vars in it
@ -292,6 +313,8 @@
dest: "/tmp/test_raw_content.ini"
config_overrides: "{{ test_raw_content_overrides }}"
config_type: ini
# NOTE(jrosser) diff true will try to evaluate {{ baz }} when the connection type is not local
diff: false
- name: Test content with jinja vars in it
config_template:
@ -306,6 +329,8 @@
dest: "/tmp/test_raw_usr_content.ini"
config_overrides: "{{ test_raw_content_overrides }}"
config_type: ini
# NOTE(jrosser) diff true will try to evaluate {{ baz }} when the connection type is not local
diff: false
- name: Read test_raw_content.ini
slurp:

View File

@ -129,38 +129,38 @@
- name: Test list only files in yaml (extend)
config_template:
src: "{{ playbook_dir }}/templates/test_list_only.yml"
dest: "/tmp/test_list_only.yml"
dest: "/tmp/test_list_only_extend.yml"
config_overrides: "{{ test_list_only_overrides }}"
config_type: yaml
list_extend: True
- name: Read test_list_only.yml
- name: Read test_list_only_extend.yml
slurp:
src: /tmp/test_list_only.yml
register: test_list_only_file
src: /tmp/test_list_only_extend.yml
register: test_list_only_extend_file
- debug:
msg: "List only Yaml Strings - {{ test_list_only_file.content | b64decode }}"
msg: "List only extend Yaml Strings - {{ test_list_only_extend_file.content | b64decode }}"
- debug:
msg: "List only Yaml Strings Expected - {{ test_list_only_file_expected.content | b64decode }}"
msg: "List only extend Yaml Strings Expected - {{ test_list_only_extend_file_expected.content | b64decode }}"
- name: Compare files
assert:
that:
- "(test_list_only_file_expected.content | b64decode) == (test_list_only_file.content | b64decode)"
- "(test_list_only_extend_file_expected.content | b64decode) == (test_list_only_extend_file.content | b64decode)"
- name: Test list only files in yaml (replace)
config_template:
src: "{{ playbook_dir }}/templates/test_list_only.yml"
dest: "/tmp/test_list_only.yml"
dest: "/tmp/test_list_only_replace.yml"
config_overrides: "{{ test_list_only_overrides }}"
config_type: yaml
list_extend: False
- name: Read test_list_only.yml
- name: Read test_list_only_replace.yml
slurp:
src: /tmp/test_list_only.yml
src: /tmp/test_list_only_replace.yml
register: test_list_only_replace_file
- debug:

View File

@ -13,80 +13,59 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Setup the host
- import_playbook: common/test-prepare-keys.yml
- import_playbook: common/test-prepare-host.yml
# Temporary work around for issue with lxc_host where on second run after
# all iptables rules have been removed, the lxc_host role is not checking
# that the rules are defined and adding them back in if they are not.
- name: Add iptables rules back in
hosts: localhost
connection: local
gather_facts: yes
become: yes
vars:
do_not_fail_lint: true
tasks:
- name: Ensure lxc iptables rules
command: /usr/local/bin/lxc-system-manage iptables-create
when: do_not_fail_lint
- import_playbook: common/test-prepare-containers.yml
- name: Test config_template
hosts: localhost:container1
connection: local
hosts: all
gather_facts: yes
tasks:
- name: Read expected test_extend.yml
slurp:
src: "{{ playbook_dir }}/files/test_extend.yml.expected"
register: extend_file_expected
- name: Read expected test_no_extend.yml
slurp:
src: "{{ playbook_dir }}/files/test_no_extend.yml.expected"
register: no_extend_file_expected
- name: Read test data
delegate_to: localhost
block:
- name: Read expected test_extend.yml
slurp:
src: "{{ playbook_dir }}/files/test_extend.yml.expected"
register: extend_file_expected
- name: Read expected test_content_no_overrides.json
slurp:
src: "{{ playbook_dir }}/files/test_content_no_overrides.json.expected"
register: content_no_overrides_file_expected
- name: Read expected test_no_extend.yml
slurp:
src: "{{ playbook_dir }}/files/test_no_extend.yml.expected"
register: no_extend_file_expected
- name: Read expected test_multiline_strs.yml
slurp:
src: "{{ playbook_dir }}/files/test_multiline_strs.yml.expected"
register: multiline_strs_file_expected
- name: Read expected test_content_no_overrides.json
slurp:
src: "{{ playbook_dir }}/files/test_content_no_overrides.json.expected"
register: content_no_overrides_file_expected
- name: Read expected test_multiline_strs.yml
slurp:
src: "{{ playbook_dir }}/files/test_multiline_strs.json.expected"
register: multiline_strs_json_file_expected
- name: Read expected test_multiline_strs.yml
slurp:
src: "{{ playbook_dir }}/files/test_multiline_strs.yml.expected"
register: multiline_strs_file_expected
- name: Read expected test_list_only.yml
slurp:
src: "{{ playbook_dir }}/files/test_list_only.yml.expected"
register: test_list_only_file_expected
- name: Read expected test_multiline_strs.yml
slurp:
src: "{{ playbook_dir }}/files/test_multiline_strs.json.expected"
register: multiline_strs_json_file_expected
- name: Read expected test_list_only.yml
slurp:
src: "{{ playbook_dir }}/files/test_list_only_replace.yml.expected"
register: test_list_only_replace_file_expected
- name: Read expected test_list_only_extend.yml
slurp:
src: "{{ playbook_dir }}/files/test_list_only_extend.yml.expected"
register: test_list_only_extend_file_expected
- name: Read expected test_jinja_variables.yml
slurp:
src: "{{ playbook_dir }}/files/test_jinja_variables.yml.expected"
register: test_jinja_variables_expected
- name: Read expected test_list_only_replace.yml
slurp:
src: "{{ playbook_dir }}/files/test_list_only_replace.yml.expected"
register: test_list_only_replace_file_expected
- name: Read expected test_jinja_variables.yml
slurp:
src: "{{ playbook_dir }}/files/test_raw_content.ini.expected"
register: test_raw_content_expected
- name: Read expected test_jinja_variables.yml
slurp:
src: "{{ playbook_dir }}/files/test_jinja_variables.yml.expected"
register: test_jinja_variables_expected
- name: Read expected test_jinja_variables.yml
slurp:
src: "{{ playbook_dir }}/files/test_raw_content.ini.expected"
register: test_raw_content_expected
- import_tasks: test-common-tasks.yml
@ -166,7 +145,7 @@
- four
- 4
test_config_yml_hostvars_overrides:
test_hostvar: "{{ ansible_facts['default_ipv4']['address'] }}"
test_hostvar: "{{ ansible_facts['architecture'] }}"
test_multiline_strs_yml_overrides:
new_multiline_str: |
This should not
@ -277,7 +256,7 @@
list_two:
- "one"
- "two"
test_hostvar: "{{ ansible_facts['default_ipv4']['address'] }}"
test_hostvar: "{{ ansible_facts['architecture'] }}"
changed: {}
removed: {}
diff_content_no_overrides_json:

50
tox.ini
View File

@ -1,5 +1,5 @@
[tox]
minversion = 3.18
minversion = 4.0
skipsdist = True
envlist = docs,linters,functional
ignore_basepython_conflict = True
@ -9,6 +9,9 @@ usedevelop = True
basepython = python3
commands =
/usr/bin/find . -type f -name "*.pyc" -delete
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
-rhttps://opendev.org/openstack/openstack-ansible/raw/branch/{env:TEST_BRANCH:master}/test-requirements.txt
passenv =
COMMON_TESTS_PATH
HOME
@ -26,7 +29,7 @@ allowlist_externals =
bash
setenv =
PYTHONUNBUFFERED=1
TEST_IDEMPOTENCE=false
TEST_IDEMPOTENCE=true
VIRTUAL_ENV={envdir}
WORKING_DIR={toxinidir}
ANSIBLE_PARAMETERS=--diff
@ -69,39 +72,16 @@ commands =
commands =
{posargs}
[testenv:molecule]
# You can use DOCKER_REGISTRY and DOCKER_IMAGE_TAG to switch between
# tested distros. I.e:
# DOCKER_IMAGE_TAG=ubuntu-systemd:jammy tox -e molecule
[testenv:pep8]
commands =
bash -c "{toxinidir}/tests/common/test-pep8.sh"
molecule test
[flake8]
# Ignores the following rules due to how ansible modules work in general
# F403 'from ansible.module_utils.basic import *' used;
# unable to detect undefined names
ignore=F403
[testenv:bashate]
commands =
bash -c "{toxinidir}/tests/common/test-bashate.sh"
[testenv:ansible-syntax]
commands =
bash -c "{toxinidir}/tests/common/test-ansible-syntax.sh"
[testenv:ansible-lint]
commands =
bash -c "{toxinidir}/tests/common/test-ansible-lint.sh"
[testenv:functional]
commands =
bash -c "{toxinidir}/tests/common/test-ansible-functional.sh"
[testenv:linters]
commands =
bash -c "{toxinidir}/tests/common/test-ansible-env-prep.sh"
{[testenv:pep8]commands}
{[testenv:bashate]commands}
{[testenv:ansible-lint]commands}
{[testenv:ansible-syntax]commands}
{[testenv:docs]commands}
passenv =
{[testenv]passenv}
DOCKER_REGISTRY
DOCKER_IMAGE_TAG
DOCKER_COMMAND

View File

@ -14,7 +14,7 @@
- project:
templates:
- openstack-ansible-role-jobs
- openstack-ansible-molecule
- openstack-ansible-deploy-aio_metal-jobs
- check-requirements
- publish-openstack-docs-pti