[OSC] Implement Share Migration show and add argument to Share Set Command
This commit adds 'openstack share migration show' and add argument '--task-state' to 'openstack share set' command, that implement the same functionality as 'manila migration-get-progress'and manila reset-task-state command. Partially-implements: bp openstack-client-support Change-Id: I288661b4294561a1a52411a0cb0fdfd1f82021ed
This commit is contained in:
parent
4951255876
commit
8fedd08b27
@ -74,6 +74,8 @@ share migration
|
|||||||
.. autoprogram-cliff:: openstack.share.v2
|
.. autoprogram-cliff:: openstack.share.v2
|
||||||
:command: share migration complete
|
:command: share migration complete
|
||||||
|
|
||||||
|
.. autoprogram-cliff:: openstack.share.v2
|
||||||
|
:command: share migration show
|
||||||
|
|
||||||
==============
|
==============
|
||||||
share networks
|
share networks
|
||||||
|
@ -704,6 +704,20 @@ class SetShare(command.Command):
|
|||||||
'Examples include: available, error, creating, deleting, '
|
'Examples include: available, error, creating, deleting, '
|
||||||
'error_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
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -744,6 +758,13 @@ class SetShare(command.Command):
|
|||||||
LOG.error(_(
|
LOG.error(_(
|
||||||
"Failed to set status for the share: %s"), e)
|
"Failed to set status for the share: %s"), e)
|
||||||
result += 1
|
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:
|
if result > 0:
|
||||||
raise exceptions.CommandError(_("One or more of the "
|
raise exceptions.CommandError(_("One or more of the "
|
||||||
@ -1340,3 +1361,29 @@ class ShareMigrationComplete(command.Command):
|
|||||||
share = apiutils.find_resource(share_client.shares,
|
share = apiutils.find_resource(share_client.shares,
|
||||||
parsed_args.share)
|
parsed_args.share)
|
||||||
share.migration_complete()
|
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])
|
||||||
|
@ -996,11 +996,9 @@ class TestShareShow(TestShare):
|
|||||||
("share", self._share.id)
|
("share", self._share.id)
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
cliutils.convert_dict_list_to_string = mock.Mock()
|
cliutils.convert_dict_list_to_string = mock.Mock()
|
||||||
cliutils.convert_dict_list_to_string.return_value = dict(
|
cliutils.convert_dict_list_to_string.return_value = dict(
|
||||||
self._export_location)
|
self._export_location)
|
||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.shares_mock.get.assert_called_with(self._share.id)
|
self.shares_mock.get.assert_called_with(self._share.id)
|
||||||
|
|
||||||
@ -1019,7 +1017,7 @@ class TestShareSet(TestShare):
|
|||||||
super(TestShareSet, self).setUp()
|
super(TestShareSet, self).setUp()
|
||||||
|
|
||||||
self._share = manila_fakes.FakeShare.create_one_share(
|
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
|
self.shares_mock.get.return_value = self._share
|
||||||
|
|
||||||
@ -1175,6 +1173,22 @@ class TestShareSet(TestShare):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
osc_exceptions.CommandError, self.cmd.take_action, parsed_args)
|
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):
|
class TestShareUnset(TestShare):
|
||||||
|
|
||||||
@ -1763,7 +1777,6 @@ class TestShowShareProperties(TestShare):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.shares_mock.get.return_value = self._share
|
self.shares_mock.get.return_value = self._share
|
||||||
|
|
||||||
self.shares_mock.get_metadata.return_value = self._share.metadata
|
self.shares_mock.get_metadata.return_value = self._share.metadata
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
@ -1780,7 +1793,6 @@ class TestShowShareProperties(TestShare):
|
|||||||
("share", self._share.id)
|
("share", self._share.id)
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.shares_mock.get.assert_called_with(self._share.id)
|
self.shares_mock.get.assert_called_with(self._share.id)
|
||||||
self.shares_mock.get_metadata.assert_called_with(self._share)
|
self.shares_mock.get_metadata.assert_called_with(self._share)
|
||||||
@ -1990,3 +2002,36 @@ class TestShareMigrationComplete(TestShare):
|
|||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
self._share.migration_complete.assert_called
|
self._share.migration_complete.assert_called
|
||||||
self.assertIsNone(result)
|
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
|
||||||
|
@ -47,6 +47,7 @@ openstack.share.v2 =
|
|||||||
share_migration_start = manilaclient.osc.v2.share:ShareMigrationStart
|
share_migration_start = manilaclient.osc.v2.share:ShareMigrationStart
|
||||||
share_migration_cancel = manilaclient.osc.v2.share:ShareMigrationCancel
|
share_migration_cancel = manilaclient.osc.v2.share:ShareMigrationCancel
|
||||||
share_migration_complete = manilaclient.osc.v2.share:ShareMigrationComplete
|
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_show = manilaclient.osc.v2.share:ShareExportLocationShow
|
||||||
share_export_location_list = manilaclient.osc.v2.share:ShareExportLocationList
|
share_export_location_list = manilaclient.osc.v2.share:ShareExportLocationList
|
||||||
share_properties_show = manilaclient.osc.v2.share:ShowShareProperties
|
share_properties_show = manilaclient.osc.v2.share:ShowShareProperties
|
||||||
|
Loading…
x
Reference in New Issue
Block a user