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
=== modified file 'charmhelpers/fetch/__init__.py'
--- charmhelpers/fetch/__init__.py 2013-08-21 11:45:37 +0000
+++ charmhelpers/fetch/__init__.py 2013-10-11 09:24:08 +0000
@@ -80,8 +80,9 @@
8080
8181
82def add_source(source, key=None):82def add_source(source, key=None):
83 if ((source.startswith('ppa:') or83 if (source.startswith('ppa:') or
84 source.startswith('http:'))):84 source.startswith('http:') or
85 source.startswith('deb ')):
85 subprocess.check_call(['add-apt-repository', '--yes', source])86 subprocess.check_call(['add-apt-repository', '--yes', source])
86 elif source.startswith('cloud:'):87 elif source.startswith('cloud:'):
87 apt_install(filter_installed_packages(['ubuntu-cloud-keyring']),88 apt_install(filter_installed_packages(['ubuntu-cloud-keyring']),
@@ -118,8 +119,11 @@
118 Note that 'null' (a.k.a. None) should not be quoted.119 Note that 'null' (a.k.a. None) should not be quoted.
119 """120 """
120 sources = safe_load(config(sources_var))121 sources = safe_load(config(sources_var))
121 keys = safe_load(config(keys_var))122 keys = config(keys_var)
122 if isinstance(sources, basestring) and isinstance(keys, basestring):123 if keys is not None:
124 keys = safe_load(keys)
125 if isinstance(sources, basestring) and (
126 keys is None or isinstance(keys, basestring)):
123 add_source(sources, keys)127 add_source(sources, keys)
124 else:128 else:
125 if not len(sources) == len(keys):129 if not len(sources) == len(keys):
126130
=== modified file 'tests/fetch/test_fetch.py'
--- tests/fetch/test_fetch.py 2013-08-21 15:45:53 +0000
+++ tests/fetch/test_fetch.py 2013-10-11 09:24:08 +0000
@@ -92,6 +92,28 @@
92 '--yes',92 '--yes',
93 source])93 source])
9494
95 @patch('subprocess.check_call')
96 def test_add_source_deb(self, check_call):
97 """add-apt-repository behaves differently when using the deb prefix.
98
99 $ add-apt-repository --yes "http://special.example.com/ubuntu precise-special main"
100 $ grep special /etc/apt/sources.list
101 deb http://special.example.com/ubuntu precise precise-special main
102 deb-src http://special.example.com/ubuntu precise precise-special main
103
104 $ add-apt-repository --yes "deb http://special.example.com/ubuntu precise-special main"
105 $ grep special /etc/apt/sources.list
106 deb http://special.example.com/ubuntu precise precise-special main
107 deb-src http://special.example.com/ubuntu precise precise-special main
108 deb http://special.example.com/ubuntu precise-special main
109 deb-src http://special.example.com/ubuntu precise-special main
110 """
111 source = "deb http://archive.ubuntu.com/ubuntu raring-backports main"
112 fetch.add_source(source=source)
113 check_call.assert_called_with(['add-apt-repository',
114 '--yes',
115 source])
116
95 @patch.object(fetch, 'filter_installed_packages')117 @patch.object(fetch, 'filter_installed_packages')
96 @patch.object(fetch, 'apt_install')118 @patch.object(fetch, 'apt_install')
97 def test_add_source_cloud(self, apt_install, filter_pkg):119 def test_add_source_cloud(self, apt_install, filter_pkg):
@@ -134,6 +156,13 @@
134156
135 @patch.object(fetch, 'config')157 @patch.object(fetch, 'config')
136 @patch.object(fetch, 'add_source')158 @patch.object(fetch, 'add_source')
159 def test_configure_sources_single_source_no_key(self, add_source, config):
160 config.side_effect = ['source', None]
161 fetch.configure_sources()
162 add_source.assert_called_with('source', None)
163
164 @patch.object(fetch, 'config')
165 @patch.object(fetch, 'add_source')
137 def test_configure_sources_multiple_sources(self, add_source, config):166 def test_configure_sources_multiple_sources(self, add_source, config):
138 sources = ["sourcea", "sourceb"]167 sources = ["sourcea", "sourceb"]
139 keys = ["keya", None]168 keys = ["keya", None]

Subscribers

People subscribed via source and target branches