Merge lp:~george-edison55/charm-helpers/fix-fetch-handler into lp:charm-helpers

Proposed by Nathan Osman
Status: Merged
Merged at revision: 586
Proposed branch: lp:~george-edison55/charm-helpers/fix-fetch-handler
Merge into: lp:charm-helpers
Diff against target: 22 lines (+2/-5)
1 file modified
charmhelpers/fetch/__init__.py (+2/-5)
To merge this branch: bzr merge lp:~george-edison55/charm-helpers/fix-fetch-handler
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+273941@code.launchpad.net

Description of the change

charmhelpers.fetch.install_remote() contains a logic error. The first line builds a list of handlers that match the provided source URI. In the case of an HTTP or HTTPS URL, both the ArchiveUrlFetchHandler and GitUrlFetchHandler will match and be added to the list.

The body of the loop is then executed twice - once for each handler. The first time, the ArchiveUrlFetchHandler will be run and installed_to will be set to the return value of handler.install(). However, this value will be overwritten by GitUrlFetchHandler the second time through the loop.

I have refactored the function to remove this problem. Now the function immediately returns the value from handler.install() and continues to the next handler only if an exception was raised.

I have checked my modifications using "make test" and everything seems to be in order. This addresses bug #1504346.

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

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/fetch/__init__.py'
2--- charmhelpers/fetch/__init__.py 2015-08-10 13:34:31 +0000
3+++ charmhelpers/fetch/__init__.py 2015-10-09 00:17:23 +0000
4@@ -382,16 +382,13 @@
5 # We ONLY check for True here because can_handle may return a string
6 # explaining why it can't handle a given source.
7 handlers = [h for h in plugins() if h.can_handle(source) is True]
8- installed_to = None
9 for handler in handlers:
10 try:
11- installed_to = handler.install(source, *args, **kwargs)
12+ return handler.install(source, *args, **kwargs)
13 except UnhandledSource as e:
14 log('Install source attempt unsuccessful: {}'.format(e),
15 level='WARNING')
16- if not installed_to:
17- raise UnhandledSource("No handler found for source {}".format(source))
18- return installed_to
19+ raise UnhandledSource("No handler found for source {}".format(source))
20
21
22 def install_from_config(config_var_name):

Subscribers

People subscribed via source and target branches