Merge lp:~paelzer/cloud-init/bug-1589174-fix-tests-in-adt-env into lp:~cloud-init-dev/cloud-init/trunk
- bug-1589174-fix-tests-in-adt-env
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 1230 |
Proposed branch: | lp:~paelzer/cloud-init/bug-1589174-fix-tests-in-adt-env |
Merge into: | lp:~cloud-init-dev/cloud-init/trunk |
Diff against target: |
727 lines (+205/-179) 5 files modified
cloudinit/config/cc_apt_configure.py (+16/-40) cloudinit/gpg.py (+76/-0) packages/bddeb (+6/-0) tests/unittests/test_handler/test_handler_apt_configure_sources_list.py (+37/-24) tests/unittests/test_handler/test_handler_apt_source.py (+70/-115) |
To merge this branch: | bzr merge lp:~paelzer/cloud-init/bug-1589174-fix-tests-in-adt-env |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
cloud-init Commiters | Pending | ||
Review via email: mp+296643@code.launchpad.net |
Commit message
Fixes to the unittests to run in more environments;
As well as some improvements that were found along testing them and due to the fact that we review some of that code again in the scope of curtin currently.
Tests:
- add a test for an alternate keyserver
- harden mirrorfail tests to detect and skip if no network is available
- improve apt_source related tests to work on CentOS7
Changes:
- gpg key handling is now in python instead of a shell blob
- packages/bddeb has an option to sign as someone else than smoser
- make exception handling of apt_source features more specific (i.e. no catch Exception)
- rename some functions to relfect better what they actually do
- capture some helper subp calls output to avoid spilling into stdout when not intended
Description of the change
Fixes to the unittests to run in more environments;
As well as some improvements that were found along testing them and due to the fact that we review some of that code again in the scope of curtin currently.
Tests:
- add a test for an alternate keyserver
- harden mirrorfail tests to detect and skip if no network is available
- improve apt_source related tests to work on CentOS7
Changes:
- gpg key handling is now in python instead of a shell blob
- packages/bddeb has an option to sign as someone else than smoser
- make exception handling of apt_source features more specific (i.e. no catch Exception)
- rename some functions to relfect better what they actually do
- capture some helper subp calls output to avoid spilling into stdout when not intended
- 1246. By Christian Ehrhardt
-
merge with upstream to avoid merge conflicts on the merge proposal
Christian Ehrhardt (paelzer) wrote : | # |
Scott Moser (smoser) wrote : | # |
mostly looks good. a couple comments. thank you.
- 1247. By Christian Ehrhardt
-
move gpg functions into gpg.py
This helps for cleaner code structuring.
ALong that makeing sure all these functions have a gpg_prefix. - 1248. By Christian Ehrhardt
-
improve error handling and reporting in gpg functions
- 1249. By Christian Ehrhardt
-
move SkipTest definition to tests/unittests
/helpers. py to be reusable - 1250. By Christian Ehrhardt
-
remove unused BIN_APT constant
- 1251. By Christian Ehrhardt
-
fix docstring for check connectivity
- 1252. By Christian Ehrhardt
-
mock is_resolvable in mirrorfail tests to remove dependency to external net
Christian Ehrhardt (paelzer) wrote : | # |
Thanks, addressed all you mentioned - will throw it through more testing now.
Christian Ehrhardt (paelzer) wrote : | # |
Ok, fine in sbuild, a partially shutdown network env and buildd (https:/
Preview Diff
1 | === modified file 'cloudinit/config/cc_apt_configure.py' | |||
2 | --- cloudinit/config/cc_apt_configure.py 2016-06-03 19:27:32 +0000 | |||
3 | +++ cloudinit/config/cc_apt_configure.py 2016-06-09 08:37:01 +0000 | |||
4 | @@ -24,6 +24,7 @@ | |||
5 | 24 | 24 | ||
6 | 25 | from cloudinit import templater | 25 | from cloudinit import templater |
7 | 26 | from cloudinit import util | 26 | from cloudinit import util |
8 | 27 | from cloudinit import gpg | ||
9 | 27 | 28 | ||
10 | 28 | distros = ['ubuntu', 'debian'] | 29 | distros = ['ubuntu', 'debian'] |
11 | 29 | 30 | ||
12 | @@ -34,21 +35,6 @@ | |||
13 | 34 | # this will match 'XXX:YYY' (ie, 'cloud-archive:foo' or 'ppa:bar') | 35 | # this will match 'XXX:YYY' (ie, 'cloud-archive:foo' or 'ppa:bar') |
14 | 35 | ADD_APT_REPO_MATCH = r"^[\w-]+:\w" | 36 | ADD_APT_REPO_MATCH = r"^[\w-]+:\w" |
15 | 36 | 37 | ||
16 | 37 | # A temporary shell program to get a given gpg key | ||
17 | 38 | # from a given keyserver | ||
18 | 39 | EXPORT_GPG_KEYID = """ | ||
19 | 40 | k=${1} ks=${2}; | ||
20 | 41 | exec 2>/dev/null | ||
21 | 42 | [ -n "$k" ] || exit 1; | ||
22 | 43 | armour=$(gpg --export --armour "${k}") | ||
23 | 44 | if [ -z "${armour}" ]; then | ||
24 | 45 | gpg --keyserver ${ks} --recv "${k}" >/dev/null && | ||
25 | 46 | armour=$(gpg --export --armour "${k}") && | ||
26 | 47 | gpg --batch --yes --delete-keys "${k}" | ||
27 | 48 | fi | ||
28 | 49 | [ -n "${armour}" ] && echo "${armour}" | ||
29 | 50 | """ | ||
30 | 51 | |||
31 | 52 | 38 | ||
32 | 53 | def handle(name, cfg, cloud, log, _args): | 39 | def handle(name, cfg, cloud, log, _args): |
33 | 54 | if util.is_false(cfg.get('apt_configure_enabled', True)): | 40 | if util.is_false(cfg.get('apt_configure_enabled', True)): |
34 | @@ -94,8 +80,8 @@ | |||
35 | 94 | def matcher(x): | 80 | def matcher(x): |
36 | 95 | return False | 81 | return False |
37 | 96 | 82 | ||
40 | 97 | errors = add_sources(cfg['apt_sources'], params, | 83 | errors = add_apt_sources(cfg['apt_sources'], params, |
41 | 98 | aa_repo_match=matcher) | 84 | aa_repo_match=matcher) |
42 | 99 | for e in errors: | 85 | for e in errors: |
43 | 100 | log.warn("Add source error: %s", ':'.join(e)) | 86 | log.warn("Add source error: %s", ':'.join(e)) |
44 | 101 | 87 | ||
45 | @@ -108,17 +94,7 @@ | |||
46 | 108 | util.logexc(log, "Failed to run debconf-set-selections") | 94 | util.logexc(log, "Failed to run debconf-set-selections") |
47 | 109 | 95 | ||
48 | 110 | 96 | ||
60 | 111 | # get gpg keyid from keyserver | 97 | def mirrorurl_to_apt_fileprefix(mirror): |
50 | 112 | def getkeybyid(keyid, keyserver): | ||
51 | 113 | with util.ExtendedTemporaryFile(suffix='.sh', mode="w+", ) as fh: | ||
52 | 114 | fh.write(EXPORT_GPG_KEYID) | ||
53 | 115 | fh.flush() | ||
54 | 116 | cmd = ['/bin/sh', fh.name, keyid, keyserver] | ||
55 | 117 | (stdout, _stderr) = util.subp(cmd) | ||
56 | 118 | return stdout.strip() | ||
57 | 119 | |||
58 | 120 | |||
59 | 121 | def mirror2lists_fileprefix(mirror): | ||
61 | 122 | string = mirror | 98 | string = mirror |
62 | 123 | # take off http:// or ftp:// | 99 | # take off http:// or ftp:// |
63 | 124 | if string.endswith("/"): | 100 | if string.endswith("/"): |
64 | @@ -135,8 +111,8 @@ | |||
65 | 135 | nmirror = new_mirrors.get(name) | 111 | nmirror = new_mirrors.get(name) |
66 | 136 | if not nmirror: | 112 | if not nmirror: |
67 | 137 | continue | 113 | continue |
70 | 138 | oprefix = os.path.join(lists_d, mirror2lists_fileprefix(omirror)) | 114 | oprefix = os.path.join(lists_d, mirrorurl_to_apt_fileprefix(omirror)) |
71 | 139 | nprefix = os.path.join(lists_d, mirror2lists_fileprefix(nmirror)) | 115 | nprefix = os.path.join(lists_d, mirrorurl_to_apt_fileprefix(nmirror)) |
72 | 140 | if oprefix == nprefix: | 116 | if oprefix == nprefix: |
73 | 141 | continue | 117 | continue |
74 | 142 | olen = len(oprefix) | 118 | olen = len(oprefix) |
75 | @@ -171,7 +147,7 @@ | |||
76 | 171 | templater.render_to_file(template_fn, '/etc/apt/sources.list', params) | 147 | templater.render_to_file(template_fn, '/etc/apt/sources.list', params) |
77 | 172 | 148 | ||
78 | 173 | 149 | ||
80 | 174 | def add_key_raw(key): | 150 | def add_apt_key_raw(key): |
81 | 175 | """ | 151 | """ |
82 | 176 | actual adding of a key as defined in key argument | 152 | actual adding of a key as defined in key argument |
83 | 177 | to the system | 153 | to the system |
84 | @@ -179,10 +155,10 @@ | |||
85 | 179 | try: | 155 | try: |
86 | 180 | util.subp(('apt-key', 'add', '-'), key) | 156 | util.subp(('apt-key', 'add', '-'), key) |
87 | 181 | except util.ProcessExecutionError: | 157 | except util.ProcessExecutionError: |
92 | 182 | raise Exception('failed add key') | 158 | raise ValueError('failed to add apt GPG Key to apt keyring') |
93 | 183 | 159 | ||
94 | 184 | 160 | ||
95 | 185 | def add_key(ent): | 161 | def add_apt_key(ent): |
96 | 186 | """ | 162 | """ |
97 | 187 | add key to the system as defined in ent (if any) | 163 | add key to the system as defined in ent (if any) |
98 | 188 | supports raw keys or keyid's | 164 | supports raw keys or keyid's |
99 | @@ -192,10 +168,10 @@ | |||
100 | 192 | keyserver = "keyserver.ubuntu.com" | 168 | keyserver = "keyserver.ubuntu.com" |
101 | 193 | if 'keyserver' in ent: | 169 | if 'keyserver' in ent: |
102 | 194 | keyserver = ent['keyserver'] | 170 | keyserver = ent['keyserver'] |
104 | 195 | ent['key'] = getkeybyid(ent['keyid'], keyserver) | 171 | ent['key'] = gpg.gpg_getkeybyid(ent['keyid'], keyserver) |
105 | 196 | 172 | ||
106 | 197 | if 'key' in ent: | 173 | if 'key' in ent: |
108 | 198 | add_key_raw(ent['key']) | 174 | add_apt_key_raw(ent['key']) |
109 | 199 | 175 | ||
110 | 200 | 176 | ||
111 | 201 | def convert_to_new_format(srclist): | 177 | def convert_to_new_format(srclist): |
112 | @@ -222,7 +198,7 @@ | |||
113 | 222 | return srcdict | 198 | return srcdict |
114 | 223 | 199 | ||
115 | 224 | 200 | ||
117 | 225 | def add_sources(srclist, template_params=None, aa_repo_match=None): | 201 | def add_apt_sources(srclist, template_params=None, aa_repo_match=None): |
118 | 226 | """ | 202 | """ |
119 | 227 | add entries in /etc/apt/sources.list.d for each abbreviated | 203 | add entries in /etc/apt/sources.list.d for each abbreviated |
120 | 228 | sources.list entry in 'srclist'. When rendering template, also | 204 | sources.list entry in 'srclist'. When rendering template, also |
121 | @@ -245,8 +221,8 @@ | |||
122 | 245 | 221 | ||
123 | 246 | # keys can be added without specifying a source | 222 | # keys can be added without specifying a source |
124 | 247 | try: | 223 | try: |
127 | 248 | add_key(ent) | 224 | add_apt_key(ent) |
128 | 249 | except Exception as detail: | 225 | except ValueError as detail: |
129 | 250 | errorlist.append([ent, detail]) | 226 | errorlist.append([ent, detail]) |
130 | 251 | 227 | ||
131 | 252 | if 'source' not in ent: | 228 | if 'source' not in ent: |
132 | 253 | 229 | ||
133 | === added file 'cloudinit/gpg.py' | |||
134 | --- cloudinit/gpg.py 1970-01-01 00:00:00 +0000 | |||
135 | +++ cloudinit/gpg.py 2016-06-09 08:37:01 +0000 | |||
136 | @@ -0,0 +1,76 @@ | |||
137 | 1 | """gpg.py - Collection of gpg key related functions""" | ||
138 | 2 | # vi: ts=4 expandtab | ||
139 | 3 | # | ||
140 | 4 | # Copyright (C) 2016 Canonical Ltd. | ||
141 | 5 | # | ||
142 | 6 | # Author: Scott Moser <scott.moser@canonical.com> | ||
143 | 7 | # Author: Juerg Haefliger <juerg.haefliger@hp.com> | ||
144 | 8 | # Author: Joshua Harlow <harlowja@yahoo-inc.com> | ||
145 | 9 | # Author: Christian Ehrhardt <christian.ehrhardt@canonical.com> | ||
146 | 10 | # | ||
147 | 11 | # This program is free software: you can redistribute it and/or modify | ||
148 | 12 | # it under the terms of the GNU General Public License version 3, as | ||
149 | 13 | # published by the Free Software Foundation. | ||
150 | 14 | # | ||
151 | 15 | # This program is distributed in the hope that it will be useful, | ||
152 | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
153 | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
154 | 18 | # GNU General Public License for more details. | ||
155 | 19 | # | ||
156 | 20 | # You should have received a copy of the GNU General Public License | ||
157 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
158 | 22 | |||
159 | 23 | from cloudinit import util | ||
160 | 24 | from cloudinit import log as logging | ||
161 | 25 | |||
162 | 26 | LOG = logging.getLogger(__name__) | ||
163 | 27 | |||
164 | 28 | |||
165 | 29 | def gpg_export_armour(key): | ||
166 | 30 | """Export gpg key, armoured key gets returned""" | ||
167 | 31 | try: | ||
168 | 32 | (armour, _) = util.subp(["gpg", "--export", "--armour", key], | ||
169 | 33 | capture=True) | ||
170 | 34 | except util.ProcessExecutionError as error: | ||
171 | 35 | # debug, since it happens for any key not on the system initially | ||
172 | 36 | LOG.debug('Failed to export armoured key "%s": %s', key, error) | ||
173 | 37 | armour = None | ||
174 | 38 | return armour | ||
175 | 39 | |||
176 | 40 | |||
177 | 41 | def gpg_recv_key(key, keyserver): | ||
178 | 42 | """Receive gpg key from the specified keyserver""" | ||
179 | 43 | LOG.debug('Receive gpg key "%s"', key) | ||
180 | 44 | try: | ||
181 | 45 | util.subp(["gpg", "--keyserver", keyserver, "--recv", key], | ||
182 | 46 | capture=True) | ||
183 | 47 | except util.ProcessExecutionError as error: | ||
184 | 48 | raise ValueError(('Failed to import key "%s" ' | ||
185 | 49 | 'from server "%s" - error %s') % | ||
186 | 50 | (key, keyserver, error)) | ||
187 | 51 | |||
188 | 52 | |||
189 | 53 | def gpg_delete_key(key): | ||
190 | 54 | """Delete the specified key from the local gpg ring""" | ||
191 | 55 | try: | ||
192 | 56 | util.subp(["gpg", "--batch", "--yes", "--delete-keys", key], | ||
193 | 57 | capture=True) | ||
194 | 58 | except util.ProcessExecutionError as error: | ||
195 | 59 | LOG.warn('Failed delete key "%s": %s', key, error) | ||
196 | 60 | |||
197 | 61 | |||
198 | 62 | def gpg_getkeybyid(keyid, keyserver): | ||
199 | 63 | """get gpg keyid from keyserver""" | ||
200 | 64 | armour = gpg_export_armour(keyid) | ||
201 | 65 | if not armour: | ||
202 | 66 | try: | ||
203 | 67 | gpg_recv_key(keyid, keyserver=keyserver) | ||
204 | 68 | armour = gpg_export_armour(keyid) | ||
205 | 69 | except ValueError: | ||
206 | 70 | LOG.exception('Failed to obtain gpg key %s', keyid) | ||
207 | 71 | raise | ||
208 | 72 | finally: | ||
209 | 73 | # delete just imported key to leave environment as it was before | ||
210 | 74 | gpg_delete_key(keyid) | ||
211 | 75 | |||
212 | 76 | return armour.rstrip('\n') | ||
213 | 0 | 77 | ||
214 | === modified file 'packages/bddeb' | |||
215 | --- packages/bddeb 2016-05-26 15:51:38 +0000 | |||
216 | +++ packages/bddeb 2016-06-09 08:37:01 +0000 | |||
217 | @@ -148,11 +148,17 @@ | |||
218 | 148 | parser.add_argument("--sign", default=False, action='store_true', | 148 | parser.add_argument("--sign", default=False, action='store_true', |
219 | 149 | help="sign result. do not pass -us -uc to debuild") | 149 | help="sign result. do not pass -us -uc to debuild") |
220 | 150 | 150 | ||
221 | 151 | parser.add_argument("--signuser", default=False, action='store', | ||
222 | 152 | help="user to sign, see man dpkg-genchanges") | ||
223 | 153 | |||
224 | 151 | args = parser.parse_args() | 154 | args = parser.parse_args() |
225 | 152 | 155 | ||
226 | 153 | if not args.sign: | 156 | if not args.sign: |
227 | 154 | args.debuild_args.extend(['-us', '-uc']) | 157 | args.debuild_args.extend(['-us', '-uc']) |
228 | 155 | 158 | ||
229 | 159 | if args.signuser: | ||
230 | 160 | args.debuild_args.extend(['-e%s' % args.signuser]) | ||
231 | 161 | |||
232 | 156 | os.environ['INIT_SYSTEM'] = args.init_system | 162 | os.environ['INIT_SYSTEM'] = args.init_system |
233 | 157 | 163 | ||
234 | 158 | capture = True | 164 | capture = True |
235 | 159 | 165 | ||
236 | === modified file 'tests/unittests/test_handler/test_handler_apt_configure_sources_list.py' | |||
237 | --- tests/unittests/test_handler/test_handler_apt_configure_sources_list.py 2016-06-05 00:50:37 +0000 | |||
238 | +++ tests/unittests/test_handler/test_handler_apt_configure_sources_list.py 2016-06-09 08:37:01 +0000 | |||
239 | @@ -20,6 +20,8 @@ | |||
240 | 20 | from cloudinit.config import cc_apt_configure | 20 | from cloudinit.config import cc_apt_configure |
241 | 21 | from cloudinit.sources import DataSourceNone | 21 | from cloudinit.sources import DataSourceNone |
242 | 22 | 22 | ||
243 | 23 | from cloudinit.distros.debian import Distro | ||
244 | 24 | |||
245 | 23 | from .. import helpers as t_help | 25 | from .. import helpers as t_help |
246 | 24 | 26 | ||
247 | 25 | LOG = logging.getLogger(__name__) | 27 | LOG = logging.getLogger(__name__) |
248 | @@ -115,38 +117,47 @@ | |||
249 | 115 | {'codename': '', 'primary': mirrorcheck, 'mirror': mirrorcheck}) | 117 | {'codename': '', 'primary': mirrorcheck, 'mirror': mirrorcheck}) |
250 | 116 | 118 | ||
251 | 117 | def test_apt_source_list_debian(self): | 119 | def test_apt_source_list_debian(self): |
255 | 118 | """test_apt_source_list_debian | 120 | """Test rendering of a source.list from template for debian""" |
253 | 119 | Test rendering of a source.list from template for debian | ||
254 | 120 | """ | ||
256 | 121 | self.apt_source_list('debian', 'http://httpredir.debian.org/debian') | 121 | self.apt_source_list('debian', 'http://httpredir.debian.org/debian') |
257 | 122 | 122 | ||
258 | 123 | def test_apt_source_list_ubuntu(self): | 123 | def test_apt_source_list_ubuntu(self): |
262 | 124 | """test_apt_source_list_ubuntu | 124 | """Test rendering of a source.list from template for ubuntu""" |
260 | 125 | Test rendering of a source.list from template for ubuntu | ||
261 | 126 | """ | ||
263 | 127 | self.apt_source_list('ubuntu', 'http://archive.ubuntu.com/ubuntu/') | 125 | self.apt_source_list('ubuntu', 'http://archive.ubuntu.com/ubuntu/') |
264 | 128 | 126 | ||
266 | 129 | @t_help.skipIf(True, "LP: #1589174") | 127 | @staticmethod |
267 | 128 | def myresolve(name): | ||
268 | 129 | """Fake util.is_resolvable for mirrorfail tests""" | ||
269 | 130 | if name == "does.not.exist": | ||
270 | 131 | print("Faking FAIL for '%s'" % name) | ||
271 | 132 | return False | ||
272 | 133 | else: | ||
273 | 134 | print("Faking SUCCESS for '%s'" % name) | ||
274 | 135 | return True | ||
275 | 136 | |||
276 | 130 | def test_apt_srcl_debian_mirrorfail(self): | 137 | def test_apt_srcl_debian_mirrorfail(self): |
283 | 131 | """test_apt_source_list_debian_mirrorfail | 138 | """Test rendering of a source.list from template for debian""" |
284 | 132 | Test rendering of a source.list from template for debian | 139 | with mock.patch.object(util, 'is_resolvable', |
285 | 133 | """ | 140 | side_effect=self.myresolve) as mockresolve: |
286 | 134 | self.apt_source_list('debian', ['http://does.not.exist', | 141 | self.apt_source_list('debian', |
287 | 135 | 'http://httpredir.debian.org/debian'], | 142 | ['http://does.not.exist', |
288 | 136 | 'http://httpredir.debian.org/debian') | 143 | 'http://httpredir.debian.org/debian'], |
289 | 144 | 'http://httpredir.debian.org/debian') | ||
290 | 145 | mockresolve.assert_any_call("does.not.exist") | ||
291 | 146 | mockresolve.assert_any_call("httpredir.debian.org") | ||
292 | 137 | 147 | ||
293 | 138 | def test_apt_srcl_ubuntu_mirrorfail(self): | 148 | def test_apt_srcl_ubuntu_mirrorfail(self): |
300 | 139 | """test_apt_source_list_ubuntu_mirrorfail | 149 | """Test rendering of a source.list from template for ubuntu""" |
301 | 140 | Test rendering of a source.list from template for ubuntu | 150 | with mock.patch.object(util, 'is_resolvable', |
302 | 141 | """ | 151 | side_effect=self.myresolve) as mockresolve: |
303 | 142 | self.apt_source_list('ubuntu', ['http://does.not.exist', | 152 | self.apt_source_list('ubuntu', |
304 | 143 | 'http://archive.ubuntu.com/ubuntu/'], | 153 | ['http://does.not.exist', |
305 | 144 | 'http://archive.ubuntu.com/ubuntu/') | 154 | 'http://archive.ubuntu.com/ubuntu/'], |
306 | 155 | 'http://archive.ubuntu.com/ubuntu/') | ||
307 | 156 | mockresolve.assert_any_call("does.not.exist") | ||
308 | 157 | mockresolve.assert_any_call("archive.ubuntu.com") | ||
309 | 145 | 158 | ||
310 | 146 | def test_apt_srcl_custom(self): | 159 | def test_apt_srcl_custom(self): |
314 | 147 | """test_apt_srcl_custom | 160 | """Test rendering from a custom source.list template""" |
312 | 148 | Test rendering from a custom source.list template | ||
313 | 149 | """ | ||
315 | 150 | cfg = util.load_yaml(YAML_TEXT_CUSTOM_SL) | 161 | cfg = util.load_yaml(YAML_TEXT_CUSTOM_SL) |
316 | 151 | mycloud = self._get_cloud('ubuntu') | 162 | mycloud = self._get_cloud('ubuntu') |
317 | 152 | 163 | ||
318 | @@ -155,8 +166,10 @@ | |||
319 | 155 | with mock.patch.object(util, 'subp', self.subp): | 166 | with mock.patch.object(util, 'subp', self.subp): |
320 | 156 | with mock.patch.object(cc_apt_configure, 'get_release', | 167 | with mock.patch.object(cc_apt_configure, 'get_release', |
321 | 157 | return_value='fakerelease'): | 168 | return_value='fakerelease'): |
324 | 158 | cc_apt_configure.handle("notimportant", cfg, mycloud, | 169 | with mock.patch.object(Distro, 'get_primary_arch', |
325 | 159 | LOG, None) | 170 | return_value='amd64'): |
326 | 171 | cc_apt_configure.handle("notimportant", cfg, mycloud, | ||
327 | 172 | LOG, None) | ||
328 | 160 | 173 | ||
329 | 161 | mockwrite.assert_called_once_with( | 174 | mockwrite.assert_called_once_with( |
330 | 162 | '/etc/apt/sources.list', | 175 | '/etc/apt/sources.list', |
331 | 163 | 176 | ||
332 | === modified file 'tests/unittests/test_handler/test_handler_apt_source.py' | |||
333 | --- tests/unittests/test_handler/test_handler_apt_source.py 2016-06-04 02:56:45 +0000 | |||
334 | +++ tests/unittests/test_handler/test_handler_apt_source.py 2016-06-09 08:37:01 +0000 | |||
335 | @@ -14,6 +14,7 @@ | |||
336 | 14 | 14 | ||
337 | 15 | from cloudinit.config import cc_apt_configure | 15 | from cloudinit.config import cc_apt_configure |
338 | 16 | from cloudinit import util | 16 | from cloudinit import util |
339 | 17 | from cloudinit import gpg | ||
340 | 17 | 18 | ||
341 | 18 | from ..helpers import TestCase | 19 | from ..helpers import TestCase |
342 | 19 | 20 | ||
343 | @@ -62,7 +63,8 @@ | |||
344 | 62 | get_rel.return_value = self.release | 63 | get_rel.return_value = self.release |
345 | 63 | self.addCleanup(patcher.stop) | 64 | self.addCleanup(patcher.stop) |
346 | 64 | 65 | ||
348 | 65 | def _get_default_params(self): | 66 | @staticmethod |
349 | 67 | def _get_default_params(): | ||
350 | 66 | """get_default_params | 68 | """get_default_params |
351 | 67 | Get the most basic default mrror and release info to be used in tests | 69 | Get the most basic default mrror and release info to be used in tests |
352 | 68 | """ | 70 | """ |
353 | @@ -86,7 +88,7 @@ | |||
354 | 86 | """ | 88 | """ |
355 | 87 | params = self._get_default_params() | 89 | params = self._get_default_params() |
356 | 88 | 90 | ||
358 | 89 | cc_apt_configure.add_sources(cfg, params) | 91 | cc_apt_configure.add_apt_sources(cfg, params) |
359 | 90 | 92 | ||
360 | 91 | self.assertTrue(os.path.isfile(filename)) | 93 | self.assertTrue(os.path.isfile(filename)) |
361 | 92 | 94 | ||
362 | @@ -98,10 +100,7 @@ | |||
363 | 98 | contents, flags=re.IGNORECASE)) | 100 | contents, flags=re.IGNORECASE)) |
364 | 99 | 101 | ||
365 | 100 | def test_apt_src_basic(self): | 102 | def test_apt_src_basic(self): |
370 | 101 | """test_apt_src_basic | 103 | """Test deb source string, overwrite mirror and filename""" |
367 | 102 | Test Fix deb source string, has to overwrite mirror conf in params. | ||
368 | 103 | Test with a filename provided in config. | ||
369 | 104 | """ | ||
371 | 105 | cfg = {'source': ('deb http://archive.ubuntu.com/ubuntu' | 104 | cfg = {'source': ('deb http://archive.ubuntu.com/ubuntu' |
372 | 106 | ' karmic-backports' | 105 | ' karmic-backports' |
373 | 107 | ' main universe multiverse restricted'), | 106 | ' main universe multiverse restricted'), |
374 | @@ -109,11 +108,7 @@ | |||
375 | 109 | self.apt_src_basic(self.aptlistfile, [cfg]) | 108 | self.apt_src_basic(self.aptlistfile, [cfg]) |
376 | 110 | 109 | ||
377 | 111 | def test_apt_src_basic_dict(self): | 110 | def test_apt_src_basic_dict(self): |
383 | 112 | """test_apt_src_basic_dict | 111 | """Test deb source string, overwrite mirror and filename (dict)""" |
379 | 113 | Test Fix deb source string, has to overwrite mirror conf in params. | ||
380 | 114 | Test with a filename provided in config. | ||
381 | 115 | Provided in a dictionary with filename being the key (new format) | ||
382 | 116 | """ | ||
384 | 117 | cfg = {self.aptlistfile: {'source': | 112 | cfg = {self.aptlistfile: {'source': |
385 | 118 | ('deb http://archive.ubuntu.com/ubuntu' | 113 | ('deb http://archive.ubuntu.com/ubuntu' |
386 | 119 | ' karmic-backports' | 114 | ' karmic-backports' |
387 | @@ -143,10 +138,7 @@ | |||
388 | 143 | contents, flags=re.IGNORECASE)) | 138 | contents, flags=re.IGNORECASE)) |
389 | 144 | 139 | ||
390 | 145 | def test_apt_src_basic_tri(self): | 140 | def test_apt_src_basic_tri(self): |
395 | 146 | """test_apt_src_basic_tri | 141 | """Test Fix three deb source string with filenames""" |
392 | 147 | Test Fix three deb source string, has to overwrite mirror conf in | ||
393 | 148 | params. Test with filenames provided in config. | ||
394 | 149 | """ | ||
396 | 150 | cfg1 = {'source': ('deb http://archive.ubuntu.com/ubuntu' | 142 | cfg1 = {'source': ('deb http://archive.ubuntu.com/ubuntu' |
397 | 151 | ' karmic-backports' | 143 | ' karmic-backports' |
398 | 152 | ' main universe multiverse restricted'), | 144 | ' main universe multiverse restricted'), |
399 | @@ -162,11 +154,7 @@ | |||
400 | 162 | self.apt_src_basic_tri([cfg1, cfg2, cfg3]) | 154 | self.apt_src_basic_tri([cfg1, cfg2, cfg3]) |
401 | 163 | 155 | ||
402 | 164 | def test_apt_src_basic_dict_tri(self): | 156 | def test_apt_src_basic_dict_tri(self): |
408 | 165 | """test_apt_src_basic_dict_tri | 157 | """Test Fix three deb source string with filenames (dict)""" |
404 | 166 | Test Fix three deb source string, has to overwrite mirror conf in | ||
405 | 167 | params. Test with filenames provided in config. | ||
406 | 168 | Provided in a dictionary with filename being the key (new format) | ||
407 | 169 | """ | ||
409 | 170 | cfg = {self.aptlistfile: {'source': | 158 | cfg = {self.aptlistfile: {'source': |
410 | 171 | ('deb http://archive.ubuntu.com/ubuntu' | 159 | ('deb http://archive.ubuntu.com/ubuntu' |
411 | 172 | ' karmic-backports' | 160 | ' karmic-backports' |
412 | @@ -182,10 +170,7 @@ | |||
413 | 182 | self.apt_src_basic_tri(cfg) | 170 | self.apt_src_basic_tri(cfg) |
414 | 183 | 171 | ||
415 | 184 | def test_apt_src_basic_nofn(self): | 172 | def test_apt_src_basic_nofn(self): |
420 | 185 | """test_apt_src_basic_nofn | 173 | """Test Fix three deb source string without filenames (dict)""" |
417 | 186 | Test Fix deb source string, has to overwrite mirror conf in params. | ||
418 | 187 | Test without a filename provided in config and test for known fallback. | ||
419 | 188 | """ | ||
421 | 189 | cfg = {'source': ('deb http://archive.ubuntu.com/ubuntu' | 174 | cfg = {'source': ('deb http://archive.ubuntu.com/ubuntu' |
422 | 190 | ' karmic-backports' | 175 | ' karmic-backports' |
423 | 191 | ' main universe multiverse restricted')} | 176 | ' main universe multiverse restricted')} |
424 | @@ -197,7 +182,7 @@ | |||
425 | 197 | Test Autoreplacement of MIRROR and RELEASE in source specs | 182 | Test Autoreplacement of MIRROR and RELEASE in source specs |
426 | 198 | """ | 183 | """ |
427 | 199 | params = self._get_default_params() | 184 | params = self._get_default_params() |
429 | 200 | cc_apt_configure.add_sources(cfg, params) | 185 | cc_apt_configure.add_apt_sources(cfg, params) |
430 | 201 | 186 | ||
431 | 202 | self.assertTrue(os.path.isfile(filename)) | 187 | self.assertTrue(os.path.isfile(filename)) |
432 | 203 | 188 | ||
433 | @@ -208,10 +193,7 @@ | |||
434 | 208 | contents, flags=re.IGNORECASE)) | 193 | contents, flags=re.IGNORECASE)) |
435 | 209 | 194 | ||
436 | 210 | def test_apt_src_replace(self): | 195 | def test_apt_src_replace(self): |
441 | 211 | """test_apt_src_replace | 196 | """Test Autoreplacement of MIRROR and RELEASE in source specs""" |
438 | 212 | Test Autoreplacement of MIRROR and RELEASE in source specs with | ||
439 | 213 | Filename being set | ||
440 | 214 | """ | ||
442 | 215 | cfg = {'source': 'deb $MIRROR $RELEASE multiverse', | 197 | cfg = {'source': 'deb $MIRROR $RELEASE multiverse', |
443 | 216 | 'filename': self.aptlistfile} | 198 | 'filename': self.aptlistfile} |
444 | 217 | self.apt_src_replacement(self.aptlistfile, [cfg]) | 199 | self.apt_src_replacement(self.aptlistfile, [cfg]) |
445 | @@ -237,10 +219,7 @@ | |||
446 | 237 | contents, flags=re.IGNORECASE)) | 219 | contents, flags=re.IGNORECASE)) |
447 | 238 | 220 | ||
448 | 239 | def test_apt_src_replace_tri(self): | 221 | def test_apt_src_replace_tri(self): |
453 | 240 | """test_apt_src_replace_tri | 222 | """Test triple Autoreplacement of MIRROR and RELEASE in source specs""" |
450 | 241 | Test three autoreplacements of MIRROR and RELEASE in source specs with | ||
451 | 242 | Filename being set | ||
452 | 243 | """ | ||
454 | 244 | cfg1 = {'source': 'deb $MIRROR $RELEASE multiverse', | 223 | cfg1 = {'source': 'deb $MIRROR $RELEASE multiverse', |
455 | 245 | 'filename': self.aptlistfile} | 224 | 'filename': self.aptlistfile} |
456 | 246 | cfg2 = {'source': 'deb $MIRROR $RELEASE main', | 225 | cfg2 = {'source': 'deb $MIRROR $RELEASE main', |
457 | @@ -250,13 +229,7 @@ | |||
458 | 250 | self.apt_src_replace_tri([cfg1, cfg2, cfg3]) | 229 | self.apt_src_replace_tri([cfg1, cfg2, cfg3]) |
459 | 251 | 230 | ||
460 | 252 | def test_apt_src_replace_dict_tri(self): | 231 | def test_apt_src_replace_dict_tri(self): |
468 | 253 | """test_apt_src_replace_dict_tri | 232 | """Test triple Autoreplacement in source specs (dict)""" |
462 | 254 | Test three autoreplacements of MIRROR and RELEASE in source specs with | ||
463 | 255 | Filename being set | ||
464 | 256 | Provided in a dictionary with filename being the key (new format) | ||
465 | 257 | We also test a new special conditions of the new format that allows | ||
466 | 258 | filenames to be overwritten inside the directory entry. | ||
467 | 259 | """ | ||
469 | 260 | cfg = {self.aptlistfile: {'source': 'deb $MIRROR $RELEASE multiverse'}, | 233 | cfg = {self.aptlistfile: {'source': 'deb $MIRROR $RELEASE multiverse'}, |
470 | 261 | 'notused': {'source': 'deb $MIRROR $RELEASE main', | 234 | 'notused': {'source': 'deb $MIRROR $RELEASE main', |
471 | 262 | 'filename': self.aptlistfile2}, | 235 | 'filename': self.aptlistfile2}, |
472 | @@ -264,10 +237,7 @@ | |||
473 | 264 | self.apt_src_replace_tri(cfg) | 237 | self.apt_src_replace_tri(cfg) |
474 | 265 | 238 | ||
475 | 266 | def test_apt_src_replace_nofn(self): | 239 | def test_apt_src_replace_nofn(self): |
480 | 267 | """test_apt_src_replace_nofn | 240 | """Test Autoreplacement of MIRROR and RELEASE in source specs nofile""" |
477 | 268 | Test Autoreplacement of MIRROR and RELEASE in source specs with | ||
478 | 269 | No filename being set | ||
479 | 270 | """ | ||
481 | 271 | cfg = {'source': 'deb $MIRROR $RELEASE multiverse'} | 241 | cfg = {'source': 'deb $MIRROR $RELEASE multiverse'} |
482 | 272 | with mock.patch.object(os.path, 'join', side_effect=self.myjoin): | 242 | with mock.patch.object(os.path, 'join', side_effect=self.myjoin): |
483 | 273 | self.apt_src_replacement(self.fallbackfn, [cfg]) | 243 | self.apt_src_replacement(self.fallbackfn, [cfg]) |
484 | @@ -280,7 +250,7 @@ | |||
485 | 280 | 250 | ||
486 | 281 | with mock.patch.object(util, 'subp', | 251 | with mock.patch.object(util, 'subp', |
487 | 282 | return_value=('fakekey 1234', '')) as mockobj: | 252 | return_value=('fakekey 1234', '')) as mockobj: |
489 | 283 | cc_apt_configure.add_sources(cfg, params) | 253 | cc_apt_configure.add_apt_sources(cfg, params) |
490 | 284 | 254 | ||
491 | 285 | # check if it added the right ammount of keys | 255 | # check if it added the right ammount of keys |
492 | 286 | calls = [] | 256 | calls = [] |
493 | @@ -299,9 +269,7 @@ | |||
494 | 299 | contents, flags=re.IGNORECASE)) | 269 | contents, flags=re.IGNORECASE)) |
495 | 300 | 270 | ||
496 | 301 | def test_apt_src_keyid(self): | 271 | def test_apt_src_keyid(self): |
500 | 302 | """test_apt_src_keyid | 272 | """Test specification of a source + keyid with filename being set""" |
498 | 303 | Test specification of a source + keyid with filename being set | ||
499 | 304 | """ | ||
501 | 305 | cfg = {'source': ('deb ' | 273 | cfg = {'source': ('deb ' |
502 | 306 | 'http://ppa.launchpad.net/' | 274 | 'http://ppa.launchpad.net/' |
503 | 307 | 'smoser/cloud-init-test/ubuntu' | 275 | 'smoser/cloud-init-test/ubuntu' |
504 | @@ -311,10 +279,7 @@ | |||
505 | 311 | self.apt_src_keyid(self.aptlistfile, [cfg], 1) | 279 | self.apt_src_keyid(self.aptlistfile, [cfg], 1) |
506 | 312 | 280 | ||
507 | 313 | def test_apt_src_keyid_tri(self): | 281 | def test_apt_src_keyid_tri(self): |
512 | 314 | """test_apt_src_keyid_tri | 282 | """Test 3x specification of a source + keyid with filename being set""" |
509 | 315 | Test specification of a source + keyid with filename being set | ||
510 | 316 | Setting three of such, check for content and keys | ||
511 | 317 | """ | ||
513 | 318 | cfg1 = {'source': ('deb ' | 283 | cfg1 = {'source': ('deb ' |
514 | 319 | 'http://ppa.launchpad.net/' | 284 | 'http://ppa.launchpad.net/' |
515 | 320 | 'smoser/cloud-init-test/ubuntu' | 285 | 'smoser/cloud-init-test/ubuntu' |
516 | @@ -351,9 +316,7 @@ | |||
517 | 351 | contents, flags=re.IGNORECASE)) | 316 | contents, flags=re.IGNORECASE)) |
518 | 352 | 317 | ||
519 | 353 | def test_apt_src_keyid_nofn(self): | 318 | def test_apt_src_keyid_nofn(self): |
523 | 354 | """test_apt_src_keyid_nofn | 319 | """Test specification of a source + keyid without filename being set""" |
521 | 355 | Test specification of a source + keyid without filename being set | ||
522 | 356 | """ | ||
524 | 357 | cfg = {'source': ('deb ' | 320 | cfg = {'source': ('deb ' |
525 | 358 | 'http://ppa.launchpad.net/' | 321 | 'http://ppa.launchpad.net/' |
526 | 359 | 'smoser/cloud-init-test/ubuntu' | 322 | 'smoser/cloud-init-test/ubuntu' |
527 | @@ -369,7 +332,7 @@ | |||
528 | 369 | params = self._get_default_params() | 332 | params = self._get_default_params() |
529 | 370 | 333 | ||
530 | 371 | with mock.patch.object(util, 'subp') as mockobj: | 334 | with mock.patch.object(util, 'subp') as mockobj: |
532 | 372 | cc_apt_configure.add_sources([cfg], params) | 335 | cc_apt_configure.add_apt_sources([cfg], params) |
533 | 373 | 336 | ||
534 | 374 | mockobj.assert_called_with(('apt-key', 'add', '-'), 'fakekey 4321') | 337 | mockobj.assert_called_with(('apt-key', 'add', '-'), 'fakekey 4321') |
535 | 375 | 338 | ||
536 | @@ -384,9 +347,7 @@ | |||
537 | 384 | contents, flags=re.IGNORECASE)) | 347 | contents, flags=re.IGNORECASE)) |
538 | 385 | 348 | ||
539 | 386 | def test_apt_src_key(self): | 349 | def test_apt_src_key(self): |
543 | 387 | """test_apt_src_key | 350 | """Test specification of a source + key with filename being set""" |
541 | 388 | Test specification of a source + key with filename being set | ||
542 | 389 | """ | ||
544 | 390 | cfg = {'source': ('deb ' | 351 | cfg = {'source': ('deb ' |
545 | 391 | 'http://ppa.launchpad.net/' | 352 | 'http://ppa.launchpad.net/' |
546 | 392 | 'smoser/cloud-init-test/ubuntu' | 353 | 'smoser/cloud-init-test/ubuntu' |
547 | @@ -396,9 +357,7 @@ | |||
548 | 396 | self.apt_src_key(self.aptlistfile, cfg) | 357 | self.apt_src_key(self.aptlistfile, cfg) |
549 | 397 | 358 | ||
550 | 398 | def test_apt_src_key_nofn(self): | 359 | def test_apt_src_key_nofn(self): |
554 | 399 | """test_apt_src_key_nofn | 360 | """Test specification of a source + key without filename being set""" |
552 | 400 | Test specification of a source + key without filename being set | ||
553 | 401 | """ | ||
555 | 402 | cfg = {'source': ('deb ' | 361 | cfg = {'source': ('deb ' |
556 | 403 | 'http://ppa.launchpad.net/' | 362 | 'http://ppa.launchpad.net/' |
557 | 404 | 'smoser/cloud-init-test/ubuntu' | 363 | 'smoser/cloud-init-test/ubuntu' |
558 | @@ -408,15 +367,13 @@ | |||
559 | 408 | self.apt_src_key(self.fallbackfn, cfg) | 367 | self.apt_src_key(self.fallbackfn, cfg) |
560 | 409 | 368 | ||
561 | 410 | def test_apt_src_keyonly(self): | 369 | def test_apt_src_keyonly(self): |
565 | 411 | """test_apt_src_keyonly | 370 | """Test specifying key without source""" |
563 | 412 | Test specification key without source | ||
564 | 413 | """ | ||
566 | 414 | params = self._get_default_params() | 371 | params = self._get_default_params() |
567 | 415 | cfg = {'key': "fakekey 4242", | 372 | cfg = {'key': "fakekey 4242", |
568 | 416 | 'filename': self.aptlistfile} | 373 | 'filename': self.aptlistfile} |
569 | 417 | 374 | ||
570 | 418 | with mock.patch.object(util, 'subp') as mockobj: | 375 | with mock.patch.object(util, 'subp') as mockobj: |
572 | 419 | cc_apt_configure.add_sources([cfg], params) | 376 | cc_apt_configure.add_apt_sources([cfg], params) |
573 | 420 | 377 | ||
574 | 421 | mockobj.assert_called_once_with(('apt-key', 'add', '-'), | 378 | mockobj.assert_called_once_with(('apt-key', 'add', '-'), |
575 | 422 | 'fakekey 4242') | 379 | 'fakekey 4242') |
576 | @@ -425,66 +382,68 @@ | |||
577 | 425 | self.assertFalse(os.path.isfile(self.aptlistfile)) | 382 | self.assertFalse(os.path.isfile(self.aptlistfile)) |
578 | 426 | 383 | ||
579 | 427 | def test_apt_src_keyidonly(self): | 384 | def test_apt_src_keyidonly(self): |
583 | 428 | """test_apt_src_keyidonly | 385 | """Test specification of a keyid without source""" |
581 | 429 | Test specification of a keyid without source | ||
582 | 430 | """ | ||
584 | 431 | params = self._get_default_params() | 386 | params = self._get_default_params() |
585 | 432 | cfg = {'keyid': "03683F77", | 387 | cfg = {'keyid': "03683F77", |
586 | 433 | 'filename': self.aptlistfile} | 388 | 'filename': self.aptlistfile} |
587 | 434 | 389 | ||
588 | 435 | with mock.patch.object(util, 'subp', | 390 | with mock.patch.object(util, 'subp', |
589 | 436 | return_value=('fakekey 1212', '')) as mockobj: | 391 | return_value=('fakekey 1212', '')) as mockobj: |
591 | 437 | cc_apt_configure.add_sources([cfg], params) | 392 | cc_apt_configure.add_apt_sources([cfg], params) |
592 | 438 | 393 | ||
593 | 439 | mockobj.assert_called_with(('apt-key', 'add', '-'), 'fakekey 1212') | 394 | mockobj.assert_called_with(('apt-key', 'add', '-'), 'fakekey 1212') |
594 | 440 | 395 | ||
595 | 441 | # filename should be ignored on key only | 396 | # filename should be ignored on key only |
596 | 442 | self.assertFalse(os.path.isfile(self.aptlistfile)) | 397 | self.assertFalse(os.path.isfile(self.aptlistfile)) |
597 | 443 | 398 | ||
598 | 399 | def apt_src_keyid_real(self, cfg, expectedkey): | ||
599 | 400 | """apt_src_keyid_real | ||
600 | 401 | Test specification of a keyid without source including | ||
601 | 402 | up to addition of the key (add_apt_key_raw mocked to keep the | ||
602 | 403 | environment as is) | ||
603 | 404 | """ | ||
604 | 405 | params = self._get_default_params() | ||
605 | 406 | |||
606 | 407 | with mock.patch.object(cc_apt_configure, 'add_apt_key_raw') as mockkey: | ||
607 | 408 | with mock.patch.object(gpg, 'gpg_getkeybyid', | ||
608 | 409 | return_value=expectedkey) as mockgetkey: | ||
609 | 410 | cc_apt_configure.add_apt_sources([cfg], params) | ||
610 | 411 | |||
611 | 412 | mockgetkey.assert_called_with(cfg['keyid'], | ||
612 | 413 | cfg.get('keyserver', | ||
613 | 414 | 'keyserver.ubuntu.com')) | ||
614 | 415 | mockkey.assert_called_with(expectedkey) | ||
615 | 416 | |||
616 | 417 | # filename should be ignored on key only | ||
617 | 418 | self.assertFalse(os.path.isfile(self.aptlistfile)) | ||
618 | 419 | |||
619 | 444 | def test_apt_src_keyid_real(self): | 420 | def test_apt_src_keyid_real(self): |
624 | 445 | """test_apt_src_keyid_real | 421 | """test_apt_src_keyid_real - Test keyid including key add""" |
621 | 446 | Test specification of a keyid without source incl | ||
622 | 447 | up to addition of the key (add_key_raw, getkeybyid mocked) | ||
623 | 448 | """ | ||
625 | 449 | keyid = "03683F77" | 422 | keyid = "03683F77" |
626 | 450 | params = self._get_default_params() | ||
627 | 451 | cfg = {'keyid': keyid, | 423 | cfg = {'keyid': keyid, |
628 | 452 | 'filename': self.aptlistfile} | 424 | 'filename': self.aptlistfile} |
629 | 453 | 425 | ||
639 | 454 | with mock.patch.object(cc_apt_configure, 'add_key_raw') as mockobj: | 426 | self.apt_src_keyid_real(cfg, EXPECTEDKEY) |
631 | 455 | with mock.patch.object(cc_apt_configure, 'getkeybyid') as gkbi: | ||
632 | 456 | gkbi.return_value = EXPECTEDKEY | ||
633 | 457 | cc_apt_configure.add_sources([cfg], params) | ||
634 | 458 | |||
635 | 459 | mockobj.assert_called_with(EXPECTEDKEY) | ||
636 | 460 | |||
637 | 461 | # filename should be ignored on key only | ||
638 | 462 | self.assertFalse(os.path.isfile(self.aptlistfile)) | ||
640 | 463 | 427 | ||
641 | 464 | def test_apt_src_longkeyid_real(self): | 428 | def test_apt_src_longkeyid_real(self): |
660 | 465 | """test_apt_src_longkeyid_real | 429 | """test_apt_src_longkeyid_real - Test long keyid including key add""" |
661 | 466 | Test specification of a long key fingerprint without source incl | 430 | keyid = "B59D 5F15 97A5 04B7 E230 6DCA 0620 BBCF 0368 3F77" |
662 | 467 | up to addition of the key (nothing but add_key_raw mocked) | 431 | cfg = {'keyid': keyid, |
663 | 468 | """ | 432 | 'filename': self.aptlistfile} |
664 | 469 | keyid = "B59D 5F15 97A5 04B7 E230 6DCA 0620 BBCF 0368 3F77" | 433 | |
665 | 470 | params = self._get_default_params() | 434 | self.apt_src_keyid_real(cfg, EXPECTEDKEY) |
666 | 471 | cfg = {'keyid': keyid, | 435 | |
667 | 472 | 'filename': self.aptlistfile} | 436 | def test_apt_src_longkeyid_ks_real(self): |
668 | 473 | 437 | """test_apt_src_longkeyid_ks_real - Test long keyid from other ks""" | |
669 | 474 | with mock.patch.object(cc_apt_configure, 'add_key_raw') as mockobj: | 438 | keyid = "B59D 5F15 97A5 04B7 E230 6DCA 0620 BBCF 0368 3F77" |
670 | 475 | with mock.patch.object(cc_apt_configure, 'getkeybyid') as gkbi: | 439 | cfg = {'keyid': keyid, |
671 | 476 | gkbi.return_value = EXPECTEDKEY | 440 | 'keyserver': 'keys.gnupg.net', |
672 | 477 | cc_apt_configure.add_sources([cfg], params) | 441 | 'filename': self.aptlistfile} |
673 | 478 | 442 | ||
674 | 479 | mockobj.assert_called_with(EXPECTEDKEY) | 443 | self.apt_src_keyid_real(cfg, EXPECTEDKEY) |
657 | 480 | |||
658 | 481 | # filename should be ignored on key only | ||
659 | 482 | self.assertFalse(os.path.isfile(self.aptlistfile)) | ||
675 | 483 | 444 | ||
676 | 484 | def test_apt_src_ppa(self): | 445 | def test_apt_src_ppa(self): |
680 | 485 | """test_apt_src_ppa | 446 | """Test adding a ppa""" |
678 | 486 | Test specification of a ppa | ||
679 | 487 | """ | ||
681 | 488 | params = self._get_default_params() | 447 | params = self._get_default_params() |
682 | 489 | cfg = {'source': 'ppa:smoser/cloud-init-test', | 448 | cfg = {'source': 'ppa:smoser/cloud-init-test', |
683 | 490 | 'filename': self.aptlistfile} | 449 | 'filename': self.aptlistfile} |
684 | @@ -493,7 +452,8 @@ | |||
685 | 493 | matcher = re.compile(r'^[\w-]+:\w').search | 452 | matcher = re.compile(r'^[\w-]+:\w').search |
686 | 494 | 453 | ||
687 | 495 | with mock.patch.object(util, 'subp') as mockobj: | 454 | with mock.patch.object(util, 'subp') as mockobj: |
689 | 496 | cc_apt_configure.add_sources([cfg], params, aa_repo_match=matcher) | 455 | cc_apt_configure.add_apt_sources([cfg], params, |
690 | 456 | aa_repo_match=matcher) | ||
691 | 497 | mockobj.assert_called_once_with(['add-apt-repository', | 457 | mockobj.assert_called_once_with(['add-apt-repository', |
692 | 498 | 'ppa:smoser/cloud-init-test']) | 458 | 'ppa:smoser/cloud-init-test']) |
693 | 499 | 459 | ||
694 | @@ -501,9 +461,7 @@ | |||
695 | 501 | self.assertFalse(os.path.isfile(self.aptlistfile)) | 461 | self.assertFalse(os.path.isfile(self.aptlistfile)) |
696 | 502 | 462 | ||
697 | 503 | def test_apt_src_ppa_tri(self): | 463 | def test_apt_src_ppa_tri(self): |
701 | 504 | """test_apt_src_ppa_tri | 464 | """Test adding three ppa's""" |
699 | 505 | Test specification of a ppa | ||
700 | 506 | """ | ||
702 | 507 | params = self._get_default_params() | 465 | params = self._get_default_params() |
703 | 508 | cfg1 = {'source': 'ppa:smoser/cloud-init-test', | 466 | cfg1 = {'source': 'ppa:smoser/cloud-init-test', |
704 | 509 | 'filename': self.aptlistfile} | 467 | 'filename': self.aptlistfile} |
705 | @@ -516,8 +474,8 @@ | |||
706 | 516 | matcher = re.compile(r'^[\w-]+:\w').search | 474 | matcher = re.compile(r'^[\w-]+:\w').search |
707 | 517 | 475 | ||
708 | 518 | with mock.patch.object(util, 'subp') as mockobj: | 476 | with mock.patch.object(util, 'subp') as mockobj: |
711 | 519 | cc_apt_configure.add_sources([cfg1, cfg2, cfg3], params, | 477 | cc_apt_configure.add_apt_sources([cfg1, cfg2, cfg3], params, |
712 | 520 | aa_repo_match=matcher) | 478 | aa_repo_match=matcher) |
713 | 521 | calls = [call(['add-apt-repository', 'ppa:smoser/cloud-init-test']), | 479 | calls = [call(['add-apt-repository', 'ppa:smoser/cloud-init-test']), |
714 | 522 | call(['add-apt-repository', 'ppa:smoser/cloud-init-test2']), | 480 | call(['add-apt-repository', 'ppa:smoser/cloud-init-test2']), |
715 | 523 | call(['add-apt-repository', 'ppa:smoser/cloud-init-test3'])] | 481 | call(['add-apt-repository', 'ppa:smoser/cloud-init-test3'])] |
716 | @@ -529,10 +487,7 @@ | |||
717 | 529 | self.assertFalse(os.path.isfile(self.aptlistfile3)) | 487 | self.assertFalse(os.path.isfile(self.aptlistfile3)) |
718 | 530 | 488 | ||
719 | 531 | def test_convert_to_new_format(self): | 489 | def test_convert_to_new_format(self): |
724 | 532 | """test_convert_to_new_format | 490 | """Test the conversion of old to new format""" |
721 | 533 | Test the conversion of old to new format | ||
722 | 534 | And the noop conversion of new to new format as well | ||
723 | 535 | """ | ||
725 | 536 | cfg1 = {'source': 'deb $MIRROR $RELEASE multiverse', | 491 | cfg1 = {'source': 'deb $MIRROR $RELEASE multiverse', |
726 | 537 | 'filename': self.aptlistfile} | 492 | 'filename': self.aptlistfile} |
727 | 538 | cfg2 = {'source': 'deb $MIRROR $RELEASE main', | 493 | cfg2 = {'source': 'deb $MIRROR $RELEASE main', |
I hope it merges without conflict now