Fix is_mgmt_vrf_enabled for the case where MGMT_VRF_CONFIG is not at all in the config DB #885
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
- 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
- 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:~#