Skip to content

Commit

Permalink
[system-health] Fix issue: show system-health CLI crashes (#2635)
Browse files Browse the repository at this point in the history
- 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 <module>
    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
  • Loading branch information
Junchao-Mellanox committed Jan 30, 2023
1 parent 5782da4 commit 75d233f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion show/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75d233f

Please sign in to comment.