Skip to content

Commit

Permalink
Add test for custom environment file
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkaholic committed Jun 11, 2020
1 parent 4265f62 commit 7c0f178
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Kafka heavily depends on zookeeper which is not part of this role. To install zo

## Role Variables

Available variables listed and described along with default values in `defaults/main.yml`.
Available variables listed and described along with default values in [defaults/main.yml](defaults/main.yml).

## Dependencies

Expand All @@ -27,7 +27,8 @@ Available variables listed and described along with default values in `defaults/

## Set up monitoring for Kafka

For enabling monitoring via JMX you have to create an environment file and set the environment variables used in the kafka startup script like this:
For enabling monitoring via JMX you have to create an environment file and set the environment variables used in the kafka startup script
according to your needs:

```
JMX_PORT=1099
Expand All @@ -42,6 +43,8 @@ This file needs to be referenced in the `kafka_environment_file` then. Here is a
vars:
kafka_environment_file: /etc/kafka/custom.env

An overview of the variables used by Kafka can be found in the [Kafka startup script](https://github.com/apache/kafka/blob/trunk/bin/kafka-run-class.sh).

## Development

Use [docker-molecule](https://github.com/nl2go/docker-molecule) following the instructions to run [Molecule](https://molecule.readthedocs.io/en/stable/)
Expand Down
12 changes: 12 additions & 0 deletions molecule/custom_environment/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Cleanup test resources
hosts: localhost
tasks:
- name: Stop zookeeper container
docker_container:
name: zookeeper
image: confluentinc/cp-zookeeper:5.5.0
state: stopped
purge_networks: yes
delegate_to: localhost
run_once: true
8 changes: 8 additions & 0 deletions molecule/custom_environment/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Configure hosts
hosts: all
become: yes
roles:
- role: ansible-role-kafka
vars:
kafka_environment_file: /etc/kafka/molecule.env
34 changes: 34 additions & 0 deletions molecule/custom_environment/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
driver:
name: docker
lint: |
set -e
yamllint .
platforms:
- name: ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
networks:
- name: kafka-network
provisioner:
name: ansible
lint: |
set -e
ansible-lint
inventory:
group_vars:
all:
kafka_version: 2.5.0
host_vars:
ubuntu18:
kafka_zookeeper_connection_hosts:
- zookeeper:2181
verifier:
name: ansible
lint: |
set -e
ansible-lint
dependency:
name: galaxy
options:
role-file: molecule/resources/requirements.yml
45 changes: 45 additions & 0 deletions molecule/custom_environment/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- name: Install required roles
hosts: all
roles:
- nl2go.openjdk
tasks:
- name: Prepare docker systemctl replacement script
get_url:
url: https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py
dest: /usr/bin/systemctl
mode: '0775'
- name: Start zookeeper container
docker_container:
name: zookeeper
image: confluentinc/cp-zookeeper:5.5.0
env:
ZOOKEEPER_CLIENT_PORT: "2181"
ZOOKEEPER_TICK_TIME: "2000"
networks:
- name: kafka-network
delegate_to: localhost
run_once: true
- name: Install additional packages needed for testing
apt:
name:
- net-tools
- procps
- name: Set JMX_PORT environment variable
lineinfile:
path: /etc/kafka/molecule.env
regexp: '^JMX_PORT='
line: JMX_PORT=1099
create: yes
- name: Set KAFKA_JMX_OPTS environment variable
lineinfile:
path: /etc/kafka/molecule.env
regexp: '^KAFKA_JMX_OPTS='
line: 'KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"'
create: yes
- name: Set KAFKA_HEAP_OPTS environment variable
lineinfile:
path: /etc/kafka/molecule.env
regexp: '^KAFKA_HEAP_OPTS='
line: 'KAFKA_HEAP_OPTS="-Xmx192M"'
create: yes
17 changes: 17 additions & 0 deletions molecule/custom_environment/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Verify kafka installation
hosts: all
tasks:
- 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: Verify JMX port is in listening ports
assert:
that:
- 1099 in tcp_ports
2 changes: 1 addition & 1 deletion tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
state: present
createhome: no

- name: set kafka_archive_name variable
- name: Set kafka_archive_name variable
set_fact:
kafka_archive_name: "kafka_{{ kafka_scala_version }}-{{ kafka_version }}"

Expand Down

0 comments on commit 7c0f178

Please sign in to comment.