summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzwei <leidong@unitedstack.com>2016-03-08 18:08:26 +0800
committerzwei <leidong@unitedstack.com>2016-03-29 16:49:18 +0800
commitedd269aff79fdd048c9feeebd0bacfb582d42b1a (patch)
tree61338a4ff2bd2f8115aa896bc0d1a26892e4e666
parentfb175864f93e617da3ceb9d582ad2966e545991c (diff)
downloadpython-cinderclient-edd269aff79fdd048c9feeebd0bacfb582d42b1a.tar.gz
Fix api v2 so that you can delete more than one volume_type at a time.
This path is also allowing us to delete them by name or ID instead of only by ID. eg: cinder --os-volume-api-version 2 type-delete test01 test02 Closes-bug: #1554794 Change-Id: I54faad2c5b60ab69f4b406310eb8059cf1e8cf76
-rw-r--r--cinderclient/tests/unit/v2/fakes.py6
-rw-r--r--cinderclient/tests/unit/v2/test_shell.py9
-rw-r--r--cinderclient/v2/shell.py22
3 files changed, 32 insertions, 5 deletions
diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py
index 7798c29..eeb444c 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 3364b71..fb8cda7 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 a854ec6..df5f1ad 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',