molecule support

Signed-off-by: Stan Rudenko <stan@truera.com>
This commit is contained in:
Stan Rudenko 2023-08-21 18:44:25 -07:00
parent 50a4c1da4c
commit 83eee4cd08
No known key found for this signature in database
GPG key ID: 959FECBB54B2011C
4 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1,8 @@
---
- name: Run role
hosts: all
any_errors_fatal: true
roles:
- prometheus.prometheus.prometheus
vars:
prometheus_agent_mode: true

View file

@ -0,0 +1 @@
---

View file

@ -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

View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+")
source "$collection_root/tests/integration/molecule.sh"