Switch to molecule for testing
Molecule is the defacto testing tool for ansible roles. Switch to it to make it easier for users to test. Change-Id: I881e895877c9702e62c4415d48b0f33f34f7487b Depends-On: https://review.openstack.org/593369 Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
48531f50f1
commit
4666971ac5
10
.yamllint
Normal file
10
.yamllint
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
braces:
|
||||||
|
max-spaces-inside: 1
|
||||||
|
level: error
|
||||||
|
brackets:
|
||||||
|
max-spaces-inside: 1
|
||||||
|
level: error
|
||||||
|
line-length: disable
|
@ -1,3 +1,4 @@
|
|||||||
|
---
|
||||||
- job:
|
- job:
|
||||||
name: ansible-role-nodepool-base
|
name: ansible-role-nodepool-base
|
||||||
pre-run: tests/playbooks/pre.yaml
|
pre-run: tests/playbooks/pre.yaml
|
||||||
@ -7,7 +8,6 @@
|
|||||||
- tests/collect-logs.yaml
|
- tests/collect-logs.yaml
|
||||||
roles:
|
roles:
|
||||||
- zuul: openstack/ansible-role-nodepool
|
- zuul: openstack/ansible-role-nodepool
|
||||||
- zuul: openstack/zuul-jobs
|
|
||||||
|
|
||||||
# Testing for nodepool_install_method: pip
|
# Testing for nodepool_install_method: pip
|
||||||
- job:
|
- job:
|
||||||
@ -69,6 +69,7 @@
|
|||||||
- ansible-role-nodepool-src-ubuntu-bionic
|
- ansible-role-nodepool-src-ubuntu-bionic
|
||||||
- ansible-role-nodepool-src-ubuntu-xenial
|
- ansible-role-nodepool-src-ubuntu-xenial
|
||||||
- tox-linters
|
- tox-linters
|
||||||
|
- windmill-tox-molecule
|
||||||
gate:
|
gate:
|
||||||
jobs:
|
jobs:
|
||||||
- ansible-role-nodepool-fedora-latest
|
- ansible-role-nodepool-fedora-latest
|
||||||
@ -78,3 +79,4 @@
|
|||||||
- ansible-role-nodepool-src-ubuntu-bionic
|
- ansible-role-nodepool-src-ubuntu-bionic
|
||||||
- ansible-role-nodepool-src-ubuntu-xenial
|
- ansible-role-nodepool-src-ubuntu-xenial
|
||||||
- tox-linters
|
- tox-linters
|
||||||
|
- windmill-tox-molecule
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
# This is a cross-platform list tracking distribution packages needed by tests;
|
# This is a cross-platform list tracking distribution packages needed by tests;
|
||||||
# see http://docs.openstack.org/infra/bindep/ for additional information.
|
# see http://docs.openstack.org/infra/bindep/ for additional information.
|
||||||
|
|
||||||
git
|
docker.io [test platform:dpkg]
|
||||||
libffi-devel [platform:rpm]
|
docker [test platform:fedora]
|
||||||
libffi-dev [platform:dpkg]
|
|
||||||
libselinux-python [platform:rpm]
|
|
||||||
libssl-dev [platform:dpkg]
|
|
||||||
openssl-devel [platform:rpm]
|
|
||||||
python2-dnf [platform:fedora]
|
|
||||||
|
9
molecule/default/Dockerfile.j2
Normal file
9
molecule/default/Dockerfile.j2
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Molecule managed
|
||||||
|
|
||||||
|
{% if item.registry is defined %}
|
||||||
|
FROM {{ item.registry.url }}/{{ item.image }}
|
||||||
|
{% else %}
|
||||||
|
FROM {{ item.image }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y python sudo bash ca-certificates python-pip python3-pip && apt-get clean;
|
34
molecule/default/molecule.yml
Normal file
34
molecule/default/molecule.yml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint:
|
||||||
|
name: yamllint
|
||||||
|
platforms:
|
||||||
|
- name: ubuntu-bionic
|
||||||
|
image: ubuntu:bionic
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
config_options:
|
||||||
|
ssh_connection:
|
||||||
|
pipelining: true
|
||||||
|
inventory:
|
||||||
|
group_vars:
|
||||||
|
all:
|
||||||
|
nodepool_service_nodepool_builder_manage: false
|
||||||
|
nodepool_service_nodepool_launcher_manage: false
|
||||||
|
lint:
|
||||||
|
name: ansible-lint
|
||||||
|
log: true
|
||||||
|
playbooks:
|
||||||
|
converge: ../../tests/playbooks/run.yaml
|
||||||
|
scenario:
|
||||||
|
name: default
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
||||||
|
directory: ../tests
|
||||||
|
options:
|
||||||
|
verbose: true
|
||||||
|
lint:
|
||||||
|
name: flake8
|
27
molecule/tests/conftest.py
Normal file
27
molecule/tests/conftest.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright 2018 Red Hat, 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.
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def platform_docker(host):
|
||||||
|
return host.file('/.dockerenv').exists
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def skip_platform_docker(request, platform_docker):
|
||||||
|
marker = request.node.get_marker('skip_if_docker')
|
||||||
|
if marker and platform_docker:
|
||||||
|
pytest.skip('Skipping docker')
|
@ -12,6 +12,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def test_nodepool_user(host):
|
def test_nodepool_user(host):
|
||||||
user = host.user('nodepool')
|
user = host.user('nodepool')
|
||||||
@ -62,6 +64,15 @@ def test_nodepool_images_directory(host):
|
|||||||
assert f.mode == 0o755
|
assert f.mode == 0o755
|
||||||
|
|
||||||
|
|
||||||
|
def test_nodepool_logs_directory(host):
|
||||||
|
f = host.file('/var/log/nodepool')
|
||||||
|
assert f.exists
|
||||||
|
assert f.is_directory
|
||||||
|
assert f.user == 'nodepool'
|
||||||
|
assert f.group == 'nodepool'
|
||||||
|
assert f.mode == 0o755
|
||||||
|
|
||||||
|
|
||||||
def test_nodepool_builder_logging_config(host):
|
def test_nodepool_builder_logging_config(host):
|
||||||
f = host.file('/etc/nodepool/builder-logging.conf')
|
f = host.file('/etc/nodepool/builder-logging.conf')
|
||||||
assert f.exists
|
assert f.exists
|
||||||
@ -71,14 +82,34 @@ def test_nodepool_builder_logging_config(host):
|
|||||||
assert f.mode == 0o644
|
assert f.mode == 0o644
|
||||||
|
|
||||||
|
|
||||||
def test_nodepool_builder_service(host):
|
def test_nodepool_builder_service_config(host):
|
||||||
f = host.file('/etc/systemd/system/nodepool-builder.service')
|
f = host.file('/etc/systemd/system/nodepool-builder.service')
|
||||||
assert f.exists
|
assert f.exists
|
||||||
assert f.is_file
|
assert f.is_file
|
||||||
assert f.user == 'root'
|
assert f.user == 'root'
|
||||||
assert f.group == 'root'
|
assert f.group == 'root'
|
||||||
assert f.mode == 0o644
|
assert f.mode == 0o644
|
||||||
|
del f
|
||||||
|
|
||||||
|
f = host.file('/etc/systemd/system/nodepool-builder.service.d')
|
||||||
|
assert f.exists
|
||||||
|
assert f.is_directory
|
||||||
|
assert f.user == 'root'
|
||||||
|
assert f.group == 'root'
|
||||||
|
assert f.mode == 0o755
|
||||||
|
del f
|
||||||
|
|
||||||
|
f = host.file(
|
||||||
|
'/etc/systemd/system/nodepool-builder.service.d/override.conf')
|
||||||
|
assert f.exists
|
||||||
|
assert f.is_file
|
||||||
|
assert f.user == 'root'
|
||||||
|
assert f.group == 'root'
|
||||||
|
assert f.mode == 0o644
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip_if_docker()
|
||||||
|
def test_nodepool_builder_service(host):
|
||||||
service = host.service('nodepool-builder')
|
service = host.service('nodepool-builder')
|
||||||
assert service.is_running
|
assert service.is_running
|
||||||
assert service.is_enabled
|
assert service.is_enabled
|
||||||
@ -93,14 +124,34 @@ def test_nodepool_launcher_logging_config(host):
|
|||||||
assert f.mode == 0o644
|
assert f.mode == 0o644
|
||||||
|
|
||||||
|
|
||||||
def test_nodepool_launcher_service(host):
|
def test_nodepool_launcher_service_config(host):
|
||||||
f = host.file('/etc/systemd/system/nodepool-launcher.service')
|
f = host.file('/etc/systemd/system/nodepool-launcher.service')
|
||||||
assert f.exists
|
assert f.exists
|
||||||
assert f.is_file
|
assert f.is_file
|
||||||
assert f.user == 'root'
|
assert f.user == 'root'
|
||||||
assert f.group == 'root'
|
assert f.group == 'root'
|
||||||
assert f.mode == 0o644
|
assert f.mode == 0o644
|
||||||
|
del f
|
||||||
|
|
||||||
|
f = host.file('/etc/systemd/system/nodepool-launcher.service.d')
|
||||||
|
assert f.exists
|
||||||
|
assert f.is_directory
|
||||||
|
assert f.user == 'root'
|
||||||
|
assert f.group == 'root'
|
||||||
|
assert f.mode == 0o755
|
||||||
|
del f
|
||||||
|
|
||||||
|
f = host.file(
|
||||||
|
'/etc/systemd/system/nodepool-launcher.service.d/override.conf')
|
||||||
|
assert f.exists
|
||||||
|
assert f.is_file
|
||||||
|
assert f.user == 'root'
|
||||||
|
assert f.group == 'root'
|
||||||
|
assert f.mode == 0o644
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip_if_docker()
|
||||||
|
def test_nodepool_launcher_service(host):
|
||||||
service = host.service('nodepool-launcher')
|
service = host.service('nodepool-launcher')
|
||||||
assert service.is_running
|
assert service.is_running
|
||||||
assert service.is_enabled
|
assert service.is_enabled
|
@ -1,6 +1,7 @@
|
|||||||
# This file is generated by Ansible
|
# This file is generated by Ansible
|
||||||
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
|
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
|
||||||
#
|
#
|
||||||
|
---
|
||||||
images-dir: /opt/nodepool/images
|
images-dir: /opt/nodepool/images
|
||||||
|
|
||||||
zookeeper-servers:
|
zookeeper-servers:
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
ansible-lint
|
ara
|
||||||
hacking<0.11,>=0.10
|
docker
|
||||||
junit2html
|
molecule
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
delegate_to: "{{ inventory_hostname }}"
|
delegate_to: "{{ inventory_hostname }}"
|
||||||
with_items:
|
with_items:
|
||||||
- "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml"
|
- "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml"
|
||||||
- "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml.html"
|
|
||||||
|
|
||||||
- name: Prepare nodepool log files
|
- name: Prepare nodepool log files
|
||||||
become: yes
|
become: yes
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
- hosts: all
|
- hosts: all
|
||||||
tasks:
|
tasks:
|
||||||
- block:
|
|
||||||
- name: Run testinfra validation
|
- name: Run testinfra validation
|
||||||
include_role:
|
include_role:
|
||||||
name: tox
|
name: tox
|
||||||
vars:
|
vars:
|
||||||
tox_envlist: testinfra
|
tox_envlist: testinfra
|
||||||
tox_install_siblings: false
|
tox_install_siblings: false
|
||||||
always:
|
|
||||||
- name: Run junit2html
|
|
||||||
include_role:
|
|
||||||
name: tox
|
|
||||||
vars:
|
|
||||||
tox_envlist: venv
|
|
||||||
tox_extra_args: -vv junit2html junit.xml
|
|
||||||
tox_install_siblings: false
|
|
||||||
|
21
tools/test-setup.sh
Executable file
21
tools/test-setup.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash -ex
|
||||||
|
# Copyright 2018 Red Hat, 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.
|
||||||
|
|
||||||
|
if ! [ $(getent group docker) ]; then
|
||||||
|
sudo groupadd docker
|
||||||
|
fi
|
||||||
|
sudo gpasswd -a ${USER} docker
|
||||||
|
sudo service docker restart
|
24
tox.ini
24
tox.ini
@ -17,10 +17,8 @@ commands=
|
|||||||
sphinx-build -b html doc/source doc/build/html
|
sphinx-build -b html doc/source doc/build/html
|
||||||
|
|
||||||
[testenv:testinfra]
|
[testenv:testinfra]
|
||||||
deps =
|
|
||||||
testinfra
|
|
||||||
commands =
|
commands =
|
||||||
pytest --sudo --junit-xml junit.xml tests/test_role.py
|
pytest --junit-xml junit.xml --sudo --verbose molecule/tests
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
@ -34,16 +32,12 @@ builtins = _
|
|||||||
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
|
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
setenv =
|
|
||||||
ANSIBLE_ROLES_PATH = ..
|
|
||||||
whitelist_externals = bash
|
|
||||||
commands =
|
commands =
|
||||||
# PEP8 Lint Check
|
molecule lint
|
||||||
flake8
|
|
||||||
# Ansible Lint Check
|
[testenv:molecule]
|
||||||
bash -c "find . -not -path '*/\.*' -type f -regex '.*.y[a]?ml' -print0 | \
|
sitepackages = True
|
||||||
xargs -t -n1 -0 ansible-lint"
|
setenv =
|
||||||
# Ansible Syntax Check
|
ANSIBLE_CALLBACK_PLUGINS = {envsitepackagesdir}/ara/plugins/callbacks
|
||||||
bash -c "find tests -type f -regex '.*.y[a]?ml' -print | xargs -t -n1 \
|
commands =
|
||||||
ansible-playbook --syntax-check -i tests/inventory \
|
molecule test
|
||||||
-e rolename=$(basename $(pwd)) > /dev/null"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user