Skip to content

Commit

Permalink
[show] fix show version (sonic-net#1686)
Browse files Browse the repository at this point in the history
#### What I did
Fix `NameError` from `show version`.
```
admin@str2-7050cx3-acs-02:~$ show version
Traceback (most recent call last):
  File "/usr/local/bin/show", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/show/main.py", line 960, in version
    chassis_info = platform.get_chassis_info()
  File "/usr/local/lib/python3.7/dist-packages/show/platform.py", line 27, in get_chassis_info
    platform_chassis = sonic_platform.platform.Platform().get_chassis()
NameError: name 'sonic_platform' is not defined
```

#### How I did it
Import `sonic_platform` before using `sonic_platform`.

Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
  • Loading branch information
lolyu authored Jun 21, 2021
1 parent 9041ba0 commit 5708497
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion show/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_chassis_info():
for k in required_keys:
if chassis_info.get(k, '') in failed_vals:
if platform_chassis is None:
import platform
import sonic_platform
platform_chassis = sonic_platform.platform.Platform().get_chassis()
try:
chassis_info[k] = getattr(platform_chassis, "get_".format(k))()
Expand Down

0 comments on commit 5708497

Please sign in to comment.