← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:fix/debian-ntp-template into cloud-init:master

 

Ryan Harper has proposed merging ~raharper/cloud-init:fix/debian-ntp-template into cloud-init:master.

Commit message:
templates/nto.conf.debian.tmpl: fix missing newline for pools
    
The debian ntp.conf template did not contain a newline for the
comment used to mark the rendered ntp pools configured.  This
resulted in an invalid line:
    
'# poolspool 0.int.pool.ntp.org iburst'
    
rather than:
    
'# pools
 pool 0.int.pool.ntp.org iburst'
    
This patch fixes the template and updates the unittest to
verify that the rendered templates puts servers and pools
at the beginning of a line.
    
LP: #1836598


Requested reviews:
  Server Team CI bot (server-team-bot): continuous-integration
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1836598 in cloud-init: "cc_ntp generates wrong config for ntpd in debian (buster)"
  https://bugs.launchpad.net/cloud-init/+bug/1836598

For more details, see:
https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/370213
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~raharper/cloud-init:fix/debian-ntp-template into cloud-init:master.
diff --git a/templates/ntp.conf.debian.tmpl b/templates/ntp.conf.debian.tmpl
index 3f07eea..affe983 100644
--- a/templates/ntp.conf.debian.tmpl
+++ b/templates/ntp.conf.debian.tmpl
@@ -19,7 +19,8 @@ filegen clockstats file clockstats type day enable
 # pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
 # pick a different set every time it starts up.  Please consider joining the
 # pool: <http://www.pool.ntp.org/join.html>
-{% if pools -%}# pools{% endif %}
+{% if pools %}# pools
+{% endif %}
 {% for pool in pools -%}
 pool {{pool}} iburst
 {% endfor %}
diff --git a/tests/unittests/test_handler/test_handler_ntp.py b/tests/unittests/test_handler/test_handler_ntp.py
index 0f22e57..79db2e8 100644
--- a/tests/unittests/test_handler/test_handler_ntp.py
+++ b/tests/unittests/test_handler/test_handler_ntp.py
@@ -268,17 +268,20 @@ class TestNtp(FilesystemMockingTestCase):
                                                  template_fn=template_fn)
                 content = util.load_file(confpath)
                 if client in ['ntp', 'chrony']:
-                    expected_servers = '\n'.join([
-                        'server {0} iburst'.format(srv) for srv in servers])
+                    content_lines = content.splitlines()
+                    expected_servers = [
+                        'server {0} iburst'.format(srv) for srv in servers]
                     print('distro=%s client=%s' % (distro, client))
-                    self.assertIn(expected_servers, content,
-                                  ('failed to render {0} conf'
-                                   ' for distro:{1}'.format(client, distro)))
-                    expected_pools = '\n'.join([
-                        'pool {0} iburst'.format(pool) for pool in pools])
-                    self.assertIn(expected_pools, content,
-                                  ('failed to render {0} conf'
-                                   ' for distro:{1}'.format(client, distro)))
+                    for sline in expected_servers:
+                        self.assertIn(sline, content_lines,
+                                      ('failed to render {0} conf'
+                                       ' for distro:{1}'.format(client, distro)))
+                    expected_pools = [
+                        'pool {0} iburst'.format(pool) for pool in pools]
+                    for pline in expected_pools:
+                        self.assertIn(pline, content_lines,
+                                      ('failed to render {0} conf'
+                                       ' for distro:{1}'.format(client, distro)))
                 elif client == 'systemd-timesyncd':
                     expected_content = (
                         "# cloud-init generated file\n" +