From f1abf30138fe7f97e7d7f2a7032778774a77deb7 Mon Sep 17 00:00:00 2001 From: Maari Tamm Date: Mon, 25 Jan 2021 19:15:55 +0000 Subject: [PATCH] [OSC] Add the option to explicitly set share status Implement the functionality of 'manila reset-state' command as 'openstack share set --status' Partially-implements bp openstack-client-support Change-Id: Ic8902272b81b7583df785b358d32c8e88609d93a --- manilaclient/osc/v2/share.py | 15 ++++++++ manilaclient/tests/unit/osc/v2/test_share.py | 38 +++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index eebf4a6fb..c06c7384e 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -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='', + 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 " diff --git a/manilaclient/tests/unit/osc/v2/test_share.py b/manilaclient/tests/unit/osc/v2/test_share.py index 32a08c270..f102e4046 100644 --- a/manilaclient/tests/unit/osc/v2/test_share.py +++ b/manilaclient/tests/unit/osc/v2/test_share.py @@ -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):