Merge ~xavpaice/charm-nagios:lp1712977 into ~nagios-charmers/charm-nagios:master

Proposed by Xav Paice
Status: Merged
Approved by: James Hebden
Approved revision: de46e970041164b85e48a197ffb05c1d4db4e45f
Merged at revision: de46e970041164b85e48a197ffb05c1d4db4e45f
Proposed branch: ~xavpaice/charm-nagios:lp1712977
Merge into: ~nagios-charmers/charm-nagios:master
Diff against target: 23 lines (+6/-1)
1 file modified
hooks/charmhelpers/core/hookenv.py (+6/-1)
Reviewer Review Type Date Requested Status
James Hebden (community) Approve
Review via email: mp+329768@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Hebden (ec0) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/charmhelpers/core/hookenv.py b/hooks/charmhelpers/core/hookenv.py
2index 12f37b2..899722f 100644
3--- a/hooks/charmhelpers/core/hookenv.py
4+++ b/hooks/charmhelpers/core/hookenv.py
5@@ -218,6 +218,8 @@ def principal_unit():
6 for rid in relation_ids(reltype):
7 for unit in related_units(rid):
8 md = _metadata_unit(unit)
9+ if not md:
10+ continue
11 subordinate = md.pop('subordinate', None)
12 if not subordinate:
13 return unit
14@@ -511,7 +513,10 @@ def _metadata_unit(unit):
15 """
16 basedir = os.sep.join(charm_dir().split(os.sep)[:-2])
17 unitdir = 'unit-{}'.format(unit.replace(os.sep, '-'))
18- with open(os.path.join(basedir, unitdir, 'charm', 'metadata.yaml')) as md:
19+ joineddir = os.path.join(basedir, unitdir, 'charm', 'metadata.yaml')
20+ if not os.path.exists(joineddir):
21+ return None
22+ with open(joineddir) as md:
23 return yaml.safe_load(md)
24
25

Subscribers

People subscribed via source and target branches