diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py index 3c9d02843..d2bcae4c0 100644 --- a/cinderclient/tests/unit/v2/fakes.py +++ b/cinderclient/tests/unit/v2/fakes.py @@ -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 # diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 7134a0b28..6226467a5 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -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') diff --git a/cinderclient/tests/unit/v2/test_types.py b/cinderclient/tests/unit/v2/test_types.py index 0a6fb8c45..0cb8981f4 100644 --- a/cinderclient/tests/unit/v2/test_types.py +++ b/cinderclient/tests/unit/v2/test_types.py @@ -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') diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 1b389799c..48ceee81d 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -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])