Merge lp:~michael.nelson/charm-helpers/configure-sources-single-source-null-key into lp:charm-helpers

Proposed by Michael Nelson
Status: Merged
Merged at revision: 83
Proposed branch: lp:~michael.nelson/charm-helpers/configure-sources-single-source-null-key
Merge into: lp:charm-helpers
Diff against target: 76 lines (+37/-4)
2 files modified
charmhelpers/fetch/__init__.py (+8/-4)
tests/fetch/test_fetch.py (+29/-0)
To merge this branch: bzr merge lp:~michael.nelson/charm-helpers/configure-sources-single-source-null-key
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+190546@code.launchpad.net

Commit message

fetch.configure_sources can take a single source and a null key.

Description of the change

This branch fixes two issues I came across while working on a charm:

1) fetch.configure_sources already accepted either a list of sources with list of keys (where individual keys could be None), but not a single source with a None key.

2) fetch.add_source() didn't pass sources starting with 'deb ' through, and apt-add-repository gives a different result depending on whether the source starts with 'deb ' in some situations (see example in the test doc string).

To post a comment you must log in.
Revision history for this message
James Page (james-page) :
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 2013-08-21 11:45:37 +0000
3+++ charmhelpers/fetch/__init__.py 2013-10-11 09:24:08 +0000
4@@ -80,8 +80,9 @@
5
6
7 def add_source(source, key=None):
8- if ((source.startswith('ppa:') or
9- source.startswith('http:'))):
10+ if (source.startswith('ppa:') or
11+ source.startswith('http:') or
12+ source.startswith('deb ')):
13 subprocess.check_call(['add-apt-repository', '--yes', source])
14 elif source.startswith('cloud:'):
15 apt_install(filter_installed_packages(['ubuntu-cloud-keyring']),
16@@ -118,8 +119,11 @@
17 Note that 'null' (a.k.a. None) should not be quoted.
18 """
19 sources = safe_load(config(sources_var))
20- keys = safe_load(config(keys_var))
21- if isinstance(sources, basestring) and isinstance(keys, basestring):
22+ keys = config(keys_var)
23+ if keys is not None:
24+ keys = safe_load(keys)
25+ if isinstance(sources, basestring) and (
26+ keys is None or isinstance(keys, basestring)):
27 add_source(sources, keys)
28 else:
29 if not len(sources) == len(keys):
30
31=== modified file 'tests/fetch/test_fetch.py'
32--- tests/fetch/test_fetch.py 2013-08-21 15:45:53 +0000
33+++ tests/fetch/test_fetch.py 2013-10-11 09:24:08 +0000
34@@ -92,6 +92,28 @@
35 '--yes',
36 source])
37
38+ @patch('subprocess.check_call')
39+ def test_add_source_deb(self, check_call):
40+ """add-apt-repository behaves differently when using the deb prefix.
41+
42+ $ add-apt-repository --yes "http://special.example.com/ubuntu precise-special main"
43+ $ grep special /etc/apt/sources.list
44+ deb http://special.example.com/ubuntu precise precise-special main
45+ deb-src http://special.example.com/ubuntu precise precise-special main
46+
47+ $ add-apt-repository --yes "deb http://special.example.com/ubuntu precise-special main"
48+ $ grep special /etc/apt/sources.list
49+ deb http://special.example.com/ubuntu precise precise-special main
50+ deb-src http://special.example.com/ubuntu precise precise-special main
51+ deb http://special.example.com/ubuntu precise-special main
52+ deb-src http://special.example.com/ubuntu precise-special main
53+ """
54+ source = "deb http://archive.ubuntu.com/ubuntu raring-backports main"
55+ fetch.add_source(source=source)
56+ check_call.assert_called_with(['add-apt-repository',
57+ '--yes',
58+ source])
59+
60 @patch.object(fetch, 'filter_installed_packages')
61 @patch.object(fetch, 'apt_install')
62 def test_add_source_cloud(self, apt_install, filter_pkg):
63@@ -134,6 +156,13 @@
64
65 @patch.object(fetch, 'config')
66 @patch.object(fetch, 'add_source')
67+ def test_configure_sources_single_source_no_key(self, add_source, config):
68+ config.side_effect = ['source', None]
69+ fetch.configure_sources()
70+ add_source.assert_called_with('source', None)
71+
72+ @patch.object(fetch, 'config')
73+ @patch.object(fetch, 'add_source')
74 def test_configure_sources_multiple_sources(self, add_source, config):
75 sources = ["sourcea", "sourceb"]
76 keys = ["keya", None]

Subscribers

People subscribed via source and target branches