Merge lp:~tcuthbert/turku-charms/turku-api-charm into lp:turku-charms/turku-api-charm

Proposed by Thomas Cuthbert
Status: Merged
Approved by: Barry Price
Approved revision: 14
Merged at revision: 11
Proposed branch: lp:~tcuthbert/turku-charms/turku-api-charm
Merge into: lp:turku-charms/turku-api-charm
Diff against target: 56 lines (+23/-8)
2 files modified
files/sick_sources (+11/-0)
hooks/hooks.py (+12/-8)
To merge this branch: bzr merge lp:~tcuthbert/turku-charms/turku-api-charm
Reviewer Review Type Date Requested Status
Barry Price Approve
Review via email: mp+397546@code.launchpad.net

Commit message

We want to wrap the execution of the script with a shell wrapper to handle mutual exclusion and a timeout

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 :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
Barry Price (barryprice) wrote :

LGTM +1

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

Change successfully merged at revision 11

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'files/sick_sources'
2--- files/sick_sources 1970-01-01 00:00:00 +0000
3+++ files/sick_sources 2021-02-05 04:25:50 +0000
4@@ -0,0 +1,11 @@
5+#!/bin/bash
6+
7+set -eu
8+
9+test -x /srv/turku.admin.canonical.com/code/current/turku_api/scripts/turku_sick_sources || exit 1
10+test -d /var/lib/turku_sick_sources || mkdir /var/lib/turku_sick_sources
11+
12+/usr/bin/flock -w 30 /var/run/turku_sick_sources.lock \
13+ /srv/turku.admin.canonical.com/code/current/turku_api/scripts/turku_sick_sources \
14+ --metrics_dir /var/lib/turku_sick_sources > /dev/null
15+exit 0
16
17=== modified file 'hooks/hooks.py'
18--- hooks/hooks.py 2021-02-05 02:24:27 +0000
19+++ hooks/hooks.py 2021-02-05 04:25:50 +0000
20@@ -16,16 +16,16 @@
21
22 def am_i_leader():
23 """Calls the is-leader juju helper to determine if server is current leader"""
24- string_to_boolean = {'True': True, 'False': False}
25- call_out = None
26+ string_to_boolean = {'true': True, 'false': False}
27+ stdout = None
28 is_leader = False
29 try:
30- call_out = subprocess.run(['is-leader'], check=True, text=True, timeout=15.0)
31- is_leader = string_to_boolean[call_out.STDOUT]
32+ stdout = subprocess.check_output(['is-leader']).decode().rstrip()
33+ is_leader = string_to_boolean[stdout.lower()]
34 except KeyError:
35- juju_log('ERROR', 'is-leader juju helper returned unexpected value: {}'.format(call_out))
36- except subprocess.CalledProcessError:
37- juju_log('ERROR', 'is-leader juju helper failed to execute: {}'.format(call_out.STDOUT + call_out.STDERR))
38+ juju_log('ERROR', 'is-leader juju helper returned unexpected value: {}'.format(stdout))
39+ except subprocess.CalledProcessError as ce:
40+ juju_log('ERROR', 'is-leader juju helper failed to execute: {}'.format(ce))
41 return is_leader
42
43
44@@ -52,7 +52,11 @@
45 @hooks.hook('leader-elected', 'leader-settings-changed')
46 def leader_elected():
47 # This manual hook exists because calling ansible every leadership event is a bad idea.
48- sick_sources_script = '/srv/turku.admin.canonical.com/code/current/turku_api/scripts/turku_sick_sources'
49+ abs_path = os.path.abspath(__file__)
50+ sick_sources_script = os.path.join(
51+ os.path.dirname(os.path.dirname(abs_path)), 'files/sick_sources'
52+ )
53+
54 cron_daily_sick_sources = '/etc/cron.daily/sick_sources'
55 is_leader = am_i_leader()
56 if is_leader:

Subscribers

People subscribed via source and target branches