Merge ~chad.smith/cloud-init:bug/cloud-tests-pkg-install into cloud-init:master

Proposed by Chad Smith
Status: Merged
Approved by: Chad Smith
Approved revision: 01cdce5e24115ba398b77f2f07bae5a40d52cf9b
Merge reported by: Chad Smith
Merged at revision: 323eb30940cae2069daf74517089220fccc4afb9
Proposed branch: ~chad.smith/cloud-init:bug/cloud-tests-pkg-install
Merge into: cloud-init:master
Diff against target: 243 lines (+59/-35)
11 files modified
tests/cloud_tests/testcases.yaml (+2/-2)
tests/cloud_tests/testcases/base.py (+21/-0)
tests/cloud_tests/testcases/modules/byobu.py (+1/-2)
tests/cloud_tests/testcases/modules/byobu.yaml (+0/-3)
tests/cloud_tests/testcases/modules/ca_certs.py (+17/-4)
tests/cloud_tests/testcases/modules/ca_certs.yaml (+6/-2)
tests/cloud_tests/testcases/modules/ntp.py (+2/-3)
tests/cloud_tests/testcases/modules/package_update_upgrade_install.py (+6/-8)
tests/cloud_tests/testcases/modules/package_update_upgrade_install.yaml (+3/-6)
tests/cloud_tests/testcases/modules/salt_minion.py (+1/-2)
tests/cloud_tests/testcases/modules/salt_minion.yaml (+0/-3)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+345256@code.launchpad.net

Commit message

tests: fix package and ca_cert cloud_tests on bionic

package_update_upgrade_install was failing as htop is now included in
Bionic images. Switch this test to install 'sl' instead.

ca_certs integration test fails on cert_count test because bionic
update-ca-certificates on bionic generates less symlinks for a given cert.

Integration tests now collect dpkg-query --show output on every instance.
Add a new assertPackageInstalled helper method which finds the package or
package version installed on the instance.

Adapt existing byobu, package_update_upgrade_install, ntp and salt_minion
tests to use assertPackageInstalled method.

LP: #1769985

Description of the change

see commit message

original failures can be seen here https://jenkins.ubuntu.com/server/view/cloud-init/job/cloud-init-integration-proposed-b/9/console

to test:
.tox/citest/bin/python -m tests.cloud_tests run -d results --os-name=bionic --platform=lxd --verbose --test modules/package_update_upgrade_install --test modules/ntp --test modules/salt_minion --test modules/byobu --preserve-data

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:75f14327cf9d08d8baa03557584033a962c7238d
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1108/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

Your commit message is incorrect.

> package_update_upgrade_install was failing as htop is not included in
> Bionic images. Switch this test to install 'sl' instead.

Actually the problem is that htop *is* in the bionic images.
We were testing that 'packages: [htop]' caused apt installation, but
since htop is already present in the base bionic image that assertion
was failing.

Maybe for that test we could instead use
 https://launchpad.net/~cloud-init-dev/+archive/ubuntu/test-archive
and install 'smello'.
Its probably a safer assumption that 'smello' is not installed
in the official images.

What you have is probably fine though.

760435b... by Chad Smith

tests: update-ca-certificates on bionic gens less links

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:760435bf8ef3514ea477805a29d15ce00984f4a4
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1109/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

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

review: Needs Fixing (continuous-integration)
01cdce5... by Chad Smith

address smoser's review comments

  - re.search MULTILINE instead of re.match DOTALL
  - use installed_version.startswith(version) to match optional
    installed package version

Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:01cdce5e24115ba398b77f2f07bae5a40d52cf9b
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1110/
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/1110/rebuild

