Add revert share to snapshot to shared file system.
Introduce revert share to snapshot method for Share class to shared file systems service. Change-Id: Id30cf928d09d5a06524616a9d6969306dc475740
This commit is contained in:
parent
72c223b52c
commit
104a361a5f
@ -32,7 +32,8 @@ service.
|
||||
|
||||
.. autoclass:: openstack.shared_file_system.v2._proxy.Proxy
|
||||
:noindex:
|
||||
:members: shares, get_share, delete_share, update_share, create_share
|
||||
:members: shares, get_share, delete_share, update_share, create_share,
|
||||
revert_share_to_snapshot
|
||||
|
||||
|
||||
Shared File System Storage Pools
|
||||
|
@ -132,6 +132,18 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
return self._create(_share.Share, **attrs)
|
||||
|
||||
def revert_share_to_snapshot(self, share_id, snapshot_id):
|
||||
"""Reverts a share to the specified snapshot, which must be
|
||||
the most recent one known to manila.
|
||||
|
||||
:param share_id: The ID of the share to revert
|
||||
:param snapshot_id: The ID of the snapshot to revert to
|
||||
:returns: Result of the ``revert``
|
||||
:rtype: ``None``
|
||||
"""
|
||||
res = self._get(_share.Share, share_id)
|
||||
res.revert_to_snapshot(self, snapshot_id)
|
||||
|
||||
def wait_for_status(self, res, status='active', failures=None,
|
||||
interval=2, wait=120):
|
||||
"""Wait for a resource to be in a particular status.
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from openstack import resource
|
||||
from openstack import utils
|
||||
|
||||
|
||||
class Share(resource.Resource):
|
||||
@ -100,3 +101,13 @@ class Share(resource.Resource):
|
||||
display_name = resource.Body("display_name", type=str)
|
||||
#: Display description for updating description
|
||||
display_description = resource.Body("display_description", type=str)
|
||||
|
||||
def _action(self, session, body):
|
||||
url = utils.urljoin(self.base_path, self.id, 'action')
|
||||
headers = {'Accept': ''}
|
||||
session.post(
|
||||
url, json=body, headers=headers)
|
||||
|
||||
def revert_to_snapshot(self, session, snapshot_id):
|
||||
body = {"revert": {"snapshot_id": snapshot_id}}
|
||||
self._action(session, body)
|
||||
|
@ -10,6 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack import resource
|
||||
from openstack.tests.functional import base
|
||||
|
||||
|
||||
@ -37,3 +38,22 @@ class BaseSharedFileSystemTest(base.BaseFunctionalTest):
|
||||
wait=self._wait_for_timeout)
|
||||
self.assertIsNotNone(share.id)
|
||||
return share
|
||||
|
||||
def create_share_snapshot(self, share_id, **kwargs):
|
||||
share_snapshot = self.user_cloud.share.create_share_snapshot(
|
||||
share_id=share_id, force=True)
|
||||
self.addCleanup(resource.wait_for_delete,
|
||||
self.user_cloud.share, share_snapshot,
|
||||
wait=self._wait_for_timeout,
|
||||
interval=2)
|
||||
self.addCleanup(self.user_cloud.share.delete_share_snapshot,
|
||||
share_snapshot.id,
|
||||
ignore_missing=False)
|
||||
self.user_cloud.share.wait_for_status(
|
||||
share_snapshot,
|
||||
status='available',
|
||||
failures=['error'],
|
||||
interval=5,
|
||||
wait=self._wait_for_timeout)
|
||||
self.assertIsNotNone(share_snapshot.id)
|
||||
return share_snapshot
|
||||
|
@ -24,6 +24,10 @@ class ShareTest(base.BaseSharedFileSystemTest):
|
||||
name=self.SHARE_NAME, size=2, share_type="dhss_false",
|
||||
share_protocol='NFS', description=None)
|
||||
self.SHARE_ID = my_share.id
|
||||
my_share_snapshot = self.create_share_snapshot(
|
||||
share_id=self.SHARE_ID
|
||||
)
|
||||
self.SHARE_SNAPSHOT_ID = my_share_snapshot.id
|
||||
|
||||
def test_get(self):
|
||||
sot = self.user_cloud.share.get_share(self.SHARE_ID)
|
||||
@ -43,3 +47,16 @@ class ShareTest(base.BaseSharedFileSystemTest):
|
||||
get_updated_share = self.user_cloud.share.get_share(
|
||||
updated_share.id)
|
||||
self.assertEqual('updated share', get_updated_share.description)
|
||||
|
||||
def test_revert_share_to_snapshot(self):
|
||||
self.user_cloud.share.revert_share_to_snapshot(
|
||||
self.SHARE_ID, self.SHARE_SNAPSHOT_ID)
|
||||
get_reverted_share = self.user_cloud.share.get_share(
|
||||
self.SHARE_ID)
|
||||
self.user_cloud.share.wait_for_status(
|
||||
get_reverted_share,
|
||||
status='available',
|
||||
failures=['error'],
|
||||
interval=5,
|
||||
wait=self._wait_for_timeout)
|
||||
self.assertIsNotNone(get_reverted_share.id)
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added revert share to snapshot to shared
|
||||
file system service.
|
Loading…
Reference in New Issue
Block a user