This repository was archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.yml
69 lines (61 loc) · 4.04 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
sudo: required
services:
- docker
env:
- distribution: centos
version: 7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
before_install:
# Pull image
- 'sudo docker pull cyverse/ansible-test:latest-${distribution}-${version}'
script:
- container_id=$(mktemp)
###############################################
#### TEST: 0 - Ansible Syntax Check
###############################################
- 'sudo docker run -it --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} cyverse/ansible-test:latest-${distribution}-${version} "${init}" > "${container_id}"'
## TEST: Ansible syntax check.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
###############################################
#### TEST 1.1
#### - Verify installation idempotence
###############################################
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars "beat_name=packetbeat"
| grep -q 'changed=0.*failed=0'
&& (echo 'Installation Idempotence test: pass' && exit 0)
|| (echo 'Installation Idempotence test: fail' && exit 1)
# Clean up
- 'sudo docker stop "$(cat ${container_id})"'
###############################################
#### TEST - beat_cfg, restart, idempotence
###############################################
- 'sudo docker run -it --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} cyverse/ansible-test:latest-${distribution}-${version} "${init}" > "${container_id}"'
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars "beat_name=packetbeat"'
- >
sudo docker exec "$(cat ${container_id})" cat /etc/packetbeat/packetbeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'packetbeat.yml should not contain the text "DNE_TEST_ONLY": fail' && exit 1)
|| (echo 'packetbeat.yml does not contain the text "DNE_TEST_ONLY": pass' && exit 0)
## Execute role with `beat_config` specified, verify correct number of changes.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_name":"packetbeat", "beat_config": {"input": {"period": 10, "procs": [".*"], "stats": {"system": true, "proc": true, "filesystem": true, "cpu_per_core": false}}, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=2.*failed=0'
&& (echo 'Correct number of changes detected: pass' && exit 0)
|| (echo 'Wrong number of changes detected: fail' && exit 1)
- >
sudo docker exec "$(cat ${container_id})" cat /etc/packetbeat/packetbeat.yml
| grep -q 'DNE_TEST_ONLY'
&& (echo 'packetbeat.yml contains the text "DNE_TEST_ONLY": pass' && exit 0)
|| (echo 'packetbeat.yml should contain the text "DNE_TEST_ONLY", but does not: fail' && exit 1)
## TODO: Verify restart
## TEST: Test role idempotence - set config.
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --extra-vars '{"beat_name":"packetbeat", "beat_config": {"input": {"period": 10, "procs": [".*"], "stats": {"system": true, "proc": true, "filesystem": true, "cpu_per_core": false}}, "output": {"elasticsearch": {"hosts": ["localhost:9200"]}}, "shipper": {"tags": ["DNE_TEST_ONLY"]}, "logging": {"to_files": true, "files": {"path": "/path/to/log/file.log"}}}}'
| grep -q 'changed=0.*failed=0'
&& (echo 'Cfg Idempotence test: pass' && exit 0)
|| (echo 'Cfg Idempotence test: fail' && exit 1)
# Clean up
- 'sudo docker stop "$(cat ${container_id})"'