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

Proposed by Brian Murray
Status: Merged
Approved by: Tim Andersson
Approved revision: 6d95301f2eff10d2c9b988b83106a7035ea8e4ec
Merged at revision: 6d95301f2eff10d2c9b988b83106a7035ea8e4ec
Proposed branch: autopkgtest-cloud:leader-file-not-found
Merge into: autopkgtest-cloud:master
Diff against target: 14 lines (+4/-1)
1 file modified
charms/focal/autopkgtest-web/reactive/autopkgtest_web.py (+4/-1)
Reviewer Review Type Date Requested Status
Tim Andersson Approve
Review via email: mp+445677@code.launchpad.net

Description of the change

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'

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

FWIW I temporarily worked around this by touching the file and then running `juju resolved autopkgtest-web/2`. Both of the units are now active and one is identified as the leader so the logic here is sound.

Revision history for this message
Tim Andersson (andersson123) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
2index 08ec944..ccea20f 100644
3--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
4+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
5@@ -370,5 +370,8 @@ def write_leadership_flag():
6 @when_not("leadership.is_leader")
7 @when("autopkgtest-cloud.leadership_flag_written")
8 def clear_leadership_flag():
9- os.unlink("/run/autopkgtest-web-is-leader")
10+ try:
11+ os.unlink("/run/autopkgtest-web-is-leader")
12+ except FileNotFoundError:
13+ pass
14 clear_flag("autopkgtest-cloud.leadership_flag_written")

Subscribers

People subscribed via source and target branches