Merge lp:~seyeongkim/charm-helpers/fixing-filenotfounderror into lp:charm-helpers

Proposed by Seyeong Kim
Status: Merged
Merged at revision: 786
Proposed branch: lp:~seyeongkim/charm-helpers/fixing-filenotfounderror
Merge into: lp:charm-helpers
Diff against target: 22 lines (+6/-1)
1 file modified
charmhelpers/core/hookenv.py (+6/-1)
To merge this branch: bzr merge lp:~seyeongkim/charm-helpers/fixing-filenotfounderror
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+329727@code.launchpad.net

This proposal supersedes a proposal from 2017-08-28.

Description of the change

ignore FileNotFoundError when getting metadata file on the other machine's unit

related bug is https://bugs.launchpad.net/nrpe-charm/+bug/1712977

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote : Posted in a previous version of this proposal

FileNotFoundError doesn't exist with older Python releases. Its probably best to return None if 'not os.path.exists' rather than catch the exception.

review: Needs Fixing
Revision history for this message
Stuart Bishop (stub) :
review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches