← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~powersj/cloud-init:fix_ntp_tests into cloud-init:master

 

Joshua Powers has proposed merging ~powersj/cloud-init:fix_ntp_tests into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~powersj/cloud-init/+git/cloud-init/+merge/326312

tests: update ntp tests after sntp added

A recent change to ntp in artful has added the sntp package
whenever ntp is installed. The tests, rather poorly, did a
`dpkg -l` instead of checking with `which`. This fixes the
ntp tests to all use `which` over expecting a certain number
of lines using dpkg and as a result make the tests OS
independent.
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~powersj/cloud-init:fix_ntp_tests into cloud-init:master.
diff --git a/tests/cloud_tests/configs/modules/ntp.yaml b/tests/cloud_tests/configs/modules/ntp.yaml
index 0d07ef5..22f34af 100644
--- a/tests/cloud_tests/configs/modules/ntp.yaml
+++ b/tests/cloud_tests/configs/modules/ntp.yaml
@@ -1,31 +1,20 @@
 #
 # Emtpy NTP config to setup using defaults
 #
-# NOTE: this should not require apt feature, use 'which' rather than 'dpkg -l'
-# NOTE: this should not require no_ntpdate feature, use 'which' to check for
-#       installation rather than 'dpkg -l', as 'grep ntp' matches 'ntpdate'
-# NOTE: the verifier should check for any ntp server not 'ubuntu.pool.ntp.org'
-required_features:
-  - apt
-  - no_ntpdate
-  - ubuntu_ntp
 cloud_config: |
   #cloud-config
   ntp:
     pools: {}
     servers: {}
 collect_scripts:
-  ntp_installed_empty: |
+  ntp_installed: |
     #!/bin/bash
-    dpkg -l | grep ntp | wc -l
+    which ntpd
   ntp_conf_dist_empty: |
     #!/bin/bash
     ls /etc/ntp.conf.dist | wc -l
-  ntp_conf_empty: |
+  ntp_conf_pool_list: |
     #!/bin/bash
-    grep '^pool' /etc/ntp.conf
-  ntp_installed_list: |
-    #!/bin/bash
-    dpkg -l | grep ntp
+    grep 'pool.ntp.org' /etc/ntp.conf | grep -v ^#
 
 # vi: ts=4 expandtab
diff --git a/tests/cloud_tests/configs/modules/ntp_pools.yaml b/tests/cloud_tests/configs/modules/ntp_pools.yaml
index 7561c7f..8304886 100644
--- a/tests/cloud_tests/configs/modules/ntp_pools.yaml
+++ b/tests/cloud_tests/configs/modules/ntp_pools.yaml
@@ -1,15 +1,10 @@
 #
 # NTP config using specific pools
 #
-# NOTE: this should not require apt feature, use 'which' rather than 'dpkg -l'
-# NOTE: this should not require no_ntpdate feature, use 'which' to check for 
-#       installation rather than 'dpkg -l', as 'grep ntp' matches 'ntpdate'
 # NOTE: lsb_release listed here because with recent cloud-init deb with
 #       (LP: 1628337) resolved, cloud-init will attempt to configure archives.
 #       this fails without lsb_release as UNAVAILABLE is used for $RELEASE
 required_features:
-  - apt
-  - no_ntpdate
   - lsb_release
 cloud_config: |
   #cloud-config
@@ -21,7 +16,7 @@ cloud_config: |
 collect_scripts:
   ntp_installed_pools: |
     #!/bin/bash
-    dpkg -l | grep ntp | wc -l
+    which ntpd
   ntp_conf_dist_pools: |
     #!/bin/bash
     ls /etc/ntp.conf.dist | wc -l
diff --git a/tests/cloud_tests/configs/modules/ntp_servers.yaml b/tests/cloud_tests/configs/modules/ntp_servers.yaml
index 9d1d65e..755e22a 100644
--- a/tests/cloud_tests/configs/modules/ntp_servers.yaml
+++ b/tests/cloud_tests/configs/modules/ntp_servers.yaml
@@ -1,12 +1,7 @@
 #
 # NTP config using specific servers
 #
