Skip to content

Commit

Permalink
Merge pull request #197 from gardar/molecule-testinfra
Browse files Browse the repository at this point in the history
skip_changelog: molecule and testinfra cleanup
  • Loading branch information
gardar authored Aug 21, 2023
2 parents 764f6db + 3d817bd commit 255dabc
Show file tree
Hide file tree
Showing 99 changed files with 793 additions and 659 deletions.
3 changes: 3 additions & 0 deletions .config/molecule/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ platforms:
command: /lib/systemd/systemd
verifier:
name: testinfra
provisioner:
playbooks:
converge: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/converge.yml"
8 changes: 8 additions & 0 deletions .config/molecule/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
any_errors_fatal: true
tasks:
- name: "Run role"
ansible.builtin.include_role:
name: "prometheus.prometheus.{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
35 changes: 0 additions & 35 deletions roles/alertmanager/molecule/alternative/converge.yml

This file was deleted.

33 changes: 33 additions & 0 deletions roles/alertmanager/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
---
provisioner:
inventory:
group_vars:
all:
alertmanager_binary_local_dir: '/tmp/alertmanager-linux-amd64'
alertmanager_config_dir: /opt/am/etc
alertmanager_db_dir: /opt/am/lib
alertmanager_web_listen_address: '127.0.0.1:9093'
alertmanager_web_external_url: 'http://localhost:9093/alertmanager'
alertmanager_resolve_timeout: 10m
alertmanager_slack_api_url: "http://example.com"
alertmanager_receivers:
- name: slack
slack_configs:
- send_resolved: true
api_url: 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'
channel: '#alerts'
alertmanager_route:
group_by: ['alertname', 'cluster', 'service']
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: slack
routes:
- match_re:
service: ^(foo1|foo2|baz)$$
receiver: slack
alertmanager_mesh:
listen-address: "127.0.0.1:6783"
peers:
- "127.0.0.1:6783"
- "alertmanager.demo.do.prometheus.io:6783"
version: 0.19.0
8 changes: 3 additions & 5 deletions roles/alertmanager/molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
---
- name: Prepare
- name: Run localhost preparation
hosts: localhost
gather_facts: false
vars:
# Version needs to be specified here as molecule doesn't have access to ansible_version at this stage
version: 0.19.0
tasks:
- name: Download alertmanager binary to local folder
become: false
ansible.builtin.get_url:
url: "https://github.com/prometheus/alertmanager/releases/download/v{{ version }}/alertmanager-{{ version }}.linux-amd64.tar.gz"
url: "https://github.com/prometheus/alertmanager/releases/download/v{{ version\
\ }}/alertmanager-{{ version }}.linux-amd64.tar.gz"
dest: "/tmp/alertmanager-{{ version }}.linux-amd64.tar.gz"
mode: 0644
register: _download_archive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ def test_files(host, files):

def test_service(host):
s = host.service("alertmanager")
# assert s.is_enabled
assert s.is_running
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u alertmanager --since "1 hour ago"')
print("\n==== journalctl -u alertmanager Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


@pytest.mark.parametrize("sockets", [
Expand Down
19 changes: 0 additions & 19 deletions roles/alertmanager/molecule/default/converge.yml

This file was deleted.

16 changes: 16 additions & 0 deletions roles/alertmanager/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
---
provisioner:
inventory:
group_vars:
all:
alertmanager_slack_api_url: "http://example.com"
alertmanager_receivers:
- name: slack
slack_configs:
- send_resolved: true
channel: '#alerts'
alertmanager_route:
group_by: ['alertname', 'cluster', 'service']
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: slack
11 changes: 9 additions & 2 deletions roles/alertmanager/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ def test_files(host, files):

def test_service(host):
s = host.service("alertmanager")
# assert s.is_enabled
assert s.is_running
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u alertmanager --since "1 hour ago"')
print("\n==== journalctl -u alertmanager Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_socket(host):
Expand Down
20 changes: 0 additions & 20 deletions roles/alertmanager/molecule/latest/converge.yml

This file was deleted.

17 changes: 17 additions & 0 deletions roles/alertmanager/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
---
provisioner:
inventory:
group_vars:
all:
alertmanager_version: latest
alertmanager_slack_api_url: "http://example.com"
alertmanager_receivers:
- name: slack
slack_configs:
- send_resolved: true
channel: '#alerts'
alertmanager_route:
group_by: ['alertname', 'cluster', 'service']
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: slack
11 changes: 9 additions & 2 deletions roles/alertmanager/molecule/latest/tests/test_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ def test_files(host, files):

def test_service(host):
s = host.service("alertmanager")
# assert s.is_enabled
assert s.is_running
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u alertmanager --since "1 hour ago"')
print("\n==== journalctl -u alertmanager Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_socket(host):
Expand Down
2 changes: 1 addition & 1 deletion roles/alertmanager/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
group: alertmanager
mode: 0644
validate: "{{ _alertmanager_binary_install_dir }}/amtool check-config %s"
no_log: "{{ 'false' if lookup('env', 'CI') else 'true' }}"
no_log: "{{ false if (lookup('env', 'CI')) or (lookup('env', 'MOLECULE_PROVISIONER_NAME')) else true }}"
notify:
- restart alertmanager

Expand Down
14 changes: 0 additions & 14 deletions roles/blackbox_exporter/molecule/alternative/converge.yml

This file was deleted.

11 changes: 11 additions & 0 deletions roles/blackbox_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
---
provisioner:
inventory:
group_vars:
all:
blackbox_exporter_web_listen_address: "127.0.0.1:9000"
blackbox_exporter_cli_flags:
log.level: "warn"
blackbox_exporter_configuration_modules:
tcp_connect:
prober: tcp
timeout: 5s
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ def test_files(host, files):

def test_service(host):
s = host.service("blackbox_exporter")
assert s.is_running
# assert s.is_enabled
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u blackbox_exporter --since "1 hour ago"')
print("\n==== journalctl -u blackbox_exporter Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_socket(host):
Expand Down
6 changes: 0 additions & 6 deletions roles/blackbox_exporter/molecule/default/converge.yml

This file was deleted.

4 changes: 4 additions & 0 deletions roles/blackbox_exporter/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
---
provisioner:
inventory:
group_vars:
all: {}
11 changes: 9 additions & 2 deletions roles/blackbox_exporter/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ def test_files(host, files):

def test_service(host):
s = host.service("blackbox_exporter")
assert s.is_running
# assert s.is_enabled
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u blackbox_exporter --since "1 hour ago"')
print("\n==== journalctl -u blackbox_exporter Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error


def test_socket(host):
Expand Down
40 changes: 0 additions & 40 deletions roles/chrony_exporter/molecule/alternative/converge.yml

This file was deleted.

20 changes: 20 additions & 0 deletions roles/chrony_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
---
provisioner:
inventory:
group_vars:
all:
chrony_exporter_binary_local_dir: "/tmp/chrony_exporter-linux-amd64"
chrony_exporter_web_listen_address: "127.0.0.1:8080"
chrony_exporter_enabled_collectors:
- sources
chrony_exporter_disabled_collectors:
- tracking

chrony_exporter_tls_server_config:
cert_file: /etc/chrony_exporter/tls.cert
key_file: /etc/chrony_exporter/tls.key
chrony_exporter_http_server_config:
http2: true
chrony_exporter_basic_auth_users:
randomuser: examplepassword
go_arch: amd64
chrony_exporter_version: 0.6.0
Loading

0 comments on commit 255dabc

Please sign in to comment.