Merge "[OSC] Implement Share Migration show and add argument to Share Set Command"

This commit is contained in:
Zuul 2022-08-01 18:54:51 +00:00 committed by Gerrit Code Review
commit 23988df0b6
4 changed files with 100 additions and 5 deletions

View File

@ -74,6 +74,8 @@ share migration
.. autoprogram-cliff:: openstack.share.v2
:command: share migration complete
.. autoprogram-cliff:: openstack.share.v2
:command: share migration show
==============
share networks

View File

@ -731,6 +731,20 @@ class SetShare(command.Command):
'Examples include: available, error, creating, deleting, '
'error_deleting.')
)
parser.add_argument(
'--task-state',
metavar="<task-state>",
required=False,
default=None,
help=_("Indicate which task state to assign the share. Options "
"include migration_starting, migration_in_progress, "
"migration_completing, migration_success, migration_error, "
"migration_cancelled, migration_driver_in_progress, "
"migration_driver_phase1_done, data_copying_starting, "
"data_copying_in_progress, data_copying_completing, "
"data_copying_completed, data_copying_cancelled, "
"data_copying_error. ")
)
return parser
def take_action(self, parsed_args):
@ -771,6 +785,13 @@ class SetShare(command.Command):
LOG.error(_(
"Failed to set status for the share: %s"), e)
result += 1
if parsed_args.task_state:
try:
share_obj.reset_task_state(parsed_args.task_state)
except Exception as e:
LOG.error(_("Failed to update share task state"
"%s"), e)
result += 1
if result > 0:
raise exceptions.CommandError(_("One or more of the "
@ -1381,3 +1402,29 @@ class ShareMigrationComplete(command.Command):
share = apiutils.find_resource(share_client.shares,
parsed_args.share)
share.migration_complete()
class ShareMigrationShow(command.ShowOne):
"""Gets migration progress of a given share when copying
(Admin only, Experimental).
"""
_description = _("Gets migration progress of a given share when copying")
def get_parser(self, prog_name):
parser = super(ShareMigrationShow, self).get_parser(prog_name)
parser.add_argument(
'share',
metavar="<share>",
help=_('Name or ID of the share to get share migration progress '
'information.')
)
return parser
def take_action(self, parsed_args):
share_client = self.app.client_manager.share
share = apiutils.find_resource(share_client.shares,
parsed_args.share)
result = share.migration_get_progress()
return self.dict2columns(result[1])

View File

@ -1060,11 +1060,9 @@ class TestShareShow(TestShare):
("share", self._share.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
cliutils.convert_dict_list_to_string = mock.Mock()
cliutils.convert_dict_list_to_string.return_value = dict(
self._export_location)
columns, data = self.cmd.take_action(parsed_args)
self.shares_mock.get.assert_called_with(self._share.id)
@ -1083,7 +1081,7 @@ class TestShareSet(TestShare):
super(TestShareSet, self).setUp()
self._share = manila_fakes.FakeShare.create_one_share(
methods={"reset_state": None}
methods={"reset_state": None, "reset_task_state": None}
)
self.shares_mock.get.return_value = self._share
@ -1239,6 +1237,22 @@ class TestShareSet(TestShare):
self.assertRaises(
osc_exceptions.CommandError, self.cmd.take_action, parsed_args)
def test_share_set_task_state(self):
new_task_state = 'migration_starting'
arglist = [
self._share.id,
'--task-state', new_task_state
]
verifylist = [
('share', self._share.id),
('task_state', new_task_state)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self._share.reset_task_state.assert_called_with(new_task_state)
self.assertIsNone(result)
class TestShareUnset(TestShare):
@ -1827,7 +1841,6 @@ class TestShowShareProperties(TestShare):
}
)
self.shares_mock.get.return_value = self._share
self.shares_mock.get_metadata.return_value = self._share.metadata
# Get the command object to test
@ -1844,7 +1857,6 @@ class TestShowShareProperties(TestShare):
("share", self._share.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.shares_mock.get.assert_called_with(self._share.id)
self.shares_mock.get_metadata.assert_called_with(self._share)
@ -2054,3 +2066,36 @@ class TestShareMigrationComplete(TestShare):
result = self.cmd.take_action(parsed_args)
self._share.migration_complete.assert_called
self.assertIsNone(result)
class TestShareMigrationShow(TestShare):
def setUp(self):
super(TestShareMigrationShow, self).setUp()
self._share = manila_fakes.FakeShare.create_one_share(
attrs={
'status': 'available',
'task_state': 'migration_in_progress'},
methods={'migration_get_progress': ("<Response [200]>",
{'total_progress': 0, 'task_state':
'migration_in_progress',
'details': {}})
})
self.shares_mock.get.return_value = self._share
self.shares_mock.manage.return_value = self._share
# Get the command objects to test
self.cmd = osc_shares.ShareMigrationShow(self.app, None)
def test_migration_show(self):
arglist = [
self._share.id
]
verifylist = [
('share', self._share.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self._share.migration_get_progress.assert_called

View File

@ -47,6 +47,7 @@ openstack.share.v2 =
share_migration_start = manilaclient.osc.v2.share:ShareMigrationStart
share_migration_cancel = manilaclient.osc.v2.share:ShareMigrationCancel
share_migration_complete = manilaclient.osc.v2.share:ShareMigrationComplete
share_migration_show = manilaclient.osc.v2.share:ShareMigrationShow
share_export_location_show = manilaclient.osc.v2.share:ShareExportLocationShow
share_export_location_list = manilaclient.osc.v2.share:ShareExportLocationList
share_properties_show = manilaclient.osc.v2.share:ShowShareProperties