Fix volume type 'is_public' flag update

Update 'is_public' flag only if flag is passed as an argument
while updating volume type. With this change If 'is_public' flag
is not passed by the user, its value will not be updated and
only arguments passed to the update api will be updated.

Added code to check if none of the argument is passed to update
volume-type then it raises the CommandError exception with
appropriate error message.

Change-Id: Ice52e204ebea5d35f04455e74e16745a8bcce3d4
Closes-Bug: #1548708
This commit is contained in:
bhagyashris
2016-02-19 06:37:53 -08:00
committed by Sean McGinnis
parent 26b4f987d0
commit 08863124f7
4 changed files with 39 additions and 1 deletions

View File

@@ -770,6 +770,13 @@ class FakeHTTPClient(base_client.HTTPClient):
def put_types_1(self, **kw):
return self.get_types_1()
def put_types_3(self, **kw):
return (200, {}, {'volume_type': {'id': 3,
'name': 'test-type-2',
'description': 'test_type-3-desc',
'is_public': True,
'extra_specs': {}}})
#
# VolumeAccess
#

View File

@@ -744,6 +744,10 @@ class ShellTest(utils.TestCase):
'--description=test_type-1-desc '
'--is-public=invalid_bool 1')
def test_type_update_without_args(self):
self.assertRaises(exceptions.CommandError, self.run_command,
'type-update 1')
def test_type_access_list(self):
self.run_command('type-access-list --volume-type 3')
self.assert_called('GET', '/types/3/os-volume-type-access')

View File

@@ -67,6 +67,27 @@ class TypesTest(utils.TestCase):
self.assertIsInstance(t, volume_types.VolumeType)
self._assert_request_id(t)
def test_update_name(self):
"""Test volume_type update shell command
Verify that only name is updated and the description and
is_public properties remains unchanged.
"""
# create volume_type with is_public True
t = cs.volume_types.create('test-type-3', 'test_type-3-desc', True)
self.assertTrue(t.is_public)
# update name only
t1 = cs.volume_types.update(t.id, 'test-type-2')
cs.assert_called('PUT',
'/types/3',
{'volume_type': {'name': 'test-type-2',
'description': None}})
# verify that name is updated and the description
# and is_public are the same.
self.assertEqual('test-type-2', t1.name)
self.assertEqual('test_type-3-desc', t1.description)
self.assertTrue(t1.is_public)
def test_get(self):
t = cs.volume_types.get('1')
cs.assert_called('GET', '/types/1')

View File

@@ -1004,7 +1004,13 @@ def do_group_type_show(cs, args):
@utils.service_type('volumev3')
def do_type_update(cs, args):
"""Updates volume type name, description, and/or is_public."""
is_public = strutils.bool_from_string(args.is_public, strict=True)
is_public = args.is_public
if args.name is None and args.description is None and is_public is None:
raise exceptions.CommandError('Specify a new type name, description, '
'is_public or a combination thereof.')
if is_public is not None:
is_public = strutils.bool_from_string(args.is_public, strict=True)
vtype = cs.volume_types.update(args.id, args.name, args.description,
is_public)
_print_volume_type_list([vtype])