Merge ~rjschwei/cloud-init:ntpSUSE into cloud-init:master

Proposed by Robert Schweikert on 2017-11-11
Status: Merged
Approved by: Chad Smith on 2017-11-16
Approved revision: f89e2404d5afa86a8b27de5b5404933c43a2d1af
Merged at revision: d90318b21d0379e24337bcb92a0a90ebfa359c35
Proposed branch: ~rjschwei/cloud-init:ntpSUSE
Merge into: cloud-init:master
Diff against target: 180 lines (+121/-14)
4 files modified
cloudinit/config/cc_ntp.py (+7/-2)
templates/ntp.conf.opensuse.tmpl (+88/-0)
templates/ntp.conf.sles.tmpl (+0/-12)
tests/unittests/test_handler/test_handler_ntp.py (+26/-0)
Reviewer Review Type Date Requested Status
Chad Smith 2017-11-11 Approve on 2017-11-16
Server Team CI bot continuous-integration Approve on 2017-11-14
Review via email: mp+333575@code.launchpad.net

Commit Message

ntp: fix configuration template rendering for openSUSE and SLES

Add opensuse distro support to cc_ntp module.

LP: #1726572

Description of the Change

Fix ntp configuration for openSUSE and SLES

LP: #1726572

To post a comment you must log in.

PASSED: Continuous integration, rev:3599ae19e439d9bab33dac6ccbb73336f00e49ef
https://jenkins.ubuntu.com/server/job/cloud-init-ci/487/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/487/rebuild

review: Approve (continuous-integration)
Chad Smith (chad.smith) wrote :

Thanks for the patch Robert. Quick little feedback here. I'll chat w/ smoser raharper about the symlink idea vs. domain-specific knowledge in cc_ntp providing suse insteada of opensuse when generating template. I feel like symlink is probably a bit more explicit.

review: Needs Information
~rjschwei/cloud-init:ntpSUSE updated on 2017-11-14
f89e240... by Robert Schweikert on 2017-11-14

- Fix typo in comment
- Simplify test substitution

PASSED: Continuous integration, rev:f89e2404d5afa86a8b27de5b5404933c43a2d1af
https://jenkins.ubuntu.com/server/job/cloud-init-ci/492/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/492/rebuild

review: Approve (continuous-integration)
Chad Smith (chad.smith) wrote :

