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
=== modified file 'charmhelpers/core/hookenv.py'
--- charmhelpers/core/hookenv.py 2017-08-10 14:31:31 +0000
+++ charmhelpers/core/hookenv.py 2017-08-28 14:14:31 +0000
@@ -218,6 +218,8 @@
218 for rid in relation_ids(reltype):218 for rid in relation_ids(reltype):
219 for unit in related_units(rid):219 for unit in related_units(rid):
220 md = _metadata_unit(unit)220 md = _metadata_unit(unit)
221 if not md:
222 continue
221 subordinate = md.pop('subordinate', None)223 subordinate = md.pop('subordinate', None)
222 if not subordinate:224 if not subordinate:
223 return unit225 return unit
@@ -511,7 +513,10 @@
511 """513 """
512 basedir = os.sep.join(charm_dir().split(os.sep)[:-2])514 basedir = os.sep.join(charm_dir().split(os.sep)[:-2])
513 unitdir = 'unit-{}'.format(unit.replace(os.sep, '-'))515 unitdir = 'unit-{}'.format(unit.replace(os.sep, '-'))
514 with open(os.path.join(basedir, unitdir, 'charm', 'metadata.yaml')) as md:516 joineddir = os.path.join(basedir, unitdir, 'charm', 'metadata.yaml')
517 if not os.path.exists(joineddir):
518 return None
519 with open(joineddir) as md:
515 return yaml.safe_load(md)520 return yaml.safe_load(md)
516521
517522

Subscribers

People subscribed via source and target branches