forked from sleighzy/ansible-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
115 lines (94 loc) · 4.35 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
sudo: required
services:
- docker
before_install:
# Update the host with latest versions
- sudo apt-get update -qq
install:
# Install Ansible on host
- pip install ansible --user
# Install docker-py
- pip install --upgrade docker-py --user
# Add ansible.cfg to pick up roles path.
- printf '[defaults]\nroles_path = ../' > ansible.cfg
# Pull a CentOS image with systemd installed for the Docker containers
- docker pull centos/systemd
script:
# Install role dependencies.
- ansible-galaxy install -r tests/requirements.yml
# Check syntax of Ansible role
- ansible-playbook tests/test.yaml -i tests/inventory --syntax-check
# Run Ansible role
- ansible-playbook tests/test.yaml -i tests/inventory --verbose
# Run the playbook and role again to ensure that it is idempotent and nothing has changed
- >
ansible-playbook tests/test.yaml -i tests/inventory --verbose
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Check that the zookeeper nodes are running
- >
docker exec zookeeper-1 systemctl status zookeeper 2>&1
| awk 'FNR == 3 {print}' | grep "active (running)"
&& (echo "ZooKeeper service running - pass" && exit 0)
|| (echo "ZooKeeper service running - fail" && exit 1)
- >
docker exec zookeeper-2 systemctl status zookeeper 2>&1
| awk 'FNR == 3 {print}' | grep "active (running)"
&& (echo "ZooKeeper service running - pass" && exit 0)
|| (echo "ZooKeeper service running - fail" && exit 1)
- >
docker exec zookeeper-3 systemctl status zookeeper 2>&1
| awk 'FNR == 3 {print}' | grep "active (running)"
&& (echo "ZooKeeper service running - pass" && exit 0)
|| (echo "ZooKeeper service running - fail" && exit 1)
# Check that the kafka nodes are running
- >
docker exec kafka-1 systemctl status kafka 2>&1
| awk 'FNR == 3 {print}' | grep "active (running)"
&& (echo "Kafka service running - pass" && exit 0)
|| (echo "Kafka service running - fail" && exit 1)
- >
docker exec kafka-2 systemctl status kafka 2>&1
| awk 'FNR == 3 {print}' | grep "active (running)"
&& (echo "Kafka service running - pass" && exit 0)
|| (echo "Kafka service running - fail" && exit 1)
- >
docker exec kafka-3 systemctl status kafka 2>&1
| awk 'FNR == 3 {print}' | grep "active (running)"
&& (echo "Kafka service running - pass" && exit 0)
|| (echo "Kafka service running - fail" && exit 1)
# Check that a Znode can be successfully created, this is to ensure that ZooKeeper is up and functioning
- >
docker exec zookeeper-1 /usr/share/zookeeper/bin/zkCli.sh create /TestZnode1 "test-node-1" 2>&1
| awk -F\" '/Created/ {print $1}' | grep "Created"
&& (echo "Znode ceate test - pass" && exit 0)
|| (echo "Znode create test - fail" && exit 1)
# Create a Kafka topic named "test" using node 1 and confirm that it was created successfully
- docker exec kafka-1 /opt/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper-1:2181 --replication-factor 1 --partitions 1 --topic test
- >
docker exec kafka-1 /opt/kafka/bin/kafka-topics.sh --list --zookeeper zookeeper-1:2181 2>&1
| awk 'FNR == 1 {print}' | grep "test"
&& (echo "Topic created - pass" && exit 0)
|| (echo "Topic created - fail" && exit 1)
# Send a test message to this topic using node 2
- docker exec kafka-2 sh -c 'echo "test message" | /opt/kafka/bin/kafka-console-producer.sh --broker-list kafka-2:9092 --topic test'
# Consume the message from the topic using node 3 to confirm it was sent successfully
- >
docker exec kafka-3 /opt/kafka/bin/kafka-console-consumer.sh --topic test --from-beginning --max-messages 1 --bootstrap-server kafka-3:9092 2>&1
| awk 'FNR == 1 {print}' | grep "test message"
&& (echo "Message consumed - pass" && exit 0)
|| (echo "Message consumed - fail" && exit 1)
after_script:
# Stop and remove the Docker containers
- docker stop zookeeper-1 && docker rm zookeeper-1
- docker stop zookeeper-2 && docker rm zookeeper-2
- docker stop zookeeper-3 && docker rm zookeeper-3
- docker stop kafka-1 && docker rm kafka-1
- docker stop kafka-2 && docker rm kafka-2
- docker stop kafka-3 && docker rm kafka-3
# Remove the Docker network
- docker network rm kafka
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/