10000 fix(anta.cli): Print multiple messages for anta nrfu text by gmuloc · Pull Request #897 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(anta.cli): Print multiple messages for anta nrfu text #897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions anta/cli/nrfu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ def print_text(ctx: click.Context) -> None:
"""Print results as simple text."""
console.print()
for test in _get_result_manager(ctx).results:
message = f" ({test.messages[0]!s})" if len(test.messages) > 0 else ""
console.print(f"{test.name} :: {test.test} :: [{test.result}]{test.result.upper()}[/{test.result}]{message}", highlight=False)
if len(test.messages) <= 1:
message = test.messages[0] if len(test.messages) == 1 else ""
console.print(f"{test.name} :: {test.test} :: [{test.result}]{test.result.upper()}[/{test.result}]({message})", highlight=False)
else: # len(test.messages) > 1
console.print(f"{test.name} :: {test.test} :: [{test.result}]{test.result.upper()}[/{test.result}]", highlight=False)
console.print("\n".join(f" {message}" for message in test.messages), highlight=False)


def print_jinja(results: ResultManager, template: pathlib.Path, output: pathlib.Path | None = None) -> None:
Expand Down
13 changes: 13 additions & 0 deletions tests/data/test_catalog_double_failure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
anta.tests.interfaces:
- VerifyInterfacesSpeed:
interfaces:
- name: Ethernet2
auto: False
speed: 10
- name: Ethernet3
auto: True
speed: 100
- name: Ethernet4
auto: False
speed: 2.5
1 change: 1 addition & 0 deletions tests/units/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
errmsg="Invalid command",
not_exec=[],
),
"show interfaces": {},
}

MOCK_CLI_TEXT: dict[str, asynceapi.EapiCommandError | str] = {
Expand Down
13 changes: 13 additions & 0 deletions tests/units/cli/nrfu/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ def test_anta_nrfu_text(click_runner: CliRunner) -> None:
assert "leaf1 :: VerifyEOSVersion :: SUCCESS" in result.output


def test_anta_nrfu_text_multiple_failures(click_runner: CliRunner) -> None:
"""Test anta nrfu text with multiple failures, catalog is given via env."""
result = click_runner.invoke(anta, ["nrfu", "text"], env={"ANTA_CATALOG": str(DATA_DIR / "test_catalog_double_failure.yml")})
assert result.exit_code == ExitCode.OK
assert (
"""spine1 :: VerifyInterfacesSpeed :: FAILURE
Interface `Ethernet2` is not found.
Interface `Ethernet3` is not found.
Interface `Ethernet4` is not found."""
in result.output
)


def test_anta_nrfu_json(click_runner: CliRunner) -> None:
"""Test anta nrfu, catalog is given via env."""
result = click_runner.invoke(anta, ["nrfu", "json"])
Expand Down
0