-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add var promtail_binary_local_dir (#104)
Co-authored-by: Patrick Jahns <[email protected]>
- Loading branch information
1 parent
787b979
commit aa512cd
Showing
10 changed files
with
181 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
molecule/scenario_with_local_binary_directory/molecule.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
lint: | | ||
set -e | ||
yamllint . | ||
flake8 | ||
platforms: | ||
- name: instance | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
privileged: true | ||
cgroupns_mode: host | ||
pre_build_image: true | ||
|
||
provisioner: | ||
name: ansible | ||
playbooks: | ||
converge: playbook.yml | ||
inventory: | ||
group_vars: | ||
python3: | ||
ansible_python_interpreter: /usr/bin/python3 | ||
scenario: | ||
name: scenario_with_local_binary_directory | ||
verifier: | ||
name: testinfra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- hosts: all | ||
any_errors_fatal: true | ||
#become: true | ||
roles: | ||
- role: ansible-role-promtail | ||
vars: | ||
promtail_version: "2.7.3" | ||
promtail_binary_local_dir: "/tmp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
- name: Prepare | ||
hosts: all | ||
gather_facts: true | ||
vars: | ||
promtail_version: "2.7.3" | ||
promtail_binary_local_dir: "/tmp" | ||
go_arch_map: | ||
x86_64: 'amd64' | ||
aarch64: 'arm64' | ||
armv7l: 'arm' | ||
armv6l: 'arm' | ||
go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}" | ||
|
||
tasks: | ||
- name: Ensure that net-tools is available | ||
package: | ||
name: net-tools | ||
state: present | ||
when: ansible_os_family == 'RedHat' | ||
- name: Download zip archive on controler | ||
get_url: | ||
url: "https://github.com/grafana/loki/releases/download/v{{ promtail_version }}/promtail-linux-{{ go_arch }}.zip" | ||
dest: "/tmp/{{ promtail_version }}_promtail-linux-{{ go_arch }}.zip" | ||
force: True | ||
delegate_to: localhost |
23 changes: 23 additions & 0 deletions
23
molecule/scenario_with_local_binary_directory/tests/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""PyTest Fixtures.""" | ||
from __future__ import absolute_import | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
|
||
def pytest_runtest_setup(item): | ||
"""Run tests only when under molecule with testinfra installed.""" | ||
try: | ||
import testinfra | ||
except ImportError: | ||
pytest.skip("Test requires testinfra", allow_module_level=True) | ||
if "MOLECULE_INVENTORY_FILE" in os.environ: | ||
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ["MOLECULE_INVENTORY_FILE"] | ||
).get_hosts("all") | ||
else: | ||
pytest.skip( | ||
"Test should run only from inside molecule.", | ||
allow_module_level=True | ||
) |
54 changes: 54 additions & 0 deletions
54
...e/scenario_with_local_binary_directory/tests/test_scenario_with_local_binary_directory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import pytest | ||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') | ||
|
||
|
||
@pytest.mark.parametrize("dir", [ | ||
"/opt/promtail", | ||
"/etc/promtail", | ||
"/etc/promtail/file_sd", | ||
"/var/lib/promtail", | ||
]) | ||
def test_directories(host, dir): | ||
d = host.file(dir) | ||
assert d.is_directory | ||
assert d.exists | ||
|
||
|
||
@pytest.mark.parametrize("files", [ | ||
"/etc/systemd/system/promtail.service", | ||
"/usr/local/bin/promtail", | ||
"/etc/promtail/promtail.yml" | ||
]) | ||
def test_files(host, files): | ||
f = host.file(files) | ||
assert f.exists | ||
assert f.is_file | ||
|
||
|
||
def test_user(host): | ||
assert host.group("promtail").exists | ||
assert host.user("promtail").exists | ||
|
||
|
||
def test_service(host): | ||
s = host.service("promtail") | ||
assert s.is_running | ||
|
||
|
||
def test_http_socket(host): | ||
s = host.socket("tcp://0.0.0.0:9080") | ||
assert s.is_listening | ||
|
||
|
||
def test_grpc_socket(host): | ||
s = host.socket("tcp://0.0.0.0:9095") | ||
assert s.is_listening | ||
|
||
|
||
def test_version(host): | ||
result = host.run("/usr/local/bin/promtail --version") | ||
assert result.rc == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters