From e23bed76e34cb00039a496690e7ad75568aaefb1 Mon Sep 17 00:00:00 2001 From: esberglu Date: Wed, 16 May 2018 19:11:46 -0500 Subject: [PATCH] PowerVM snapshot cleanup This patch cleans up some nits left after the merge of [1]. - Uses mock_open() in test_stream_blockdev_to_glance - Removes errant quote in InstanceDiskToMgmt() header - Fixes method header for generate_snapshot_metadata() [1] https://review.openstack.org/#/c/543023/ Change-Id: Iba75282db968f74ac2e4474c872ba59f9cd77652 --- nova/tests/unit/virt/powervm/test_image.py | 17 ++++++----------- nova/virt/powervm/image.py | 4 +++- nova/virt/powervm/tasks/storage.py | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/nova/tests/unit/virt/powervm/test_image.py b/nova/tests/unit/virt/powervm/test_image.py index 371edfb2b988..2004927f1669 100644 --- a/nova/tests/unit/virt/powervm/test_image.py +++ b/nova/tests/unit/virt/powervm/test_image.py @@ -21,25 +21,20 @@ from nova import test from nova.virt.powervm import image -if six.PY2: - _BUILTIN = '__builtin__' -else: - _BUILTIN = 'builtins' - class TestImage(test.TestCase): @mock.patch('nova.utils.temporary_chown', autospec=True) - @mock.patch(_BUILTIN + '.open', autospec=True) @mock.patch('nova.image.api.API', autospec=True) - def test_stream_blockdev_to_glance(self, mock_api, mock_open, mock_chown): - mock_open.return_value.__enter__.return_value = 'mock_stream' - image.stream_blockdev_to_glance('context', mock_api, 'image_id', - 'metadata', '/dev/disk') + def test_stream_blockdev_to_glance(self, mock_api, mock_chown): + mock_open = mock.mock_open() + with mock.patch.object(six.moves.builtins, 'open', new=mock_open): + image.stream_blockdev_to_glance('context', mock_api, 'image_id', + 'metadata', '/dev/disk') mock_chown.assert_called_with('/dev/disk') mock_open.assert_called_with('/dev/disk', 'rb') mock_api.update.assert_called_with('context', 'image_id', 'metadata', - 'mock_stream') + mock_open.return_value) @mock.patch('nova.image.api.API', autospec=True) def test_generate_snapshot_metadata(self, mock_api): diff --git a/nova/virt/powervm/image.py b/nova/virt/powervm/image.py index 929cec7b042a..1d8e497e85a4 100644 --- a/nova/virt/powervm/image.py +++ b/nova/virt/powervm/image.py @@ -43,9 +43,11 @@ def generate_snapshot_metadata(context, image_api, image_id, instance): :param image_api: Handle to the glance image API. :param image_id: UUID of the prepared glance image. :param instance: The Nova instance whose disk is to be snapshotted. - :return: A dict of metadata suitable for image_api.upload. + :return: A dict of metadata suitable for image_api.update. """ image = image_api.get(context, image_id) + + # TODO(esberglu): Update this to v2 metadata metadata = { 'name': image['name'], 'is_public': False, diff --git a/nova/virt/powervm/tasks/storage.py b/nova/virt/powervm/tasks/storage.py index 839046be5410..2638f19c3a10 100644 --- a/nova/virt/powervm/tasks/storage.py +++ b/nova/virt/powervm/tasks/storage.py @@ -212,7 +212,7 @@ class DeleteVOpt(task.Task): class InstanceDiskToMgmt(task.Task): - """The task to connect an instance's disk to the management partition." + """The task to connect an instance's disk to the management partition. This task will connect the instance's disk to the management partition and discover it. We do these two pieces together because their reversion