Skip to content

Commit

Permalink
feat: Log when show version modelName is an empty string (#850)
Browse files Browse the repository at this point in the history
* Feat: Log when show version modelName is an empty string

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
gmuloc and pre-commit-ci[bot] authored Oct 10, 2024
1 parent 42476d9 commit 2541572
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions anta/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ async def refresh(self) -> None:
self.hw_model = show_version.json_output.get("modelName", None)
if self.hw_model is None:
logger.critical("Cannot parse 'show version' returned by device %s", self.name)
# in some cases it is possible that 'modelName' comes back empty
# and it is nice to get a meaninfule error message
elif self.hw_model == "":
logger.critical("Got an empty 'modelName' in the 'show version' returned by device %s", self.name)
else:
logger.warning("Could not connect to device %s: cannot open eAPI port", self.name)

Expand Down
16 changes: 16 additions & 0 deletions tests/units/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,22 @@
{"is_online": True, "established": False, "hw_model": None},
id="httpx.ConnectError",
),
pytest.param(
{},
(
{"return_value": True},
{
"return_value": [
{
"mfgName": "Arista",
"modelName": "",
}
]
},
),
{"is_online": True, "established": False, "hw_model": ""},
id="modelName empty string",
),
]
COLLECT_PARAMS: list[ParameterSet] = [
pytest.param(
Expand Down

0 comments on commit 2541572

Please sign in to comment.