review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) :
review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=323eb309

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/cloud_tests/testcases.yaml b/tests/cloud_tests/testcases.yaml
2index a3e2990..a16d1dd 100644
3--- a/tests/cloud_tests/testcases.yaml
4+++ b/tests/cloud_tests/testcases.yaml
5@@ -24,9 +24,9 @@ base_test_data:
6 status.json: |
7 #!/bin/sh
8 cat /run/cloud-init/status.json
9- cloud-init-version: |
10+ package-versions: |
11 #!/bin/sh
12- dpkg-query -W -f='${Version}' cloud-init
13+ dpkg-query --show
14 system.journal.gz: |
15 #!/bin/sh
16 [ -d /run/systemd ] || { echo "not systemd."; exit 0; }
17diff --git a/tests/cloud_tests/testcases/base.py b/tests/cloud_tests/testcases/base.py
18index 0d1916b..696db8d 100644
19--- a/tests/cloud_tests/testcases/base.py
20+++ b/tests/cloud_tests/testcases/base.py
21@@ -31,6 +31,27 @@ class CloudTestCase(unittest.TestCase):
22 def is_distro(self, distro_name):
23 return self.os_cfg['os'] == distro_name
24
25+ def assertPackageInstalled(self, name, version=None):
26+ """Check dpkg-query --show output for matching package name.
27+
28+ @param name: package base name
29+ @param version: string representing a package version or part of a
30+ version.
31+ """
32+ pkg_out = self.get_data_file('package-versions')
33+ pkg_match = re.search(
34+ '^%s\t(?P<version>.*)$' % name, pkg_out, re.MULTILINE)
35+ if pkg_match:
36+ installed_version = pkg_match.group('version')
37+ if not version:
38+ return # Success
39+ if installed_version.startswith(version):
40+ return # Success
41+ raise AssertionError(
42+ 'Expected package version %s-%s not found. Found %s' %
43+ name, version, installed_version)
44+ raise AssertionError('Package not installed: %s' % name)
45+
46 def os_version_cmp(self, cmp_version):
47 """Compare the version of the test to comparison_version.
48
49diff --git a/tests/cloud_tests/testcases/modules/byobu.py b/tests/cloud_tests/testcases/modules/byobu.py
50index 005ca01..74d0529 100644
51--- a/tests/cloud_tests/testcases/modules/byobu.py
52+++ b/tests/cloud_tests/testcases/modules/byobu.py
53@@ -9,8 +9,7 @@ class TestByobu(base.CloudTestCase):
54
55 def test_byobu_installed(self):
56 """Test byobu installed."""
57- out = self.get_data_file('byobu_installed')
58- self.assertIn('/usr/bin/byobu', out)
59+ self.assertPackageInstalled('byobu')
60
61 def test_byobu_profile_enabled(self):
62 """Test byobu profile.d file exists."""
63diff --git a/tests/cloud_tests/testcases/modules/byobu.yaml b/tests/cloud_tests/testcases/modules/byobu.yaml
64index a9aa1f3..d002a61 100644
65--- a/tests/cloud_tests/testcases/modules/byobu.yaml
66+++ b/tests/cloud_tests/testcases/modules/byobu.yaml
67@@ -7,9 +7,6 @@ cloud_config: |
68 #cloud-config
69 byobu_by_default: enable
70 collect_scripts:
71- byobu_installed: |
72- #!/bin/bash
73- which byobu
74 byobu_profile_enabled: |
75 #!/bin/bash
76 ls /etc/profile.d/Z97-byobu.sh
77diff --git a/tests/cloud_tests/testcases/modules/ca_certs.py b/tests/cloud_tests/testcases/modules/ca_certs.py
78index e75f041..6b56f63 100644
79--- a/tests/cloud_tests/testcases/modules/ca_certs.py
80+++ b/tests/cloud_tests/testcases/modules/ca_certs.py
81@@ -7,10 +7,23 @@ from tests.cloud_tests.testcases import base
82 class TestCaCerts(base.CloudTestCase):
83 """Test ca certs module."""
84
85- def test_cert_count(self):
86- """Test the count is proper."""
87- out = self.get_data_file('cert_count')
88- self.assertEqual(5, int(out))
89+ def test_certs_updated(self):
90+ """Test certs have been updated in /etc/ssl/certs."""
91+ out = self.get_data_file('cert_links')
92+ # Bionic update-ca-certificates creates less links debian #895075
93+ unlinked_files = []
94+ links = {}
95+ for cert_line in out.splitlines():
96+ if '->' in cert_line:
97+ fname, _sep, link = cert_line.split()
98+ links[fname] = link
99+ else:
100+ unlinked_files.append(cert_line)
101+ self.assertEqual(['ca-certificates.crt'], unlinked_files)
102+ self.assertEqual('cloud-init-ca-certs.pem', links['a535c1f3.0'])
103+ self.assertEqual(
104+ '/usr/share/ca-certificates/cloud-init-ca-certs.crt',
105+ links['cloud-init-ca-certs.pem'])
106
107 def test_cert_installed(self):
108 """Test line from our cert exists."""
109diff --git a/tests/cloud_tests/testcases/modules/ca_certs.yaml b/tests/cloud_tests/testcases/modules/ca_certs.yaml
110index d939f43..2cd9155 100644
111--- a/tests/cloud_tests/testcases/modules/ca_certs.yaml
112+++ b/tests/cloud_tests/testcases/modules/ca_certs.yaml
113@@ -43,9 +43,13 @@ cloud_config: |
114 DiH5uEqBXExjrj0FslxcVKdVj5glVcSmkLwZKbEU1OKwleT/iXFhvooWhQ==
115 -----END CERTIFICATE-----
116 collect_scripts:
117- cert_count: |
118+ cert_links: |
119 #!/bin/bash
120- ls -l /etc/ssl/certs | wc -l
121+ # links printed <filename> -> <link target>
122+ # non-links printed <filename>
123+ for file in `ls /etc/ssl/certs`; do
124+ [ -h /etc/ssl/certs/$file ] && echo -n $file ' -> ' && readlink /etc/ssl/certs/$file || echo $file;
125+ done
126 cert: |
127 #!/bin/bash
128 md5sum /etc/ssl/certs/ca-certificates.crt
129diff --git a/tests/cloud_tests/testcases/modules/ntp.py b/tests/cloud_tests/testcases/modules/ntp.py
130index b50e52f..c63cc15 100644
131--- a/tests/cloud_tests/testcases/modules/ntp.py
132+++ b/tests/cloud_tests/testcases/modules/ntp.py
133@@ -9,15 +9,14 @@ class TestNtp(base.CloudTestCase):
134
135 def test_ntp_installed(self):
136 """Test ntp installed"""
137- out = self.get_data_file('ntp_installed')
138- self.assertEqual(0, int(out))
139+ self.assertPackageInstalled('ntp')
140
141 def test_ntp_dist_entries(self):
142 """Test dist config file is empty"""
143 out = self.get_data_file('ntp_conf_dist_empty')
144 self.assertEqual(0, int(out))
145
146- def test_ntp_entires(self):
147+ def test_ntp_entries(self):
148 """Test config entries"""
149 out = self.get_data_file('ntp_conf_pool_list')
150 self.assertIn('pool.ntp.org iburst', out)
151diff --git a/tests/cloud_tests/testcases/modules/package_update_upgrade_install.py b/tests/cloud_tests/testcases/modules/package_update_upgrade_install.py
152index a92dec2..fecad76 100644
153--- a/tests/cloud_tests/testcases/modules/package_update_upgrade_install.py
154+++ b/tests/cloud_tests/testcases/modules/package_update_upgrade_install.py
155@@ -7,15 +7,13 @@ from tests.cloud_tests.testcases import base
156 class TestPackageInstallUpdateUpgrade(base.CloudTestCase):
157 """Test package install update upgrade module."""
158
159- def test_installed_htop(self):
160- """Test htop got installed."""
161- out = self.get_data_file('dpkg_htop')
162- self.assertEqual(1, int(out))
163+ def test_installed_sl(self):
164+ """Test sl got installed."""
165+ self.assertPackageInstalled('sl')
166
167 def test_installed_tree(self):
168 """Test tree got installed."""
169- out = self.get_data_file('dpkg_tree')
170- self.assertEqual(1, int(out))
171+ self.assertPackageInstalled('tree')
172
173 def test_apt_history(self):
174 """Test apt history for update command."""
175@@ -23,13 +21,13 @@ class TestPackageInstallUpdateUpgrade(base.CloudTestCase):
176 self.assertIn(
177 'Commandline: /usr/bin/apt-get --option=Dpkg::Options'
178 '::=--force-confold --option=Dpkg::options::=--force-unsafe-io '
179- '--assume-yes --quiet install htop tree', out)
180+ '--assume-yes --quiet install sl tree', out)
181
182 def test_cloud_init_output(self):
183 """Test cloud-init-output for install & upgrade stuff."""
184 out = self.get_data_file('cloud-init-output.log')
185 self.assertIn('Setting up tree (', out)
186- self.assertIn('Setting up htop (', out)
187+ self.assertIn('Setting up sl (', out)
188 self.assertIn('Reading package lists...', out)
189 self.assertIn('Building dependency tree...', out)
190 self.assertIn('Reading state information...', out)
191diff --git a/tests/cloud_tests/testcases/modules/package_update_upgrade_install.yaml b/tests/cloud_tests/testcases/modules/package_update_upgrade_install.yaml
192index 71d24b8..dd79e43 100644
193--- a/tests/cloud_tests/testcases/modules/package_update_upgrade_install.yaml
194+++ b/tests/cloud_tests/testcases/modules/package_update_upgrade_install.yaml
195@@ -15,7 +15,7 @@ required_features:
196 cloud_config: |
197 #cloud-config
198 packages:
199- - htop
200+ - sl
201 - tree
202 package_update: true
203 package_upgrade: true
204@@ -23,11 +23,8 @@ collect_scripts:
205 apt_history_cmdline: |
206 #!/bin/bash
207 grep ^Commandline: /var/log/apt/history.log
208- dpkg_htop: |
209+ dpkg_show: |
210 #!/bin/bash
211- dpkg -l | grep htop | wc -l
212- dpkg_tree: |
213- #!/bin/bash
214- dpkg -l | grep tree | wc -l
215+ dpkg-query --show
216
217 # vi: ts=4 expandtab
218diff --git a/tests/cloud_tests/testcases/modules/salt_minion.py b/tests/cloud_tests/testcases/modules/salt_minion.py
219index 70917a4..fc9688e 100644
220--- a/tests/cloud_tests/testcases/modules/salt_minion.py
221+++ b/tests/cloud_tests/testcases/modules/salt_minion.py
222@@ -33,7 +33,6 @@ class Test(base.CloudTestCase):
223
224 def test_minion_installed(self):
225 """Test if the salt-minion package is installed"""
226- out = self.get_data_file('minion_installed')
227- self.assertEqual(1, int(out))
228+ self.assertPackageInstalled('salt-minion')
229
230 # vi: ts=4 expandtab
231diff --git a/tests/cloud_tests/testcases/modules/salt_minion.yaml b/tests/cloud_tests/testcases/modules/salt_minion.yaml
232index f20b976..c24aa17 100644
233--- a/tests/cloud_tests/testcases/modules/salt_minion.yaml
234+++ b/tests/cloud_tests/testcases/modules/salt_minion.yaml
235@@ -35,8 +35,5 @@ collect_scripts:
236 grains: |
237 #!/bin/bash
238 cat /etc/salt/grains
239- minion_installed: |
240- #!/bin/bash
241- dpkg -l | grep salt-minion | grep ii | wc -l
242
243 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches