[OSC] Add the option to explicitly set share status
Implement the functionality of 'manila reset-state' command as 'openstack share set <share> --status' Partially-implements bp openstack-client-support Change-Id: Ic8902272b81b7583df785b358d32c8e88609d93a
This commit is contained in:
parent
4eec42711a
commit
f1abf30138
|
@ -615,6 +615,14 @@ class SetShare(command.Command):
|
|||
help=_('Level of visibility for share. '
|
||||
'Defines whether other tenants are able to see it or not. ')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--status',
|
||||
metavar='<status>',
|
||||
default=None,
|
||||
help=_('Explicitly update the status of a share (Admin only). '
|
||||
'Examples include: available, error, creating, deleting, '
|
||||
'error_deleting.')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
@ -648,6 +656,13 @@ class SetShare(command.Command):
|
|||
LOG.error(_("Failed to update share display name, visibility "
|
||||
"or display description: %s"), e)
|
||||
result += 1
|
||||
if parsed_args.status:
|
||||
try:
|
||||
share_obj.reset_state(parsed_args.status)
|
||||
except Exception as e:
|
||||
LOG.error(_(
|
||||
"Failed to set status for the share: %s"), e)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
raise exceptions.CommandError(_("One or more of the "
|
||||
|
|
|
@ -1050,7 +1050,9 @@ class TestShareSet(TestShare):
|
|||
def setUp(self):
|
||||
super(TestShareSet, self).setUp()
|
||||
|
||||
self._share = manila_fakes.FakeShare.create_one_share()
|
||||
self._share = manila_fakes.FakeShare.create_one_share(
|
||||
methods={"reset_state": None}
|
||||
)
|
||||
self.shares_mock.get.return_value = self._share
|
||||
|
||||
# Get the command object to test
|
||||
|
@ -1171,6 +1173,40 @@ class TestShareSet(TestShare):
|
|||
self.assertRaises(
|
||||
osc_exceptions.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
def test_share_set_status(self):
|
||||
new_status = 'available'
|
||||
arglist = [
|
||||
self._share.id,
|
||||
'--status', new_status
|
||||
]
|
||||
verifylist = [
|
||||
('share', self._share.id),
|
||||
('status', new_status)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self._share.reset_state.assert_called_with(new_status)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_share_set_status_exception(self):
|
||||
new_status = 'available'
|
||||
arglist = [
|
||||
self._share.id,
|
||||
'--status', new_status
|
||||
]
|
||||
verifylist = [
|
||||
('share', self._share.id),
|
||||
('status', new_status)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self._share.reset_state.side_effect = Exception()
|
||||
self.assertRaises(
|
||||
osc_exceptions.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
|
||||
class TestShareUnset(TestShare):
|
||||
|
||||
|
|
Loading…
Reference in New Issue