[RBAC] Add share snapshot metadata tests
The tests validate policy of share snapshot metadata actions
for admin,member and reader users in a project scope.
Change-Id: I4de5c256ef468419cabf0293e05c0855fa67e095
diff --git a/manila_tempest_tests/services/share/v2/json/shares_client.py b/manila_tempest_tests/services/share/v2/json/shares_client.py
index 6d5e8fb..bf944d4 100644
--- a/manila_tempest_tests/services/share/v2/json/shares_client.py
+++ b/manila_tempest_tests/services/share/v2/json/shares_client.py
@@ -2147,4 +2147,5 @@
f'/{resource}s/{resource_id}/metadata/{key}')
resp, body = self.get(uri)
self.expected_success(200, resp.status)
- return self._parse_resp(body)
+ body = json.loads(body)
+ return rest_client.ResponseBody(resp, body)
diff --git a/manila_tempest_tests/tests/api/test_metadata.py b/manila_tempest_tests/tests/api/test_metadata.py
index d2ae326..bd73963 100644
--- a/manila_tempest_tests/tests/api/test_metadata.py
+++ b/manila_tempest_tests/tests/api/test_metadata.py
@@ -41,8 +41,8 @@
# verify metadata items
for key in md:
- get_value = self.shares_v2_client.get_metadata_item(share["id"],
- key)
+ get_value = self.shares_v2_client.get_metadata_item(
+ share["id"], key)['meta']
self.assertEqual(md[key], get_value[key])
@decorators.idempotent_id('9070249f-6e94-4a38-a036-08debee547c3')
diff --git a/manila_tempest_tests/tests/api/test_snapshot_metadata.py b/manila_tempest_tests/tests/api/test_snapshot_metadata.py
index fb64618..0596213 100644
--- a/manila_tempest_tests/tests/api/test_snapshot_metadata.py
+++ b/manila_tempest_tests/tests/api/test_snapshot_metadata.py
@@ -72,7 +72,7 @@
# verify metadata items
for key in md:
get_value = self.shares_v2_client.get_metadata_item(
- snapshot['id'], key, resource="snapshot")
+ snapshot['id'], key, resource="snapshot")['meta']
self.assertEqual(md[key], get_value[key])
@decorators.idempotent_id('5d537913-ce6f-4771-beb2-84e2390b06d3')
diff --git a/manila_tempest_tests/tests/rbac/base.py b/manila_tempest_tests/tests/rbac/base.py
index 5aaf35e..b1eba9b 100644
--- a/manila_tempest_tests/tests/rbac/base.py
+++ b/manila_tempest_tests/tests/rbac/base.py
@@ -83,9 +83,10 @@
return share
@classmethod
- def create_snapshot(cls, client, share_id, name=None):
+ def create_snapshot(cls, client, share_id, name=None, metadata=None):
name = name or data_utils.rand_name('snapshot')
- snapshot = client.create_snapshot(share_id, name=name)['snapshot']
+ snapshot = client.create_snapshot(
+ share_id, name=name, metadata=metadata)['snapshot']
waiters.wait_for_resource_status(
client, snapshot['id'], 'available', resource_name='snapshot')
cls.addClassResourceCleanup(
diff --git a/manila_tempest_tests/tests/rbac/test_snapshots.py b/manila_tempest_tests/tests/rbac/test_snapshots.py
index beffc52..810ba9b 100644
--- a/manila_tempest_tests/tests/rbac/test_snapshots.py
+++ b/manila_tempest_tests/tests/rbac/test_snapshots.py
@@ -24,6 +24,7 @@
from manila_tempest_tests.common import waiters
from manila_tempest_tests.tests.api import base
from manila_tempest_tests.tests.rbac import base as rbac_base
+from manila_tempest_tests import utils
CONF = config.CONF
@@ -74,6 +75,18 @@
def test_reset_snapshot(self):
pass
+ @abc.abstractmethod
+ def test_set_snapshot_metadata(self):
+ pass
+
+ @abc.abstractmethod
+ def test_get_snapshot_metadata(self):
+ pass
+
+ @abc.abstractmethod
+ def test_delete_snapshot_metadata(self):
+ pass
+
class TestProjectAdminTestsNFS(ShareRbacSnapshotsTests, base.BaseSharesTest):
@@ -202,6 +215,60 @@
'snapshot_reset_state', expected_status=202,
snapshot_id=alt_snap['id'], status='error')
+ @decorators.idempotent_id('8c0858d5-5670-4c21-ab1f-7d74a7f8cb6d')
+ @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_set_snapshot_metadata(self):
+ snap = self.create_snapshot(
+ self.share_member_client, self.share['id'])
+ metadata = {u'key': u'value'}
+ self.do_request(
+ 'set_metadata', expected_status=200,
+ resource_id=snap['id'], resource='snapshot', metadata=metadata)
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'])
+ self.do_request(
+ 'set_metadata', expected_status=200,
+ resource_id=alt_snap['id'], resource='snapshot', metadata=metadata)
+
+ @decorators.idempotent_id('235b3fe2-55bf-4a43-b703-ca413ce76a41')
+ @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_get_snapshot_metadata(self):
+ metadata = {u'key': u'value'}
+ snap = self.create_snapshot(
+ self.share_member_client, self.share['id'],
+ metadata=metadata)
+ self.do_request(
+ 'get_metadata_item', expected_status=200,
+ resource_id=snap['id'], key='key', resource='snapshot')
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'],
+ metadata=metadata)
+ self.do_request(
+ 'get_metadata_item', expected_status=200,
+ resource_id=alt_snap['id'], key='key', resource='snapshot')
+
+ @decorators.idempotent_id('7490eb85-fcdc-45ae-89ba-14cf34c58b3b')
+ @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_delete_snapshot_metadata(self):
+ metadata = {u'key': u'value'}
+ snap = self.create_snapshot(
+ self.share_member_client, self.share['id'], metadata=metadata)
+ self.do_request(
+ 'delete_metadata', expected_status=200, resource_id=snap['id'],
+ resource='snapshot', key='key')
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'],
+ metadata=metadata)
+ self.do_request(
+ 'delete_metadata', expected_status=200, resource_id=alt_snap['id'],
+ resource='snapshot', key='key')
+
class TestProjectMemberTestsNFS(ShareRbacSnapshotsTests, base.BaseSharesTest):
@@ -320,6 +387,59 @@
'snapshot_reset_state', expected_status=lib_exc.Forbidden,
snapshot_id=alt_snap['id'], status='error')
+ @decorators.idempotent_id('a2849a7a-66ae-4cf9-9bac-6420dddd8f03')
+ @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_set_snapshot_metadata(self):
+ snap = self.create_snapshot(self.client, self.share['id'])
+ metadata = {u'key': u'value'}
+ self.do_request(
+ 'set_metadata', expected_status=200,
+ resource_id=snap['id'], resource='snapshot', metadata=metadata)
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'])
+ self.do_request(
+ 'set_metadata', expected_status=lib_exc.NotFound,
+ resource_id=alt_snap['id'], resource='snapshot', metadata=metadata)
+
+ @decorators.idempotent_id('9a3fc032-eb0c-49e9-8026-d26b05520d95')
+ @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_get_snapshot_metadata(self):
+ metadata = {u'key': u'value'}
+ share_client = getattr(self, 'share_member_client', self.client)
+ snap = self.create_snapshot(
+ share_client, self.share['id'], metadata=metadata)
+ self.do_request(
+ 'get_metadata_item', expected_status=200,
+ resource_id=snap['id'], key='key', resource='snapshot')
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'],
+ metadata=metadata)
+ self.do_request(
+ 'get_metadata_item', expected_status=lib_exc.NotFound,
+ resource_id=alt_snap['id'], key='key', resource='snapshot')
+
+ @decorators.idempotent_id('aa3ecadd-b87f-4bcd-ab2c-6a19d27c0adb')
+ @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_delete_snapshot_metadata(self):
+ metadata = {u'key': u'value'}
+ snap = self.create_snapshot(
+ self.client, self.share['id'], metadata=metadata)
+ self.do_request(
+ 'delete_metadata', expected_status=200, resource_id=snap['id'],
+ resource='snapshot', key='key')
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'],
+ metadata=metadata)
+ self.do_request(
+ 'delete_metadata', expected_status=lib_exc.NotFound,
+ resource_id=alt_snap['id'], resource='snapshot', key='key')
+
class TestProjectReaderTestsNFS(TestProjectMemberTestsNFS):
"""Test suite for basic share snapshot operations by reader user
@@ -405,6 +525,47 @@
def test_reset_snapshot(self):
super(TestProjectReaderTestsNFS, self).test_reset_snapshot()
+ @decorators.idempotent_id('c9177029-3161-4b5b-b7cb-76f8259a459a')
+ @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_set_snapshot_metadata(self):
+ snap = self.create_snapshot(
+ self.share_member_client, self.share['id'])
+ metadata = {u'key': u'value'}
+ self.do_request(
+ 'set_metadata', expected_status=lib_exc.Forbidden,
+ resource_id=snap['id'], resource='snapshot', metadata=metadata)
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'])
+ self.do_request(
+ 'set_metadata', expected_status=lib_exc.Forbidden,
+ resource_id=alt_snap['id'], resource='snapshot', metadata=metadata)
+
+ @decorators.idempotent_id('e5471262-fb4f-4a80-91c1-cc925b94f2c1')
+ @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_get_snapshot_metadata(self):
+ super(TestProjectMemberTestsNFS, self).test_get_snapshot_metadata()
+
+ @decorators.idempotent_id('e1c0251b-b8f4-439f-b697-ea3fc024c2ff')
+ @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
+ @utils.skip_if_microversion_not_supported("2.73")
+ def test_delete_snapshot_metadata(self):
+ metadata = {u'key': u'value'}
+ snap = self.create_snapshot(
+ self.share_member_client, self.share['id'], metadata=metadata)
+ self.do_request(
+ 'delete_metadata', expected_status=lib_exc.Forbidden,
+ resource_id=snap['id'], resource='snapshot', key='key')
+
+ alt_snap = self.create_snapshot(
+ self.alt_project_share_v2_client, self.alt_share['id'],
+ metadata=metadata)
+ self.do_request(
+ 'delete_metadata', expected_status=lib_exc.Forbidden,
+ resource_id=alt_snap['id'], resource='snapshot', key='key')
+
class TestProjectAdminTestsCEPHFS(TestProjectAdminTestsNFS):
protocol = 'cephfs'