Merge "[OSC] Implement Share Revert Command"
This commit is contained in:
commit
5285705e44
@ -44,6 +44,8 @@ shares
|
||||
.. autoprogram-cliff:: openstack.share.v2
|
||||
:command: share export location list
|
||||
|
||||
.. autoprogram-cliff:: openstack.share.v2
|
||||
:command: share revert
|
||||
|
||||
==================
|
||||
share access rules
|
||||
|
@ -1066,3 +1066,32 @@ class ShowShareProperties(command.ShowOne):
|
||||
share_properties = share_client.shares.get_metadata(share)
|
||||
|
||||
return self.dict2columns(share_properties._info)
|
||||
|
||||
|
||||
class RevertShare(command.Command):
|
||||
"""Revert a share to snapshot."""
|
||||
|
||||
_description = _("Revert a share to the specified snapshot.")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RevertShare, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'snapshot',
|
||||
metavar="<snapshot>",
|
||||
help=_('Name or ID of the snapshot to restore. The snapshot '
|
||||
'must be the most recent one known to manila.')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
|
||||
snapshot = apiutils.find_resource(share_client.share_snapshots,
|
||||
parsed_args.snapshot)
|
||||
share = apiutils.find_resource(share_client.shares,
|
||||
snapshot.share_id)
|
||||
try:
|
||||
share.revert_to_snapshot(snapshot)
|
||||
except Exception as e:
|
||||
raise exceptions.CommandError(_(
|
||||
"Failed to revert share to snapshot: %s" % (e)))
|
||||
|
@ -1821,3 +1821,48 @@ class TestShowShareProperties(TestShare):
|
||||
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.datalist, data)
|
||||
|
||||
|
||||
class TestShareRevert(TestShare):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareRevert, self).setUp()
|
||||
|
||||
self.share = manila_fakes.FakeShare.create_one_share(
|
||||
attrs={'revert_to_snapshot_support': True},
|
||||
methods={'revert_to_snapshot': None}
|
||||
)
|
||||
self.share_snapshot = (
|
||||
manila_fakes.FakeShareSnapshot.create_one_snapshot(
|
||||
attrs={'share_id': self.share.id}))
|
||||
self.shares_mock.get.return_value = self.share
|
||||
self.snapshots_mock.get.return_value = self.share_snapshot
|
||||
|
||||
self.cmd = osc_shares.RevertShare(self.app, None)
|
||||
|
||||
def test_share_revert(self):
|
||||
arglist = [
|
||||
self.share_snapshot.id
|
||||
]
|
||||
verifylist = [
|
||||
('snapshot', self.share_snapshot.id)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.shares_mock.get.assert_called_with(self.share_snapshot.share_id)
|
||||
self.share.revert_to_snapshot.assert_called_with(self.share_snapshot)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_share_revert_exception(self):
|
||||
arglist = [
|
||||
self.share_snapshot.id
|
||||
]
|
||||
verifylist = [
|
||||
('snapshot', self.share_snapshot.id)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.share.revert_to_snapshot.side_effect = Exception()
|
||||
self.assertRaises(
|
||||
osc_exceptions.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
@ -47,6 +47,7 @@ openstack.share.v2 =
|
||||
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
|
||||
share_revert = manilaclient.osc.v2.share:RevertShare
|
||||
share_access_create = manilaclient.osc.v2.share_access_rules:ShareAccessAllow
|
||||
share_access_delete = manilaclient.osc.v2.share_access_rules:ShareAccessDeny
|
||||
share_access_list = manilaclient.osc.v2.share_access_rules:ListShareAccess
|
||||
|
Loading…
Reference in New Issue
Block a user