← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~hyask/autopkgtest-cloud:skia/reactive_charm_status into autopkgtest-cloud:master

 

Skia has proposed merging ~hyask/autopkgtest-cloud:skia/reactive_charm_status into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~hyask/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/461531
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/reactive_charm_status into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
index 2e8f376..b00037f 100644
--- a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
+++ b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
@@ -52,12 +52,16 @@ RABBITMQ_CRED_PATH = os.path.expanduser("~ubuntu/rabbitmq.cred")
 
 @when_not("autopkgtest.autopkgtest_cloud_symlinked")
 def symlink_autopkgtest_cloud():
+    status.maintenance("Creating symlink to charmed autopkgtest-cloud code")
     with UnixUser("ubuntu"):
         try:
             autopkgtest_cloud = os.path.join(charm_dir(), "autopkgtest-cloud")
             os.symlink(autopkgtest_cloud, AUTOPKGTEST_CLOUD_LOCATION)
         except FileExistsError:
             pass
+    status.maintenance(
+        "Done creating symlink to charmed autopkgtest-cloud code"
+    )
     set_flag("autopkgtest.autopkgtest_cloud_symlinked")
 
 
@@ -97,7 +101,9 @@ def clone_autopkgtest_package_configs():
 @when("autopkgtest.autodep8_cloned")
 @when_not("autopkgtest.autodep8_installed")
 def initially_install_autodep8():
+    status.maintenance("Installing autodep8")
     install_autodep8(AUTODEP8_LOCATION)
+    status.maintenance("Done installing autodep8")
     set_flag("autopkgtest.autodep8_installed")
 
 
@@ -125,6 +131,7 @@ def clone_autopkgtest():
     "autopkgtest.influx-creds-written",
 )
 def set_up_systemd_units():
+    status.maintenance("Installing systemd units")
     for unit in glob.glob(os.path.join(charm_dir(), "units", "*")):
         base = os.path.basename(unit)
         dest = os.path.join(os.path.sep, "etc", "systemd", "system", base)
@@ -141,30 +148,39 @@ def set_up_systemd_units():
             if not os.path.islink(dest):
                 os.unlink(dest)
                 link_and_enable()
+    status.maintenance("Done installing systemd units")
     set_flag("autopkgtest.systemd_units_linked_and_enabled")
 
 
 @when("autopkgtest.systemd_units_linked_and_enabled")
 @when_not("autopkgtest.target_running")
 def start():
+    status.maintenance("Enabling and starting autopkgtest systemd target")
     subprocess.check_call(
         ["systemctl", "enable", "--now", "autopkgtest.target"]
     )
+    status.maintenance("Done enabling and starting autopkgtest systemd target")
     set_flag("autopkgtest.target_running")
 
 
 @hook("stop")
 @when("autopkgtest.target_running")
 def stop():
+    status.maintenance("Disabling and stopping autopkgtest systemd target")
     subprocess.check_call(
         ["systemctl", "disable", "--now", "autopkgtest.target"]
     )
+    status.maintenance(
+        "Done disabling and stopping autopkgtest systemd target"
+    )
     clear_flag("autopkgtest.target_running")
 
 
 @when_all("autopkgtest.target-restart-needed", "autopkgtest.target_running")
 def restart_target():
+    status.maintenance("Restarting autopkgtest systemd target")
     subprocess.check_call(["systemctl", "restart", "autopkgtest.target"])
+    status.maintenance("Done restarting autopkgtest systemd target")
     clear_flag("autopkgtest.target-restart-needed")
 
 
@@ -180,7 +196,9 @@ def is_active():
 )
 @hook("upgrade-charm")
 def daemon_reload():
+    status.maintenance("Reloading systemd configuration after change")
     subprocess.check_call(["systemctl", "daemon-reload"])
+    status.maintenance("Done reloading systemd configuration after change")
     clear_flag("autopkgtest.daemon-reload-needed")
 
 
@@ -193,6 +211,7 @@ def install_apt_packages():
 
 @hook("install")
 def enable_persistent_journal():
+    status.maintenance("Enabling persistent journal")
     try:
         journal_dir = os.path.join(os.path.sep, "var", "log", "journal")
         os.makedirs(journal_dir)
@@ -202,6 +221,7 @@ def enable_persistent_journal():
         subprocess.check_call(["systemctl", "restart", "systemd-journald"])
     except FileExistsError:
         pass
+    status.maintenance("Done enabling persistent journal")
 
 
 @when("amqp.connected")
@@ -237,16 +257,19 @@ def set_up_rabbitmq(rabbitmq):
 
 @when_not("amqp.available")
 def clear_rabbitmq():
+    status.maintenance("clearing rabbitmq configuration")
     try:
         log("rabbitmq not available, deleting credentials file")
         os.unlink(RABBITMQ_CRED_PATH)
         clear_flag("autopkgtest.rabbitmq-configured")
     except FileNotFoundError:
         pass
