Skip to content

Commit c876bec

Browse files
zekker6bykvaadm
authored andcommitted
feat: molecule testing for victoria_cluster role (#2)
* add molecule tests for victoria_cluster role * restore use_environment usage * review fixes: remove cache update, switch to platform native modules
1 parent e3d0cba commit c876bec

File tree

6 files changed

+201
-2
lines changed

6 files changed

+201
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
22
.vagrant
3+
.vscode

roles/docker/tasks/main.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
- name: Install Docker into Debian like system
22
block:
33
- name: install packages
4-
package:
4+
apt:
55
name:
66
- apt-transport-https
77
- ca-certificates
88
- curl
99
- gnupg2
1010
- software-properties-common
1111
state: present
12+
update_cache: yes
13+
cache_valid_time: 3600
1214

1315
- name: install repo key
1416
apt_key:
@@ -26,6 +28,7 @@
2628
- docker-ce-cli
2729
- containerd.io
2830
update_cache: yes
31+
cache_valid_time: 3600
2932
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
3033

3134
- name: Install Docker into RedHat like system
@@ -43,9 +46,10 @@
4346
value: 0
4447

4548
- name: Install Docker
46-
package:
49+
yum:
4750
name: docker-ce
4851
state: latest
52+
update_cache: yes
4953
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
5054

5155
- name: put docker config
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
- name: ensure docker
3+
become: true
4+
hosts: all
5+
roles: [ docker ]
6+
7+
- name: ensure victoria_storage
8+
become: true
9+
hosts: all
10+
roles: [ victoria_cluster ]
11+
vars:
12+
vm_role: victoria-storage
13+
if_name: enp0s8
14+
tags: [ 'vm_storage', 'victoria_cluster' ]
15+
16+
- name: ensure victoria_select
17+
become: true
18+
hosts: all
19+
roles: [ victoria_cluster ]
20+
vars:
21+
vm_role: victoria-select
22+
if_name: enp0s8
23+
tags: [ 'vm_select', 'victoria_cluster' ]
24+
25+
- name: ensure victoria_insert
26+
become: true
27+
hosts: all
28+
roles: [ victoria_cluster ]
29+
vars:
30+
vm_role: victoria-insert
31+
if_name: enp0s8
32+
tags: [ 'vm_insert', 'victoria_cluster' ]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
5+
driver:
6+
name: vagrant
7+
8+
lint: |
9+
set -ex
10+
yamllint .
11+
ansible-lint .
12+
13+
platforms:
14+
- name: victoria-cluster-bionic-1
15+
box: ubuntu/bionic64
16+
memory: 2048
17+
cpus: 1
18+
groups:
19+
- victoria_cluster
20+
interfaces:
21+
- auto_config: true
22+
network_name: private_network
23+
type: dhcp
24+
25+
- name: victoria-cluster-bionic-2
26+
box: ubuntu/bionic64
27+
memory: 2048
28+
cpus: 1
29+
groups:
30+
- victoria_cluster
31+
interfaces:
32+
- auto_config: true
33+
network_name: private_network
34+
type: dhcp
35+
36+
- name: victoria-cluster-bionic-3
37+
box: ubuntu/bionic64
38+
memory: 2048
39+
cpus: 1
40+
groups:
41+
- victoria_cluster
42+
interfaces:
43+
- auto_config: true
44+
network_name: private_network
45+
type: dhcp
46+
47+
provisioner:
48+
name: ansible
49+
50+
verifier:
51+
name: ansible
52+
enabled: True
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
port:
2+
tcp:8480:
3+
title: Ensure vminsert is listening
4+
listening: true
5+
6+
tcp:8481:
7+
title: Ensure vmselect is listening
8+
listening: true
9+
10+
tcp:8482:
11+
title: Ensure vmstorage is listening
12+
listening: true
13+
14+
tcp:8400:
15+
title: Ensure vmstorage is listening
16+
listening: true
17+
18+
tcp:8401:
19+
title: Ensure vmstorage is listening
20+
listening: true
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
# Molecule Goss Tests
3+
4+
- name: Verify
5+
hosts: all
6+
become: true
7+
vars:
8+
goss_version: v0.3.10
9+
goss_arch: amd64
10+
goss_bin: /usr/local/bin/goss
11+
goss_sha256sum: 150f25495ca0d1d4fd2ef8d0e750dbd767a15e9a522505f99b61dd1dd40a76d4
12+
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
13+
goss_test_directory: /tmp/molecule/goss
14+
goss_format: documentation
15+
tasks:
16+
- name: Download and install Goss
17+
get_url:
18+
url: "{{ goss_url }}"
19+
dest: "{{ goss_bin }}"
20+
sha256sum: "{{ goss_sha256sum }}"
21+
mode: "u=rwx,go=rx"
22+
register: download_goss
23+
until: download_goss is succeeded
24+
retries: 3
25+
26+
- name: Create Molecule directory for test files
27+
file:
28+
path: "{{ goss_test_directory }}"
29+
state: directory
30+
31+
- name: Find Goss tests on localhost
32+
find:
33+
paths: "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}"
34+
patterns:
35+
- "test[-.\\w]*.yml"
36+
- "test_host_{{ ansible_hostname }}[-.\\w]*.yml"
37+
excludes:
38+
- "test_host_(?!{{ ansible_hostname }})[-.\\w]*.yml"
39+
use_regex: true
40+
delegate_to: localhost
41+
register: test_files
42+
changed_when: false
43+
become: false
44+
45+
- name: debug
46+
debug:
47+
msg: "{{ test_files.files }}"
48+
verbosity: 3
49+
50+
- name: Copy Goss tests to remote
51+
copy:
52+
src: "{{ item.path }}"
53+
dest: "{{ goss_test_directory }}/{{ item.path | basename }}"
54+
with_items:
55+
- "{{ test_files.files }}"
56+
loop_control:
57+
label: "{{ item.path | basename }}"
58+
59+
- name: Register test files
60+
find:
61+
paths:
62+
- "{{ goss_test_directory }}"
63+
patterns:
64+
- "test_*.yml"
65+
register: test_files
66+
67+
- block:
68+
- name: Execute Goss tests
69+
command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}"
70+
register: test_results
71+
with_items: "{{ test_files.files | map(attribute='path') | list }}"
72+
loop_control:
73+
label: "{{ item | basename }}"
74+
failed_when: false
75+
76+
- name: Display details about the Goss results
77+
debug:
78+
msg: "{{ item.stdout_lines }}"
79+
with_items: "{{ test_results.results }}"
80+
loop_control:
81+
label: "{{ item[item.ansible_loop_var] | basename }}"
82+
83+
- name: Fail when tests fail
84+
fail:
85+
msg: "Goss failed to validate"
86+
when: item.rc != 0
87+
with_items: "{{ test_results.results }}"
88+
loop_control:
89+
label: "{{ item[item.ansible_loop_var] | basename }}"
90+
when: test_files is succeeded

0 commit comments

Comments
 (0)