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
diff --git a/scripts/auto_lint.py b/scripts/auto_lint.py
index 0c5fc11..cbc4389 100755
--- a/scripts/auto_lint.py
+++ b/scripts/auto_lint.py
@@ -24,6 +24,7 @@ from base64 import b64decode
24import json24import json
25import logging25import logging
26from os.path import join26from os.path import join
27import os
27import subprocess28import subprocess
28from sys import exit29from sys import exit
2930
@@ -35,6 +36,7 @@ VAR_LIB = "/var/snap/juju-lint/common"
35LINT_CONFIG_PATH = join(VAR_LIB, "auto-lint-config.json")36LINT_CONFIG_PATH = join(VAR_LIB, "auto-lint-config.json")
36JUJU_STATUS_PATH = join(VAR_LIB, "juju-status.json")37JUJU_STATUS_PATH = join(VAR_LIB, "juju-status.json")
37LINT_RESULTS_PATH = join(VAR_LIB, "lint-results.txt")38LINT_RESULTS_PATH = join(VAR_LIB, "lint-results.txt")
39PID_FILENAME = "/tmp/auto_lint.pid"
3840
39# Deal with https://github.com/juju/python-libjuju/issues/136, set to 32MB41# Deal with https://github.com/juju/python-libjuju/issues/136, set to 32MB
40MAX_FRAME_SIZE = 2 ** 2542MAX_FRAME_SIZE = 2 ** 25
@@ -244,13 +246,26 @@ def main():
244 loglevel = logging.DEBUG if args.debug else logging.ERROR246 loglevel = logging.DEBUG if args.debug else logging.ERROR
245 logging.basicConfig(level=loglevel)247 logging.basicConfig(level=loglevel)
246248
247 auto_lint_config = read_json_file(LINT_CONFIG_PATH)249 # Ensure a single instance via a simple pidfile
248 verify_auto_lint_config(auto_lint_config)250 pid = str(os.getpid())
249 juju_status = loop.run(get_juju_status(auto_lint_config))251
250 write_file(252 if os.path.isfile(PID_FILENAME):
251 JUJU_STATUS_PATH, json.dumps(juju_status, cls=TypeEncoder, sort_keys=True)253 exit("{} already exists, exiting".format(PID_FILENAME))
252 )254
253 lint_juju(auto_lint_config)255 with open(PID_FILENAME, "w") as f:
256 f.write(pid)
257
258 # Read config, get juju model information and lint it
259 try:
260 auto_lint_config = read_json_file(LINT_CONFIG_PATH)
261 verify_auto_lint_config(auto_lint_config)
262 juju_status = loop.run(get_juju_status(auto_lint_config))
263 write_file(
264 JUJU_STATUS_PATH, json.dumps(juju_status, cls=TypeEncoder, sort_keys=True)
265 )
266 lint_juju(auto_lint_config)
267 finally:
268 os.unlink(PID_FILENAME)
254269
255270
256if __name__ == "__main__":271if __name__ == "__main__":

Subscribers

People subscribed via source and target branches

to all changes: