Skip to content

Commit 74a70ee

Browse files
authored
Improve errors for lab command and speed up topology builder (#136)
0.2.5 branch
2 parents 9805395 + 4964947 commit 74a70ee

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/evengsdk/cli/lab/commands.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,15 @@ def _get_all_labs(client: EvengClient) -> List:
118118

119119
# Get the lab information from all other folders (non-root)
120120
status.update("Retrieving nested folders...")
121+
122+
# The EVE-NG PRO version shows labs in the root folder and The "Running"
123+
# folder if the lab is running. We need to skip the "Running" folder to
124+
# avoid duplicates.
121125
labs_in_nested_folders = chain(
122-
*thread_executor(_get_lab_folder, (x["name"] for x in root_folders))
126+
*thread_executor(
127+
_get_lab_folder,
128+
(x["name"] for x in root_folders if x["name"] != "Running"),
129+
)
123130
)
124131
# flatten the results to single iterable
125132
# (labs from root folder + labs from nested)
@@ -261,6 +268,10 @@ def topology(ctx, path, output):
261268
"""
262269
client = get_client(ctx)
263270
resp = client.api.get_lab_topology(path)
271+
272+
if not resp.get("data"):
273+
cli_print_error("No Topology information available. Is the lab empty?")
274+
264275
table_header = [
265276
("type", {}),
266277
("source", dict(justify="center", style="cyan", no_wrap=True)),

src/evengsdk/cli/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = "0.2.4"
2+
__version__ = "0.2.5"

src/tests/cli/test_cli_lab.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ def test_lab_list(self):
108108
result = self._run_commands(["lab", "list"])
109109
assert result.exit_code == 0, result.output
110110

111-
@pytest.mark.skip(reason="TODO: fix empty lab raises error")
112-
def test_list_lab_topology(self):
111+
def test_list_lab_empty_topology(self, cli_lab_path):
113112
"""
114113
Arrange/Act: Run the `lab` command with the 'topology' subcommand.
115114
Assert: The output indicates that lab topology is retrieved
116115
successfully.
117116
"""
118-
result = self._run_commands(["lab", "topology"])
119-
assert result.exit_code == 0, result.output
117+
result = self._run_commands(["lab", "topology"], cli_lab_path)
118+
assert result.exit_code > 0
119+
assert "no topology" in result.output.lower()
120120

121121

122122
@pytest.mark.usefixtures("setup_cli_lab")

0 commit comments

Comments
 (0)