Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for Molecule tests #223

Merged
merged 22 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e7614e1
added more tests types in Pipefile
rshad Aug 20, 2019
61625f8
adding new test /molecule/stack
rshad Aug 20, 2019
8bfe42c
deleted a wrong test and stack folder
rshad Aug 21, 2019
0e24c57
fixed communications between containers
rshad Aug 21, 2019
40ab9eb
adapted wazuh-agent test playbook and created run.sh
rshad Aug 21, 2019
65c9785
deleted filebeat test
rshad Aug 21, 2019
defd2ab
added a worker test
rshad Aug 22, 2019
675e2c5
possible solution for ansible variables access and improving Pipefile
rshad Aug 22, 2019
e1b084c
Adding hash_behaviour: merge in order not to override the default var…
rshad Aug 22, 2019
902658b
generalizing .. Adding hash_behaviour: merge in order not to override…
rshad Aug 22, 2019
38d954a
adding execution scenario for elasticsearch test
rshad Aug 22, 2019
3249fd8
adapted testinfra tests for the worker
rshad Aug 22, 2019
76029f9
added vars to default/playbook.yml
rshad Aug 23, 2019
adbf200
fixes for the managers tests and added more tasks in Pipfile
rshad Aug 23, 2019
726a896
adapted kibana test
rshad Aug 23, 2019
ce862ef
made the platform selection dynamic
rshad Aug 23, 2019
a837d8a
made the platform selection dynamic
rshad Aug 23, 2019
3de387b
made the platform selection dynamic ..
rshad Aug 23, 2019
f4e4ed4
automated the selection of a platform - platform restriction
rshad Aug 23, 2019
c54b040
done!
rshad Aug 23, 2019
53d96c1
deleted testing tasks
rshad Aug 23, 2019
234271b
added destroy statements to Pipfile and uncommented idempotence
rshad Aug 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,22 @@ molecule = "==2.20.2"
python_version = "2.7"

[scripts]
test ="molecule test --destroy=never"
worker ="molecule test -s worker --destroy=never"
agent ="molecule test -s wazuh-agent --destroy=never"
elasticsearch ="molecule test -s elasticsearch --destroy=never"
kibana ="molecule test -s kibana --destroy=never"

# Verify ..
verify ="molecule verify"
verify_worker ="molecule verify -s worker"
verify_agent ="molecule verify -s agent"
verify_elasticsearch ="molecule verify -s elasticsearch"
verify_kibana ="molecule verify -s kibana"

# Destroy ..
destroy ="molecule destroy"
test ="molecule test"
agent ="molecule test -s wazuh-agent"
elasticsearch ="molecule test -s elasticsearch"
filebeat ="molecule test -s filebeat"
kibana ="molecule test -s kibana"
destroy_worker ="molecule destroy -s worker"
destroy_agent ="molecule destroy -s agent"
destroy_elasticsearch ="molecule destroy -s elasticsearch"
destroy_kibana ="molecule destroy -s kibana"
14 changes: 9 additions & 5 deletions molecule/default/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@

- name: Create docker network(s)
docker_network:
name: "{{ item }}"
docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}"
name: "main"
state: present
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"

- name: Sleep 5 seconds till the network gets created if it's not
# Pause for 5 minutes to build app cache.
pause:
seconds: 10

- name: Create molecule instance(s)
docker_container:
Expand All @@ -65,7 +68,8 @@
exposed_ports: "{{ item.exposed_ports | default(omit) }}"
published_ports: "{{ item.published_ports | default(omit) }}"
ulimits: "{{ item.ulimits | default(omit) }}"
networks: "{{ item.networks | default(omit) }}"
networks:
- name: "main"
dns_servers: "{{ item.dns_servers | default(omit) }}"
register: server
with_items: "{{ molecule_yml.platforms }}"
Expand All @@ -78,4 +82,4 @@
register: docker_jobs
until: docker_jobs.finished
retries: 300
with_items: "{{ server.results }}"
with_items: "{{ server.results }}"
69 changes: 0 additions & 69 deletions molecule/default/molecule.yml

This file was deleted.

47 changes: 47 additions & 0 deletions molecule/default/molecule.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
enabled: false
platforms:
- name: manager_platform_
image: imagename
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 2048m
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
env:
ANSIBLE_ROLES_PATH: ../../roles
lint:
name: ansible-lint
enabled: true
scenario:
name: default
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- side_effect
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
name: flake8
enabled: true
15 changes: 14 additions & 1 deletion molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@
hosts: all
roles:
- role: wazuh/ansible-wazuh-manager

