← Back to team overview

canonical-hw-cert team mailing list archive

[Merge] ~pwlars/testflinger-agent/+git/testflinger-agent-charm:avoid-permission-problems-restart-file into ~canonical-hw-cert/testflinger-agent/+git/testflinger-agent-charm:main

 

Paul Larson has proposed merging ~pwlars/testflinger-agent/+git/testflinger-agent-charm:avoid-permission-problems-restart-file 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/431593

Avoid permission problems that could occur, and it's pointless to recreate this anyway since it already exists
-- 
Your team Canonical Hardware Certification is requested to review the proposed merge of ~pwlars/testflinger-agent/+git/testflinger-agent-charm:avoid-permission-problems-restart-file into ~canonical-hw-cert/testflinger-agent/+git/testflinger-agent-charm:main.
diff --git a/src/charm.py b/src/charm.py
index d3bfde8..4dbd939 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -170,8 +170,11 @@ class TestflingerAgentCharm(CharmBase):
 
     def _signal_restart_agent(self):
         """Signal testflinger-agent to restart when it's not busy"""
-        restart_file = f"/tmp/TESTFLINGER-DEVICE-RESTART-{self.app.name}"
-        open(restart_file, mode="w").close()
+        restart_file = PosixPath(
+                f"/tmp/TESTFLINGER-DEVICE-RESTART-{self.app.name}")
+        if restart_file.exists():
+            return
+        restart_file.open(mode="w").close()
         shutil.chown(restart_file, "ubuntu", "ubuntu")
 
     def _write_config_files(self):

Follow ups