Fix shares CLI for using CGs
For the moment, share can not be neither created with CG nor deleted if belongs to some CG. So, add experimental header to 'share create' operation to fix the former case and update 'delete share' operation to make it support deletion of shares that belongs to CG in general. Change-Id: I497a9ab845552fd7e0d66e7352d637c6a86082af Closes-Bug: #1496518 Closes-Bug: #1497215
This commit is contained in:
parent
4502d284c2
commit
0bbd2144f7
@ -431,6 +431,19 @@ class ShellTest(test_utils.TestCase):
|
|||||||
self.run_command('delete 1234')
|
self.run_command('delete 1234')
|
||||||
self.assert_called('DELETE', '/shares/1234')
|
self.assert_called('DELETE', '/shares/1234')
|
||||||
|
|
||||||
|
@ddt.data(
|
||||||
|
'--cg 1234', '--consistency-group 1234', '--consistency_group 1234')
|
||||||
|
@mock.patch.object(shell_v1, '_find_consistency_group', mock.Mock())
|
||||||
|
def test_delete_with_cg(self, cg_cmd):
|
||||||
|
fcg = type(
|
||||||
|
'FakeConsistencyGroup', (object,), {'id': cg_cmd.split()[-1]})
|
||||||
|
shell_v1._find_consistency_group.return_value = fcg
|
||||||
|
|
||||||
|
self.run_command('delete 1234 %s' % cg_cmd)
|
||||||
|
|
||||||
|
self.assert_called('DELETE', '/shares/1234?consistency_group_id=1234')
|
||||||
|
self.assertTrue(shell_v1._find_consistency_group.called)
|
||||||
|
|
||||||
def test_delete_not_found(self):
|
def test_delete_not_found(self):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.CommandError,
|
exceptions.CommandError,
|
||||||
|
@ -45,9 +45,9 @@ class Share(common_base.Resource):
|
|||||||
"""Migrate the share to a new host."""
|
"""Migrate the share to a new host."""
|
||||||
self.manager.migrate_share(self, host, force_host_copy)
|
self.manager.migrate_share(self, host, force_host_copy)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self, consistency_group_id=None):
|
||||||
"""Delete this share."""
|
"""Delete this share."""
|
||||||
self.manager.delete(self)
|
self.manager.delete(self, consistency_group_id=consistency_group_id)
|
||||||
|
|
||||||
def force_delete(self):
|
def force_delete(self):
|
||||||
"""Delete the specified share ignoring its current state."""
|
"""Delete the specified share ignoring its current state."""
|
||||||
@ -322,12 +322,17 @@ class ShareManager(base.ManagerWithFind):
|
|||||||
|
|
||||||
return self._list(path, 'shares')
|
return self._list(path, 'shares')
|
||||||
|
|
||||||
def delete(self, share):
|
def delete(self, share, consistency_group_id=None):
|
||||||
"""Delete a share.
|
"""Delete a share.
|
||||||
|
|
||||||
:param share: either share object or text with its ID.
|
:param share: either share object or text with its ID.
|
||||||
|
:param consistency_group_id: text - ID of the consistency group to
|
||||||
|
which the share belongs to.
|
||||||
"""
|
"""
|
||||||
self._delete("/shares/%s" % common_base.getid(share))
|
url = "/shares/%s" % common_base.getid(share)
|
||||||
|
if consistency_group_id:
|
||||||
|
url += "?consistency_group_id=%s" % consistency_group_id
|
||||||
|
self._delete(url)
|
||||||
|
|
||||||
def force_delete(self, share):
|
def force_delete(self, share):
|
||||||
"""Delete a share forcibly - share status will be avoided.
|
"""Delete a share forcibly - share status will be avoided.
|
||||||
|
@ -107,6 +107,7 @@ def _print_share_instance(cs, instance):
|
|||||||
cliutils.print_dict(info)
|
cliutils.print_dict(info)
|
||||||
|
|
||||||
|
|
||||||
|
@api_versions.experimental_api
|
||||||
def _find_consistency_group(cs, consistency_group):
|
def _find_consistency_group(cs, consistency_group):
|
||||||
"""Get a consistency group ID."""
|
"""Get a consistency group ID."""
|
||||||
return apiclient_utils.find_resource(cs.consistency_groups,
|
return apiclient_utils.find_resource(cs.consistency_groups,
|
||||||
@ -659,6 +660,16 @@ def do_unmanage(cs, args):
|
|||||||
metavar='<share>',
|
metavar='<share>',
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='Name or ID of the share(s).')
|
help='Name or ID of the share(s).')
|
||||||
|
@cliutils.arg(
|
||||||
|
'--consistency-group',
|
||||||
|
'--consistency_group',
|
||||||
|
'--cg',
|
||||||
|
metavar='<consistency-group>',
|
||||||
|
action='single_alias',
|
||||||
|
help='Optional consistency group name or ID which contains the share. '
|
||||||
|
'(Default=None)',
|
||||||
|
default=None)
|
||||||
|
@cliutils.service_type('sharev2')
|
||||||
def do_delete(cs, args):
|
def do_delete(cs, args):
|
||||||
"""Remove one or more shares."""
|
"""Remove one or more shares."""
|
||||||
failure_count = 0
|
failure_count = 0
|
||||||
@ -666,7 +677,12 @@ def do_delete(cs, args):
|
|||||||
for share in args.share:
|
for share in args.share:
|
||||||
try:
|
try:
|
||||||
share_ref = _find_share(cs, share)
|
share_ref = _find_share(cs, share)
|
||||||
share_ref.delete()
|
if args.consistency_group:
|
||||||
|
consistency_group_id = _find_consistency_group(
|
||||||
|
cs, args.consistency_group).id
|
||||||
|
share_ref.delete(consistency_group_id=consistency_group_id)
|
||||||
|
else:
|
||||||
|
share_ref.delete()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failure_count += 1
|
failure_count += 1
|
||||||
print("Delete for share %s failed: %s" % (share, e),
|
print("Delete for share %s failed: %s" % (share, e),
|
||||||
|
Loading…
Reference in New Issue
Block a user