diff --git a/roles/prometheus/molecule/agentmode/converge.yml b/roles/prometheus/molecule/agentmode/converge.yml new file mode 100644 index 00000000..b3520e80 --- /dev/null +++ b/roles/prometheus/molecule/agentmode/converge.yml @@ -0,0 +1,8 @@ +--- +- name: Run role + hosts: all + any_errors_fatal: true + roles: + - prometheus.prometheus.prometheus + vars: + prometheus_agent_mode: true diff --git a/roles/prometheus/molecule/agentmode/molecule.yml b/roles/prometheus/molecule/agentmode/molecule.yml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/roles/prometheus/molecule/agentmode/molecule.yml @@ -0,0 +1 @@ +--- diff --git a/roles/prometheus/molecule/agentmode/tests/test_default.py b/roles/prometheus/molecule/agentmode/tests/test_default.py new file mode 100644 index 00000000..ce2d54dc --- /dev/null +++ b/roles/prometheus/molecule/agentmode/tests/test_default.py @@ -0,0 +1,44 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import yaml +import testinfra.utils.ansible_runner +import pytest + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +@pytest.fixture() +def AnsibleDefaults(): + with open("defaults/main.yml", 'r') as stream: + return yaml.full_load(stream) + + +@pytest.mark.parametrize('file, content', [ + ("/etc/systemd/system/prometheus.service", + "storage.agent.path=/var/lib/prometheus"), + ("/etc/systemd/system/prometheus.service", + "enable-feature=agent"), +]) +def test_file_contents(host, file, content): + f = host.file(file) + assert f.exists + assert f.is_file + assert f.contains(content) + + +def test_service(host): + s = host.service("prometheus") + assert s.is_running + + +# # "/agent" page is available (http 200) when agent mode is enabled +def test_agent_enabled(host): + output = host.check_output('curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:9090/agent') + assert '200' in output + +def test_socket(host): + s = host.socket("tcp://0.0.0.0:9090") + assert s.is_listening diff --git a/tests/integration/targets/molecule-prometheus-agentmode/runme.sh b/tests/integration/targets/molecule-prometheus-agentmode/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-prometheus-agentmode/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh"