Merge ~racb/uvtool:python3 into uvtool:master

Proposed by Robie Basak
Status: Merged
Merged at revision: 803a19101ba135e427c2f04e91779ea84ba078c1
Proposed branch: ~racb/uvtool:python3
Merge into: uvtool:master
Diff against target: 467 lines (+90/-80)
8 files modified
bin/uvt-kvm (+2/-2)
bin/uvt-simplestreams-libvirt (+2/-2)
uvtool/libvirt/__init__.py (+2/-2)
uvtool/libvirt/kvm.py (+49/-40)
uvtool/libvirt/simplestreams.py (+15/-11)
uvtool/ssh.py (+6/-7)
uvtool/tests/test_kvm.py (+7/-8)
uvtool/tests/test_simplestreams.py (+7/-8)
Reviewer Review Type Date Requested Status
Christian Ehrhardt  Approve
Canonical Server Pending
Review via email: mp+372616@code.launchpad.net

Description of the change

Convert to Python 3.

To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote :

Current branch status:

It seems to work, ish.

There seems to be a problem in the libvirt Python binding in Eoan resulting in a generic SystemError instead of a libvirt.libvirtError which leads to misleading error messages, and difficulty in catching things.

Some debugging and experiments are still in the branch and need removing.

It all needs splitting into separate commits with individual explanations.

Revision history for this message
Robie Basak (racb) wrote :

Also the tests need fixing.

Revision history for this message
Robie Basak (racb) wrote :

I think this branch is now ready to review for merging into master.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

I only started to review, but already thanks for breaking these down into one commit per type of change :-)

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Clarification request on "Fix cloud-init userdata YAML unicode encoding" see inline comment.

review: Needs Information
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

env shebang (see inline comment) ?

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

I'm clearly no expert on copyright statements, but I think since you essentially touched everything I think many of the old 2014 statements should be bumped to 2014-2019 (!2014 as well of course).

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

I found a few nit picks and interesting questions on the proposed branch, but overall it LGTM and I approve. You can implement my feedback prior to the merge if you want, but it isn't a requirement.

review: Approve
Revision history for this message
Robie Basak (racb) wrote :

Thank you for the review!

> I'm clearly no expert on copyright statements, but I think since you essentially touched everything I think many of the old 2014 statements should be bumped to 2014-2019 (!2014 as well of course).

Agreed. I'll do that and one other item from inline responses.

Revision history for this message
Robie Basak (racb) :
Revision history for this message
Robie Basak (racb) wrote :
Download full text (6.9 KiB)

Force pushed the branch with review fixes. range-diff available at ..., also pasted below.

Two changes in the end:

1) Copyright messages.

2) Adjusted the bytes decode from subprocess.check_output to make it cleaner: doing it immediately, rather than after a splitlines(). Since this no longer expands the generator, I added to the commit that handles this to ensure the generator is expanded before YAML encoding. It seems more Python to me to expand generators later, closer to the YAML encoding itself, since the rest of the time an unexpanded generator is perfectly acceptable whenever a sequence is expected.

range-diff:

1: 1e67e4b ! 1: 6f40d41 Fix error handlers
    @@ -13,6 +13,15 @@
      --- a/uvtool/libvirt/kvm.py
      +++ b/uvtool/libvirt/kvm.py
     @@
    +
    + # Wrapper around cloud-localds and libvirt
    +
    +-# Copyright (C) 2012-3 Canonical Ltd.
    ++# Copyright (C) 2012-9 Canonical Ltd.
    + # Author: Robie Basak <email address hidden>
    + #
    + # This program is free software: you can redistribute it and/or modify
    +@@
      def main(args):
          # Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1063766
          # (LP: #1228231)
    @@ -27,6 +36,15 @@
      --- a/uvtool/libvirt/simplestreams.py
      +++ b/uvtool/libvirt/simplestreams.py
     @@
    +
    + # Keep Ubuntu Cloud images synced to a local libvirt storage pool.
    +
    +-# Copyright (C) 2013 Canonical Ltd.
    ++# Copyright (C) 2013-9 Canonical Ltd.
    + # Author: Robie Basak <email address hidden>
    + #
    + # This program is free software: you can redistribute it and/or modify
    +@@
      def main(argv=None):
          # Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1063766
          # (LP: #1228231)
 2: 41537b3 ! 2: 201a392 mock -> unittest.mock
    @@ -8,6 +8,12 @@
      diff --git a/uvtool/tests/test_kvm.py b/uvtool/tests/test_kvm.py
      --- a/uvtool/tests/test_kvm.py
      +++ b/uvtool/tests/test_kvm.py
    +@@
    +-# Copyright (C) 2014 Canonical Ltd.
    ++# Copyright (C) 2014-9 Canonical Ltd.
    + # Author: Robie Basak <email address hidden>
    + #
    + # This program is free software: you can redistribute it and/or modify
     @@
      # along with this program. If not, see <http://www.gnu.org/licenses/>.

    @@ -46,6 +52,12 @@
      diff --git a/uvtool/tests/test_simplestreams.py b/uvtool/tests/test_simplestreams.py
      --- a/uvtool/tests/test_simplestreams.py
      +++ b/uvtool/tests/test_simplestreams.py
    +@@
    +-# Copyright (C) 2014 Canonical Ltd.
    ++# Copyright (C) 2014-9 Canonical Ltd.
    + # Author: Robie Basak <email address hidden>
    + #
    + # This program is free software: you can redistribute it and/or modify
     @@
      # along with this program. If not, see <http://www.gnu.org/licenses/>.

 3: b3b08ce ! 3: ed5a131 lxml encoding into strings instead of bytes
    @@ -8,6 +8,12 @@
      diff --git a/uvtool/libvirt/__init__.py b/uvtool/libvirt/__init__.py
      --- a/uvtool/libvirt/__init__.py
      +++ b/uvtool/libvirt/__init__.py
    +@@
    +-# Copyright (C) 2013 Canonical Ltd.
    ++# Copyright (C) 2013-9 Canonical Ltd.
   ...

Read more...

Revision history for this message
Robie Basak (racb) wrote :

Pasting the range-diff makes a mess. It's also https://paste.ubuntu.com/p/P5yrkY2qSZ/ and I won't do that in future.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Thank you, LGTM now (it was good before, but now even better) :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/uvt-kvm b/bin/uvt-kvm
2index c96c50d..282e866 100755
3--- a/bin/uvt-kvm
4+++ b/bin/uvt-kvm
5@@ -1,8 +1,8 @@
6-#!/usr/bin/python
7+#!/usr/bin/python3
8
9 # Wrapper around cloud-localds and libvirt
10
11-# Copyright (C) 2012-3 Canonical Ltd.
12+# Copyright (C) 2012-9 Canonical Ltd.
13 # Author: Robie Basak <robie.basak@canonical.com>
14 #
15 # This program is free software: you can redistribute it and/or modify
16diff --git a/bin/uvt-simplestreams-libvirt b/bin/uvt-simplestreams-libvirt
17index 7693b02..b220da2 100755
18--- a/bin/uvt-simplestreams-libvirt
19+++ b/bin/uvt-simplestreams-libvirt
20@@ -1,8 +1,8 @@
21-#!/usr/bin/python
22+#!/usr/bin/python3
23
24 # Keep Ubuntu Cloud images synced to a local libvirt storage pool.
25
26-# Copyright (C) 2013 Canonical Ltd.
27+# Copyright (C) 2013-9 Canonical Ltd.
28 # Author: Robie Basak <robie.basak@canonical.com>
29 #
30 # This program is free software: you can redistribute it and/or modify
31diff --git a/uvtool/libvirt/__init__.py b/uvtool/libvirt/__init__.py
32index 2cd950c..3988e24 100644
33--- a/uvtool/libvirt/__init__.py
34+++ b/uvtool/libvirt/__init__.py
35@@ -1,4 +1,4 @@
36-# Copyright (C) 2013 Canonical Ltd.
37+# Copyright (C) 2013-9 Canonical Ltd.
38 # Author: Robie Basak <robie.basak@canonical.com>
39 #
40 # This program is free software: you can redistribute it and/or modify
41@@ -91,7 +91,7 @@ def _create_volume_from_fobj_with_size(new_volume_name, fobj, fobj_size,
42 E.target(E.format(type=image_type)),
43 *extra
44 )
45- vol = pool.createXML(etree.tostring(new_vol), 0)
46+ vol = pool.createXML(etree.tostring(new_vol, encoding=str), 0)
47
48 try:
49 stream = conn.newStream(0)
50diff --git a/uvtool/libvirt/kvm.py b/uvtool/libvirt/kvm.py
51index 705e068..c5b10d7 100755
52--- a/uvtool/libvirt/kvm.py
53+++ b/uvtool/libvirt/kvm.py
54@@ -1,8 +1,8 @@
55-#!/usr/bin/python
56+#!/usr/bin/python3
57
58 # Wrapper around cloud-localds and libvirt
59
60-# Copyright (C) 2012-3 Canonical Ltd.
61+# Copyright (C) 2012-9 Canonical Ltd.
62 # Author: Robie Basak <robie.basak@canonical.com>
63 #
64 # This program is free software: you can redistribute it and/or modify
65@@ -23,15 +23,16 @@ from __future__ import print_function
66 from __future__ import unicode_literals
67
68 import argparse
69+import base64
70 import errno
71 import functools
72+import io
73 import itertools
74 import os
75 import platform
76 import shutil
77 import signal
78 import string
79-import StringIO
80 import subprocess
81 import sys
82 import tempfile
83@@ -92,19 +93,19 @@ def subprocess_setup():
84 def run_script_once_arg_to_config(arg, unique_id):
85 with open(arg, 'rb') as f:
86 script = f.read()
87- encoded_script = script.encode('base64')
88+ encoded_script = base64.b64encode(script).decode('ascii')
89 return [
90- b'cloud-init-per',
91- b'once',
92- unique_id.encode('utf-8'),
93- b'sh', b'-c',
94+ 'cloud-init-per',
95+ 'once',
96+ unique_id,
97+ 'sh', '-c',
98 (
99- b'f=$(mktemp --tmpdir %s-XXXXXXXXXX) && ' +
100- b'echo "%s" | base64 -d > "$f" && ' +
101- b'chmod 700 "$f" && ' +
102- b'"$f" && ' +
103- b'rm "$f"'
104- ) % (unique_id.encode('utf-8'), encoded_script)
105+ 'f=$(mktemp --tmpdir %s-XXXXXXXXXX) && ' +
106+ 'echo "%s" | base64 -d > "$f" && ' +
107+ 'chmod 700 "$f" && ' +
108+ '"$f" && ' +
109+ 'rm "$f"'
110+ ) % (unique_id, encoded_script)
111 ]
112
113
114@@ -122,7 +123,7 @@ def get_ssh_agent_public_keys():
115 output = subprocess.check_output(
116 ['ssh-add', '-L'],
117 stderr=fpnull
118- )
119+ ).decode()
120 except subprocess.CalledProcessError:
121 return None
122
123@@ -140,7 +141,7 @@ def read_ssh_public_key_file(filename):
124 filename = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa.pub')
125
126 try:
127- f = open(filename, 'rb')
128+ f = open(filename, 'r')
129 except IOError as e:
130 if e.errno != errno.ENOENT:
131 raise
132@@ -178,43 +179,44 @@ def create_default_user_data(fobj, args, ssh_host_keys=None):
133
134 """
135
136- ssh_authorized_keys = get_ssh_authorized_keys(args.ssh_public_key_file)
137+ ssh_authorized_keys = list(
138+ get_ssh_authorized_keys(args.ssh_public_key_file),
139+ )
140
141 data = {
142- b'hostname': args.hostname.encode('ascii'),
143- b'manage_etc_hosts': b'localhost',
144- b'ssh_keys': uvtool.ssh.generate_ssh_host_keys()[0],
145+ 'hostname': args.hostname,
146+ 'manage_etc_hosts': 'localhost',
147+ 'ssh_keys': uvtool.ssh.generate_ssh_host_keys()[0],
148 }
149
150 if ssh_host_keys:
151- data[b'ssh_keys'] = ssh_host_keys
152+ data['ssh_keys'] = ssh_host_keys
153
154 if ssh_authorized_keys:
155- data[b'ssh_authorized_keys'] = ssh_authorized_keys
156+ data['ssh_authorized_keys'] = ssh_authorized_keys
157
158 if args.password:
159- data[b'password'] = args.password.encode('utf-8')
160- data[b'chpasswd'] = {b'expire': False}
161- data[b'ssh_pwauth'] = True
162+ data['password'] = args.password
163+ data['chpasswd'] = {'expire': False}
164+ data['ssh_pwauth'] = True
165
166 if args.run_script_once:
167- data[b'runcmd'] = run_script_once_args_to_config(args.run_script_once)
168+ data['runcmd'] = run_script_once_args_to_config(args.run_script_once)
169
170 if args.packages:
171- data[b'packages'] = [
172- s.encode('ascii') # Debian Policy dictates a-z,0-9,+,-,.
173- for s in itertools.chain(*[p.split(',') for p in args.packages])
174- ]
175+ data['packages'] = list(
176+ itertools.chain(*[p.split(',') for p in args.packages])
177+ )
178
179- fobj.write("#cloud-config\n")
180- fobj.write(yaml.dump(data))
181+ fobj.write(b"#cloud-config\n")
182+ fobj.write(yaml.dump(data).encode())
183
184
185 def create_default_meta_data(fobj, args):
186 data = {
187- b'instance-id': str(uuid.uuid1()).encode('ascii'),
188+ 'instance-id': str(uuid.uuid1()),
189 }
190- fobj.write(yaml.dump(data))
191+ fobj.write(yaml.dump(data).encode())
192
193
194 def create_ds_image(
195@@ -325,7 +327,7 @@ def create_cow_volume_by_path(backing_volume_path, new_volume_name,
196 E.format(type='qcow2'),
197 )
198 )
199- return pool.createXML(etree.tostring(new_vol), 0)
200+ return pool.createXML(etree.tostring(new_vol, encoding=str), 0)
201
202
203 def compose_domain_xml(name, volumes, template_path, cpu=1, memory=512,
204@@ -435,7 +437,7 @@ def compose_domain_xml(name, volumes, template_path, cpu=1, memory=512,
205 )
206 metadata.append(EX.ssh_known_hosts(ssh_known_hosts))
207
208- return etree.tostring(tree)
209+ return etree.tostring(tree, encoding=str)
210
211
212 def get_base_image(filters):
213@@ -579,7 +581,7 @@ def destroy(hostname):
214
215 def get_lts_series():
216 output = subprocess.check_output(['distro-info', '--lts'], close_fds=True)
217- return output.strip()
218+ return output.strip().decode()
219
220
221 def apply_default_fobj(args, key, create_default_data_fn):
222@@ -597,7 +599,7 @@ def apply_default_fobj(args, key, create_default_data_fn):
223 if specified_fobj:
224 return specified_fobj
225 else:
226- default_fobj = StringIO.StringIO()
227+ default_fobj = io.BytesIO()
228 create_default_data_fn(default_fobj, args)
229 default_fobj.seek(0)
230 return default_fobj
231@@ -652,6 +654,7 @@ def ssh(name, login_name, arguments, stdin=None, checked=False, sysexit=True,
232 )
233 if ssh_known_hosts:
234 ssh_known_hosts_file = tempfile.NamedTemporaryFile(
235+ mode='w',
236 prefix='uvt-kvm.known_hoststmp')
237 objects_to_close.append(ssh_known_hosts_file)
238 ssh_known_hosts_file.write(ssh_known_hosts)
239@@ -864,10 +867,16 @@ class DeveloperOptionAction(argparse.Action):
240 def main(args):
241 # Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1063766
242 # (LP: #1228231)
243- libvirt.registerErrorHandler(lambda _: None, None)
244+ def noop(*args, **kwargs): pass
245+ libvirt.registerErrorHandler(noop, None)
246
247 parser = argparse.ArgumentParser()
248- subparsers = parser.add_subparsers()
249+ # Workarounds needed here: set dest and required
250+ # https://bugs.python.org/issue9253#msg181855
251+ # https://stackoverflow.com/q/22990977/478206
252+ # https://stackoverflow.com/a/23354355/478206
253+ subparsers = parser.add_subparsers(dest='subcommand')
254+ subparsers.required = True
255 create_subparser = subparsers.add_parser('create')
256 create_subparser.set_defaults(func=main_create)
257 create_subparser.add_argument(
258diff --git a/uvtool/libvirt/simplestreams.py b/uvtool/libvirt/simplestreams.py
259index 7b24dff..d4cb8bc 100755
260--- a/uvtool/libvirt/simplestreams.py
261+++ b/uvtool/libvirt/simplestreams.py
262@@ -1,8 +1,8 @@
263-#!/usr/bin/python
264+#!/usr/bin/python3
265
266 # Keep Ubuntu Cloud images synced to a local libvirt storage pool.
267
268-# Copyright (C) 2013 Canonical Ltd.
269+# Copyright (C) 2013-9 Canonical Ltd.
270 # Author: Robie Basak <robie.basak@canonical.com>
271 #
272 # This program is free software: you can redistribute it and/or modify
273@@ -107,7 +107,7 @@ BASE64_PREFIX = 'x-uvt-b64-'
274 def _encode_libvirt_pool_name(product_name, version_name):
275 return BASE64_PREFIX + base64.b64encode(
276 (' '.join([product_name, version_name])).encode(), b'-_'
277- )
278+ ).decode()
279
280
281 def _decode_libvirt_pool_name(encoded_pool_name):
282@@ -119,7 +119,7 @@ def _decode_libvirt_pool_name(encoded_pool_name):
283 return base64.b64decode(
284 encoded_pool_name[len(BASE64_PREFIX):],
285 altchars=b'-_'
286- ).split(None, 1)
287+ ).decode().split(None, 1)
288
289
290 def purge_pool(conn=None):
291@@ -164,16 +164,14 @@ def _load_products(path=None, content_id=None, clean=False):
292 def new_product():
293 return {'versions': {}}
294 products = collections.defaultdict(new_product)
295- for encoded_libvirt_name_string, metadata in pool_metadata.items():
296- encoded_libvirt_name_bytes = encoded_libvirt_name_string.encode(
297- 'utf-8')
298+ for encoded_libvirt_name_string, metadata in list(pool_metadata.items()):
299 if not uvtool.libvirt.have_volume_by_name(
300- encoded_libvirt_name_bytes, pool_name=LIBVIRT_POOL_NAME):
301+ encoded_libvirt_name_string, pool_name=LIBVIRT_POOL_NAME):
302 if clean:
303 del pool_metadata[encoded_libvirt_name_string]
304 continue
305 product, version = _decode_libvirt_pool_name(
306- encoded_libvirt_name_bytes)
307+ encoded_libvirt_name_string)
308 assert(product == metadata['product_name'])
309 assert(version == metadata['version_name'])
310 products[product]['versions'][version] = {
311@@ -292,13 +290,19 @@ def main_purge(args):
312 def main(argv=None):
313 # Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1063766
314 # (LP: #1228231)
315- libvirt.registerErrorHandler(lambda _: None, None)
316+ def noop(*args, **kwargs): pass
317+ libvirt.registerErrorHandler(noop, None)
318
319 system_arch = subprocess.check_output(
320 ['dpkg', '--print-architecture']).decode().strip()
321 parser = argparse.ArgumentParser()
322 parser.add_argument('--verbose', '-v', action='store_true')
323- subparsers = parser.add_subparsers()
324+ # Workarounds needed here: set dest and required
325+ # https://bugs.python.org/issue9253#msg181855
326+ # https://stackoverflow.com/q/22990977/478206
327+ # https://stackoverflow.com/a/23354355/478206
328+ subparsers = parser.add_subparsers(dest='subcommand')
329+ subparsers.required = True
330
331 sync_subparser = subparsers.add_parser('sync')
332 sync_subparser.set_defaults(func=main_sync)
333diff --git a/uvtool/ssh.py b/uvtool/ssh.py
334index bb6b6d4..0516603 100644
335--- a/uvtool/ssh.py
336+++ b/uvtool/ssh.py
337@@ -1,6 +1,6 @@
338-#!/usr/bin/python
339+#!/usr/bin/python3
340
341-# Copyright (C) 2014 Canonical Ltd.
342+# Copyright (C) 2014-9 Canonical Ltd.
343 # Author: Robie Basak <robie.basak@canonical.com>
344 #
345 # This program is free software: you can redistribute it and/or modify
346@@ -36,7 +36,7 @@ def _keygen(key_type, private_path):
347
348
349 def read_file(path):
350- with open(path, 'rb') as f:
351+ with open(path, 'r') as f:
352 return f.read()
353
354
355@@ -52,9 +52,8 @@ def generate_ssh_host_keys():
356 # ssh-keygen(1) defines that ".pub" is appended
357 public_path = private_path + ".pub"
358
359- key_type_utf8 = key_type.encode('utf-8')
360- private_ci_key = key_type_utf8 + b'_private'
361- public_ci_key = key_type_utf8 + b'_public'
362+ private_ci_key = key_type + '_private'
363+ public_ci_key = key_type + '_public'
364
365 private_key = read_file(private_path)
366 public_key = read_file(public_path)
367@@ -66,4 +65,4 @@ def generate_ssh_host_keys():
368 finally:
369 shutil.rmtree(tmp_dir)
370
371- return cloud_init_result, b''.join(known_hosts_result)
372+ return cloud_init_result, ''.join(known_hosts_result)
373diff --git a/uvtool/tests/test_kvm.py b/uvtool/tests/test_kvm.py
374index 7a96ebf..13d7da6 100644
375--- a/uvtool/tests/test_kvm.py
376+++ b/uvtool/tests/test_kvm.py
377@@ -1,4 +1,4 @@
378-# Copyright (C) 2014 Canonical Ltd.
379+# Copyright (C) 2014-9 Canonical Ltd.
380 # Author: Robie Basak <robie.basak@canonical.com>
381 #
382 # This program is free software: you can redistribute it and/or modify
383@@ -15,8 +15,7 @@
384 # along with this program. If not, see <http://www.gnu.org/licenses/>.
385
386 import unittest
387-
388-import mock
389+import unittest.mock
390
391 from uvtool.libvirt.kvm import main_ssh
392
393@@ -25,18 +24,18 @@ class TestKVM(unittest.TestCase):
394 def check_ssh(self, args_hostname, args_login_name, expected_hostname,
395 expected_login_name):
396
397- parser = mock.Mock()
398- args = mock.Mock()
399+ parser = unittest.mock.Mock()
400+ args = unittest.mock.Mock()
401 args.login_name = args_login_name
402 args.name = args_hostname
403- args.ssh_arguments = mock.sentinel.ssh_arguments
404+ args.ssh_arguments = unittest.mock.sentinel.ssh_arguments
405 args.insecure = True
406- with mock.patch('uvtool.libvirt.kvm.ssh') as ssh_mock:
407+ with unittest.mock.patch('uvtool.libvirt.kvm.ssh') as ssh_mock:
408 main_ssh(parser, args)
409 ssh_mock.assert_called_with(
410 expected_hostname,
411 expected_login_name,
412- mock.sentinel.ssh_arguments,
413+ unittest.mock.sentinel.ssh_arguments,
414 insecure=True,
415 )
416
417diff --git a/uvtool/tests/test_simplestreams.py b/uvtool/tests/test_simplestreams.py
418index 211454d..883391e 100644
419--- a/uvtool/tests/test_simplestreams.py
420+++ b/uvtool/tests/test_simplestreams.py
421@@ -1,4 +1,4 @@
422-# Copyright (C) 2014 Canonical Ltd.
423+# Copyright (C) 2014-9 Canonical Ltd.
424 # Author: Robie Basak <robie.basak@canonical.com>
425 #
426 # This program is free software: you can redistribute it and/or modify
427@@ -15,8 +15,7 @@
428 # along with this program. If not, see <http://www.gnu.org/licenses/>.
429
430 import unittest
431-
432-import mock
433+import unittest.mock
434
435 import uvtool.libvirt.simplestreams as simplestreams
436
437@@ -28,7 +27,7 @@ import uvtool.libvirt.simplestreams as simplestreams
438 # NormalizedVersion as described in PEP-0386. As this is a temporary hack
439 # anyway, this will do for now, since we know that the mock version on Ubuntu
440 # Precise will never change.
441-ON_PRECISE = mock.__version__ == '0.7.2'
442+ON_PRECISE = unittest.mock.__version__ == '0.7.2'
443
444 FAKE_VOLUME_PRODUCT_NAME = 'com.ubuntu.cloud:server:12.04:amd64'
445 FAKE_VOLUME_VERSION_0 = '20131119'
446@@ -39,9 +38,9 @@ ENCODED_FAKE_VOLUME_PRODUCT_NAME_1 = simplestreams._encode_libvirt_pool_name(
447 FAKE_VOLUME_PRODUCT_NAME, FAKE_VOLUME_VERSION_1)
448
449 @unittest.skipIf(ON_PRECISE, 'mock version is too old')
450-@mock.patch('uvtool.libvirt.simplestreams.uvtool.libvirt')
451-@mock.patch('uvtool.libvirt.simplestreams.pool_metadata', new={})
452-@mock.patch('uvtool.libvirt.simplestreams.libvirt')
453+@unittest.mock.patch('uvtool.libvirt.simplestreams.uvtool.libvirt')
454+@unittest.mock.patch('uvtool.libvirt.simplestreams.pool_metadata', new={})
455+@unittest.mock.patch('uvtool.libvirt.simplestreams.libvirt')
456 class TestSimpleStreams(unittest.TestCase):
457 def testSync(self, libvirt, uvtool_libvirt):
458 uvtool_libvirt.have_volume_by_name.return_value = False
459@@ -61,7 +60,7 @@ class TestSimpleStreams(unittest.TestCase):
460 # least once by uvtool.libvirt.simplestreams directly. This is more of
461 # an assertion about the test being correct than part of the test
462 # itself.
463- libvirt.assert_has_calls([mock.call.open(u'qemu:///system')])
464+ libvirt.assert_has_calls([unittest.mock.call.open(u'qemu:///system')])
465
466 # create_volume_from_fobj should have been called exactly once to
467 # create the volume with the name that we expect

Subscribers

People subscribed via source and target branches