+    status.maintenance("Done clearing rabbitmq configuration")
 
 
 @when("config.changed.nova-rcs")
 def update_nova_rcs():
+    status.maintenance("Updating nova rc files")
     # pylint: disable=import-outside-toplevel
     import base64
     from io import BytesIO
@@ -268,10 +291,12 @@ def update_nova_rcs():
     log("...got {}".format(", ".join(tar.getnames())), "INFO")
 
     tar.extractall(os.path.expanduser("~ubuntu/cloudrcs/"))
+    status.maintenance("Done updating nova rc files")
 
 
 @when("config.default.nova-rcs")
 def clear_old_rcs():
+    status.maintenance("Cleaning old nova rc files")
     rcfiles = glob.glob(os.path.expanduser("~ubuntu/cloudrcs/*.rc"))
 
     if not rcfiles:
@@ -284,6 +309,7 @@ def clear_old_rcs():
         os.unlink(rcfile)
 
     log("...done", "INFO")
+    status.maintenance("Done cleaning old nova rc files")
 
 
 @when_all(
@@ -327,6 +353,8 @@ def enable_disable_units():
         nworkers_yaml or {}, lxdremotes_yaml or {}, releases.split()
     )
 
+    status.maintenance("Done enabling and starting worker units")
+
     set_flag("autopkgtest.reload-needed")
     set_flag("autopkgtest.daemon-reload-needed")
     set_flag("autopkgtest.target-restart-needed")
@@ -339,7 +367,9 @@ def enable_disable_units():
 )
 @when_not("autopkgtest.ubuntu_added_to_lxd_group")
 def add_ubuntu_user_to_lxd_group():
+    status.maintenance("Adding ubuntu user to lxd group")
     subprocess.check_call(["adduser", "ubuntu", "lxd"])
+    status.maintenance("Done adding ubuntu user to lxd group")
     set_flag("autopkgtest.ubuntu_added_to_lxd_group")
 
 
@@ -405,6 +435,7 @@ def write_v2_config():
 
 
 def write_swift_config():
+    status.maintenance("Writing swift configuration")
     with open(
         os.path.expanduser("~ubuntu/swift-password.cred"), "w"
     ) as swift_password_file:
@@ -416,6 +447,7 @@ def write_swift_config():
                         str(config()[key]).strip(),
                     )
                 )
+    status.maintenance("Done writing swift configuration")
 
 
 @when_any(
@@ -432,6 +464,8 @@ def write_swift_config():
 )
 @when_any("config.set.nova-rcs", "config.set.lxd-remotes")
 def write_worker_config():
+    status.maintenance("Writing worker configuration")
+
     # pylint: disable=import-outside-toplevel
     import configparser
 
@@ -523,23 +557,28 @@ def write_worker_config():
         conf["autopkgtest"]["architectures"] = arch
         write(conf_file)
 
+    status.maintenance("Done writing worker configuration")
     set_flag("autopkgtest.daemon-reload-needed")
     set_flag("autopkgtest.reload-needed")
 
 
 @when("config.changed.net-name")
 def write_net_name():
+    status.maintenance("Writing net-name configuration")
     clear_flag("autopkgtest.net-name-written")
     with open(os.path.expanduser("~ubuntu/net-name.rc"), "w") as f:
         f.write('NET_NAME="{}"\n'.format(config().get("net-name")))
+    status.maintenance("Done writing net-name configuration")
     set_flag("autopkgtest.net-name-written")
     set_flag("autopkgtest.reload-needed")
 
 
 @when("config.changed.mirror")
 def write_mirror():
+    status.maintenance("Writing mirror configuration")
     with open(os.path.expanduser("~ubuntu/mirror.rc"), "w") as f:
         f.write('MIRROR="{}"\n'.format(config().get("mirror")))
+    status.maintenance("Done writing mirror configuration")
     set_flag("autopkgtest.reload-needed")
 
 
@@ -555,6 +594,7 @@ def reload_systemd_units():
 
 @hook("tmp-storage-attached")
 def fix_tmp_permissions():
+    status.maintenance("Fixing tmp permissions")
     storageids = storage_list("tmp")
     if not storageids:
         status.blocked("Cannot locate attached storage")
@@ -564,6 +604,7 @@ def fix_tmp_permissions():
     mount = storage_get("location", storageid)
 
     os.chmod(mount, 0o777)
+    status.maintenance("Done fixing tmp permissions")
 
 
 @when_any(
@@ -583,6 +624,7 @@ def fix_tmp_permissions():
     "config.set.influxdb-context",
 )
 def write_influx_creds():
+    status.maintenance("Writing influxdb credentials")
     influxdb_hostname = config().get("influxdb-hostname")
     influxdb_port = config().get("influxdb-port")
     influxdb_username = config().get("influxdb-username")
@@ -603,6 +645,7 @@ def write_influx_creds():
         """
             )
         )
+    status.maintenance("Done writing influxdb credentials")
     set_flag("autopkgtest.influx-creds-written")
 
 
@@ -615,8 +658,10 @@ def write_influx_creds():
     "config.set.influxdb-context",
 )
 def unset_influx_creds():
+    status.maintenance("Deleting influxdb credentials")
     try:
         os.unlink(os.path.expanduser("~ubuntu/influx.cred"))
     except FileNotFoundError:
         pass
+    status.maintenance("Done deleting influxdb credentials")
     clear_flag("autopkgtest.influx-creds-written")
diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
index 6920fc1..d0c33a7 100644
--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
@@ -37,12 +37,14 @@ def install_apt_packages():
 
 @when_not("autopkgtest-web.autopkgtest_web_symlinked")
 def symlink_autopkgtest_cloud():
+    status.maintenance("Creating symlink to charmed autopkgtest-web code")
     try:
         autopkgtest_cloud = os.path.join(charm_dir(), "webcontrol")
         os.symlink(autopkgtest_cloud, os.path.expanduser("~ubuntu/webcontrol"))
-        set_flag("autopkgtest-web.autopkgtest_web_symlinked")
     except FileExistsError:
         pass
+    status.maintenance("Done creating symlink to charmed autopkgtest-web code")
+    set_flag("autopkgtest-web.autopkgtest_web_symlinked")
 
 
 @when("amqp.connected")
@@ -60,6 +62,7 @@ def setup_rabbitmq(rabbitmq):
     "config.set.indexed-packages-fp",
 )
 def write_autopkgtest_cloud_conf(rabbitmq):
+    status.waiting("Writing autopkgtest-cloud config")
     swiftinternal = config().get("storage-url-internal")
     hostname = config().get("hostname")
     cookies = config().get("cookies")
@@ -87,6 +90,7 @@ def write_autopkgtest_cloud_conf(rabbitmq):
             )
         )
     os.rename(f"{AUTOPKGTEST_CLOUD_CONF}.new", AUTOPKGTEST_CLOUD_CONF)
+    status.waiting("Done writing autopkgtest-cloud config")
     set_flag("autopkgtest-web.config-written")
 
 
@@ -95,6 +99,7 @@ def write_autopkgtest_cloud_conf(rabbitmq):
     "autopkgtest-web.config-written",
 )
 def set_up_systemd_units():
+    status.waiting("Setting up systemd units")
     any_changed = False
     for unit in glob.glob(os.path.join(charm_dir(), "units", "*")):
         base = os.path.basename(unit)
@@ -114,7 +119,7 @@ def set_up_systemd_units():
         if "NeedDaemonReload=yes" in p.stdout:
             # any_changed is true here because the systemd unit has changed on disk
             any_changed = True
-        status.maintenance("Installing systemd units")
+        status.maintenance(f"Installing systemd unit {base}")
         subprocess.check_call(["systemctl", "enable", base])
 
     if any_changed:
@@ -149,6 +154,7 @@ def initially_configure_website(website):
     "autopkgtest-web.website-initially-configured",
 )
 def set_up_web_config(apache):
+    status.maintenance("Setting up web config (apache)")
     webcontrol_dir = os.path.join(charm_dir(), "webcontrol")
     sn = config().get("hostname")
     https_proxy = config().get("https-proxy")
@@ -231,6 +237,7 @@ def set_up_web_config(apache):
             )
         )
     )
+    status.maintenance("Done setting up web config (apache)")
     set_flag("autopkgtest-web.website-initially-configured")
     apache.send_ports([80])  # haproxy is doing SSL termination
     apache.send_enabled()
@@ -238,6 +245,7 @@ def set_up_web_config(apache):
 
 @when_all("config.changed.github-secrets", "config.set.github-secrets")
 def write_github_secrets():
+    status.maintenance("Writing github secrets")
     github_secrets = config().get("github-secrets")
 
     with open(GITHUB_SECRETS_PATH, "w") as f:
@@ -250,10 +258,12 @@ def write_github_secrets():
         )
     except FileExistsError:
         pass
+    status.maintenance("Done writing github secrets")
 
 
 @when_not("config.set.github-secrets")
 def clear_github_secrets():
+    status.maintenance("Clearing github secrets")
     try:
         os.unlink(GITHUB_SECRETS_PATH)
     except FileNotFoundError:
@@ -263,12 +273,14 @@ def clear_github_secrets():
         os.unlink(os.path.expanduser("~www-data/github-secrets.json"))
     except FileNotFoundError:
         pass
+    status.maintenance("Done clearing github secrets")
 
 
 @when_all(
     "config.changed.swift-web-credentials", "config.set.swift-web-credentials"
 )
 def write_swift_web_credentials():
+    status.maintenance("Writing swift web credentials")
     swift_credentials = config().get("swift-web-credentials")
 
     with open(SWIFT_WEB_CREDENTIALS_PATH, "w") as f:
@@ -281,18 +293,22 @@ def write_swift_web_credentials():
         )
     except FileExistsError:
         pass
+    status.maintenance("Done writing swift web credentials")
 
 
 @when_all("config.changed.public-swift-creds", "config.set.public-swift-creds")
 def write_openstack_creds():
+    status.maintenance("Writing openstack credentials")
     public_swift_creds = config().get("public-swift-creds")
 
     with open(PUBLIC_SWIFT_CREDS_PATH, "w") as f:
         f.write(public_swift_creds)
+    status.maintenance("Done writing openstack credentials")
 
 
 @when_not("config.set.swift-web-credentials")
 def clear_swift_web_credentials():
+    status.maintenance("Clearing swift web credentials")
     try:
         os.unlink(SWIFT_WEB_CREDENTIALS_PATH)
     except FileNotFoundError:
@@ -302,6 +318,7 @@ def clear_swift_web_credentials():
         os.unlink(os.path.expanduser("~www-data/swift-web-credentials.conf"))
     except FileNotFoundError:
         pass
+    status.maintenance("Done clearing swift web credentials")
 
 
 @when_all(
@@ -309,6 +326,7 @@ def clear_swift_web_credentials():
     "config.set.github-status-credentials",
 )
 def write_github_status_credentials():
+    status.maintenance("Writing github status credentials")
     github_status_credentials = config().get("github-status-credentials")
 
     with open(GITHUB_STATUS_CREDENTIALS_PATH, "w") as f:
@@ -321,10 +339,12 @@ def write_github_status_credentials():
         )
     except FileExistsError:
         pass
+    status.maintenance("Done writing github status credentials")
 
 
 @when_not("config.set.github-status-credentials")
 def clear_github_status_credentials():
+    status.maintenance("Clearing github status credentials")
     try:
         os.unlink(GITHUB_STATUS_CREDENTIALS_PATH)
     except FileNotFoundError:
@@ -336,18 +356,22 @@ def clear_github_status_credentials():
         )
     except FileNotFoundError:
         pass
+    status.maintenance("Done clearing github status credentials")
 
 
 @when_not("autopkgtest-web.runtime-dir-created")
 def make_runtime_tmpfiles():
+    status.maintenance("Making runtime tmpfiles")
     with open("/etc/tmpfiles.d/autopkgtest-web-runtime.conf", "w") as r:
         r.write("D %t/autopkgtest_webcontrol 0755 www-data www-data\n")
     subprocess.check_call(["systemd-tmpfiles", "--create"])
+    status.maintenance("Done making runtime tmpfiles")
     set_flag("autopkgtest-web.runtime-dir-created")
 
 
 @when_not("autopkgtest-web.running-json-symlinked")
 def symlink_running():
+    status.maintenance("Creating symlink to running.json")
     try:
         os.symlink(
             os.path.join(
@@ -355,6 +379,7 @@ def symlink_running():
             ),
             os.path.join(charm_dir(), "webcontrol", "static", "running.json"),
         )
+        status.maintenance("Done creating symlink to running.json")
         set_flag("autopkgtest-web.running-json-symlinked")
     except FileExistsError:
         pass
@@ -362,6 +387,7 @@ def symlink_running():
 
 @when_not("autopkgtest-web.public-db-symlinked")
 def symlink_public_db():
+    status.maintenance("Creating symlink for public database")
     try:
         publicdir = os.path.expanduser("~ubuntu/public/")
         os.makedirs(publicdir)
@@ -372,6 +398,7 @@ def symlink_public_db():
                 charm_dir(), "webcontrol", "static", "autopkgtest.db"
             ),
         )
+        status.maintenance("Done creating symlink for public database")
         set_flag("autopkgtest-web.public-db-symlinked")
     except FileExistsError:
         pass
@@ -380,15 +407,19 @@ def symlink_public_db():
 @when("leadership.is_leader")
 @when_not("autopkgtest-cloud.leadership_flag_written")
 def write_leadership_flag():
+    status.maintenance("Setting leader")
     with open("/run/autopkgtest-web-is-leader", "w") as _:
+        status.maintenance("Done setting leader")
         set_flag("autopkgtest-cloud.leadership_flag_written")
 
 
 @when_not("leadership.is_leader")
 @when("autopkgtest-cloud.leadership_flag_written")
 def clear_leadership_flag():
+    status.maintenance("Clearing leader")
     try:
         os.unlink("/run/autopkgtest-web-is-leader")
     except FileNotFoundError:
         pass
+    status.maintenance("Done clearing leader")
     clear_flag("autopkgtest-cloud.leadership_flag_written")