summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Belanger <pabelanger@redhat.com>2018-08-17 12:55:10 -0400
committerPaul Belanger <pabelanger@redhat.com>2018-08-19 11:32:19 -0400
commit4666971ac5c2d2ac612aa085a002c1db60be09f6 (patch)
tree36e4ae4d1361e208f99855fe6d5920171d516efe
parent48531f50f1d3c1ad83c13115ea19164ed1a7be63 (diff)
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>
Notes
Notes (review): Code-Review+2: Paul Belanger <pabelanger@redhat.com> Workflow+1: Paul Belanger <pabelanger@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 23 Aug 2018 20:59:39 +0000 Reviewed-on: https://review.openstack.org/593110 Project: openstack/ansible-role-nodepool Branch: refs/heads/master
-rw-r--r--.yamllint10
-rw-r--r--.zuul.yaml4
-rw-r--r--bindep.txt9
-rw-r--r--meta/main.yml16
-rw-r--r--molecule/default/Dockerfile.j29
-rw-r--r--molecule/default/molecule.yml34
-rw-r--r--molecule/tests/conftest.py27
-rw-r--r--molecule/tests/test_role.py (renamed from tests/test_role.py)55
-rw-r--r--tasks/install/pip.yaml2
-rw-r--r--templates/etc/nodepool/nodepool.yaml1
-rw-r--r--test-requirements.txt6
-rw-r--r--tests/collect-logs.yaml1
-rw-r--r--tests/playbooks/post.yaml21
-rwxr-xr-xtools/test-setup.sh21
-rw-r--r--tox.ini22
15 files changed, 186 insertions, 52 deletions
diff --git a/.yamllint b/.yamllint
new file mode 100644
index 0000000..a4d53d6
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,10 @@
1extends: default
2
3rules:
4 braces:
5 max-spaces-inside: 1
6 level: error
7 brackets:
8 max-spaces-inside: 1
9 level: error
10 line-length: disable
diff --git a/.zuul.yaml b/.zuul.yaml
index ba9c219..11eed27 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -1,3 +1,4 @@
1---
1- job: 2- job:
2 name: ansible-role-nodepool-base 3 name: ansible-role-nodepool-base
3 pre-run: tests/playbooks/pre.yaml 4 pre-run: tests/playbooks/pre.yaml
@@ -7,7 +8,6 @@
7 - tests/collect-logs.yaml 8 - tests/collect-logs.yaml
8 roles: 9 roles:
9 - zuul: openstack/ansible-role-nodepool 10 - zuul: openstack/ansible-role-nodepool
10 - zuul: openstack/zuul-jobs
11 11
12# Testing for nodepool_install_method: pip 12# Testing for nodepool_install_method: pip
13- job: 13- job:
@@ -69,6 +69,7 @@
69 - ansible-role-nodepool-src-ubuntu-bionic 69 - ansible-role-nodepool-src-ubuntu-bionic
70 - ansible-role-nodepool-src-ubuntu-xenial 70 - ansible-role-nodepool-src-ubuntu-xenial
71 - tox-linters 71 - tox-linters
72 - windmill-tox-molecule
72 gate: 73 gate:
73 jobs: 74 jobs:
74 - ansible-role-nodepool-fedora-latest 75 - ansible-role-nodepool-fedora-latest
@@ -78,3 +79,4 @@
78 - ansible-role-nodepool-src-ubuntu-bionic 79 - ansible-role-nodepool-src-ubuntu-bionic
79 - ansible-role-nodepool-src-ubuntu-xenial 80 - ansible-role-nodepool-src-ubuntu-xenial
80 - tox-linters 81 - tox-linters
82 - windmill-tox-molecule
diff --git a/bindep.txt b/bindep.txt
index cb8c48d..a62fb2d 100644
--- a/bindep.txt
+++ b/bindep.txt
@@ -1,10 +1,5 @@
1# This is a cross-platform list tracking distribution packages needed by tests; 1# This is a cross-platform list tracking distribution packages needed by tests;
2# see http://docs.openstack.org/infra/bindep/ for additional information. 2# see http://docs.openstack.org/infra/bindep/ for additional information.
3 3
4git 4docker.io [test platform:dpkg]
5libffi-devel [platform:rpm] 5docker [test platform:fedora]
6libffi-dev [platform:dpkg]
7libselinux-python [platform:rpm]
8libssl-dev [platform:dpkg]
9openssl-devel [platform:rpm]
10python2-dnf [platform:fedora]
diff --git a/meta/main.yml b/meta/main.yml
index 9370487..48af3e6 100644
--- a/meta/main.yml
+++ b/meta/main.yml
@@ -23,13 +23,13 @@ galaxy_info:
23 license: Apache 23 license: Apache
24 min_ansible_version: 2.4 24 min_ansible_version: 2.4
25 platforms: 25 platforms:
26 - name: Fedora 26 - name: Fedora
27 versions: 27 versions:
28 - 27 28 - 27
29 - name: Ubuntu 29 - name: Ubuntu
30 versions: 30 versions:
31 - 16.04 31 - 16.04
32 - 18.04 32 - 18.04
33 categories: 33 categories:
34 - system 34 - system
35dependencies: [] 35dependencies: []
diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2
new file mode 100644
index 0000000..0a084c6
--- /dev/null
+++ b/molecule/default/Dockerfile.j2
@@ -0,0 +1,9 @@
1# Molecule managed
2
3{% if item.registry is defined %}
4FROM {{ item.registry.url }}/{{ item.image }}
5{% else %}
6FROM {{ item.image }}
7{% endif %}
8
9RUN apt-get update && apt-get install -y python sudo bash ca-certificates python-pip python3-pip && apt-get clean;
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
new file mode 100644
index 0000000..4eda9ea
--- /dev/null
+++ b/molecule/default/molecule.yml
@@ -0,0 +1,34 @@
1---
2dependency:
3 name: galaxy
4driver:
5 name: docker
6lint:
7 name: yamllint
8platforms:
9 - name: ubuntu-bionic
10 image: ubuntu:bionic
11provisioner:
12 name: ansible
13 config_options:
14 ssh_connection:
15 pipelining: true
16 inventory:
17 group_vars:
18 all:
19 nodepool_service_nodepool_builder_manage: false
20 nodepool_service_nodepool_launcher_manage: false
21 lint:
22 name: ansible-lint
23 log: true
24 playbooks:
25 converge: ../../tests/playbooks/run.yaml
26scenario:
27 name: default
28verifier:
29 name: testinfra
30 directory: ../tests
31 options:
32 verbose: true
33 lint:
34 name: flake8
diff --git a/molecule/tests/conftest.py b/molecule/tests/conftest.py
new file mode 100644
index 0000000..7ef1c47
--- /dev/null
+++ b/molecule/tests/conftest.py
@@ -0,0 +1,27 @@
1# Copyright 2018 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import pytest
16
17
18@pytest.fixture
19def platform_docker(host):
20 return host.file('/.dockerenv').exists
21
22
23@pytest.fixture(autouse=True)
24def skip_platform_docker(request, platform_docker):
25 marker = request.node.get_marker('skip_if_docker')
26 if marker and platform_docker:
27 pytest.skip('Skipping docker')
diff --git a/tests/test_role.py b/molecule/tests/test_role.py
index edf219e..6b87e65 100644
--- a/tests/test_role.py
+++ b/molecule/tests/test_role.py
@@ -12,6 +12,8 @@
12# License for the specific language governing permissions and limitations 12# License for the specific language governing permissions and limitations
13# under the License. 13# under the License.
14 14
15import pytest
16
15 17
16def test_nodepool_user(host): 18def test_nodepool_user(host):
17 user = host.user('nodepool') 19 user = host.user('nodepool')
@@ -62,6 +64,15 @@ def test_nodepool_images_directory(host):
62 assert f.mode == 0o755 64 assert f.mode == 0o755
63 65
64 66
67def test_nodepool_logs_directory(host):
68 f = host.file('/var/log/nodepool')
69 assert f.exists
70 assert f.is_directory
71 assert f.user == 'nodepool'
72 assert f.group == 'nodepool'
73 assert f.mode == 0o755
74
75
65def test_nodepool_builder_logging_config(host): 76def test_nodepool_builder_logging_config(host):
66 f = host.file('/etc/nodepool/builder-logging.conf') 77 f = host.file('/etc/nodepool/builder-logging.conf')
67 assert f.exists 78 assert f.exists
@@ -71,14 +82,34 @@ def test_nodepool_builder_logging_config(host):
71 assert f.mode == 0o644 82 assert f.mode == 0o644
72 83
73 84
74def test_nodepool_builder_service(host): 85def test_nodepool_builder_service_config(host):
75 f = host.file('/etc/systemd/system/nodepool-builder.service') 86 f = host.file('/etc/systemd/system/nodepool-builder.service')
76 assert f.exists 87 assert f.exists
77 assert f.is_file 88 assert f.is_file
78 assert f.user == 'root' 89 assert f.user == 'root'
79 assert f.group == 'root' 90 assert f.group == 'root'
80 assert f.mode == 0o644 91 assert f.mode == 0o644
92 del f
93
94 f = host.file('/etc/systemd/system/nodepool-builder.service.d')
95 assert f.exists
96 assert f.is_directory
97 assert f.user == 'root'
98 assert f.group == 'root'
99 assert f.mode == 0o755
100 del f
101
102 f = host.file(
103 '/etc/systemd/system/nodepool-builder.service.d/override.conf')
104 assert f.exists
105 assert f.is_file
106 assert f.user == 'root'
107 assert f.group == 'root'
108 assert f.mode == 0o644
109
81 110
111@pytest.mark.skip_if_docker()
112def test_nodepool_builder_service(host):
82 service = host.service('nodepool-builder') 113 service = host.service('nodepool-builder')
83 assert service.is_running 114 assert service.is_running
84 assert service.is_enabled 115 assert service.is_enabled
@@ -93,14 +124,34 @@ def test_nodepool_launcher_logging_config(host):
93 assert f.mode == 0o644 124 assert f.mode == 0o644
94 125
95 126
96def test_nodepool_launcher_service(host): 127def test_nodepool_launcher_service_config(host):
97 f = host.file('/etc/systemd/system/nodepool-launcher.service') 128 f = host.file('/etc/systemd/system/nodepool-launcher.service')
98 assert f.exists 129 assert f.exists
99 assert f.is_file 130 assert f.is_file
100 assert f.user == 'root' 131 assert f.user == 'root'
101 assert f.group == 'root' 132 assert f.group == 'root'
102 assert f.mode == 0o644 133 assert f.mode == 0o644
134 del f
103 135
136 f = host.file('/etc/systemd/system/nodepool-launcher.service.d')
137 assert f.exists
138 assert f.is_directory
139 assert f.user == 'root'
140 assert f.group == 'root'
141 assert f.mode == 0o755
142 del f
143
144 f = host.file(
145 '/etc/systemd/system/nodepool-launcher.service.d/override.conf')
146 assert f.exists
147 assert f.is_file
148 assert f.user == 'root'
149 assert f.group == 'root'
150 assert f.mode == 0o644
151
152
153@pytest.mark.skip_if_docker()
154def test_nodepool_launcher_service(host):
104 service = host.service('nodepool-launcher') 155 service = host.service('nodepool-launcher')
105 assert service.is_running 156 assert service.is_running
106 assert service.is_enabled 157 assert service.is_enabled
diff --git a/tasks/install/pip.yaml b/tasks/install/pip.yaml
index 1e7e77f..c901f7c 100644
--- a/tasks/install/pip.yaml
+++ b/tasks/install/pip.yaml
@@ -16,7 +16,7 @@
16 become: true 16 become: true
17 pip: 17 pip:
18 executable: "{{ nodepool_pip_executable|default(omit) }}" 18 executable: "{{ nodepool_pip_executable|default(omit) }}"
19 editable : "{{ nodepool_pip_editable|default(omit) }}" 19 editable: "{{ nodepool_pip_editable|default(omit) }}"
20 extra_args: "{{ nodepool_pip_extra_args|default(omit) }}" 20 extra_args: "{{ nodepool_pip_extra_args|default(omit) }}"
21 name: "{{ nodepool_pip_name }}" 21 name: "{{ nodepool_pip_name }}"
22 version: "{{ nodepool_pip_version|default(omit) }}" 22 version: "{{ nodepool_pip_version|default(omit) }}"
diff --git a/templates/etc/nodepool/nodepool.yaml b/templates/etc/nodepool/nodepool.yaml
index a2ca430..68611b5 100644
--- a/templates/etc/nodepool/nodepool.yaml
+++ b/templates/etc/nodepool/nodepool.yaml
@@ -1,6 +1,7 @@
1# This file is generated by Ansible 1# This file is generated by Ansible
2# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN 2# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
3# 3#
4---
4images-dir: /opt/nodepool/images 5images-dir: /opt/nodepool/images
5 6
6zookeeper-servers: 7zookeeper-servers:
diff --git a/test-requirements.txt b/test-requirements.txt
index bea5a9f..6a1de18 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,3 +1,3 @@
1ansible-lint 1ara
2hacking<0.11,>=0.10 2docker
3junit2html 3molecule
diff --git a/tests/collect-logs.yaml b/tests/collect-logs.yaml
index 9bc3850..56cf33d 100644
--- a/tests/collect-logs.yaml
+++ b/tests/collect-logs.yaml
@@ -21,7 +21,6 @@
21 delegate_to: "{{ inventory_hostname }}" 21 delegate_to: "{{ inventory_hostname }}"
22 with_items: 22 with_items:
23 - "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml" 23 - "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml"
24 - "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml.html"
25 24
26 - name: Prepare nodepool log files 25 - name: Prepare nodepool log files
27 become: yes 26 become: yes
diff --git a/tests/playbooks/post.yaml b/tests/playbooks/post.yaml
index f9d1a11..7988287 100644
--- a/tests/playbooks/post.yaml
+++ b/tests/playbooks/post.yaml
@@ -1,17 +1,8 @@
1- hosts: all 1- hosts: all
2 tasks: 2 tasks:
3 - block: 3 - name: Run testinfra validation
4 - name: Run testinfra validation 4 include_role:
5 include_role: 5 name: tox
6 name: tox 6 vars:
7 vars: 7 tox_envlist: testinfra
8 tox_envlist: testinfra 8 tox_install_siblings: false
9 tox_install_siblings: false
10 always:
11 - name: Run junit2html
12 include_role:
13 name: tox
14 vars:
15 tox_envlist: venv
16 tox_extra_args: -vv junit2html junit.xml
17 tox_install_siblings: false
diff --git a/tools/test-setup.sh b/tools/test-setup.sh
new file mode 100755
index 0000000..5256b02
--- /dev/null
+++ b/tools/test-setup.sh
@@ -0,0 +1,21 @@
1#!/bin/bash -ex
2# Copyright 2018 Red Hat, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17if ! [ $(getent group docker) ]; then
18 sudo groupadd docker
19fi
20sudo gpasswd -a ${USER} docker
21sudo service docker restart
diff --git a/tox.ini b/tox.ini
index 9c9fccf..07b53ec 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,10 +17,8 @@ commands=
17 sphinx-build -b html doc/source doc/build/html 17 sphinx-build -b html doc/source doc/build/html
18 18
19[testenv:testinfra] 19[testenv:testinfra]
20deps =
21 testinfra
22commands = 20commands =
23 pytest --sudo --junit-xml junit.xml tests/test_role.py 21 pytest --junit-xml junit.xml --sudo --verbose molecule/tests
24 22
25[testenv:venv] 23[testenv:venv]
26commands = {posargs} 24commands = {posargs}
@@ -34,16 +32,12 @@ builtins = _
34exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build 32exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
35 33
36[testenv:linters] 34[testenv:linters]
35commands =
36 molecule lint
37
38[testenv:molecule]
39sitepackages = True
37setenv = 40setenv =
38 ANSIBLE_ROLES_PATH = .. 41 ANSIBLE_CALLBACK_PLUGINS = {envsitepackagesdir}/ara/plugins/callbacks
39whitelist_externals = bash
40commands = 42commands =
41 # PEP8 Lint Check 43 molecule test
42 flake8
43 # Ansible Lint Check
44 bash -c "find . -not -path '*/\.*' -type f -regex '.*.y[a]?ml' -print0 | \
45 xargs -t -n1 -0 ansible-lint"
46 # Ansible Syntax Check
47 bash -c "find tests -type f -regex '.*.y[a]?ml' -print | xargs -t -n1 \
48 ansible-playbook --syntax-check -i tests/inventory \
49 -e rolename=$(basename $(pwd)) > /dev/null"