mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-10 06:14:13 +00:00
fix: add missing alternative/latest molecule scenarios
Signed-off-by: gardar <gardar@users.noreply.github.com>
This commit is contained in:
parent
457da4282b
commit
02ff0e7219
7 changed files with 208 additions and 0 deletions
28
roles/process_exporter/molecule/alternative/molecule.yml
Normal file
28
roles/process_exporter/molecule/alternative/molecule.yml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
provisioner:
|
||||||
|
inventory:
|
||||||
|
group_vars:
|
||||||
|
all:
|
||||||
|
process_exporter_binary_local_dir: "/tmp/process_exporter-linux-amd64"
|
||||||
|
process_exporter_web_listen_address: "127.0.0.1:8080"
|
||||||
|
process_exporter_tls_server_config:
|
||||||
|
cert_file: /etc/process_exporter/tls.cert
|
||||||
|
key_file: /etc/process_exporter/tls.key
|
||||||
|
process_exporter_http_server_config:
|
||||||
|
http2: true
|
||||||
|
process_exporter_basic_auth_users:
|
||||||
|
randomuser: examplepassword
|
||||||
|
go_arch: amd64
|
||||||
|
process_exporter_version: 0.7.10
|
||||||
|
process_exporter_names: |
|
||||||
|
{% raw %}
|
||||||
|
- name: "{{.Comm}}"
|
||||||
|
cmdline:
|
||||||
|
- systemd
|
||||||
|
- name: "{{.Comm}}"
|
||||||
|
cmdline:
|
||||||
|
- systemd-journald
|
||||||
|
- name: "{{.Comm}}"
|
||||||
|
cmdline:
|
||||||
|
- crond
|
||||||
|
{% endraw %}
|
77
roles/process_exporter/molecule/alternative/prepare.yml
Normal file
77
roles/process_exporter/molecule/alternative/prepare.yml
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
---
|
||||||
|
- name: Run local preparation
|
||||||
|
hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Download process_exporter binary to local folder
|
||||||
|
become: false
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "https://github.com/ncabatoff/process-exporter/releases/download/v{{\
|
||||||
|
\ process_exporter_version }}/process_exporter-{{ process_exporter_version }}.linux-{{\
|
||||||
|
\ go_arch }}.tar.gz"
|
||||||
|
dest: "/tmp/process_exporter-{{ process_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
||||||
|
mode: 0644
|
||||||
|
register: _download_binary
|
||||||
|
until: _download_binary is succeeded
|
||||||
|
retries: 5
|
||||||
|
delay: 2
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Unpack process_exporter binary
|
||||||
|
become: false
|
||||||
|
ansible.builtin.unarchive:
|
||||||
|
src: "/tmp/process_exporter-{{ process_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
||||||
|
dest: "/tmp"
|
||||||
|
creates: "/tmp/process-exporter-{{ process_exporter_version }}.linux-{{ go_arch }}/process-exporter"
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Link to process_exporter binaries directory
|
||||||
|
become: false
|
||||||
|
ansible.builtin.file:
|
||||||
|
src: "/tmp/process-exporter-{{ process_exporter_version }}.linux-amd64"
|
||||||
|
dest: "/tmp/process_exporter-linux-amd64"
|
||||||
|
state: link
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Install pyOpenSSL for certificate generation
|
||||||
|
ansible.builtin.pip:
|
||||||
|
name: "pyOpenSSL"
|
||||||
|
|
||||||
|
- name: Create private key
|
||||||
|
community.crypto.openssl_privatekey:
|
||||||
|
path: "/tmp/tls.key"
|
||||||
|
|
||||||
|
- name: Create CSR
|
||||||
|
community.crypto.openssl_csr:
|
||||||
|
path: "/tmp/tls.csr"
|
||||||
|
privatekey_path: "/tmp/tls.key"
|
||||||
|
|
||||||
|
- name: Create certificate
|
||||||
|
community.crypto.x509_certificate:
|
||||||
|
path: "/tmp/tls.cert"
|
||||||
|
csr_path: "/tmp/tls.csr"
|
||||||
|
privatekey_path: "/tmp/tls.key"
|
||||||
|
provider: selfsigned
|
||||||
|
|
||||||
|
- name: Run target preparation
|
||||||
|
hosts: all
|
||||||
|
any_errors_fatal: true
|
||||||
|
tasks:
|
||||||
|
- name: Create process_exporter cert dir
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ process_exporter_tls_server_config.cert_file | dirname }}"
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: u+rwX,g+rwX,o=rX
|
||||||
|
|
||||||
|
- name: Copy cert and key
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ item.src }}"
|
||||||
|
dest: "{{ item.dest }}"
|
||||||
|
mode: "{{ item.mode | default('0644') }}"
|
||||||
|
loop:
|
||||||
|
- src: "/tmp/tls.cert"
|
||||||
|
dest: "{{ process_exporter_tls_server_config.cert_file }}"
|
||||||
|
- src: "/tmp/tls.key"
|
||||||
|
dest: "{{ process_exporter_tls_server_config.key_file }}"
|
|
@ -0,0 +1,46 @@
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
|
def test_directories(host):
|
||||||
|
dirs = [
|
||||||
|
"/var/lib/process_exporter"
|
||||||
|
]
|
||||||
|
for dir in dirs:
|
||||||
|
d = host.file(dir)
|
||||||
|
assert not d.exists
|
||||||
|
|
||||||
|
|
||||||
|
def test_service(host):
|
||||||
|
s = host.service("process_exporter")
|
||||||
|
try:
|
||||||
|
assert s.is_running
|
||||||
|
except AssertionError:
|
||||||
|
# Capture service logs
|
||||||
|
journal_output = host.run('journalctl -u process_exporter --since "1 hour ago"')
|
||||||
|
print("\n==== journalctl -u process_exporter Output ====\n")
|
||||||
|
print(journal_output)
|
||||||
|
print("\n============================================\n")
|
||||||
|
raise # Re-raise the original assertion error
|
||||||
|
|
||||||
|
|
||||||
|
def test_protecthome_property(host):
|
||||||
|
s = host.service("process_exporter")
|
||||||
|
p = s.systemd_properties
|
||||||
|
assert p.get("ProtectHome") == "yes"
|
||||||
|
|
||||||
|
|
||||||
|
def test_socket(host):
|
||||||
|
sockets = [
|
||||||
|
"tcp://127.0.0.1:8080"
|
||||||
|
]
|
||||||
|
for socket in sockets:
|
||||||
|
s = host.socket(socket)
|
||||||
|
assert s.is_listening
|
6
roles/process_exporter/molecule/latest/molecule.yml
Normal file
6
roles/process_exporter/molecule/latest/molecule.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
provisioner:
|
||||||
|
inventory:
|
||||||
|
group_vars:
|
||||||
|
all:
|
||||||
|
process_exporter_version: latest
|
43
roles/process_exporter/molecule/latest/tests/test_latest.py
Normal file
43
roles/process_exporter/molecule/latest/tests/test_latest.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("files", [
|
||||||
|
"/etc/systemd/system/process_exporter.service",
|
||||||
|
"/usr/local/bin/process_exporter"
|
||||||
|
])
|
||||||
|
def test_files(host, files):
|
||||||
|
f = host.file(files)
|
||||||
|
assert f.exists
|
||||||
|
assert f.is_file
|
||||||
|
|
||||||
|
|
||||||
|
def test_service(host):
|
||||||
|
s = host.service("process_exporter")
|
||||||
|
try:
|
||||||
|
assert s.is_running
|
||||||
|
except AssertionError:
|
||||||
|
# Capture service logs
|
||||||
|
journal_output = host.run('journalctl -u process_exporter --since "1 hour ago"')
|
||||||
|
print("\n==== journalctl -u process_exporter Output ====\n")
|
||||||
|
print(journal_output)
|
||||||
|
print("\n============================================\n")
|
||||||
|
raise # Re-raise the original assertion error
|
||||||
|
|
||||||
|
|
||||||
|
def test_protecthome_property(host):
|
||||||
|
s = host.service("process_exporter")
|
||||||
|
p = s.systemd_properties
|
||||||
|
assert p.get("ProtectHome") == "read-only"
|
||||||
|
|
||||||
|
|
||||||
|
def test_socket(host):
|
||||||
|
s = host.socket("tcp://0.0.0.0:9256")
|
||||||
|
assert s.is_listening
|
4
tests/integration/targets/molecule-process_exporter-alternative/runme.sh
Executable file
4
tests/integration/targets/molecule-process_exporter-alternative/runme.sh
Executable 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"
|
4
tests/integration/targets/molecule-process_exporter-latest/runme.sh
Executable file
4
tests/integration/targets/molecule-process_exporter-latest/runme.sh
Executable 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"
|
Loading…
Reference in a new issue