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

updated "show ntp" to use cgexec when management vrf is enabled #627

Merged
merged 4 commits into from
Sep 9, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,26 @@ def bgp(verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def ntp(verbose):
"""Show NTP information"""
cmd = "ntpq -p -n"
run_command(cmd, display_cmd=verbose)
ntpcmd = "ntpq -p -n"
if ctx.invoked_subcommand is None:
cmd = 'sonic-cfggen -d --var-json "MGMT_VRF_CONFIG"'

p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subb
process.PIPE)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
res = p.communicate()
if p.returncode == 0 :
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderrr
=subprocess.PIPE)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
mvrf_dict = json.loads(p.stdout.read())

# if the mgmtVrfEnabled attribute is configured, check the value
# and print Enabled or Disabled accordingly.
if 'mgmtVrfEnabled' in mvrf_dict['vrf_global']:
if (mvrf_dict['vrf_global']['mgmtVrfEnabled'] == "true"):
#ManagementVRF is enabled. Call ntpq using cgexec
ntpcmd = "cgexec -g l3mdev:mgmt ntpq -p -n"
Copy link
Contributor

Choose a reason for hiding this comment

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

This command should be run with sudo privilege by either prepending the ntpcmd string or running show ntp with sudo

$ show ntp
cgroup change of group failed
$ sudo show ntp                               
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================

run_command(ntpcmd, display_cmd=verbose)



#
Expand Down