Update Cinder test that incorrectly handles 404
The volume test that checks the "volume:delete" action incorrectly
handles a 404. When a role doesn't have permission to delete a
volume, Cinder actually throws a 403 and not a 404.
This commit also refactors existing test to group basic volume CRUD
(create, read, update, and delete) tests into a single file.
Additionally, there was not a test for "volume:update", so this commit
also covers that action.
Change-Id: Ib5f63ecc1ac51918ee4b1e35763b0c91aa7d5ae2
Closes-Bug: #1671903
diff --git a/patrole_tempest_plugin/tests/api/volume/test_volume_actions_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_volume_actions_rbac.py
index 996e2b7..29f6a80 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_volume_actions_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_volume_actions_rbac.py
@@ -79,15 +79,6 @@
# Detach the volume
self._detach_volume()
- @testtools.skipUnless(CONF.service_available.nova,
- "Nova is needed to create a server")
- @rbac_rule_validation.action(service="cinder", rule="volume:get")
- @decorators.idempotent_id('c4c3fdd5-b1b1-49c3-b977-a9f40ee9257a')
- def test_get_volume_attachment(self):
- self.rbac_utils.switch_role(self, switchToRbacRole=True)
- # Get attachment
- self.client.show_volume(self.volume['id'])
-
@testtools.skipIf(True, "Patrole bug #1672799")
@rbac_rule_validation.action(service="cinder",
rule="volume:copy_volume_to_image")
diff --git a/patrole_tempest_plugin/tests/api/volume/test_volume_basic_crud.py b/patrole_tempest_plugin/tests/api/volume/test_volume_basic_crud.py
new file mode 100644
index 0000000..70f53fd
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/volume/test_volume_basic_crud.py
@@ -0,0 +1,78 @@
+# Copyright 2017 AT&T Corporation.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from tempest import config
+from tempest.lib.common.utils import data_utils
+from tempest.lib import decorators
+
+from patrole_tempest_plugin import rbac_rule_validation
+from patrole_tempest_plugin.tests.api.volume import rbac_base
+
+CONF = config.CONF
+
+
+class VolumesV2BasicCrudRbacTest(rbac_base.BaseVolumeRbacTest):
+
+ @rbac_rule_validation.action(service="cinder",
+ rule="volume:create")
+ @decorators.idempotent_id('426b08ef-6394-4d06-9128-965d5a6c38ef')
+ def test_create_volume(self):
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.create_volume()
+
+ @rbac_rule_validation.action(service="cinder",
+ rule="volume:delete")
+ @decorators.idempotent_id('6de9f9c2-509f-4558-867b-af21c7163be4')
+ def test_delete_volume(self):
+ volume = self.create_volume()
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.volumes_client.delete_volume(volume['id'])
+
+ @rbac_rule_validation.action(service="cinder", rule="volume:get")
+ @decorators.idempotent_id('c4c3fdd5-b1b1-49c3-b977-a9f40ee9257a')
+ def test_get_volume(self):
+ volume = self.create_volume()
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.volumes_client.show_volume(volume['id'])
+
+ @rbac_rule_validation.action(service="cinder",
+ rule="volume:get_all")
+ @decorators.idempotent_id('e3ab7906-b04b-4c45-aa11-1104d302f940')
+ def test_volume_list(self):
+ # Get a list of Volumes
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.volumes_client.list_volumes()
+
+ @rbac_rule_validation.action(
+ service="cinder",
+ rule="volume_extension:get_volumes_image_metadata")
+ @decorators.idempotent_id('3d48ca91-f02b-4616-a69d-4a8b296c8529')
+ def test_volume_list_image_metadata(self):
+ # Get a list of Volumes
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.volumes_client.list_volumes(detail=True)
+
+ @rbac_rule_validation.action(service="cinder", rule="volume:update")
+ @decorators.idempotent_id('b751b889-9a9b-40d8-ae7d-4b0f65e71ac7')
+ def test_update_volume(self):
+ volume = self.create_volume()
+ new_name = data_utils.rand_name('volume')
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.volumes_client.update_volume(volume['id'],
+ name=new_name)
+
+
+class VolumesV3BasicCrudRbacTest(VolumesV2BasicCrudRbacTest):
+ _api_version = 3
diff --git a/patrole_tempest_plugin/tests/api/volume/test_volume_create_delete_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_volume_create_delete_rbac.py
deleted file mode 100644
index d028180..0000000
--- a/patrole_tempest_plugin/tests/api/volume/test_volume_create_delete_rbac.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# Copyright 2017 AT&T Corporation.
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from oslo_log import log as logging
-
-from tempest import config
-from tempest.lib import decorators
-from tempest.lib import exceptions
-
-from patrole_tempest_plugin import rbac_exceptions
-from patrole_tempest_plugin import rbac_rule_validation
-from patrole_tempest_plugin.tests.api.volume import rbac_base
-
-CONF = config.CONF
-LOG = logging.getLogger(__name__)
-
-
-class CreateDeleteVolumeRbacTest(rbac_base.BaseVolumeRbacTest):
-
- def _create_volume(self):
- # create_volume waits for volume status to be
- # "available" before returning and automatically
- # cleans up at the end of testing
- volume = self.create_volume()
- return volume
-
- @rbac_rule_validation.action(service="cinder",
- rule="volume:create")
- @decorators.idempotent_id('426b08ef-6394-4d06-9128-965d5a6c38ef')
- def test_create_volume(self):
- self.rbac_utils.switch_role(self, switchToRbacRole=True)
- # Create a volume
- self._create_volume()
-
- @rbac_rule_validation.action(service="cinder",
- rule="volume:delete")
- @decorators.idempotent_id('6de9f9c2-509f-4558-867b-af21c7163be4')
- def test_delete_volume(self):
- try:
- # Create a volume
- volume = self._create_volume()
- self.rbac_utils.switch_role(self, switchToRbacRole=True)
- # Delete a volume
- self.volumes_client.delete_volume(volume['id'])
- except exceptions.NotFound as e:
- raise rbac_exceptions.RbacActionFailed(e)
-
-
-class CreateDeleteVolumeV3RbacTest(CreateDeleteVolumeRbacTest):
- _api_version = 3
diff --git a/patrole_tempest_plugin/tests/api/volume/test_volumes_list_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_volumes_list_rbac.py
deleted file mode 100644
index 8c0a9e0..0000000
--- a/patrole_tempest_plugin/tests/api/volume/test_volumes_list_rbac.py
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright 2017 AT&T Corp
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from tempest import config
-from tempest.lib import decorators
-
-from patrole_tempest_plugin import rbac_rule_validation
-from patrole_tempest_plugin.tests.api.volume import rbac_base
-
-CONF = config.CONF
-
-
-class VolumesListRbacTest(rbac_base.BaseVolumeRbacTest):
-
- @classmethod
- def setup_clients(cls):
- super(VolumesListRbacTest, cls).setup_clients()
- cls.client = cls.os.volumes_client
-
- @rbac_rule_validation.action(service="cinder",
- rule="volume:get_all")
- @decorators.idempotent_id('e3ab7906-b04b-4c45-aa11-1104d302f940')
- def test_volume_list(self):
- # Get a list of Volumes
- self.rbac_utils.switch_role(self, switchToRbacRole=True)
- self.client.list_volumes()
-
- @rbac_rule_validation.action(
- service="cinder",
- rule="volume_extension:get_volumes_image_metadata")
- @decorators.idempotent_id('3d48ca91-f02b-4616-a69d-4a8b296c8529')
- def test_volume_list_image_metadata(self):
- # Get a list of Volumes
- self.rbac_utils.switch_role(self, switchToRbacRole=True)
- self.client.list_volumes(detail=True)
-
-
-class VolumeListV3RbacTest(VolumesListRbacTest):
- _api_version = 3