Skip to content

Commit

Permalink
Fix more failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Feb 24, 2024
1 parent 4132574 commit d6e7e2f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@

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 = []
for dir in dirs:
d = host.file(dir)
assert not d.exists


# def test_service(host):
# s = host.service("dcgm_exporter")
# try:
# assert s.is_running
# except AssertionError:
# # Capture service logs
# journal_output = host.run('journalctl -u dcgm_exporter --since "1 hour ago"')
# print("\n==== journalctl -u dcgm_exporter Output ====\n")
# print(journal_output)
# print("\n============================================\n")
# raise # Re-raise the original assertion error
@pytest.mark.parametrize("dir", [
"/etc/dcgm_exporter",
])
def test_directories(host, dir):
d = host.file(dir)
assert d.is_directory
assert d.exists


@pytest.mark.parametrize("file", [
"/etc/systemd/system/dcgm_exporter.service",
"/usr/local/bin/dcgm_exporter",
"/etc/dcgm_exporter/counters.csv",
"/etc/dcgm_exporter/config.yaml",
])
def test_files(host, file):
f = host.file(file)
assert f.exists
assert f.is_file


def test_protecthome_property(host):
Expand Down
81 changes: 33 additions & 48 deletions roles/nvidia_dcgm_exporter/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,44 @@

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 = [
"/etc/dcgm_exporter"
]
for dir in dirs:
d = host.file(dir)
assert d.is_directory
assert d.exists


def test_files(host):
files = [
"/etc/systemd/system/dcgm_exporter.service",
"/usr/local/bin/dcgm_exporter",
"/etc/dcgm_exporter/counters.csv"
]
for file in files:
f = host.file(file)
assert f.exists
assert f.is_file


def test_permissions_didnt_change(host):
dirs = [
"/etc",
"/root",
"/usr",
"/var"
]
for file in dirs:
f = host.file(file)
assert f.exists
assert f.is_directory
assert f.user == "root"
assert f.group == "root"
@pytest.mark.parametrize("dir", [
"/etc/dcgm_exporter",
])
def test_directories(host, dir):
d = host.file(dir)
assert d.is_directory
assert d.exists


@pytest.mark.parametrize("file", [
"/etc/systemd/system/dcgm_exporter.service",
"/usr/local/bin/dcgm_exporter",
"/etc/dcgm_exporter/counters.csv"
])
def test_files(host, file):
f = host.file(file)
assert f.exists
assert f.is_file


@pytest.mark.parametrize("dir", [
"/etc",
"/root",
"/usr",
"/var",
])
def test_permissions_didnt_change(host, dir):
f = host.file(dir)
assert f.exists
assert f.is_directory
assert f.user == "root"
assert f.group == "root"


def test_user(host):
Expand All @@ -52,19 +50,6 @@ def test_user(host):
assert host.user("dcgmexp").home == "/"


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


def test_protecthome_property(host):
s = host.service("dcgm_exporter")
p = s.systemd_properties
Expand Down
35 changes: 9 additions & 26 deletions roles/nvidia_dcgm_exporter/molecule/latest/tests/test_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


@pytest.mark.parametrize("dir", [
"/etc/dcgm_exporter",
])
def test_directories(host, dir):
d = host.file(dir)
assert d.is_directory
assert d.exists


@pytest.mark.parametrize("files", [
"/etc/systemd/system/dcgm_exporter.service",
"/usr/local/bin/dcgm_exporter"
Expand All @@ -17,29 +26,3 @@ def test_files(host, files):
f = host.file(files)
assert f.exists
assert f.is_file


def test_directories(host):
dirs = []
for dir in dirs:
d = host.file(dir)
assert d.is_directory
assert d.exists


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


# def test_socket(host):
# s = host.socket("tcp://0.0.0.0:9010")
# assert s.is_listening
5 changes: 4 additions & 1 deletion roles/nvidia_dcgm_exporter/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
when: dcgm_exporter_system_user != "root"

- name: Get binary
run_once: true
when:
- dcgm_exporter_binary_local_dir | length == 0
- not dcgm_exporter_skip_install
Expand All @@ -27,6 +26,7 @@
block:
- name: Download golang to local folder
become: false
run_once: true
ansible.builtin.get_url:
url: "{{ _golang_download_url }}"
dest: /tmp/golang-{{ golang_version }}.linux-{{ go_arch }}.tar.gz
Expand All @@ -40,6 +40,7 @@

- name: Unpack golang
become: false
run_once: true
ansible.builtin.unarchive:
src: /tmp/golang-{{ golang_version }}.linux-{{ go_arch }}.tar.gz
dest: /tmp
Expand All @@ -49,6 +50,7 @@

- name: Clone dcgm_exporter repository to local folder
become: false
run_once: true
ansible.builtin.git:
repo: "{{ dcgm_exporter_git_url }}"
dest: /tmp/dcgm_exporter
Expand All @@ -58,6 +60,7 @@

- name: Compile dcgm-exporter binary
become: false
run_once: true
community.general.make:
chdir: /tmp/dcgm_exporter
target: binary
Expand Down

0 comments on commit d6e7e2f

Please sign in to comment.