Skip to content

Commit

Permalink
Refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
Deezzir committed Sep 13, 2024
1 parent 439376e commit 60bdf85
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# so users can see available options by running
# `sudo snap get dcgm`.
if [ -z "$(snapctl get nv-hostengine-port)" ]; then
# Setting to empty string for the nv-hostengine binary to use the default port. (5555)
snapctl set nv-hostengine-port=""
fi

if [ -z "$(snapctl get dcgm-exporter-address)" ]; then
# Setting to empty string for the dcgm-exporter binary to use the default address. (:9400)
snapctl set dcgm-exporter-address=""
fi
2 changes: 1 addition & 1 deletion snap/local/run_dcgm_exporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
# Build the argument list for the dcgm-exporter command
args=()

# Add the dcgm-exporter-port option if it is set. Default: “:9400”
# Add the dcgm-exporter-address option if it is set. Default: “:9400”
dcgm_exporter_address="$(snapctl get dcgm-exporter-address)"

if [ -n "$dcgm_exporter_address" ]; then
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import subprocess

import pytest
from tenacity import retry, stop_after_delay, wait_fixed


@retry(wait=wait_fixed(5), stop=stop_after_delay(20))
def check_dcgm_exporter_service():
dcgm_exporter_service = "dcgm.dcgm-exporter"

result = subprocess.run(
f"sudo snap services {dcgm_exporter_service}".split(),
check=True,
capture_output=True,
text=True,
)
assert " active" in result.stdout.strip(), f"{dcgm_exporter_service} service is not active"


@pytest.fixture(scope="session", autouse=True)
Expand All @@ -15,6 +29,9 @@ def install_dcgm_snap():
shell=True,
)

subprocess.run("sudo snap start dcgm.dcgm-exporter".split(), check=True)
check_dcgm_exporter_service()

yield

subprocess.run("sudo snap remove --purge dcgm".split(), check=True)
4 changes: 2 additions & 2 deletions tests/functional/requirments.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tenacity==9.0.0
pyyaml==6.0.2
tenacity
pyyaml
17 changes: 3 additions & 14 deletions tests/functional/test_snap_dcgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,10 @@
from tenacity import retry, stop_after_delay, wait_fixed


@retry(wait=wait_fixed(5), stop=stop_after_delay(15))
@retry(wait=wait_fixed(5), stop=stop_after_delay(30))
def test_dcgm_exporter():
"""Test of the dcgm-exporter service and its endpoint."""
endpoint = "http://localhost:9400/metrics"
dcgm_exporter_service = "dcgm.dcgm-exporter"

subprocess.run(f"sudo snap start {dcgm_exporter_service}".split(), check=True)

result = subprocess.run(
f"sudo snap services {dcgm_exporter_service}".split(),
check=True,
capture_output=True,
text=True,
)
assert " active" in result.stdout.strip(), "dcgm-exporter service is not active"

# Check the exporter endpoint, will raise an exception if the endpoint is not reachable
urllib.request.urlopen(endpoint)
Expand All @@ -37,7 +26,7 @@ def test_dcgm_nv_hostengine():
text=True,
)

assert " active" in service.stdout.strip(), "nv-hostengine service is not active"
assert " active" in service.stdout.strip(), f"{nv_hostengine_service} service is not active"


def test_dcgmi():
Expand All @@ -48,7 +37,7 @@ def test_dcgmi():
assert "GPU ID" in result.stdout.strip(), "DCGMI is not working"


def test_dcgm_port_configs():
def test_dcgm_bind_configs():
"""Test snap port configuratin."""
services = ["dcgm.dcgm-exporter", "dcgm.nv-hostengine"]
configs = ["dcgm-exporter-address", "nv-hostengine-port"]
Expand Down

0 comments on commit 60bdf85

Please sign in to comment.