summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Belanger <pabelanger@redhat.com>2018-08-14 22:52:50 -0400
committerPaul Belanger <pabelanger@redhat.com>2018-08-16 20:26:51 -0400
commitefc9d57e2c6369a242e264196fe0b43be90cbafc (patch)
tree2d38a066da80d17ba8f07e4963bff4d6dad04cf3
parentb5fd6f6672cb402bd237e9d95302e966bd341d06 (diff)
Switch to testinfra for role validation
We can switch to using testinfra to help ensure ansible did everything properly. Change-Id: I9e21cd16f1149d76308043a97658c93e7f14ac42 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: Fri, 17 Aug 2018 01:59:51 +0000 Reviewed-on: https://review.openstack.org/591888 Project: openstack/ansible-role-nodepool Branch: refs/heads/master
-rw-r--r--.zuul.yaml4
-rw-r--r--test-requirements.txt1
-rw-r--r--tests/collect-logs.yaml10
-rw-r--r--tests/playbooks/post.yaml17
-rw-r--r--tests/playbooks/run.yaml137
-rw-r--r--tests/test_role.py106
-rw-r--r--tox.ini6
7 files changed, 143 insertions, 138 deletions
diff --git a/.zuul.yaml b/.zuul.yaml
index eb54f95..ba9c219 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -2,7 +2,9 @@
2 name: ansible-role-nodepool-base 2 name: ansible-role-nodepool-base
3 pre-run: tests/playbooks/pre.yaml 3 pre-run: tests/playbooks/pre.yaml
4 run: tests/playbooks/run.yaml 4 run: tests/playbooks/run.yaml
5 post-run: tests/collect-logs.yaml 5 post-run:
6 - tests/playbooks/post.yaml
7 - tests/collect-logs.yaml
6 roles: 8 roles:
7 - zuul: openstack/ansible-role-nodepool 9 - zuul: openstack/ansible-role-nodepool
8 - zuul: openstack/zuul-jobs 10 - zuul: openstack/zuul-jobs
diff --git a/test-requirements.txt b/test-requirements.txt
index 4c4414f..bea5a9f 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,2 +1,3 @@
1ansible-lint 1ansible-lint
2hacking<0.11,>=0.10 2hacking<0.11,>=0.10
3junit2html
diff --git a/tests/collect-logs.yaml b/tests/collect-logs.yaml
index 263a6c3..9bc3850 100644
--- a/tests/collect-logs.yaml
+++ b/tests/collect-logs.yaml
@@ -13,6 +13,16 @@
13 - nodepool-builder 13 - nodepool-builder
14 - nodepool-launcher 14 - nodepool-launcher
15 15
16 - name: Collect testinfra reports
17 synchronize:
18 dest: "{{ zuul_output_dir }}/logs"
19 src: "{{ item }}"
20 verify_host: true
21 delegate_to: "{{ inventory_hostname }}"
22 with_items:
23 - "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml"
24 - "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/junit.xml.html"
25
16 - name: Prepare nodepool log files 26 - name: Prepare nodepool log files
17 become: yes 27 become: yes
18 synchronize: 28 synchronize:
diff --git a/tests/playbooks/post.yaml b/tests/playbooks/post.yaml
new file mode 100644
index 0000000..f9d1a11
--- /dev/null
+++ b/tests/playbooks/post.yaml
@@ -0,0 +1,17 @@
1- hosts: all
2 tasks:
3 - block:
4 - name: Run testinfra validation
5 include_role:
6 name: tox
7 vars:
8 tox_envlist: testinfra
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/tests/playbooks/run.yaml b/tests/playbooks/run.yaml
index 6bfcbcd..915330b 100644
--- a/tests/playbooks/run.yaml
+++ b/tests/playbooks/run.yaml
@@ -34,105 +34,6 @@
34 - nodepool_service_nodepool_builder 34 - nodepool_service_nodepool_builder
35 - nodepool_service_nodepool_launcher 35 - nodepool_service_nodepool_launcher
36 36
37 - name: Ensure nodepool_user_name is nodepool.
38 shell: /usr/bin/getent passwd nodepool
39 tags: skip_ansible_lint
40
41 - name: Ensure nodepool_user_group is nodepool.
42 shell: /usr/bin/getent group nodepool
43 tags: skip_ansible_lint
44
45 - name: Register nodepool_user_home_getent.
46 shell: '/usr/bin/getent passwd nodepool | cut -d: -f6'
47 register: nodepool_user_home_getent
48 tags: skip_ansible_lint
49
50 - name: Assert nodepool_user_home is /var/lib/nodepool.
51 assert:
52 that:
53 - nodepool_user_home_getent.stdout == '/var/lib/nodepool'
54
55 - name: Register /opt/nodepool/images
56 stat:
57 path: /opt/nodepool/images
58 register: _nodepool_images_dir_stat
59
60 - name: Assert /opt/nodepool/images tests.
61 assert:
62 that:
63 - _nodepool_images_dir_stat.stat.exists
64 - _nodepool_images_dir_stat.stat.isdir
65 - _nodepool_images_dir_stat.stat.pw_name == 'nodepool'
66 - _nodepool_images_dir_stat.stat.gr_name == 'nodepool'
67 - _nodepool_images_dir_stat.stat.mode == '0755'
68
69 - name: Register /etc/nodepool/nodepool.yaml
70 stat:
71 path: /etc/nodepool/nodepool.yaml
72 register: nodepool_yaml_stat
73
74 - name: Assert nodepool_yaml_stat tests.
75 assert:
76 that:
77 - nodepool_yaml_stat.stat.exists
78 - nodepool_yaml_stat.stat.isreg
79 - nodepool_yaml_stat.stat.pw_name == 'nodepool'
80 - nodepool_yaml_stat.stat.gr_name == 'nodepool'
81 - nodepool_yaml_stat.stat.mode == '0644'
82
83 - name: Register /etc/nodepool/builder-logging.conf
84 stat:
85 path: /etc/nodepool/builder-logging.conf
86 register: builder_logging_conf_stat
87
88 - name: Assert buidler_logging_conf_stat tests.
89 assert:
90 that:
91 - builder_logging_conf_stat.stat.exists
92 - builder_logging_conf_stat.stat.isreg
93 - builder_logging_conf_stat.stat.pw_name == 'nodepool'
94 - builder_logging_conf_stat.stat.gr_name == 'nodepool'
95 - builder_logging_conf_stat.stat.mode == '0644'
96
97 - name: Register /etc/nodepool/launcher-logging.conf
98 stat:
99 path: /etc/nodepool/launcher-logging.conf
100 register: launcher_logging_conf_stat
101
102 - name: Assert buidler_logging_conf_stat tests.
103 assert:
104 that:
105 - launcher_logging_conf_stat.stat.exists
106 - launcher_logging_conf_stat.stat.isreg
107 - launcher_logging_conf_stat.stat.pw_name == 'nodepool'
108 - launcher_logging_conf_stat.stat.gr_name == 'nodepool'
109 - launcher_logging_conf_stat.stat.mode == '0644'
110
111 - name: Register /etc/nodepool/secure.conf
112 stat:
113 path: /etc/nodepool/secure.conf
114 register: secure_conf_stat
115
116 - name: Assert secure_conf_stat tests.
117 assert:
118 that:
119 - secure_conf_stat.stat.exists
120 - secure_conf_stat.stat.isreg
121 - secure_conf_stat.stat.pw_name == 'nodepool'
122 - secure_conf_stat.stat.gr_name == 'nodepool'
123 - secure_conf_stat.stat.mode == '0600'
124
125 - name: Register nodepool_user_home_stat.
126 stat:
127 path: /var/lib/nodepool
128 register: nodepool_user_home_stat
129
130 - name: Assert nodepool_user_home tests.
131 assert:
132 that:
133 - nodepool_user_home_stat.stat.exists
134 - nodepool_user_home_stat.stat.isdir
135
136 - name: Register nodepool_git_dest_stat. 37 - name: Register nodepool_git_dest_stat.
137 stat: 38 stat:
138 path: /home/zuul/src/git.openstack.org/openstack-infra/nodepool 39 path: /home/zuul/src/git.openstack.org/openstack-infra/nodepool
@@ -145,41 +46,3 @@
145 - nodepool_git_dest_stat.stat.exists 46 - nodepool_git_dest_stat.stat.exists
146 - nodepool_git_dest_stat.stat.isdir 47 - nodepool_git_dest_stat.stat.isdir
147 when: nodepool_install_method == 'git' 48 when: nodepool_install_method == 'git'
148
149 - name: Register /etc/systemd/system/nodepool-builder.service
150 stat:
151 path: /etc/systemd/system/nodepool-builder.service
152 register: _nodepool_builder_service_systemd_stat
153
154 - name: Assert _nodepool_builder_service_systemd_stat tests.
155 assert:
156 that:
157 - _nodepool_builder_service_systemd_stat.stat.exists
158 - _nodepool_builder_service_systemd_stat.stat.isreg
159 - _nodepool_builder_service_systemd_stat.stat.pw_name == 'root'
160 - _nodepool_builder_service_systemd_stat.stat.gr_name == 'root'
161 - _nodepool_builder_service_systemd_stat.stat.mode == '0644'
162
163 - name: Ensure nodepool-builder is running.
164 become: yes
165 shell: /usr/sbin/service nodepool-builder status
166 tags: skip_ansible_lint
167
168 - name: Register /etc/systemd/system/nodepool-launcher.service
169 stat:
170 path: /etc/systemd/system/nodepool-launcher.service
171 register: _nodepool_launcher_service_systemd_stat
172
173 - name: Assert _nodepool_launcher_service_systemd_stat tests.
174 assert:
175 that:
176 - _nodepool_launcher_service_systemd_stat.stat.exists
177 - _nodepool_launcher_service_systemd_stat.stat.isreg
178 - _nodepool_launcher_service_systemd_stat.stat.pw_name == 'root'
179 - _nodepool_launcher_service_systemd_stat.stat.gr_name == 'root'
180 - _nodepool_launcher_service_systemd_stat.stat.mode == '0644'
181
182 - name: Ensure nodepool-launcher is running.
183 become: yes
184 shell: /usr/sbin/service nodepool-launcher status
185 tags: skip_ansible_lint
diff --git a/tests/test_role.py b/tests/test_role.py
new file mode 100644
index 0000000..edf219e
--- /dev/null
+++ b/tests/test_role.py
@@ -0,0 +1,106 @@
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
15
16def test_nodepool_user(host):
17 user = host.user('nodepool')
18 assert user.exists
19 assert user.name == 'nodepool'
20 assert user.group == 'nodepool'
21 assert user.home == '/var/lib/nodepool'
22
23 f = host.file('/var/lib/nodepool')
24 assert f.exists
25 assert f.is_directory
26 assert f.user == 'nodepool'
27 assert f.group == 'nodepool'
28 # TODO(pabelanger): Validate mode
29
30
31def test_nodepool_config(host):
32 f = host.file('/etc/nodepool')
33 assert f.exists
34 assert f.is_directory
35 assert f.user == 'nodepool'
36 assert f.group == 'nodepool'
37 # TODO(pabelanger): Validate mode
38 del f
39
40 f = host.file('/etc/nodepool/nodepool.yaml')
41 assert f.exists
42 assert f.is_file
43 assert f.user == 'nodepool'
44 assert f.group == 'nodepool'
45 assert f.mode == 0o644
46 del f
47
48 f = host.file('/etc/nodepool/secure.conf')
49 assert f.exists
50 assert f.is_file
51 assert f.user == 'nodepool'
52 assert f.group == 'nodepool'
53 assert f.mode == 0o600
54
55
56def test_nodepool_images_directory(host):
57 f = host.file('/opt/nodepool/images')
58 assert f.exists
59 assert f.is_directory
60 assert f.user == 'nodepool'
61 assert f.group == 'nodepool'
62 assert f.mode == 0o755
63
64
65def test_nodepool_builder_logging_config(host):
66 f = host.file('/etc/nodepool/builder-logging.conf')
67 assert f.exists
68 assert f.is_file
69 assert f.user == 'nodepool'
70 assert f.group == 'nodepool'
71 assert f.mode == 0o644
72
73
74def test_nodepool_builder_service(host):
75 f = host.file('/etc/systemd/system/nodepool-builder.service')
76 assert f.exists
77 assert f.is_file
78 assert f.user == 'root'
79 assert f.group == 'root'
80 assert f.mode == 0o644
81
82 service = host.service('nodepool-builder')
83 assert service.is_running
84 assert service.is_enabled
85
86
87def test_nodepool_launcher_logging_config(host):
88 f = host.file('/etc/nodepool/launcher-logging.conf')
89 assert f.exists
90 assert f.is_file
91 assert f.user == 'nodepool'
92 assert f.group == 'nodepool'
93 assert f.mode == 0o644
94
95
96def test_nodepool_launcher_service(host):
97 f = host.file('/etc/systemd/system/nodepool-launcher.service')
98 assert f.exists
99 assert f.is_file
100 assert f.user == 'root'
101 assert f.group == 'root'
102 assert f.mode == 0o644
103
104 service = host.service('nodepool-launcher')
105 assert service.is_running
106 assert service.is_enabled
diff --git a/tox.ini b/tox.ini
index dc90799..9c9fccf 100644
--- a/tox.ini
+++ b/tox.ini
@@ -16,6 +16,12 @@ commands=
16 doc8 doc 16 doc8 doc
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]
20deps =
21 testinfra
22commands =
23 pytest --sudo --junit-xml junit.xml tests/test_role.py
24
19[testenv:venv] 25[testenv:venv]
20commands = {posargs} 26commands = {posargs}
21 27