Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix is_mgmt_vrf_enabled for the case where MGMT_VRF_CONFIG is not at all in the config DB #885

Merged
merged 5 commits into from
May 14, 2020

Conversation

bsun-sudo
Copy link
Contributor

- What I did
Fix is_mgmt_vrf_enabled for the case where MGMT_VRF_CONFIG is not at all in the config DB.
This is the case where mgmt vrf is never configured. The function throws error at
File "/usr/lib/python2.7/dist-packages/show/main.py", line 651, in is_mgmt_vrf_enabled
mvrf_dict = json.loads(p.stdout.read())
Two show commands uses is_mgmt_vrf_enabled. "show mgmt-vrf" and "show ntp"
Both commands throw error if mgmt vrf is never configured

- How I did it
Check if MGMT_VRF_CONFIG is present, if not, return false right away.

- How to verify it

  1. With no MGMT_VRF_CONFIG in config DB, run "show mgmt-vrf"
  2. add mgmt vrf, run "show mgmt-vrf"
  3. del mgmt vrf, run "show mgmt-vrf"

- Previous command output (if the output of a command-line utility has changed)
"show mgmt-vrf"
root@sonic:~# show mgmt-vrf
Traceback (most recent call last):
File "/usr/bin/show", line 12, in
sys.exit(cli())
File "/usr/lib/python2.7/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python2.7/dist-packages/click/core.py", line 1043, in invoke
return Command.invoke(self, ctx)
File "/usr/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/show/main.py", line 671, in mgmt_vrf
if is_mgmt_vrf_enabled(ctx) is False:
File "/usr/lib/python2.7/dist-packages/show/main.py", line 651, in is_mgmt_vrf_enabled
mvrf_dict = json.loads(p.stdout.read())
File "/usr/lib/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

- New command output (if the output of a command-line utility has changed)

"show mgmt-vrf"
root@sonic:~# show mgmt-vrf

ManagementVRF : Disabled
root@sonic:~#

Copy link
Contributor

@prsunny prsunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@lguohan lguohan merged commit c52e268 into sonic-net:master May 14, 2020
abdosi pushed a commit that referenced this pull request May 20, 2020
…g DB (#885)

Fix is_mgmt_vrf_enabled for the case where MGMT_VRF_CONFIG is not at all in the config DB.
This is the case where mgmt vrf is never configured. The function throws error at
File "/usr/lib/python2.7/dist-packages/show/main.py", line 651, in is_mgmt_vrf_enabled
mvrf_dict = json.loads(p.stdout.read())
Two show commands uses is_mgmt_vrf_enabled. "show mgmt-vrf" and "show ntp"
Both commands throw error if mgmt vrf is never configured

Co-authored-by: Bing Sun <[email protected]>
abdosi pushed a commit to abdosi/sonic-utilities that referenced this pull request Aug 4, 2020
…g DB (sonic-net#885)

Fix is_mgmt_vrf_enabled for the case where MGMT_VRF_CONFIG is not at all in the config DB.
This is the case where mgmt vrf is never configured. The function throws error at
File "/usr/lib/python2.7/dist-packages/show/main.py", line 651, in is_mgmt_vrf_enabled
mvrf_dict = json.loads(p.stdout.read())
Two show commands uses is_mgmt_vrf_enabled. "show mgmt-vrf" and "show ntp"
Both commands throw error if mgmt vrf is never configured

Co-authored-by: Bing Sun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants