Skip to content

Commit

Permalink
Fix is_mgmt_vrf_enabled when MGMT_VRF_CONFIG is not present the confi…
Browse files Browse the repository at this point in the history
…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 <Bing_Sun@dell.com>
  • Loading branch information
bsun-sudo and Bing Sun committed May 14, 2020
1 parent ffd0bd1 commit c52e268
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,19 @@ def is_mgmt_vrf_enabled(ctx):
cmd = 'sonic-cfggen -d --var-json "MGMT_VRF_CONFIG"'

p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout = p.communicate()[0]
if p.returncode == 0:
mvrf_dict = json.loads(stdout)

# if the mgmtVrfEnabled attribute is configured, check the value
# and return True accordingly.
if 'mgmtVrfEnabled' in mvrf_dict['vrf_global']:
if (mvrf_dict['vrf_global']['mgmtVrfEnabled'] == "true"):
#ManagementVRF is enabled. Return True.
return True
try :
mvrf_dict = json.loads(p.stdout.read())
except ValueError:
print("MGMT_VRF_CONFIG is not present.")
return False

# if the mgmtVrfEnabled attribute is configured, check the value
# and return True accordingly.
if 'mgmtVrfEnabled' in mvrf_dict['vrf_global']:
if (mvrf_dict['vrf_global']['mgmtVrfEnabled'] == "true"):
#ManagementVRF is enabled. Return True.
return True

return False

#
Expand Down

0 comments on commit c52e268

Please sign in to comment.