Fix upload_to_image method
Commit Ie639179c5bbbaca4de62b42b368830afcfd8f7ac introduced 'visibility' and 'protected' params. These params should be used only with v3.1 microversion. Also these changes break current v2 users. This patch fixes these issues. Closes-Bug: #1584056 Change-Id: I0574631791c475bbefdb6e7d1647a20d0759df64
This commit is contained in:
parent
0cdcfb5988
commit
9e19357e4b
@ -44,6 +44,11 @@ class TestCase(testtools.TestCase):
|
||||
self.assertTrue(hasattr(obj, 'request_ids'))
|
||||
self.assertEqual(REQUEST_ID, obj.request_ids)
|
||||
|
||||
def assert_called_anytime(self, method, url, body=None,
|
||||
partial_body=None):
|
||||
return self.shell.cs.assert_called_anytime(method, url, body,
|
||||
partial_body)
|
||||
|
||||
|
||||
class FixturedTestCase(TestCase):
|
||||
|
||||
|
@ -71,11 +71,6 @@ class ShellTest(utils.TestCase):
|
||||
return self.shell.cs.assert_called(method, url, body,
|
||||
partial_body, **kwargs)
|
||||
|
||||
def assert_called_anytime(self, method, url, body=None,
|
||||
partial_body=None):
|
||||
return self.shell.cs.assert_called_anytime(method, url, body,
|
||||
partial_body)
|
||||
|
||||
def test_list(self):
|
||||
self.run_command('list')
|
||||
# NOTE(jdg): we default to detail currently
|
||||
@ -359,9 +354,7 @@ class ShellTest(utils.TestCase):
|
||||
expected = {'os-volume_upload_image': {'force': False,
|
||||
'container_format': 'bare',
|
||||
'disk_format': 'raw',
|
||||
'image_name': 'test-image',
|
||||
'protected': False,
|
||||
'visibility': 'private'}}
|
||||
'image_name': 'test-image'}}
|
||||
self.run_command('upload-to-image 1234 test-image')
|
||||
self.assert_called_anytime('GET', '/volumes/1234')
|
||||
self.assert_called_anytime('POST', '/volumes/1234/action',
|
||||
@ -371,27 +364,12 @@ class ShellTest(utils.TestCase):
|
||||
expected = {'os-volume_upload_image': {'force': 'True',
|
||||
'container_format': 'bare',
|
||||
'disk_format': 'raw',
|
||||
'image_name': 'test-image',
|
||||
'protected': False,
|
||||
'visibility': 'private'}}
|
||||
'image_name': 'test-image'}}
|
||||
self.run_command('upload-to-image --force=True 1234 test-image')
|
||||
self.assert_called_anytime('GET', '/volumes/1234')
|
||||
self.assert_called_anytime('POST', '/volumes/1234/action',
|
||||
body=expected)
|
||||
|
||||
def test_upload_to_image_public_protected(self):
|
||||
expected = {'os-volume_upload_image': {'force': False,
|
||||
'container_format': 'bare',
|
||||
'disk_format': 'raw',
|
||||
'image_name': 'test-image',
|
||||
'protected': 'True',
|
||||
'visibility': 'public'}}
|
||||
self.run_command('upload-to-image --visibility=public '
|
||||
'--protected=True 1234 test-image')
|
||||
self.assert_called_anytime('GET', '/volumes/1234')
|
||||
self.assert_called_anytime('POST', '/volumes/1234/action',
|
||||
body=expected)
|
||||
|
||||
def test_create_size_required_if_not_snapshot_or_clone(self):
|
||||
self.assertRaises(SystemExit, self.run_command, 'create')
|
||||
|
||||
|
@ -68,3 +68,28 @@ class ShellTest(utils.TestCase):
|
||||
def test_list_availability_zone(self):
|
||||
self.run_command('availability-zone-list')
|
||||
self.assert_called('GET', '/os-availability-zone')
|
||||
|
||||
def test_upload_to_image(self):
|
||||
expected = {'os-volume_upload_image': {'force': False,
|
||||
'container_format': 'bare',
|
||||
'disk_format': 'raw',
|
||||
'image_name': 'test-image',
|
||||
'protected': False,
|
||||
'visibility': 'private'}}
|
||||
self.run_command('upload-to-image 1234 test-image')
|
||||
self.assert_called_anytime('GET', '/volumes/1234')
|
||||
self.assert_called_anytime('POST', '/volumes/1234/action',
|
||||
body=expected)
|
||||
|
||||
def test_upload_to_image_public_protected(self):
|
||||
expected = {'os-volume_upload_image': {'force': False,
|
||||
'container_format': 'bare',
|
||||
'disk_format': 'raw',
|
||||
'image_name': 'test-image',
|
||||
'protected': 'True',
|
||||
'visibility': 'public'}}
|
||||
self.run_command('upload-to-image --visibility=public '
|
||||
'--protected=True 1234 test-image')
|
||||
self.assert_called_anytime('GET', '/volumes/1234')
|
||||
self.assert_called_anytime('POST', '/volumes/1234/action',
|
||||
body=expected)
|
||||
|
@ -64,3 +64,46 @@ def _treeizeAvailabilityZone(zone):
|
||||
return result
|
||||
|
||||
|
||||
# TODO(e0ne): remove copy-paste of this function in a next cinderclient release
|
||||
def _print_volume_image(image):
|
||||
utils.print_dict(image[1]['os-volume_upload_image'])
|
||||
|
||||
|
||||
@utils.arg('volume',
|
||||
metavar='<volume>',
|
||||
help='Name or ID of volume to snapshot.')
|
||||
@utils.arg('--force',
|
||||
metavar='<True|False>',
|
||||
const=True,
|
||||
nargs='?',
|
||||
default=False,
|
||||
help='Enables or disables upload of '
|
||||
'a volume that is attached to an instance. '
|
||||
'Default=False.')
|
||||
@utils.arg('--container-format',
|
||||
metavar='<container-format>',
|
||||
default='bare',
|
||||
help='Container format type. '
|
||||
'Default is bare.')
|
||||
@utils.arg('--container_format',
|
||||
help=argparse.SUPPRESS)
|
||||
@utils.arg('--disk-format',
|
||||
metavar='<disk-format>',
|
||||
default='raw',
|
||||
help='Disk format type. '
|
||||
'Default is raw.')
|
||||
@utils.arg('--disk_format',
|
||||
help=argparse.SUPPRESS)
|
||||
@utils.arg('image_name',
|
||||
metavar='<image-name>',
|
||||
help='The new image name.')
|
||||
@utils.arg('--image_name',
|
||||
help=argparse.SUPPRESS)
|
||||
@utils.service_type('volumev2')
|
||||
def do_upload_to_image(cs, args):
|
||||
"""Uploads volume to Image Service as an image."""
|
||||
volume = utils.find_volume(cs, args.volume)
|
||||
_print_volume_image(volume.upload_to_image(args.force,
|
||||
args.image_name,
|
||||
args.container_format,
|
||||
args.disk_format))
|
||||
|
@ -15,5 +15,31 @@
|
||||
|
||||
"""Volume interface (v2 extension)."""
|
||||
|
||||
from cinderclient.v3.volumes import * # flake8: noqa
|
||||
from cinderclient import api_versions
|
||||
from cinderclient.v3 import volumes
|
||||
|
||||
|
||||
class Volume(volumes.Volume):
|
||||
def upload_to_image(self, force, image_name, container_format,
|
||||
disk_format):
|
||||
"""Upload a volume to image service as an image."""
|
||||
return self.manager.upload_to_image(self, force, image_name,
|
||||
container_format, disk_format)
|
||||
|
||||
|
||||
class VolumeManager(volumes.VolumeManager):
|
||||
resource_class = Volume
|
||||
|
||||
@api_versions.wraps("2.0")
|
||||
def upload_to_image(self, volume, force, image_name, container_format,
|
||||
disk_format):
|
||||
"""Upload volume to image service as image.
|
||||
|
||||
:param volume: The :class:`Volume` to upload.
|
||||
"""
|
||||
return self._action('os-volume_upload_image',
|
||||
volume,
|
||||
{'force': force,
|
||||
'image_name': image_name,
|
||||
'container_format': container_format,
|
||||
'disk_format': disk_format})
|
||||
|
@ -453,9 +453,9 @@ class VolumeManager(base.ManagerWithFind):
|
||||
"""
|
||||
return self._action("os-show_image_metadata", volume)
|
||||
|
||||
@api_versions.wraps("2.0", "3.0")
|
||||
@api_versions.wraps("3.0")
|
||||
def upload_to_image(self, volume, force, image_name, container_format,
|
||||
disk_format, visibility, protected):
|
||||
disk_format):
|
||||
"""Upload volume to image service as image.
|
||||
|
||||
:param volume: The :class:`Volume` to upload.
|
||||
|
Loading…
Reference in New Issue
Block a user