Skip to content

Commit f14330c

Browse files
authored
Revert "Simple 7407 diagnostics in client" (#137)
* Revert "Fixed get_diagnostics (error handling, fixed endpoint construction). Added new unit tests." This reverts commit f4f5e8f. * Revert "Updated get_diagnostics method to use new endpoints. Returning either selected ones or all by default." This reverts commit 0822b26.
1 parent f4f5e8f commit f14330c

File tree

2 files changed

+11
-75
lines changed

2 files changed

+11
-75
lines changed

tests/test_client_library.py

-39
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from virl2_client.virl2_client import (
3434
ClientConfig,
3535
ClientLibrary,
36-
DiagnosticCategory,
3736
InitializationError,
3837
Version,
3938
)
@@ -740,41 +739,3 @@ def test_convergence_parametrization(client_library_server_current, mocked_sessi
740739
with pytest.raises(RuntimeError) as err:
741740
lab.wait_until_lab_converged(max_iterations=1)
742741
assert ("has not converged, maximum tries %s exceeded" % 1) in err.value.args[0]
743-
744-
745-
@pytest.mark.parametrize(
746-
"categories, expected_paths",
747-
[
748-
(None, [diag.value for diag in DiagnosticCategory]),
749-
([DiagnosticCategory.COMPUTES], [DiagnosticCategory.COMPUTES.value]),
750-
(
751-
[DiagnosticCategory.LABS, DiagnosticCategory.SERVICES],
752-
[DiagnosticCategory.LABS.value, DiagnosticCategory.SERVICES.value],
753-
),
754-
],
755-
)
756-
def test_get_diagnostics_paths(client_library, categories, expected_paths):
757-
with respx.mock(base_url="https://0.0.0.0/api/v0/") as respx_mock:
758-
for path in expected_paths:
759-
respx_mock.get(f"diagnostics/{path}").mock(
760-
return_value=httpx.Response(200, json={"data": "sample"})
761-
)
762-
diagnostics_data = client_library.get_diagnostics(categories=categories)
763-
for path in expected_paths:
764-
assert path in diagnostics_data
765-
assert diagnostics_data[path] == {"data": "sample"}
766-
767-
768-
def test_get_diagnostics_error_handling(client_library):
769-
with respx.mock(base_url="https://0.0.0.0/api/v0/") as respx_mock:
770-
for diag_type in DiagnosticCategory:
771-
respx_mock.get(f"diagnostics/{diag_type.value}").mock(
772-
return_value=httpx.Response(404)
773-
)
774-
775-
diagnostics_data = client_library.get_diagnostics()
776-
777-
for diag_type in DiagnosticCategory:
778-
assert diagnostics_data[diag_type.value] == {
779-
"error": f"Failed to fetch {diag_type.value} diagnostics"
780-
}

virl2_client/virl2_client.py

+11-36
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import os
2525
import re
2626
import time
27-
from enum import Enum
2827
from functools import lru_cache
2928
from pathlib import Path
3029
from threading import RLock
@@ -163,18 +162,6 @@ def make_client(self) -> ClientLibrary:
163162
return client
164163

165164

166-
class DiagnosticCategory(Enum):
167-
COMPUTES = "computes"
168-
LABS = "labs"
169-
LAB_EVENTS = "lab_events"
170-
NODE_LAUNCH_QUEUE = "node_launch_queue"
171-
SERVICES = "services"
172-
NODE_DEFINITIONS = "node_definitions"
173-
USER_LIST = "user_list"
174-
LICENSING = "licensing"
175-
STARTUP_SCHEDULER = "startup_scheduler"
176-
177-
178165
class ClientLibrary:
179166
"""Python bindings for the REST API of a CML controller."""
180167

@@ -207,7 +194,7 @@ class ClientLibrary:
207194
"labs": "labs",
208195
"lab": "labs/{lab_id}",
209196
"lab_topology": "labs/{lab_id}/topology",
210-
"diagnostics": "diagnostics/{category}",
197+
"diagnostics": "diagnostics",
211198
"system_health": "system_health",
212199
"system_stats": "system_stats",
213200
"populate_lab_tiles": "populate_lab_tiles",
@@ -639,11 +626,16 @@ def all_labs(self, show_all: bool = False) -> list[Lab]:
639626
:param show_all: Whether to get only labs owned by the admin or all user labs.
640627
:returns: A list of Lab objects.
641628
"""
642-
lab_ids = self.get_lab_list(show_all=show_all)
629+
url = {"url": self._url_for("labs")}
630+
if show_all:
631+
url["params"] = {"show_all": True}
632+
lab_ids = self._session.get(**url).json()
633+
643634
result = []
644635
for lab_id in lab_ids:
645636
lab = self.join_existing_lab(lab_id)
646637
result.append(lab)
638+
647639
return result
648640

649641
@locked
@@ -818,31 +810,14 @@ def join_existing_lab(self, lab_id: str, sync_lab: bool = True) -> Lab:
818810
self._labs[lab_id] = lab
819811
return lab
820812

821-
def get_diagnostics(
822-
self, categories: list[DiagnosticCategory] | None = None
823-
) -> dict:
813+
def get_diagnostics(self) -> dict:
824814
"""
825-
Return selected diagnostic data as a JSON object.
815+
Return the controller diagnostic data as a JSON object.
826816
827-
:param categories: List of diagnostic categories to fetch. If None, fetch all.
828817
:returns: The diagnostic data.
829818
"""
830-
if categories is None:
831-
categories = list(DiagnosticCategory)
832-
833-
diagnostics_data = {}
834-
for category in categories:
835-
value = category.value
836-
url = self._url_for("diagnostics", category=value)
837-
try:
838-
response = self._session.get(url)
839-
response.raise_for_status()
840-
diagnostics_data[value] = response.json()
841-
except httpx.HTTPStatusError:
842-
diagnostics_data[value] = {
843-
"error": f"Failed to fetch {value} diagnostics"
844-
}
845-
return diagnostics_data
819+
url = self._url_for("diagnostics")
820+
return self._session.get(url).json()
846821

847822
def get_system_health(self) -> dict:
848823
"""

0 commit comments

Comments
 (0)