Merge ~hyask/autopkgtest-cloud:skia/reactive_charm_status into autopkgtest-cloud:master
- Git
- lp:~hyask/autopkgtest-cloud
- skia/reactive_charm_status
- Merge into master
Proposed by
Skia
Status: | Merged |
---|---|
Merged at revision: | 127c2d83e913154613974c313a46715606e6a133 |
Proposed branch: | ~hyask/autopkgtest-cloud:skia/reactive_charm_status |
Merge into: | autopkgtest-cloud:master |
Diff against target: |
486 lines (+78/-2) 2 files modified
charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py (+45/-0) charms/focal/autopkgtest-web/reactive/autopkgtest_web.py (+33/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Andersson | Approve | ||
Review via email: mp+461531@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py |
2 | index 2e8f376..b00037f 100644 |
3 | --- a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py |
4 | +++ b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py |
5 | @@ -52,12 +52,16 @@ RABBITMQ_CRED_PATH = os.path.expanduser("~ubuntu/rabbitmq.cred") |
6 | |
7 | @when_not("autopkgtest.autopkgtest_cloud_symlinked") |
8 | def symlink_autopkgtest_cloud(): |
9 | + status.maintenance("Creating symlink to charmed autopkgtest-cloud code") |
10 | with UnixUser("ubuntu"): |
11 | try: |
12 | autopkgtest_cloud = os.path.join(charm_dir(), "autopkgtest-cloud") |
13 | os.symlink(autopkgtest_cloud, AUTOPKGTEST_CLOUD_LOCATION) |
14 | except FileExistsError: |
15 | pass |
16 | + status.maintenance( |
17 | + "Done creating symlink to charmed autopkgtest-cloud code" |
18 | + ) |
19 | set_flag("autopkgtest.autopkgtest_cloud_symlinked") |
20 | |
21 | |
22 | @@ -97,7 +101,9 @@ def clone_autopkgtest_package_configs(): |
23 | @when("autopkgtest.autodep8_cloned") |
24 | @when_not("autopkgtest.autodep8_installed") |
25 | def initially_install_autodep8(): |
26 | + status.maintenance("Installing autodep8") |
27 | install_autodep8(AUTODEP8_LOCATION) |
28 | + status.maintenance("Done installing autodep8") |
29 | set_flag("autopkgtest.autodep8_installed") |
30 | |
31 | |
32 | @@ -125,6 +131,7 @@ def clone_autopkgtest(): |
33 | "autopkgtest.influx-creds-written", |
34 | ) |
35 | def set_up_systemd_units(): |
36 | + status.maintenance("Installing systemd units") |
37 | for unit in glob.glob(os.path.join(charm_dir(), "units", "*")): |
38 | base = os.path.basename(unit) |
39 | dest = os.path.join(os.path.sep, "etc", "systemd", "system", base) |
40 | @@ -141,30 +148,39 @@ def set_up_systemd_units(): |
41 | if not os.path.islink(dest): |
42 | os.unlink(dest) |
43 | link_and_enable() |
44 | + status.maintenance("Done installing systemd units") |
45 | set_flag("autopkgtest.systemd_units_linked_and_enabled") |
46 | |
47 | |
48 | @when("autopkgtest.systemd_units_linked_and_enabled") |
49 | @when_not("autopkgtest.target_running") |
50 | def start(): |
51 | + status.maintenance("Enabling and starting autopkgtest systemd target") |
52 | subprocess.check_call( |
53 | ["systemctl", "enable", "--now", "autopkgtest.target"] |
54 | ) |
55 | + status.maintenance("Done enabling and starting autopkgtest systemd target") |
56 | set_flag("autopkgtest.target_running") |
57 | |
58 | |
59 | @hook("stop") |
60 | @when("autopkgtest.target_running") |
61 | def stop(): |
62 | + status.maintenance("Disabling and stopping autopkgtest systemd target") |
63 | subprocess.check_call( |
64 | ["systemctl", "disable", "--now", "autopkgtest.target"] |
65 | ) |
66 | + status.maintenance( |
67 | + "Done disabling and stopping autopkgtest systemd target" |
68 | + ) |
69 | clear_flag("autopkgtest.target_running") |
70 | |
71 | |
72 | @when_all("autopkgtest.target-restart-needed", "autopkgtest.target_running") |
73 | def restart_target(): |
74 | + status.maintenance("Restarting autopkgtest systemd target") |
75 | subprocess.check_call(["systemctl", "restart", "autopkgtest.target"]) |
76 | + status.maintenance("Done restarting autopkgtest systemd target") |
77 | clear_flag("autopkgtest.target-restart-needed") |
78 | |
79 | |
80 | @@ -180,7 +196,9 @@ def is_active(): |
81 | ) |
82 | @hook("upgrade-charm") |
83 | def daemon_reload(): |
84 | + status.maintenance("Reloading systemd configuration after change") |
85 | subprocess.check_call(["systemctl", "daemon-reload"]) |
86 | + status.maintenance("Done reloading systemd configuration after change") |
87 | clear_flag("autopkgtest.daemon-reload-needed") |
88 | |
89 | |
90 | @@ -193,6 +211,7 @@ def install_apt_packages(): |
91 | |
92 | @hook("install") |
93 | def enable_persistent_journal(): |
94 | + status.maintenance("Enabling persistent journal") |
95 | try: |
96 | journal_dir = os.path.join(os.path.sep, "var", "log", "journal") |
97 | os.makedirs(journal_dir) |
98 | @@ -202,6 +221,7 @@ def enable_persistent_journal(): |
99 | subprocess.check_call(["systemctl", "restart", "systemd-journald"]) |
100 | except FileExistsError: |
101 | pass |
102 | + status.maintenance("Done enabling persistent journal") |
103 | |
104 | |
105 | @when("amqp.connected") |
106 | @@ -237,16 +257,19 @@ def set_up_rabbitmq(rabbitmq): |
107 | |
108 | @when_not("amqp.available") |
109 | def clear_rabbitmq(): |
110 | + status.maintenance("clearing rabbitmq configuration") |
111 | try: |
112 | log("rabbitmq not available, deleting credentials file") |
113 | os.unlink(RABBITMQ_CRED_PATH) |
114 | clear_flag("autopkgtest.rabbitmq-configured") |
115 | except FileNotFoundError: |
116 | pass |
117 | + status.maintenance("Done clearing rabbitmq configuration") |
118 | |
119 | |
120 | @when("config.changed.nova-rcs") |
121 | def update_nova_rcs(): |
122 | + status.maintenance("Updating nova rc files") |
123 | # pylint: disable=import-outside-toplevel |
124 | import base64 |
125 | from io import BytesIO |
126 | @@ -268,10 +291,12 @@ def update_nova_rcs(): |
127 | log("...got {}".format(", ".join(tar.getnames())), "INFO") |
128 | |
129 | tar.extractall(os.path.expanduser("~ubuntu/cloudrcs/")) |
130 | + status.maintenance("Done updating nova rc files") |
131 | |
132 | |
133 | @when("config.default.nova-rcs") |
134 | def clear_old_rcs(): |
135 | + status.maintenance("Cleaning old nova rc files") |
136 | rcfiles = glob.glob(os.path.expanduser("~ubuntu/cloudrcs/*.rc")) |
137 | |
138 | if not rcfiles: |
139 | @@ -284,6 +309,7 @@ def clear_old_rcs(): |
140 | os.unlink(rcfile) |
141 | |
142 | log("...done", "INFO") |
143 | + status.maintenance("Done cleaning old nova rc files") |
144 | |
145 | |
146 | @when_all( |
147 | @@ -327,6 +353,8 @@ def enable_disable_units(): |
148 | nworkers_yaml or {}, lxdremotes_yaml or {}, releases.split() |
149 | ) |
150 | |
151 | + status.maintenance("Done enabling and starting worker units") |
152 | + |
153 | set_flag("autopkgtest.reload-needed") |
154 | set_flag("autopkgtest.daemon-reload-needed") |
155 | set_flag("autopkgtest.target-restart-needed") |
156 | @@ -339,7 +367,9 @@ def enable_disable_units(): |
157 | ) |
158 | @when_not("autopkgtest.ubuntu_added_to_lxd_group") |
159 | def add_ubuntu_user_to_lxd_group(): |
160 | + status.maintenance("Adding ubuntu user to lxd group") |
161 | subprocess.check_call(["adduser", "ubuntu", "lxd"]) |
162 | + status.maintenance("Done adding ubuntu user to lxd group") |
163 | set_flag("autopkgtest.ubuntu_added_to_lxd_group") |
164 | |
165 | |
166 | @@ -405,6 +435,7 @@ def write_v2_config(): |
167 | |
168 | |
169 | def write_swift_config(): |
170 | + status.maintenance("Writing swift configuration") |
171 | with open( |
172 | os.path.expanduser("~ubuntu/swift-password.cred"), "w" |
173 | ) as swift_password_file: |
174 | @@ -416,6 +447,7 @@ def write_swift_config(): |
175 | str(config()[key]).strip(), |
176 | ) |
177 | ) |
178 | + status.maintenance("Done writing swift configuration") |
179 | |
180 | |
181 | @when_any( |
182 | @@ -432,6 +464,8 @@ def write_swift_config(): |
183 | ) |
184 | @when_any("config.set.nova-rcs", "config.set.lxd-remotes") |
185 | def write_worker_config(): |
186 | + status.maintenance("Writing worker configuration") |
187 | + |
188 | # pylint: disable=import-outside-toplevel |
189 | import configparser |
190 | |
191 | @@ -523,23 +557,28 @@ def write_worker_config(): |
192 | conf["autopkgtest"]["architectures"] = arch |
193 | write(conf_file) |
194 | |
195 | + status.maintenance("Done writing worker configuration") |
196 | set_flag("autopkgtest.daemon-reload-needed") |
197 | set_flag("autopkgtest.reload-needed") |
198 | |
199 | |
200 | @when("config.changed.net-name") |
201 | def write_net_name(): |
202 | + status.maintenance("Writing net-name configuration") |
203 | clear_flag("autopkgtest.net-name-written") |
204 | with open(os.path.expanduser("~ubuntu/net-name.rc"), "w") as f: |
205 | f.write('NET_NAME="{}"\n'.format(config().get("net-name"))) |
206 | + status.maintenance("Done writing net-name configuration") |
207 | set_flag("autopkgtest.net-name-written") |
208 | set_flag("autopkgtest.reload-needed") |
209 | |
210 | |
211 | @when("config.changed.mirror") |
212 | def write_mirror(): |
213 | + status.maintenance("Writing mirror configuration") |
214 | with open(os.path.expanduser("~ubuntu/mirror.rc"), "w") as f: |
215 | f.write('MIRROR="{}"\n'.format(config().get("mirror"))) |
216 | + status.maintenance("Done writing mirror configuration") |
217 | set_flag("autopkgtest.reload-needed") |
218 | |
219 | |
220 | @@ -555,6 +594,7 @@ def reload_systemd_units(): |
221 | |
222 | @hook("tmp-storage-attached") |
223 | def fix_tmp_permissions(): |
224 | + status.maintenance("Fixing tmp permissions") |
225 | storageids = storage_list("tmp") |
226 | if not storageids: |
227 | status.blocked("Cannot locate attached storage") |
228 | @@ -564,6 +604,7 @@ def fix_tmp_permissions(): |
229 | mount = storage_get("location", storageid) |
230 | |
231 | os.chmod(mount, 0o777) |
232 | + status.maintenance("Done fixing tmp permissions") |
233 | |
234 | |
235 | @when_any( |
236 | @@ -583,6 +624,7 @@ def fix_tmp_permissions(): |
237 | "config.set.influxdb-context", |
238 | ) |
239 | def write_influx_creds(): |
240 | + status.maintenance("Writing influxdb credentials") |
241 | influxdb_hostname = config().get("influxdb-hostname") |
242 | influxdb_port = config().get("influxdb-port") |
243 | influxdb_username = config().get("influxdb-username") |
244 | @@ -603,6 +645,7 @@ def write_influx_creds(): |
245 | """ |
246 | ) |
247 | ) |
248 | + status.maintenance("Done writing influxdb credentials") |
249 | set_flag("autopkgtest.influx-creds-written") |
250 | |
251 | |
252 | @@ -615,8 +658,10 @@ def write_influx_creds(): |
253 | "config.set.influxdb-context", |
254 | ) |
255 | def unset_influx_creds(): |
256 | + status.maintenance("Deleting influxdb credentials") |
257 | try: |
258 | os.unlink(os.path.expanduser("~ubuntu/influx.cred")) |
259 | except FileNotFoundError: |
260 | pass |
261 | + status.maintenance("Done deleting influxdb credentials") |
262 | clear_flag("autopkgtest.influx-creds-written") |
263 | diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py |
264 | index 6920fc1..d0c33a7 100644 |
265 | --- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py |
266 | +++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py |
267 | @@ -37,12 +37,14 @@ def install_apt_packages(): |
268 | |
269 | @when_not("autopkgtest-web.autopkgtest_web_symlinked") |
270 | def symlink_autopkgtest_cloud(): |
271 | + status.maintenance("Creating symlink to charmed autopkgtest-web code") |
272 | try: |
273 | autopkgtest_cloud = os.path.join(charm_dir(), "webcontrol") |
274 | os.symlink(autopkgtest_cloud, os.path.expanduser("~ubuntu/webcontrol")) |
275 | - set_flag("autopkgtest-web.autopkgtest_web_symlinked") |
276 | except FileExistsError: |
277 | pass |
278 | + status.maintenance("Done creating symlink to charmed autopkgtest-web code") |
279 | + set_flag("autopkgtest-web.autopkgtest_web_symlinked") |
280 | |
281 | |
282 | @when("amqp.connected") |
283 | @@ -60,6 +62,7 @@ def setup_rabbitmq(rabbitmq): |
284 | "config.set.indexed-packages-fp", |
285 | ) |
286 | def write_autopkgtest_cloud_conf(rabbitmq): |
287 | + status.waiting("Writing autopkgtest-cloud config") |
288 | swiftinternal = config().get("storage-url-internal") |
289 | hostname = config().get("hostname") |
290 | cookies = config().get("cookies") |
291 | @@ -87,6 +90,7 @@ def write_autopkgtest_cloud_conf(rabbitmq): |
292 | ) |
293 | ) |
294 | os.rename(f"{AUTOPKGTEST_CLOUD_CONF}.new", AUTOPKGTEST_CLOUD_CONF) |
295 | + status.waiting("Done writing autopkgtest-cloud config") |
296 | set_flag("autopkgtest-web.config-written") |
297 | |
298 | |
299 | @@ -95,6 +99,7 @@ def write_autopkgtest_cloud_conf(rabbitmq): |
300 | "autopkgtest-web.config-written", |
301 | ) |
302 | def set_up_systemd_units(): |
303 | + status.waiting("Setting up systemd units") |
304 | any_changed = False |
305 | for unit in glob.glob(os.path.join(charm_dir(), "units", "*")): |
306 | base = os.path.basename(unit) |
307 | @@ -114,7 +119,7 @@ def set_up_systemd_units(): |
308 | if "NeedDaemonReload=yes" in p.stdout: |
309 | # any_changed is true here because the systemd unit has changed on disk |
310 | any_changed = True |
311 | - status.maintenance("Installing systemd units") |
312 | + status.maintenance(f"Installing systemd unit {base}") |
313 | subprocess.check_call(["systemctl", "enable", base]) |
314 | |
315 | if any_changed: |
316 | @@ -149,6 +154,7 @@ def initially_configure_website(website): |
317 | "autopkgtest-web.website-initially-configured", |
318 | ) |
319 | def set_up_web_config(apache): |
320 | + status.maintenance("Setting up web config (apache)") |
321 | webcontrol_dir = os.path.join(charm_dir(), "webcontrol") |
322 | sn = config().get("hostname") |
323 | https_proxy = config().get("https-proxy") |
324 | @@ -231,6 +237,7 @@ def set_up_web_config(apache): |
325 | ) |
326 | ) |
327 | ) |
328 | + status.maintenance("Done setting up web config (apache)") |
329 | set_flag("autopkgtest-web.website-initially-configured") |
330 | apache.send_ports([80]) # haproxy is doing SSL termination |
331 | apache.send_enabled() |
332 | @@ -238,6 +245,7 @@ def set_up_web_config(apache): |
333 | |
334 | @when_all("config.changed.github-secrets", "config.set.github-secrets") |
335 | def write_github_secrets(): |
336 | + status.maintenance("Writing github secrets") |
337 | github_secrets = config().get("github-secrets") |
338 | |
339 | with open(GITHUB_SECRETS_PATH, "w") as f: |
340 | @@ -250,10 +258,12 @@ def write_github_secrets(): |
341 | ) |
342 | except FileExistsError: |
343 | pass |
344 | + status.maintenance("Done writing github secrets") |
345 | |
346 | |
347 | @when_not("config.set.github-secrets") |
348 | def clear_github_secrets(): |
349 | + status.maintenance("Clearing github secrets") |
350 | try: |
351 | os.unlink(GITHUB_SECRETS_PATH) |
352 | except FileNotFoundError: |
353 | @@ -263,12 +273,14 @@ def clear_github_secrets(): |
354 | os.unlink(os.path.expanduser("~www-data/github-secrets.json")) |
355 | except FileNotFoundError: |
356 | pass |
357 | + status.maintenance("Done clearing github secrets") |
358 | |
359 | |
360 | @when_all( |
361 | "config.changed.swift-web-credentials", "config.set.swift-web-credentials" |
362 | ) |
363 | def write_swift_web_credentials(): |
364 | + status.maintenance("Writing swift web credentials") |
365 | swift_credentials = config().get("swift-web-credentials") |
366 | |
367 | with open(SWIFT_WEB_CREDENTIALS_PATH, "w") as f: |
368 | @@ -281,18 +293,22 @@ def write_swift_web_credentials(): |
369 | ) |
370 | except FileExistsError: |
371 | pass |
372 | + status.maintenance("Done writing swift web credentials") |
373 | |
374 | |
375 | @when_all("config.changed.public-swift-creds", "config.set.public-swift-creds") |
376 | def write_openstack_creds(): |
377 | + status.maintenance("Writing openstack credentials") |
378 | public_swift_creds = config().get("public-swift-creds") |
379 | |
380 | with open(PUBLIC_SWIFT_CREDS_PATH, "w") as f: |
381 | f.write(public_swift_creds) |
382 | + status.maintenance("Done writing openstack credentials") |
383 | |
384 | |
385 | @when_not("config.set.swift-web-credentials") |
386 | def clear_swift_web_credentials(): |
387 | + status.maintenance("Clearing swift web credentials") |
388 | try: |
389 | os.unlink(SWIFT_WEB_CREDENTIALS_PATH) |
390 | except FileNotFoundError: |
391 | @@ -302,6 +318,7 @@ def clear_swift_web_credentials(): |
392 | os.unlink(os.path.expanduser("~www-data/swift-web-credentials.conf")) |
393 | except FileNotFoundError: |
394 | pass |
395 | + status.maintenance("Done clearing swift web credentials") |
396 | |
397 | |
398 | @when_all( |
399 | @@ -309,6 +326,7 @@ def clear_swift_web_credentials(): |
400 | "config.set.github-status-credentials", |
401 | ) |
402 | def write_github_status_credentials(): |
403 | + status.maintenance("Writing github status credentials") |
404 | github_status_credentials = config().get("github-status-credentials") |
405 | |
406 | with open(GITHUB_STATUS_CREDENTIALS_PATH, "w") as f: |
407 | @@ -321,10 +339,12 @@ def write_github_status_credentials(): |
408 | ) |
409 | except FileExistsError: |
410 | pass |
411 | + status.maintenance("Done writing github status credentials") |
412 | |
413 | |
414 | @when_not("config.set.github-status-credentials") |
415 | def clear_github_status_credentials(): |
416 | + status.maintenance("Clearing github status credentials") |
417 | try: |
418 | os.unlink(GITHUB_STATUS_CREDENTIALS_PATH) |
419 | except FileNotFoundError: |
420 | @@ -336,18 +356,22 @@ def clear_github_status_credentials(): |
421 | ) |
422 | except FileNotFoundError: |
423 | pass |
424 | + status.maintenance("Done clearing github status credentials") |
425 | |
426 | |
427 | @when_not("autopkgtest-web.runtime-dir-created") |
428 | def make_runtime_tmpfiles(): |
429 | + status.maintenance("Making runtime tmpfiles") |
430 | with open("/etc/tmpfiles.d/autopkgtest-web-runtime.conf", "w") as r: |
431 | r.write("D %t/autopkgtest_webcontrol 0755 www-data www-data\n") |
432 | subprocess.check_call(["systemd-tmpfiles", "--create"]) |
433 | + status.maintenance("Done making runtime tmpfiles") |
434 | set_flag("autopkgtest-web.runtime-dir-created") |
435 | |
436 | |
437 | @when_not("autopkgtest-web.running-json-symlinked") |
438 | def symlink_running(): |
439 | + status.maintenance("Creating symlink to running.json") |
440 | try: |
441 | os.symlink( |
442 | os.path.join( |
443 | @@ -355,6 +379,7 @@ def symlink_running(): |
444 | ), |
445 | os.path.join(charm_dir(), "webcontrol", "static", "running.json"), |
446 | ) |
447 | + status.maintenance("Done creating symlink to running.json") |
448 | set_flag("autopkgtest-web.running-json-symlinked") |
449 | except FileExistsError: |
450 | pass |
451 | @@ -362,6 +387,7 @@ def symlink_running(): |
452 | |
453 | @when_not("autopkgtest-web.public-db-symlinked") |
454 | def symlink_public_db(): |
455 | + status.maintenance("Creating symlink for public database") |
456 | try: |
457 | publicdir = os.path.expanduser("~ubuntu/public/") |
458 | os.makedirs(publicdir) |
459 | @@ -372,6 +398,7 @@ def symlink_public_db(): |
460 | charm_dir(), "webcontrol", "static", "autopkgtest.db" |
461 | ), |
462 | ) |
463 | + status.maintenance("Done creating symlink for public database") |
464 | set_flag("autopkgtest-web.public-db-symlinked") |
465 | except FileExistsError: |
466 | pass |
467 | @@ -380,15 +407,19 @@ def symlink_public_db(): |
468 | @when("leadership.is_leader") |
469 | @when_not("autopkgtest-cloud.leadership_flag_written") |
470 | def write_leadership_flag(): |
471 | + status.maintenance("Setting leader") |
472 | with open("/run/autopkgtest-web-is-leader", "w") as _: |
473 | + status.maintenance("Done setting leader") |
474 | set_flag("autopkgtest-cloud.leadership_flag_written") |
475 | |
476 | |
477 | @when_not("leadership.is_leader") |
478 | @when("autopkgtest-cloud.leadership_flag_written") |
479 | def clear_leadership_flag(): |
480 | + status.maintenance("Clearing leader") |
481 | try: |
482 | os.unlink("/run/autopkgtest-web-is-leader") |
483 | except FileNotFoundError: |
484 | pass |
485 | + status.maintenance("Done clearing leader") |
486 | clear_flag("autopkgtest-cloud.leadership_flag_written") |
one inline comment, nothing needs amending. LGTM provided CI passes!