From 2541572566f6aed8ad7326ff77ef644027cb0674 Mon Sep 17 00:00:00 2001 From: Guillaume Mulocher Date: Thu, 10 Oct 2024 15:23:25 +0200 Subject: [PATCH] feat: Log when show version modelName is an empty string (#850) * 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> --- anta/device.py | 4 ++++ tests/units/test_device.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/anta/device.py b/anta/device.py index 35b7f4c04..d7d2b0de2 100644 --- a/anta/device.py +++ b/anta/device.py @@ -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) diff --git a/tests/units/test_device.py b/tests/units/test_device.py index 62c16c9ef..faf614481 100644 --- a/tests/units/test_device.py +++ b/tests/units/test_device.py @@ -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(