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