From 104a361a5f42a1612796df8694fa2232f8fd7c5e Mon Sep 17 00:00:00 2001 From: cheng-jiab Date: Sun, 28 Nov 2021 22:24:09 -0500 Subject: [PATCH] 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 --- .../user/proxies/shared_file_system.rst | 3 ++- openstack/shared_file_system/v2/_proxy.py | 12 +++++++++++ openstack/shared_file_system/v2/share.py | 11 ++++++++++ .../functional/shared_file_system/base.py | 20 +++++++++++++++++++ .../shared_file_system/test_share.py | 17 ++++++++++++++++ ...d-file-system-shares-2e1d44a1bb882d6d.yaml | 5 +++++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add-shared-file-system-shares-2e1d44a1bb882d6d.yaml diff --git a/doc/source/user/proxies/shared_file_system.rst b/doc/source/user/proxies/shared_file_system.rst index 0ea5925d5..6c8b6cb5e 100644 --- a/doc/source/user/proxies/shared_file_system.rst +++ b/doc/source/user/proxies/shared_file_system.rst @@ -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 diff --git a/openstack/shared_file_system/v2/_proxy.py b/openstack/shared_file_system/v2/_proxy.py index 4d34fd293..e87274569 100644 --- a/openstack/shared_file_system/v2/_proxy.py +++ b/openstack/shared_file_system/v2/_proxy.py @@ -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. diff --git a/openstack/shared_file_system/v2/share.py b/openstack/shared_file_system/v2/share.py index d2bd95d48..75cc636e2 100644 --- a/openstack/shared_file_system/v2/share.py +++ b/openstack/shared_file_system/v2/share.py @@ -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) diff --git a/openstack/tests/functional/shared_file_system/base.py b/openstack/tests/functional/shared_file_system/base.py index 9a78b2edb..2dac91937 100644 --- a/openstack/tests/functional/shared_file_system/base.py +++ b/openstack/tests/functional/shared_file_system/base.py @@ -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 diff --git a/openstack/tests/functional/shared_file_system/test_share.py b/openstack/tests/functional/shared_file_system/test_share.py index 4a4951ac7..a134140cd 100644 --- a/openstack/tests/functional/shared_file_system/test_share.py +++ b/openstack/tests/functional/shared_file_system/test_share.py @@ -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) diff --git a/releasenotes/notes/add-shared-file-system-shares-2e1d44a1bb882d6d.yaml b/releasenotes/notes/add-shared-file-system-shares-2e1d44a1bb882d6d.yaml new file mode 100644 index 000000000..6946d2313 --- /dev/null +++ b/releasenotes/notes/add-shared-file-system-shares-2e1d44a1bb882d6d.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added revert share to snapshot to shared + file system service.