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

[show] Fix ntp conf file path #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,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')
Loading