vars:
wazuh_manager_config:
cluster:
disable: 'no'
name: 'wazuh'
node_name: 'manager'
node_type: 'master'
key: 'ugdtAnd7Pi9myP7CVts4qZaZQEQcRYZa'
port: '1516'
bind_addr: '0.0.0.0'
nodes:
- 'manager_bionic'
hidden: 'no'
- { role: wazuh/ansible-filebeat, filebeat_output_elasticsearch_hosts: 'elasticsearch_bionic:9200' }
19 changes: 19 additions & 0 deletions molecule/default/playbook.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Converge
hosts: all
roles:
- role: wazuh/ansible-wazuh-manager
vars:
wazuh_manager_config:
cluster:
disable: 'no'
name: 'wazuh'
node_name: 'manager'
node_type: 'master'
key: 'ugdtAnd7Pi9myP7CVts4qZaZQEQcRYZa'
port: '1516'
bind_addr: '0.0.0.0'
nodes:
- 'manager_platform'
hidden: 'no'
- { role: wazuh/ansible-filebeat, filebeat_output_elasticsearch_hosts: 'elasticsearch_platform:9200' }
9 changes: 9 additions & 0 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,17 @@ def test_open_ports(host):
"""Test if the main port is open and the agent-auth is not open."""
distribution = host.system_info.distribution.lower()
if distribution == 'ubuntu':
assert host.socket("tcp://0.0.0.0:1516").is_listening
assert host.socket("tcp://0.0.0.0:1515").is_listening
assert host.socket("tcp://0.0.0.0:1514").is_listening
elif distribution == 'centos':
assert host.socket("tcp://0.0.0.0:1516").is_listening
assert host.socket("tcp://127.0.0.1:1515").is_listening
assert host.socket("tcp://127.0.0.1:1514").is_listening


def test_filebeat_is_installed(host):
"""Test if the elasticsearch package is installed."""
filebeat = host.package("filebeat")
assert filebeat.is_installed
assert filebeat.version.startswith('7.2.1')
56 changes: 25 additions & 31 deletions molecule/elasticsearch/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,19 @@ lint:
options:
config-data:
ignore: .virtualenv
platforms:
#- name: bionic
# image: solita/ubuntu-systemd:bionic
# command: /sbin/init
# ulimits:
# - nofile:262144:262144
# privileged: true
# memory_reservation: 2048m
#- name: xenial
# image: solita/ubuntu-systemd:xenial
# privileged: true
# memory_reservation: 2048m
# command: /sbin/init
# ulimits:
# - nofile:262144:262144
#- name: trusty
#image: ubuntu:trusty
#privileged: true
#memory_reservation: 2048m
#ulimits:
#- nofile:262144:262144
#- name: centos6
# image: centos:6
# privileged: true
# memory_reservation: 2048m
# ulimits:
# - nofile:262144:262144
- name: centos7
image: milcom/centos7-systemd
memory_reservation: 2048m
privileged: true
bionics:
- name: elasticsearch_bionic
image: solita/ubuntu-systemd:bionic
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 2048m
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
playbooks:
docker:
create: ../default/create.yml
Expand All @@ -57,6 +35,22 @@ provisioner:
group_vars:
all:
elasticsearch_jvm_xms: 512
scenario:
name: elasticsearch
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
#- idempotence
- side_effect
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
Expand Down
57 changes: 57 additions & 0 deletions molecule/elasticsearch/molecule.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
- name: elasticsearch_platform_
image: imagename
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 2048m
provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
playbooks:
docker:
create: ../default/create.yml
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
env:
ANSIBLE_ROLES_PATH: ../../roles
lint:
name: ansible-lint
enabled: true
inventory:
group_vars:
all:
elasticsearch_jvm_xms: 512
scenario:
name: elasticsearch
test_sequence:
- lint
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- side_effect
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
name: flake8
2 changes: 1 addition & 1 deletion molecule/elasticsearch/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
hosts: all
roles:
- role: elastic-stack/ansible-elasticsearch
elasticsearch_network_host: 'localhost'
elasticsearch_network_host: 'elasticsearch_bionic'
6 changes: 6 additions & 0 deletions molecule/elasticsearch/playbook.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
roles:
- role: elastic-stack/ansible-elasticsearch
elasticsearch_network_host: 'elasticsearch_platform'
Loading