Merge ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:zazatests into ~livepatch-charmers/charm-canonical-livepatch:master
- Git
- lp:~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm
- zazatests
- Merge into master
Proposed by
Barry Price
Status: | Work in progress |
---|---|
Proposed branch: | ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:zazatests |
Merge into: | ~livepatch-charmers/charm-canonical-livepatch:master |
Diff against target: |
506 lines (+140/-215) 12 files modified
.gitignore (+1/-0) Makefile (+11/-21) dev/null (+0/-159) files/check_canonical-livepatch.py (+1/-3) metadata.yaml (+1/-1) reactive/canonical_livepatch.py (+11/-29) test-requirements.txt (+1/-0) tests/basic_deployment.py (+13/-0) tests/bundles/bionic.yaml (+18/-0) tests/bundles/xenial.yaml (+18/-0) tests/tests.yaml (+21/-2) tox.ini (+44/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Livepatch charm developers | Pending | ||
Review via email: mp+369790@code.launchpad.net |
Commit message
First pass at switching from amulet to tox+zaza for tests. Also dropping official support for Trusty as it's EOL. Oh, and some reformatting via `black`.
Description of the change
To post a comment you must log in.
- 3b5ee0d... by Barry Price
-
Obsolete comment removed
- 4bfc463... by Barry Price
-
Basic tests for an LXD deploy, need to figure out whether/how we can require an OpenStack controller for some test suites
Unmerged commits
- 4bfc463... by Barry Price
-
Basic tests for an LXD deploy, need to figure out whether/how we can require an OpenStack controller for some test suites
- 3b5ee0d... by Barry Price
-
Obsolete comment removed
- f8061f8... by Barry Price
-
First pass at switching from amulet to tox+zaza for tests. Also dropping official support for Trusty as it's EOL
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/.gitignore b/.gitignore | |||
2 | 0 | new file mode 100644 | 0 | new file mode 100644 |
3 | index 0000000..33defe4 | |||
4 | --- /dev/null | |||
5 | +++ b/.gitignore | |||
6 | @@ -0,0 +1 @@ | |||
7 | 1 | .tox/ | ||
8 | diff --git a/Makefile b/Makefile | |||
9 | index e7f78ad..7459cb2 100644 | |||
10 | --- a/Makefile | |||
11 | +++ b/Makefile | |||
12 | @@ -5,35 +5,25 @@ all: test | |||
13 | 5 | 5 | ||
14 | 6 | .PHONY: clean | 6 | .PHONY: clean |
15 | 7 | clean: | 7 | clean: |
16 | 8 | @rm -f .unit-state.db | ||
17 | 9 | @find . -name "*.pyc" -type f -exec rm -f '{}' \; | 8 | @find . -name "*.pyc" -type f -exec rm -f '{}' \; |
18 | 10 | @find . -name "__pycache__" -type d -prune -exec rm -rf '{}' \; | 9 | @find . -name "__pycache__" -type d -prune -exec rm -rf '{}' \; |
19 | 11 | 10 | ||
20 | 12 | .PHONY: testdeps | ||
21 | 13 | testdeps: | ||
22 | 14 | @sudo apt-get update | ||
23 | 15 | @sudo apt-get install -y make flake8 python3-flake8 python3-pip python-pip snapd libffi-dev | ||
24 | 16 | @which juju >/dev/null || (sudo snap install juju --classic) | ||
25 | 17 | @which charm >/dev/null || (sudo snap install charm --classic) | ||
26 | 18 | @which bundletester >/dev/null || (pip2 install bundletester juju-deployer) | ||
27 | 19 | @pip3 install amulet | ||
28 | 20 | |||
29 | 21 | .PHONY: lint | 11 | .PHONY: lint |
30 | 22 | lint: | 12 | lint: |
32 | 23 | @flake8 --max-complexity=16 --max-line-length=120 --exclude=lib/* && echo OK | 13 | @echo "Normalising python layout with black." |
33 | 14 | @tox -e black | ||
34 | 15 | @echo "Running flake8" | ||
35 | 16 | @tox -e lint | ||
36 | 24 | 17 | ||
37 | 25 | .PHONY: charmbuild | 18 | .PHONY: charmbuild |
38 | 26 | charmbuild: | 19 | charmbuild: |
40 | 27 | mkdir $(BUILDDEST) | 20 | mkdir -p $(BUILDDEST) |
41 | 28 | charm build --output-dir $(BUILDDEST) --report | 21 | charm build --output-dir $(BUILDDEST) --report |
42 | 29 | 22 | ||
47 | 30 | .PHONY: test | 23 | .PHONY: smoketest |
48 | 31 | test: check-jujumodel | 24 | smoketest: |
49 | 32 | @echo "Running functional tests (including lint and unit tests)..." | 25 | @tox -e func-smoke |
46 | 33 | bundletester -t $(BUILTCHARMDIR) -Fvl DEBUG -e $(JUJU_MODEL) | ||
50 | 34 | 26 | ||
56 | 35 | .PHONY: check-jujumodel | 27 | .PHONY: test |
57 | 36 | check-jujumodel: | 28 | test: |
58 | 37 | ifndef JUJU_MODEL | 29 | @tox -e func |
54 | 38 | $(error JUJU_MODEL is undefined) | ||
55 | 39 | endif | ||
59 | diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py | |||
60 | index cafd472..0006714 100755 | |||
61 | --- a/files/check_canonical-livepatch.py | |||
62 | +++ b/files/check_canonical-livepatch.py | |||
63 | @@ -142,9 +142,7 @@ def is_container(): | |||
64 | 142 | def main(): | 142 | def main(): |
65 | 143 | arch = os.uname()[4] | 143 | arch = os.uname()[4] |
66 | 144 | if arch not in supported_archs: | 144 | if arch not in supported_archs: |
70 | 145 | raise nagios_plugin3.CriticalError( | 145 | raise nagios_plugin3.CriticalError("canonical-livepatch not supported on this architecture ({}).".format(arch)) |
68 | 146 | "canonical-livepatch not supported on this architecture ({}).".format(arch) | ||
69 | 147 | ) | ||
71 | 148 | elif is_container(): | 146 | elif is_container(): |
72 | 149 | print("canonical-livepatch not needed in OS containers.") | 147 | print("canonical-livepatch not needed in OS containers.") |
73 | 150 | else: | 148 | else: |
74 | diff --git a/metadata.yaml b/metadata.yaml | |||
75 | index 6c22c45..e3e557f 100644 | |||
76 | --- a/metadata.yaml | |||
77 | +++ b/metadata.yaml | |||
78 | @@ -2,7 +2,7 @@ name: canonical-livepatch | |||
79 | 2 | display-name: Canonical Livepatch | 2 | display-name: Canonical Livepatch |
80 | 3 | summary: Ubuntu Linux Livepatching Utility and Daemon | 3 | summary: Ubuntu Linux Livepatching Utility and Daemon |
81 | 4 | maintainer: Livepatch charm developers <livepatch-charmers@lists.launchpad.net> | 4 | maintainer: Livepatch charm developers <livepatch-charmers@lists.launchpad.net> |
83 | 5 | series: ['bionic', 'xenial', 'trusty'] | 5 | series: ['bionic', 'xenial'] |
84 | 6 | description: | | 6 | description: | |
85 | 7 | This charms installs and configures the Ubuntu Linux Livepatching Utility and Daemon | 7 | This charms installs and configures the Ubuntu Linux Livepatching Utility and Daemon |
86 | 8 | tags: | 8 | tags: |
87 | diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py | |||
88 | index f9c1e6e..30692a1 100644 | |||
89 | --- a/reactive/canonical_livepatch.py | |||
90 | +++ b/reactive/canonical_livepatch.py | |||
91 | @@ -19,12 +19,7 @@ def file_to_units(local_path, unit_path): | |||
92 | 19 | perms = 0o644 | 19 | perms = 0o644 |
93 | 20 | 20 | ||
94 | 21 | fh = open(local_path, 'r') | 21 | fh = open(local_path, 'r') |
101 | 22 | write_file( | 22 | write_file(path=unit_path, content=fh.read().encode(), owner='root', perms=perms) |
96 | 23 | path=unit_path, | ||
97 | 24 | content=fh.read().encode(), | ||
98 | 25 | owner='root', | ||
99 | 26 | perms=perms, | ||
100 | 27 | ) | ||
102 | 28 | 23 | ||
103 | 29 | 24 | ||
104 | 30 | def wait_for_path(file_path, timeout=30): | 25 | def wait_for_path(file_path, timeout=30): |
105 | @@ -74,12 +69,7 @@ def write_status_to_disk(): | |||
106 | 74 | 69 | ||
107 | 75 | current_status = get_livepatch_status() | 70 | current_status = get_livepatch_status() |
108 | 76 | perms = 0o644 | 71 | perms = 0o644 |
115 | 77 | write_file( | 72 | write_file(path='/var/lib/nagios/canonical-livepatch-status.txt', content=current_status, owner='root', perms=perms) |
110 | 78 | path='/var/lib/nagios/canonical-livepatch-status.txt', | ||
111 | 79 | content=current_status, | ||
112 | 80 | owner='root', | ||
113 | 81 | perms=perms, | ||
114 | 82 | ) | ||
116 | 83 | 73 | ||
117 | 84 | 74 | ||
118 | 85 | def get_patch_details(): | 75 | def get_patch_details(): |
119 | @@ -161,7 +151,7 @@ register_trigger(when='config.changed.livepatch_proxy', clear_flag='livepatch-pr | |||
120 | 161 | @when_not('canonical-livepatch.supported') | 151 | @when_not('canonical-livepatch.supported') |
121 | 162 | def livepatch_supported(): | 152 | def livepatch_supported(): |
122 | 163 | arch = uname()[4] | 153 | arch = uname()[4] |
124 | 164 | supported_archs = ['x86_64', ] | 154 | supported_archs = ['x86_64'] |
125 | 165 | if arch not in supported_archs: | 155 | if arch not in supported_archs: |
126 | 166 | hookenv.log('Livepatch does not currently support {} architecture'.format(arch)) | 156 | hookenv.log('Livepatch does not currently support {} architecture'.format(arch)) |
127 | 167 | unit_update('blocked', 'Architecture {} is not supported by livepatch'.format(arch)) | 157 | unit_update('blocked', 'Architecture {} is not supported by livepatch'.format(arch)) |
128 | @@ -177,7 +167,7 @@ def livepatch_supported(): | |||
129 | 177 | def install_livepatch(): | 167 | def install_livepatch(): |
130 | 178 | config = hookenv.config() | 168 | config = hookenv.config() |
131 | 179 | snap_channel = config.get('snap_channel') | 169 | snap_channel = config.get('snap_channel') |
133 | 180 | snap.install('canonical-livepatch', **{'channel': snap_channel, }) | 170 | snap.install('canonical-livepatch', **{'channel': snap_channel}) |
134 | 181 | 171 | ||
135 | 182 | 172 | ||
136 | 183 | @when('snap.installed.canonical-livepatch') | 173 | @when('snap.installed.canonical-livepatch') |
137 | @@ -210,8 +200,8 @@ def proxy_settings(): | |||
138 | 210 | @when('livepatch-proxy.configured') | 200 | @when('livepatch-proxy.configured') |
139 | 211 | @when_not('canonical-livepatch.connected') | 201 | @when_not('canonical-livepatch.connected') |
140 | 212 | def canonical_livepatch_connect(): | 202 | def canonical_livepatch_connect(): |
143 | 213 | # So if we've just installed snapd on a trusty system, we will not be on | 203 | # So if we've just installed snapd on a trusty system, or are somehow |
144 | 214 | # the HWE kernel yet and unfortunately need to reboot first! | 204 | # running an older kernel onto a supported series, we will need to reboot |
145 | 215 | current = LooseVersion(uname()[2]) | 205 | current = LooseVersion(uname()[2]) |
146 | 216 | required = LooseVersion('4.4') | 206 | required = LooseVersion('4.4') |
147 | 217 | uptrack_path = '/usr/sbin/uptrack-upgrade' | 207 | uptrack_path = '/usr/sbin/uptrack-upgrade' |
148 | @@ -250,7 +240,7 @@ def change_channel(): | |||
149 | 250 | config = hookenv.config() | 240 | config = hookenv.config() |
150 | 251 | snap_channel = config.get('snap_channel') | 241 | snap_channel = config.get('snap_channel') |
151 | 252 | # refresh to the given channel | 242 | # refresh to the given channel |
153 | 253 | snap.refresh('canonical-livepatch', **{'channel': snap_channel, }) | 243 | snap.refresh('canonical-livepatch', **{'channel': snap_channel}) |
154 | 254 | 244 | ||
155 | 255 | 245 | ||
156 | 256 | # Set up Nagios checks when the nrpe-external-master subordinate is related | 246 | # Set up Nagios checks when the nrpe-external-master subordinate is related |
157 | @@ -266,28 +256,20 @@ def configure_nagios(nagios): | |||
158 | 266 | nrpe_setup = nrpe.NRPE(hostname=hostname, primary=False) | 256 | nrpe_setup = nrpe.NRPE(hostname=hostname, primary=False) |
159 | 267 | 257 | ||
160 | 268 | # install nagios support files | 258 | # install nagios support files |
169 | 269 | file_to_units( | 259 | file_to_units('files/check_canonical-livepatch.cron', '/etc/cron.d/check_canonical-livepatch') |
170 | 270 | 'files/check_canonical-livepatch.cron', | 260 | file_to_units('files/check_canonical-livepatch.py', '/usr/lib/nagios/plugins/check_canonical-livepatch.py') |
163 | 271 | '/etc/cron.d/check_canonical-livepatch', | ||
164 | 272 | ) | ||
165 | 273 | file_to_units( | ||
166 | 274 | 'files/check_canonical-livepatch.py', | ||
167 | 275 | '/usr/lib/nagios/plugins/check_canonical-livepatch.py', | ||
168 | 276 | ) | ||
171 | 277 | 261 | ||
172 | 278 | # write current status to disk to satisfy the nagios check | 262 | # write current status to disk to satisfy the nagios check |
173 | 279 | write_status_to_disk() | 263 | write_status_to_disk() |
174 | 280 | 264 | ||
175 | 281 | # remove check from previous release with poorly formed name | 265 | # remove check from previous release with poorly formed name |
179 | 282 | nrpe_setup.remove_check( | 266 | nrpe_setup.remove_check(shortname='check_canonical-livepatch') |
177 | 283 | shortname='check_canonical-livepatch' | ||
178 | 284 | ) | ||
180 | 285 | 267 | ||
181 | 286 | # use charmhelpers to create the check | 268 | # use charmhelpers to create the check |
182 | 287 | nrpe_setup.add_check( | 269 | nrpe_setup.add_check( |
183 | 288 | 'canonical-livepatch', | 270 | 'canonical-livepatch', |
184 | 289 | 'Verify canonical-livepatch is working', | 271 | 'Verify canonical-livepatch is working', |
186 | 290 | '/usr/lib/nagios/plugins/check_canonical-livepatch.py' | 272 | '/usr/lib/nagios/plugins/check_canonical-livepatch.py', |
187 | 291 | ) | 273 | ) |
188 | 292 | 274 | ||
189 | 293 | nrpe_setup.write() | 275 | nrpe_setup.write() |
190 | diff --git a/test-requirements.txt b/test-requirements.txt | |||
191 | 294 | new file mode 100644 | 276 | new file mode 100644 |
192 | index 0000000..b7c9112 | |||
193 | --- /dev/null | |||
194 | +++ b/test-requirements.txt | |||
195 | @@ -0,0 +1 @@ | |||
196 | 1 | git+https://github.com/openstack-charmers/zaza.git#egg=zaza | ||
197 | diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py | |||
198 | 0 | new file mode 100644 | 2 | new file mode 100644 |
199 | index 0000000..a07e880 | |||
200 | --- /dev/null | |||
201 | +++ b/tests/basic_deployment.py | |||
202 | @@ -0,0 +1,13 @@ | |||
203 | 1 | #!/usr/bin/python3 | ||
204 | 2 | |||
205 | 3 | import unittest | ||
206 | 4 | |||
207 | 5 | import zaza.model as model | ||
208 | 6 | |||
209 | 7 | |||
210 | 8 | class BasicDeployment(unittest.TestCase): | ||
211 | 9 | def test_ubuntu_series(self): | ||
212 | 10 | first_unit = model.get_units('mongo')[0] | ||
213 | 11 | result = model.run_on_leader('mongo', 'lsb_release -cs') | ||
214 | 12 | self.assertEqual(result['Code'], '0') | ||
215 | 13 | self.assertEqual(result['Stdout'].strip(), first_unit.series) | ||
216 | diff --git a/tests/bundles/bionic.yaml b/tests/bundles/bionic.yaml | |||
217 | 0 | new file mode 100644 | 14 | new file mode 100644 |
218 | index 0000000..f95419d | |||
219 | --- /dev/null | |||
220 | +++ b/tests/bundles/bionic.yaml | |||
221 | @@ -0,0 +1,18 @@ | |||
222 | 1 | series: bionic | ||
223 | 2 | applications: | ||
224 | 3 | mongo: | ||
225 | 4 | charm: cs:mongodb | ||
226 | 5 | num_units: 1 | ||
227 | 6 | livepatch: | ||
228 | 7 | charm: ../../../builds/canonical-livepatch | ||
229 | 8 | series: bionic | ||
230 | 9 | nrpe: | ||
231 | 10 | charm: cs:nrpe | ||
232 | 11 | num_units: 0 | ||
233 | 12 | relations: | ||
234 | 13 | - - mongo | ||
235 | 14 | - livepatch | ||
236 | 15 | - - mongo | ||
237 | 16 | - nrpe:nrpe-external-master | ||
238 | 17 | - - livepatch | ||
239 | 18 | - nrpe:nrpe-external-master | ||
240 | diff --git a/tests/bundles/xenial.yaml b/tests/bundles/xenial.yaml | |||
241 | 0 | new file mode 100644 | 19 | new file mode 100644 |
242 | index 0000000..5b52957 | |||
243 | --- /dev/null | |||
244 | +++ b/tests/bundles/xenial.yaml | |||
245 | @@ -0,0 +1,18 @@ | |||
246 | 1 | series: xenial | ||
247 | 2 | applications: | ||
248 | 3 | mongo: | ||
249 | 4 | charm: cs:mongodb | ||
250 | 5 | num_units: 1 | ||
251 | 6 | livepatch: | ||
252 | 7 | charm: ../../../builds/canonical-livepatch | ||
253 | 8 | series: xenial | ||
254 | 9 | nrpe: | ||
255 | 10 | charm: cs:nrpe | ||
256 | 11 | num_units: 0 | ||
257 | 12 | relations: | ||
258 | 13 | - - mongo | ||
259 | 14 | - livepatch | ||
260 | 15 | - - mongo | ||
261 | 16 | - nrpe:nrpe-external-master | ||
262 | 17 | - - livepatch | ||
263 | 18 | - nrpe:nrpe-external-master | ||
264 | diff --git a/tests/multiseries b/tests/multiseries | |||
265 | 0 | deleted file mode 100755 | 19 | deleted file mode 100755 |
266 | index 55adc62..0000000 | |||
267 | --- a/tests/multiseries | |||
268 | +++ /dev/null | |||
269 | @@ -1,159 +0,0 @@ | |||
270 | 1 | #!/usr/bin/env python3 | ||
271 | 2 | |||
272 | 3 | import amulet | ||
273 | 4 | import unittest | ||
274 | 5 | from time import sleep | ||
275 | 6 | from yaml import safe_load | ||
276 | 7 | |||
277 | 8 | |||
278 | 9 | class TestDeployment(unittest.TestCase): | ||
279 | 10 | series = 'bionic' # latest LTS | ||
280 | 11 | |||
281 | 12 | @classmethod | ||
282 | 13 | def setUpClass(cls): | ||
283 | 14 | cls.deployment = amulet.Deployment(series=cls.series) | ||
284 | 15 | |||
285 | 16 | # deploy mongodb as our parent | ||
286 | 17 | cls.deployment.add('mongodb-{}'.format(cls.series), 'mongodb') | ||
287 | 18 | |||
288 | 19 | # deploy our own charm | ||
289 | 20 | cls.deployment.add('livepatch-{}'.format(cls.series), 'canonical-livepatch') | ||
290 | 21 | |||
291 | 22 | # and deploy the nrpe subordinate to test nagios checks | ||
292 | 23 | cls.deployment.add('nrpe-{}'.format(cls.series), 'nrpe') | ||
293 | 24 | |||
294 | 25 | # set nrpe to export its definitions | ||
295 | 26 | cls.deployment.configure('nrpe-{}'.format(cls.series), { | ||
296 | 27 | 'export_nagios_definitions': True, | ||
297 | 28 | }) | ||
298 | 29 | |||
299 | 30 | # relate subordinates to parent charm | ||
300 | 31 | cls.deployment.relate( | ||
301 | 32 | 'mongodb-{}:juju-info'.format(cls.series), | ||
302 | 33 | 'livepatch-{}:juju-info'.format(cls.series) | ||
303 | 34 | ) | ||
304 | 35 | cls.deployment.relate( | ||
305 | 36 | 'mongodb-{}:nrpe-external-master'.format(cls.series), | ||
306 | 37 | 'nrpe-{}:nrpe-external-master'.format(cls.series) | ||
307 | 38 | ) | ||
308 | 39 | |||
309 | 40 | # relate livepatch to nrpe for its own nagios checks | ||
310 | 41 | cls.deployment.relate( | ||
311 | 42 | 'livepatch-{}:nrpe-external-master'.format(cls.series), | ||
312 | 43 | 'nrpe-{}:nrpe-external-master'.format(cls.series) | ||
313 | 44 | ) | ||
314 | 45 | |||
315 | 46 | try: | ||
316 | 47 | cls.deployment.setup(timeout=3600) | ||
317 | 48 | cls.deployment.sentry.wait() | ||
318 | 49 | except amulet.helpers.TimeoutError: | ||
319 | 50 | amulet.raise_status( | ||
320 | 51 | amulet.SKIP, | ||
321 | 52 | msg="Environment wasn't stood up in time" | ||
322 | 53 | ) | ||
323 | 54 | |||
324 | 55 | def test_install(self): | ||
325 | 56 | livepatch = self.deployment.sentry['livepatch-{}'.format(self.series)][0] | ||
326 | 57 | |||
327 | 58 | # verify the snap was installed | ||
328 | 59 | output, exit_code = livepatch.run( | ||
329 | 60 | 'stat /snap/bin/canonical-livepatch' | ||
330 | 61 | ) | ||
331 | 62 | self.assertEqual(exit_code, 0) | ||
332 | 63 | |||
333 | 64 | def test_status(self): | ||
334 | 65 | livepatch = self.deployment.sentry['livepatch-{}'.format(self.series)][0] | ||
335 | 66 | |||
336 | 67 | # run a status check - we expect this to return 1 due to no access key | ||
337 | 68 | output, exit_code = livepatch.run('sudo canonical-livepatch status') | ||
338 | 69 | self.assertEqual(exit_code, 1) | ||
339 | 70 | |||
340 | 71 | def test_nagios_init(self): | ||
341 | 72 | livepatch = self.deployment.sentry['livepatch-{}'.format(self.series)][0] | ||
342 | 73 | |||
343 | 74 | # check for nagios bits | ||
344 | 75 | for path in [ | ||
345 | 76 | '/etc/cron.d/check_canonical-livepatch', | ||
346 | 77 | '/usr/lib/nagios/plugins/check_canonical-livepatch.py', | ||
347 | 78 | '/var/lib/nagios/canonical-livepatch-status.txt' | ||
348 | 79 | ]: | ||
349 | 80 | output, exit_code = livepatch.run('stat {}'.format(path)) | ||
350 | 81 | self.assertEqual(exit_code, 0) | ||
351 | 82 | |||
352 | 83 | def test_nagios_context_change(self): | ||
353 | 84 | livepatch = self.deployment.sentry['livepatch-{}'.format(self.series)][0] | ||
354 | 85 | |||
355 | 86 | test_context_name = 'amulet1' | ||
356 | 87 | |||
357 | 88 | # set context name | ||
358 | 89 | self.deployment.configure('livepatch-{}'.format(self.series), { | ||
359 | 90 | 'nagios_context': test_context_name, | ||
360 | 91 | }) | ||
361 | 92 | |||
362 | 93 | # nrpe updates can take a while | ||
363 | 94 | sleep(30) | ||
364 | 95 | |||
365 | 96 | # confirm it showed up in the right place | ||
366 | 97 | output, exit_code = livepatch.run( | ||
367 | 98 | 'grep {} /var/lib/nagios/export/' | ||
368 | 99 | 'service__*_check_canonical-livepatch' | ||
369 | 100 | '.cfg'.format(test_context_name)) | ||
370 | 101 | self.assertEqual(exit_code, 0) | ||
371 | 102 | |||
372 | 103 | def test_channel_change(self): | ||
373 | 104 | livepatch = self.deployment.sentry['livepatch-{}'.format(self.series)][0] | ||
374 | 105 | |||
375 | 106 | # verify the current channel | ||
376 | 107 | output, exit_code = livepatch.run('snap info canonical-livepatch') | ||
377 | 108 | self.assertEqual(exit_code, 0) | ||
378 | 109 | |||
379 | 110 | # confirm we're tracking 'stable' | ||
380 | 111 | output_yaml = safe_load(output) | ||
381 | 112 | channel = output_yaml['tracking'] | ||
382 | 113 | self.assertEqual(channel, 'stable') | ||
383 | 114 | |||
384 | 115 | # change channel to 'beta' | ||
385 | 116 | self.deployment.configure('livepatch-{}'.format(self.series), { | ||
386 | 117 | 'snap_channel': 'beta', | ||
387 | 118 | }) | ||
388 | 119 | |||
389 | 120 | # wait for that to settle | ||
390 | 121 | sleep(30) | ||
391 | 122 | |||
392 | 123 | # verify the current channel | ||
393 | 124 | output, exit_code = livepatch.run('snap info canonical-livepatch') | ||
394 | 125 | self.assertEqual(exit_code, 0) | ||
395 | 126 | |||
396 | 127 | # confirm we're tracking 'beta' | ||
397 | 128 | output_yaml = safe_load(output) | ||
398 | 129 | channel = output_yaml['tracking'] | ||
399 | 130 | self.assertEqual(channel, 'beta') | ||
400 | 131 | |||
401 | 132 | def test_nagios_servicegroup_change(self): | ||
402 | 133 | livepatch = self.deployment.sentry['livepatch-{}'.format(self.series)][0] | ||
403 | 134 | |||
404 | 135 | test_servicegroup_name = 'amulet2' | ||
405 | 136 | |||
406 | 137 | # set servicegroup name | ||
407 | 138 | self.deployment.configure('livepatch-{}'.format(self.series), { | ||
408 | 139 | 'nagios_servicegroups': test_servicegroup_name, | ||
409 | 140 | }) | ||
410 | 141 | |||
411 | 142 | # nrpe updates can take a while | ||
412 | 143 | sleep(30) | ||
413 | 144 | |||
414 | 145 | # confirm it showed up in the right place | ||
415 | 146 | output, exit_code = livepatch.run( | ||
416 | 147 | 'grep {} /var/lib/nagios/export/' | ||
417 | 148 | 'service__*_check_canonical-livepatch' | ||
418 | 149 | '.cfg'.format(test_servicegroup_name) | ||
419 | 150 | ) | ||
420 | 151 | self.assertEqual(exit_code, 0) | ||
421 | 152 | |||
422 | 153 | |||
423 | 154 | class TestXenialDeployment(TestDeployment): | ||
424 | 155 | series = 'xenial' | ||
425 | 156 | |||
426 | 157 | |||
427 | 158 | if __name__ == '__main__': | ||
428 | 159 | unittest.main() | ||
429 | diff --git a/tests/tests.yaml b/tests/tests.yaml | |||
430 | index 757bcc2..2754f7c 100644 | |||
431 | --- a/tests/tests.yaml | |||
432 | +++ b/tests/tests.yaml | |||
433 | @@ -1,2 +1,21 @@ | |||
436 | 1 | makefile: | 1 | charm-name: canonical-livepatch |
437 | 2 | - lint | 2 | tests: |
438 | 3 | - zaza.charm_tests.noop.tests.NoopTest | ||
439 | 4 | configure: | ||
440 | 5 | - zaza.charm_tests.noop.setup.basic_setup | ||
441 | 6 | gate_bundles: | ||
442 | 7 | - bionic | ||
443 | 8 | smoke_bundles: | ||
444 | 9 | - bionic | ||
445 | 10 | tests: | ||
446 | 11 | - tests.basic_deployment.BasicDeployment | ||
447 | 12 | target_deploy_status: | ||
448 | 13 | mongo: | ||
449 | 14 | workload-status: active | ||
450 | 15 | workload-status-message: Unit is ready | ||
451 | 16 | livepatch: | ||
452 | 17 | workload-status: blocked | ||
453 | 18 | workload-status-message: Livepatch is not needed in OS containers | ||
454 | 19 | nrpe: | ||
455 | 20 | workload-status: active | ||
456 | 21 | workload-status-message: ready | ||
457 | diff --git a/tox.ini b/tox.ini | |||
458 | 3 | new file mode 100644 | 22 | new file mode 100644 |
459 | index 0000000..4b3e051 | |||
460 | --- /dev/null | |||
461 | +++ b/tox.ini | |||
462 | @@ -0,0 +1,44 @@ | |||
463 | 1 | [tox] | ||
464 | 2 | envlist = pep8 | ||
465 | 3 | skipsdist = True | ||
466 | 4 | |||
467 | 5 | [testenv] | ||
468 | 6 | setenv = VIRTUAL_ENV={envdir} | ||
469 | 7 | PYTHONHASHSEED=0 | ||
470 | 8 | whitelist_externals = juju | ||
471 | 9 | passenv = HOME TERM CS_API_* OS_* AMULET_* | ||
472 | 10 | deps = -r{toxinidir}/test-requirements.txt | ||
473 | 11 | install_command = | ||
474 | 12 | pip install {opts} {packages} | ||
475 | 13 | |||
476 | 14 | [testenv:proof] | ||
477 | 15 | basepython = python3 | ||
478 | 16 | deps=charm-tools | ||
479 | 17 | commands = charm-proof | ||
480 | 18 | |||
481 | 19 | [testenv:black] | ||
482 | 20 | commands = black --skip-string-normalization --line-length=120 . | ||
483 | 21 | deps = black | ||
484 | 22 | |||
485 | 23 | [testenv:lint] | ||
486 | 24 | commands = flake8 | ||
487 | 25 | deps = flake8 | ||
488 | 26 | |||
489 | 27 | [testenv:func-noop] | ||
490 | 28 | basepython = python3 | ||
491 | 29 | commands = | ||
492 | 30 | true | ||
493 | 31 | |||
494 | 32 | [testenv:func] | ||
495 | 33 | basepython = python3 | ||
496 | 34 | commands = | ||
497 | 35 | functest-run-suite --keep-model | ||
498 | 36 | |||
499 | 37 | [testenv:func-smoke] | ||
500 | 38 | basepython = python3 | ||
501 | 39 | commands = | ||
502 | 40 | functest-run-suite --keep-model --smoke | ||
503 | 41 | |||
504 | 42 | [testenv:venv] | ||
505 | 43 | commands = {posargs} | ||
506 | 44 |