diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py index 7798c2995..eeb444c5f 100644 --- a/cinderclient/tests/unit/v2/fakes.py +++ b/cinderclient/tests/unit/v2/fakes.py @@ -688,6 +688,12 @@ class FakeHTTPClient(base_client.HTTPClient): def delete_types_1(self, **kw): return (202, {}, None) + def delete_types_3_extra_specs_k(self, **kw): + return(204, {}, None) + + def delete_types_3(self, **kw): + return (202, {}, None) + def put_types_1(self, **kw): return self.get_types_1() diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 3364b71fc..fb8cda765 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -713,6 +713,15 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/types/3/action', body=expected) + def test_type_delete(self): + self.run_command('type-delete 1') + self.assert_called('DELETE', '/types/1') + + def test_type_delete_multiple(self): + self.run_command('type-delete 1 3') + self.assert_called_anytime('DELETE', '/types/1') + self.assert_called('DELETE', '/types/3') + def test_encryption_type_list(self): """ Test encryption-type-list shell command. diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index a854ec6eb..df5f1add3 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -937,13 +937,25 @@ def do_type_create(cs, args): _print_volume_type_list([vtype]) -@utils.arg('id', - metavar='<id>', - help='ID of volume type to delete.') +@utils.arg('vol_type', + metavar='<vol_type>', nargs='+', + help='Name or ID of volume type or types to delete.') @utils.service_type('volumev2') def do_type_delete(cs, args): - """Deletes a volume type.""" - cs.volume_types.delete(args.id) + """Deletes volume type or types.""" + failure_count = 0 + for vol_type in args.vol_type: + try: + vtype = _find_volume_type(cs, vol_type) + cs.volume_types.delete(vtype) + print("Request to delete volume type %s has been accepted." + % (vol_type)) + except Exception as e: + failure_count += 1 + print("Delete for volume type %s failed: %s" % (vol_type, e)) + if failure_count == len(args.vol_type): + raise exceptions.CommandError("Unable to delete any of the " + "specified types.") @utils.arg('vtype',