← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] autopkgtest-cloud:leader-file-not-found into autopkgtest-cloud:master

 

Brian Murray has proposed merging autopkgtest-cloud:leader-file-not-found into autopkgtest-cloud:master.

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

For more details, see:
https://code.launchpad.net/~ubuntu-release/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/445677

One of the autopkgtest-web servers is in an error state due to the /run/autopkgtest-web-is-leader file not being available when trying to remove it. If the file is already gone then the charm should just proceed.

2023-06-29 15:26:50 INFO unit.autopkgtest-web/2.juju-log server.go:316 Invoking reactive handler: reactive/autopkgtest_web.py:368:clear_leadership_flag
2023-06-29 15:26:50 ERROR unit.autopkgtest-web/2.juju-log server.go:316 Hook error:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-autopkgtest-web-2/.venv/lib/python3.8/site-packages/charms/reactive/__init__.py", line 74, in main
    bus.dispatch(restricted=restricted_mode)
  File "/var/lib/juju/agents/unit-autopkgtest-web-2/.venv/lib/python3.8/site-packages/charms/reactive/bus.py", line 390, in dispatch
    _invoke(other_handlers)
  File "/var/lib/juju/agents/unit-autopkgtest-web-2/.venv/lib/python3.8/site-packages/charms/reactive/bus.py", line 359, in _invoke
    handler.invoke()
  File "/var/lib/juju/agents/unit-autopkgtest-web-2/.venv/lib/python3.8/site-packages/charms/reactive/bus.py", line 181, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/unit-autopkgtest-web-2/charm/reactive/autopkgtest_web.py", line 371, in clear_leadership_flag  
    os.unlink("/run/autopkgtest-web-is-leader")
FileNotFoundError: [Errno 2] No such file or directory: '/run/autopkgtest-web-is-leader'

-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of autopkgtest-cloud:leader-file-not-found into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
index 08ec944..ccea20f 100644
--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
@@ -370,5 +370,8 @@ def write_leadership_flag():
 @when_not("leadership.is_leader")
 @when("autopkgtest-cloud.leadership_flag_written")
 def clear_leadership_flag():
-    os.unlink("/run/autopkgtest-web-is-leader")
+    try:
+        os.unlink("/run/autopkgtest-web-is-leader")
+    except FileNotFoundError:
+        pass
     clear_flag("autopkgtest-cloud.leadership_flag_written")

Follow ups