Approving this branch as is, we'll work on the template engine improvements in another branch so that we don't have to have duplication of templates.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/config/cc_ntp.py b/cloudinit/config/cc_ntp.py
2index d43d060..f50bcb3 100644
3--- a/cloudinit/config/cc_ntp.py
4+++ b/cloudinit/config/cc_ntp.py
5@@ -23,7 +23,7 @@ frequency = PER_INSTANCE
6 NTP_CONF = '/etc/ntp.conf'
7 TIMESYNCD_CONF = '/etc/systemd/timesyncd.conf.d/cloud-init.conf'
8 NR_POOL_SERVERS = 4
9-distros = ['centos', 'debian', 'fedora', 'opensuse', 'ubuntu']
10+distros = ['centos', 'debian', 'fedora', 'opensuse', 'sles', 'ubuntu']
11
12
13 # The schema definition for each cloud-config module is a strict contract for
14@@ -174,8 +174,13 @@ def rename_ntp_conf(config=None):
15
16 def generate_server_names(distro):
17 names = []
18+ pool_distro = distro
19+ # For legal reasons x.pool.sles.ntp.org does not exist,
20+ # use the opensuse pool
21+ if distro == 'sles':
22+ pool_distro = 'opensuse'
23 for x in range(0, NR_POOL_SERVERS):
24- name = "%d.%s.pool.ntp.org" % (x, distro)
25+ name = "%d.%s.pool.ntp.org" % (x, pool_distro)
26 names.append(name)
27 return names
28
29diff --git a/templates/ntp.conf.opensuse.tmpl b/templates/ntp.conf.opensuse.tmpl
30new file mode 100644
31index 0000000..f3ab565
32--- /dev/null
33+++ b/templates/ntp.conf.opensuse.tmpl
34@@ -0,0 +1,88 @@
35+## template:jinja
36+
37+##
38+## Radio and modem clocks by convention have addresses in the
39+## form 127.127.t.u, where t is the clock type and u is a unit
40+## number in the range 0-3.
41+##
42+## Most of these clocks require support in the form of a
43+## serial port or special bus peripheral. The particular
44+## device is normally specified by adding a soft link
45+## /dev/device-u to the particular hardware device involved,
46+## where u correspond to the unit number above.
47+##
48+## Generic DCF77 clock on serial port (Conrad DCF77)
49+## Address: 127.127.8.u
50+## Serial Port: /dev/refclock-u
51+##
52+## (create soft link /dev/refclock-0 to the particular ttyS?)
53+##
54+# server 127.127.8.0 mode 5 prefer
55+
56+##
57+## Undisciplined Local Clock. This is a fake driver intended for backup
58+## and when no outside source of synchronized time is available.
59+##
60+# server 127.127.1.0 # local clock (LCL)
61+# fudge 127.127.1.0 stratum 10 # LCL is unsynchronized
62+
63+##
64+## Add external Servers using
65+## # rcntpd addserver <yourserver>
66+## The servers will only be added to the currently running instance, not
67+## to /etc/ntp.conf.
68+##
69+{% if pools %}# pools
70+{% endif %}
71+{% for pool in pools -%}
72+pool {{pool}} iburst
73+{% endfor %}
74+{%- if servers %}# servers
75+{% endif %}
76+{% for server in servers -%}
77+server {{server}} iburst
78+{% endfor %}
79+
80+# Access control configuration; see /usr/share/doc/packages/ntp/html/accopt.html for
81+# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
82+# might also be helpful.
83+#
84+# Note that "restrict" applies to both servers and clients, so a configuration
85+# that might be intended to block requests from certain clients could also end
86+# up blocking replies from your own upstream servers.
87+
88+# By default, exchange time with everybody, but don't allow configuration.
89+restrict -4 default notrap nomodify nopeer noquery
90+restrict -6 default notrap nomodify nopeer noquery
91+
92+# Local users may interrogate the ntp server more closely.
93+restrict 127.0.0.1
94+restrict ::1
95+
96+# Clients from this (example!) subnet have unlimited access, but only if
97+# cryptographically authenticated.
98+#restrict 192.168.123.0 mask 255.255.255.0 notrust
99+
100+##
101+## Miscellaneous stuff
102+##
103+
104+driftfile /var/lib/ntp/drift/ntp.drift # path for drift file
105+
106+logfile /var/log/ntp # alternate log file
107+# logconfig =syncstatus + sysevents
108+# logconfig =all
109+
110+# statsdir /tmp/ # directory for statistics files
111+# filegen peerstats file peerstats type day enable
112+# filegen loopstats file loopstats type day enable
113+# filegen clockstats file clockstats type day enable
114+
115+#
116+# Authentication stuff
117+#
118+keys /etc/ntp.keys # path for keys file
119+trustedkey 1 # define trusted keys
120+requestkey 1 # key (7) for accessing server variables
121+controlkey 1 # key (6) for accessing server variables
122+
123diff --git a/templates/ntp.conf.sles.tmpl b/templates/ntp.conf.sles.tmpl
124index 5c5fc4d..f3ab565 100644
125--- a/templates/ntp.conf.sles.tmpl
126+++ b/templates/ntp.conf.sles.tmpl
127@@ -1,17 +1,5 @@
128 ## template:jinja
129
130-################################################################################
131-## /etc/ntp.conf
132-##
133-## Sample NTP configuration file.
134-## See package 'ntp-doc' for documentation, Mini-HOWTO and FAQ.
135-## Copyright (c) 1998 S.u.S.E. GmbH Fuerth, Germany.
136-##
137-## Author: Michael Andres, <ma@suse.de>
138-## Michael Skibbe, <mskibbe@suse.de>
139-##
140-################################################################################
141-
142 ##
143 ## Radio and modem clocks by convention have addresses in the
144 ## form 127.127.t.u, where t is the clock type and u is a unit
145diff --git a/tests/unittests/test_handler/test_handler_ntp.py b/tests/unittests/test_handler/test_handler_ntp.py
146index 3abe578..28a8455 100644
147--- a/tests/unittests/test_handler/test_handler_ntp.py
148+++ b/tests/unittests/test_handler/test_handler_ntp.py
149@@ -430,5 +430,31 @@ class TestNtp(FilesystemMockingTestCase):
150 "[Time]\nNTP=192.168.2.1 192.168.2.2 0.mypool.org \n",
151 content.decode())
152
153+ def test_write_ntp_config_template_defaults_pools_empty_lists_sles(self):
154+ """write_ntp_config_template defaults pools servers upon empty config.
155+
156+ When both pools and servers are empty, default NR_POOL_SERVERS get
157+ configured.
158+ """
159+ distro = 'sles'
160+ mycloud = self._get_cloud(distro)
161+ ntp_conf = self.tmp_path('ntp.conf', self.new_root) # Doesn't exist
162+ # Create ntp.conf.tmpl
163+ with open('{0}.tmpl'.format(ntp_conf), 'wb') as stream:
164+ stream.write(NTP_TEMPLATE)
165+ with mock.patch('cloudinit.config.cc_ntp.NTP_CONF', ntp_conf):
166+ cc_ntp.write_ntp_config_template({}, mycloud, ntp_conf)
167+ content = util.read_file_or_url('file://' + ntp_conf).contents
168+ default_pools = [
169+ "{0}.opensuse.pool.ntp.org".format(x)
170+ for x in range(0, cc_ntp.NR_POOL_SERVERS)]
171+ self.assertEqual(
172+ "servers []\npools {0}\n".format(default_pools),
173+ content.decode())
174+ self.assertIn(
175+ "Adding distro default ntp pool servers: {0}".format(
176+ ",".join(default_pools)),
177+ self.logs.getvalue())
178+
179
180 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches