← Back to team overview

canonical-hw-cert team mailing list archive

[Merge] ~pwlars/testflinger-agent/+git/testflinger-agent-charm:add-update-action into ~canonical-hw-cert/testflinger-agent/+git/testflinger-agent-charm:main

 

Paul Larson has proposed merging ~pwlars/testflinger-agent/+git/testflinger-agent-charm:add-update-action into ~canonical-hw-cert/testflinger-agent/+git/testflinger-agent-charm:main.

Requested reviews:
  Canonical Hardware Certification (canonical-hw-cert)

For more details, see:
https://code.launchpad.net/~pwlars/testflinger-agent/+git/testflinger-agent-charm/+merge/432013

I realized that the way I wrote this was a little too strict about checking that there were actual changes before doing things like re-pulling the git trees. However, we previously relied on lazy checking to force a refresh by simply issuing an empty config change.  That's certainly a valid way to do it, and it's idempotent but having an action may be a more appropriate method.

This allows you to force an agent-host unit to update all the git repos and configs by simply running an action from juju. ex:

$ juju run-action dragonboard006/0 update
-- 
Your team Canonical Hardware Certification is requested to review the proposed merge of ~pwlars/testflinger-agent/+git/testflinger-agent-charm:add-update-action into ~canonical-hw-cert/testflinger-agent/+git/testflinger-agent-charm:main.
diff --git a/actions.yaml b/actions.yaml
new file mode 100644
index 0000000..8fe6009
--- /dev/null
+++ b/actions.yaml
@@ -0,0 +1,2 @@
+update:
+  description: Force an update of git repos and config files
diff --git a/src/charm.py b/src/charm.py
index 4dbd939..0695483 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -45,6 +45,7 @@ class TestflingerAgentCharm(CharmBase):
         self.framework.observe(self.on.config_changed, self._on_config_changed)
         self.framework.observe(self.on.start, self._on_start)
         self.framework.observe(self.on.remove, self._on_remove)
+        self.framework.observe(self.on.update_action, self._on_update_action)
         self._stored.set_default(
             testflinger_agent_repo="",
             testflinger_agent_branch="",
@@ -255,6 +256,14 @@ class TestflingerAgentCharm(CharmBase):
             contents = res.read()
         return contents
 
+    def _on_update_action(self, event):
+        """Force an update of git trees and config files"""
+        self.unit.status = MaintenanceStatus("Handling update action")
+        self._update_repos()
+        self._write_config_files()
+        self._signal_restart_agent()
+        self.unit.status = ActiveStatus()
+
 
 if __name__ == "__main__":
     main(TestflingerAgentCharm)

Follow ups