-# NOTE: this should not require apt feature, use 'which' rather than 'dpkg -l'
-# NOTE: this should not require no_ntpdate feature, use 'which' to check for 
-#       installation rather than 'dpkg -l', as 'grep ntp' matches 'ntpdate'
 required_features:
-  - apt
-  - no_ntpdate
   - lsb_release
 cloud_config: |
   #cloud-config
@@ -17,7 +12,7 @@ cloud_config: |
 collect_scripts:
   ntp_installed_servers: |
     #!/bin/sh
-    dpkg -l | grep -c ntp
+    which ntpd
   ntp_conf_dist_servers: |
     #!/bin/sh
     cat /etc/ntp.conf.dist | wc -l
diff --git a/tests/cloud_tests/testcases/modules/ntp.py b/tests/cloud_tests/testcases/modules/ntp.py
index a4b8c3d..4dc66ff 100644
--- a/tests/cloud_tests/testcases/modules/ntp.py
+++ b/tests/cloud_tests/testcases/modules/ntp.py
@@ -9,8 +9,8 @@ class TestNtp(base.CloudTestCase):
 
     def test_ntp_installed(self):
         """Test ntp installed"""
-        out = self.get_data_file('ntp_installed_empty')
-        self.assertEqual(1, int(out))
+        out = self.get_data_file('ntp_installed')
+        self.assertEqual('/usr/sbin/ntpd', out.rstrip())
 
     def test_ntp_dist_entries(self):
         """Test dist config file is empty"""
@@ -19,10 +19,7 @@ class TestNtp(base.CloudTestCase):
 
     def test_ntp_entires(self):
         """Test config entries"""
-        out = self.get_data_file('ntp_conf_empty')
-        self.assertIn('pool 0.ubuntu.pool.ntp.org iburst', out)
-        self.assertIn('pool 1.ubuntu.pool.ntp.org iburst', out)
-        self.assertIn('pool 2.ubuntu.pool.ntp.org iburst', out)
-        self.assertIn('pool 3.ubuntu.pool.ntp.org iburst', out)
+        out = self.get_data_file('ntp_conf_pool_list')
+        self.assertIn('pool.ntp.org iburst', out)
 
 # vi: ts=4 expandtab
diff --git a/tests/cloud_tests/testcases/modules/ntp_pools.py b/tests/cloud_tests/testcases/modules/ntp_pools.py
index 336076d..c070d53 100644
--- a/tests/cloud_tests/testcases/modules/ntp_pools.py
+++ b/tests/cloud_tests/testcases/modules/ntp_pools.py
@@ -10,7 +10,7 @@ class TestNtpPools(base.CloudTestCase):
     def test_ntp_installed(self):
         """Test ntp installed"""
         out = self.get_data_file('ntp_installed_pools')
-        self.assertEqual(1, int(out))
+        self.assertEqual('/usr/sbin/ntpd', out.rstrip())
 
     def test_ntp_dist_entries(self):
         """Test dist config file is empty"""
diff --git a/tests/cloud_tests/testcases/modules/ntp_servers.py b/tests/cloud_tests/testcases/modules/ntp_servers.py
index 4010cf8..e199d63 100644
--- a/tests/cloud_tests/testcases/modules/ntp_servers.py
+++ b/tests/cloud_tests/testcases/modules/ntp_servers.py
@@ -10,7 +10,7 @@ class TestNtpServers(base.CloudTestCase):
     def test_ntp_installed(self):
         """Test ntp installed"""
         out = self.get_data_file('ntp_installed_servers')
-        self.assertEqual(1, int(out))
+        self.assertEqual('/usr/sbin/ntpd', out.rstrip())
 
     def test_ntp_dist_entries(self):
         """Test dist config file is empty"""

Follow ups