Skip to content

Commit

Permalink
Fix ntp conf file path (#3525)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekrnv authored Sep 9, 2024
1 parent 5eb266a commit d103bfd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ def ntp(verbose):
"""Show NTP running configuration"""
ntp_servers = []
ntp_dict = {}
with open("/etc/ntp.conf") as ntp_file:
with open("/etc/ntpsec/ntp.conf") as ntp_file:
data = ntp_file.readlines()
for line in data:
if line.startswith("server "):
Expand Down
37 changes: 37 additions & 0 deletions tests/ntp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###############################################################################
# This file was AUTOMATICALLY GENERATED. DO NOT MODIFY.
# Controlled by ntp-config.service
###############################################################################

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

# To avoid ntpd from panic and exit if the drift between new time and
# current system time is large.
tinker panic 0

driftfile /var/lib/ntpsec/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list

server 10.1.1.1 iburst
restrict 10.1.1.1 kod limited nomodify noquery

server 10.22.1.12 iburst
restrict 10.22.1.12 kod limited nomodify noquery


interface ignore wildcard


interface listen eth0
interface listen 127.0.0.1


# Access control configuration
# By default, exchange time with everybody, but don't allow configuration.
# NTPsec doesn't establish peer associations, and so nopeer has no effect, and
# has been removed from here
restrict default kod nomodify noquery limited

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
14 changes: 14 additions & 0 deletions tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,20 @@ def test_rc_syslog(self, mock_rc):
assert result.exit_code == 0
assert '[1.1.1.1]' in result.output

@patch('builtins.open', mock_open(
read_data=open('tests/ntp.conf').read()))
def test_ntp(self):
runner = CliRunner()

result = runner.invoke(
show.cli.commands['runningconfiguration'].commands['ntp'])
print(result.exit_code)
print(result.output)

assert result.exit_code == 0
assert '10.1.1.1' in result.output
assert '10.22.1.12' in result.output

@classmethod
def teardown_class(cls):
print('TEARDOWN')

0 comments on commit d103bfd

Please sign in to comment.