Merge "[OSC] Add the option to explicitly set share status"

This commit is contained in:
Zuul 2021-02-01 13:09:29 +00:00 committed by Gerrit Code Review
commit 8789a3c85c
2 changed files with 52 additions and 1 deletions

View File

@ -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 "

View File

@ -1051,7 +1051,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
@ -1172,6 +1174,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):