Merge ~jfguedez/charm-juju-lint:bug/1942946 into charm-juju-lint:master

Proposed by Jose Guedez
Status: Merged
Approved by: James Troup
Approved revision: 995815acbc902938df9c30ec8aef85568aa072d7
Merged at revision: 643e1a1b45feec5ea614841323d7e806811cda68
Proposed branch: ~jfguedez/charm-juju-lint:bug/1942946
Merge into: charm-juju-lint:master
Diff against target: 54 lines (+22/-7)
1 file modified
scripts/auto_lint.py (+22/-7)
Reviewer Review Type Date Requested Status
BootStack Reviewers Pending
BootStack Reviewers Pending
Review via email: mp+408276@code.launchpad.net

Commit message

Prevent auto_lint.py from running more than one instance simultaneously

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Failed to merge change (unable to merge source repository due to conflicts), setting status to needs review.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 643e1a1b45feec5ea614841323d7e806811cda68

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/auto_lint.py b/scripts/auto_lint.py
2index 0c5fc11..cbc4389 100755
3--- a/scripts/auto_lint.py
4+++ b/scripts/auto_lint.py
5@@ -24,6 +24,7 @@ from base64 import b64decode
6 import json
7 import logging
8 from os.path import join
9+import os
10 import subprocess
11 from sys import exit
12
13@@ -35,6 +36,7 @@ VAR_LIB = "/var/snap/juju-lint/common"
14 LINT_CONFIG_PATH = join(VAR_LIB, "auto-lint-config.json")
15 JUJU_STATUS_PATH = join(VAR_LIB, "juju-status.json")
16 LINT_RESULTS_PATH = join(VAR_LIB, "lint-results.txt")
17+PID_FILENAME = "/tmp/auto_lint.pid"
18
19 # Deal with https://github.com/juju/python-libjuju/issues/136, set to 32MB
20 MAX_FRAME_SIZE = 2 ** 25
21@@ -244,13 +246,26 @@ def main():
22 loglevel = logging.DEBUG if args.debug else logging.ERROR
23 logging.basicConfig(level=loglevel)
24
25- auto_lint_config = read_json_file(LINT_CONFIG_PATH)
26- verify_auto_lint_config(auto_lint_config)
27- juju_status = loop.run(get_juju_status(auto_lint_config))
28- write_file(
29- JUJU_STATUS_PATH, json.dumps(juju_status, cls=TypeEncoder, sort_keys=True)
30- )
31- lint_juju(auto_lint_config)
32+ # Ensure a single instance via a simple pidfile
33+ pid = str(os.getpid())
34+
35+ if os.path.isfile(PID_FILENAME):
36+ exit("{} already exists, exiting".format(PID_FILENAME))
37+
38+ with open(PID_FILENAME, "w") as f:
39+ f.write(pid)
40+
41+ # Read config, get juju model information and lint it
42+ try:
43+ auto_lint_config = read_json_file(LINT_CONFIG_PATH)
44+ verify_auto_lint_config(auto_lint_config)
45+ juju_status = loop.run(get_juju_status(auto_lint_config))
46+ write_file(
47+ JUJU_STATUS_PATH, json.dumps(juju_status, cls=TypeEncoder, sort_keys=True)
48+ )
49+ lint_juju(auto_lint_config)
50+ finally:
51+ os.unlink(PID_FILENAME)
52
53
54 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches

to all changes: