Skip to content

ntp: T4909 rewrite NTP op mode in the new format #3307

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

Merged
merged 1 commit into from
May 2, 2024

Conversation

Giggum
Copy link
Contributor

@Giggum Giggum commented Apr 14, 2024

Change Summary

Op commands are rewritten in Python and encompasses the existing chronyc calls that were in show_ntp.sh.

Have also added two additional functions. Op-mode definition has been updated accordingly and follows the chronyc command language so that there's alignment between xml and python source.

Op commands consist of:
show ntp
show ntp activity
show ntp sources
show ntp tracking
note: show ntp activity and sources are new additions, while tracking has been renamed from previous system.

See task in Maniphest for additional info,

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

https://vyos.dev/T4909

Related PR(s)

Component(s) name

Proposed changes

How to test

Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly -> will do as subsequent step

@vyosbot vyosbot requested review from a team, dmbaturin, sarthurdev, zdc, jestabro, sever-sever and c-po and removed request for a team April 14, 2024 07:33
@sever-sever
Copy link
Member

There is no check if the service is not configured

vyos@r4# delete service ntp 
[edit]
vyos@r4# commit
[edit]
vyos@r4# sudo su
root@r4:/home/vyos# sudo ./ntp.py show_summary --command activity
Traceback (most recent call last):
  File "/home/vyos/./ntp.py", line 45, in <module>
    res = vyos.opmode.run(sys.modules[__name__])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/opmode.py", line 263, in run
    res = func(**args)
          ^^^^^^^^^^^^
  File "/home/vyos/./ntp.py", line 24, in show_summary
    output = cmd(f"chronyc '{command}'")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/utils/process.py", line 155, in cmd
    raise OSError(code, feedback)
PermissionError: [Errno 1] failed to run command: chronyc 'activity'
returned: 506 Cannot talk to daemon
exit code: 1
root@r4:/home/vyos# 

@sever-sever
Copy link
Member

The commit message does not include the task number, but you marked it as done.

For future use please git commit --amend and push --force to override the previous commit

@Giggum
Copy link
Contributor Author

Giggum commented Apr 14, 2024

There is no check if the service is not configured

vyos@r4# delete service ntp 
[edit]
vyos@r4# commit
[edit]
vyos@r4# sudo su
root@r4:/home/vyos# sudo ./ntp.py show_summary --command activity
Traceback (most recent call last):
  File "/home/vyos/./ntp.py", line 45, in <module>
    res = vyos.opmode.run(sys.modules[__name__])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/opmode.py", line 263, in run
    res = func(**args)
          ^^^^^^^^^^^^
  File "/home/vyos/./ntp.py", line 24, in show_summary
    output = cmd(f"chronyc '{command}'")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/utils/process.py", line 155, in cmd
    raise OSError(code, feedback)
PermissionError: [Errno 1] failed to run command: chronyc 'activity'
returned: 506 Cannot talk to daemon
exit code: 1
root@r4:/home/vyos# 

Added this function to ntp.py
def is_configured(): # Check if ntp is configured config = ConfigTreeQuery() if not config.exists("service ntp"): raise vyos.opmode.UnconfiguredSubsystem("NTP service is not enabled")

@Giggum Giggum marked this pull request as draft April 15, 2024 12:29
@Giggum
Copy link
Contributor Author

Giggum commented Apr 16, 2024

@dmbaturin, @sever-sever I've posted a question here seeking feedback https://vyos.dev/T4909 would appreciate you input.

Copy link
Contributor Author

@Giggum Giggum left a comment

Choose a reason for hiding this comment

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

Feedback implemented (1) add raw mode, (2) check if ntp service is configured

@Giggum Giggum marked this pull request as ready for review April 17, 2024 20:25
@vyosbot vyosbot requested review from a team and sever-sever and removed request for a team April 17, 2024 20:25
Copy link
Contributor Author

@Giggum Giggum left a comment

Choose a reason for hiding this comment

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

Feedback has been incorporated and changes applied as result.

@sever-sever
Copy link
Member

The commit message does not include the task number, but you marked it as done.

For future use please git commit --amend and push --force to override the previous commit

Use please this in the future
This way you’ll have one commit instead of 10 commits

it will be difficult to revert the changes for example

It is a good idea to have just one commit.
Thanks.

@GurliGebis
Copy link
Contributor

@Giggum a way to fix it would be to git rebase current and then mark all the fix commit as that, so they just gets merged into the main commit, and then force push.

ntp: T4909: Rewrite NTP op mode in new format

Adapts ntp.xml.in to reference new ntp.py file
Add ntp.py
Adds a check to ntp.py to verify if the ntp service is configured
Adds raw mode to ntp.py
For raw output, replaces the original method of parsing the command line output FROM re.split+regex TO csv.reader.
Separates chrony commands into equivalent functions show_tracking, show_sources, source_sourcestats and show_activity
Revises the names of raw dictionary keys variables to be lowercase
Corrects a comment typo and renames function  name used for raw mode
@Giggum
Copy link
Contributor Author

Giggum commented Apr 23, 2024

@sever-sever, @GurliGebis thank you both was abled to squash those commits into one.

@Giggum Giggum requested a review from dmbaturin April 23, 2024 01:15
@GurliGebis
Copy link
Contributor

@sever-sever, @GurliGebis thank you both was abled to squash those commits into one.

You're welcome 🙂

@c-po c-po merged commit f97a325 into vyos:current May 2, 2024
@c-po
Copy link
Member

c-po commented May 2, 2024

@Mergifyio backport sagitta

Copy link
Contributor

mergify bot commented May 2, 2024

backport sagitta

✅ Backports have been created

dmbaturin added a commit that referenced this pull request May 2, 2024
ntp: T4909 rewrite NTP op mode in the new format (backport #3307)
@Giggum Giggum deleted the vyos-1x-T4909 branch May 3, 2024 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

5 participants