Skip to content

Commit

Permalink
Organize verification steps
Browse files Browse the repository at this point in the history
  • Loading branch information
build-failure committed Jun 26, 2020
1 parent e102578 commit 3ce8297
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 67 deletions.
1 change: 1 addition & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ provisioner:
playbooks:
create: ../resources/playbooks/create.yml
destroy: ../resources/playbooks/destroy.yml
verify: verify/main.yml
verifier:
name: ansible
lint: |
Expand Down
67 changes: 0 additions & 67 deletions molecule/default/verify.yml

This file was deleted.

15 changes: 15 additions & 0 deletions molecule/default/verify/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Gather facts on listening ports
listen_ports_facts:
- name: Create list of listening ports
set_fact:
tcp_ports: "{{ ansible_facts.tcp_listen | map(attribute='port') | sort | list }}"
- name: Verify Kafka port is in listening ports
assert:
that:
- 9092 in tcp_ports
- name: Check that Kafka log file exists
stat:
path: /var/log/kafka/server.log
register: stat_log_result
failed_when: not stat_log_result.stat.exists
37 changes: 37 additions & 0 deletions molecule/default/verify/create_topic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: Create random topic name
set_fact:
topic_name: "{{ 9999999999999999999999 | random | to_uuid }}"
run_once: yes
- name: Add a topic to the Kafka server
environment:
KAFKA_OPTS: "-Djava.security.auth.login.config={{ kafka_conf_dir }}/jaas.cfg"
command: "/usr/local/kafka/bin/kafka-topics.sh \
--create --bootstrap-server {{ kafka_host }}:9092 --replication-factor 3 --partitions 1 --topic {{ topic_name }} \
--command-config {{ kafka_test_client_conf }}"
register: create_topic_result
run_once: yes
- name: Verify topic creation return code
assert:
that:
- create_topic_result.rc == 0
- name: Verify topic creation output
assert:
that:
- "'Created topic {{ topic_name }}' in create_topic_result.stdout"
- name: List topics from the Kafka server
environment:
KAFKA_OPTS: "-Djava.security.auth.login.config={{ kafka_conf_dir }}/jaas.cfg"
command: "/usr/local/kafka/bin/kafka-topics.sh \
--list --bootstrap-server {{ kafka_host }}:9092 \
--command-config {{ kafka_test_client_conf }}"
register: list_topics_result
changed_when: no
- name: Verify topic listing return code
assert:
that:
- list_topics_result.rc == 0
- name: Verify created topic is in topic list
assert:
that:
- "'{{ topic_name }}' in list_topics_result.stdout"
14 changes: 14 additions & 0 deletions molecule/default/verify/jmx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Test JMX connection without authentication
shell: echo "exit" | java -jar /opt/jmxterm.jar -l {{ kafka_jmx_host }}:1099
register: jmx_status_noauth
changed_when: no
failed_when: jmx_status_noauth.rc != 1
- name: Test JMX connection with authentication
shell: echo "exit" | java -jar /opt/jmxterm.jar -l {{ kafka_jmx_host }}:1099 -u jmx -p molecule
register: jmx_status_auth
changed_when: no
- name: Verify JMX connection
assert:
that:
- "'Welcome to JMX terminal' in jmx_status_auth.stderr"
7 changes: 7 additions & 0 deletions molecule/default/verify/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Verify Kafka installation
hosts: kafka
tasks:
- include_tasks: base.yml
- include_tasks: create_topic.yml
- include_tasks: jmx.yml

0 comments on commit 3ce8297

Please sign in to comment.