From 75d233fef15f36744785b6e1a7aa0f277c339603 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Tue, 31 Jan 2023 02:15:01 +0800 Subject: [PATCH] [system-health] Fix issue: show system-health CLI crashes (#2635) - What I did Fix issue: show system-health CLI crashes root@switch:/home/admin# show system-health summary Traceback (most recent call last): File "/usr/local/bin/show", line 8, in sys.exit(cli()) File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 764, in __call__ return self.main(*args, **kwargs) File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/usr/local/lib/python3.9/dist-packages/show/system_health.py", line 113, in summary _, chassis, stat = get_system_health_status() File "/usr/local/lib/python3.9/dist-packages/show/system_health.py", line 10, in get_system_health_status if os.environ["UTILITIES_UNIT_TESTING"] == "1": File "/usr/lib/python3.9/os.py", line 679, in __getitem__ raise KeyError(key) from None KeyError: 'UTILITIES_UNIT_TESTING' - How I did it Use dict.get instead of [] operator. - How to verify it Manual test --- show/system_health.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/system_health.py b/show/system_health.py index a97214e76a..08e9e70594 100644 --- a/show/system_health.py +++ b/show/system_health.py @@ -7,7 +7,7 @@ def get_system_health_status(): - if os.environ["UTILITIES_UNIT_TESTING"] == "1": + if os.environ.get("UTILITIES_UNIT_TESTING") == "1": modules_path = os.path.join(os.path.dirname(__file__), "..") sys.path.insert(0, modules_path) from tests.system_health_test import MockerManager