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
This commit is contained in:
esberglu 2018-05-16 19:11:46 -05:00
parent 7bdb7dbbdd
commit e23bed76e3
3 changed files with 10 additions and 13 deletions

View File

@ -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):

View File

@ -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,

View File

@ -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