Initial Cinder tests
Adds Cinder RBAC base and create/delete volume tests
Implements bp: initial-tests-volume
Co-Authored-By: Rick Bartra <rb560u@att.com>
Co-Authored-By: David Purcell <david.purcell@att.com>
Change-Id: I57b405135e5dccf350661e6edb7582900885dc17
diff --git a/patrole_tempest_plugin/tests/api/rbac_base.py b/patrole_tempest_plugin/tests/api/rbac_base.py
index 786927f..1e6de8e 100644
--- a/patrole_tempest_plugin/tests/api/rbac_base.py
+++ b/patrole_tempest_plugin/tests/api/rbac_base.py
@@ -13,6 +13,7 @@
# Maybe these should be in lib or recreated?
from tempest.api.image import base as image_base
+from tempest.api.volume import base as vol_base
from tempest import config
CONF = config.CONF
@@ -37,3 +38,24 @@
super(BaseV2ImageRbacTest, cls).setup_clients()
cls.auth_provider = cls.os.auth_provider
cls.admin_client = cls.os_adm.image_client_v2
+
+
+class BaseVolumeRbacTest(vol_base.BaseVolumeTest):
+
+ credentials = ['primary', 'admin']
+
+ @classmethod
+ def skip_checks(cls):
+ super(BaseVolumeRbacTest, cls).skip_checks()
+ if not CONF.rbac.rbac_flag:
+ raise cls.skipException(
+ "%s skipped as RBAC Flag not enabled" % cls.__name__)
+ if 'admin' not in CONF.auth.tempest_roles:
+ raise cls.skipException(
+ "%s skipped because tempest roles is not admin" % cls.__name__)
+
+ @classmethod
+ def setup_clients(cls):
+ super(BaseVolumeRbacTest, cls).setup_clients()
+ cls.auth_provider = cls.os.auth_provider
+ cls.admin_client = cls.os_adm.volumes_client
diff --git a/patrole_tempest_plugin/tests/api/volume/__init__.py b/patrole_tempest_plugin/tests/api/volume/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/volume/__init__.py
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
new file mode 100644
index 0000000..e535f96
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/volume/test_volume_create_delete_rbac.py
@@ -0,0 +1,67 @@
+# Copyright 2016 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 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.rbac_utils import rbac_utils
+from patrole_tempest_plugin.tests.api import rbac_base
+
+CONF = config.CONF
+LOG = logging.getLogger(__name__)
+
+
+class CreateDeleteVolumeRbacTest(rbac_base.BaseVolumeRbacTest):
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(CreateDeleteVolumeRbacTest, self).tearDown()
+
+ 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(component="Volume", service="cinder",
+ rule="volume:create")
+ @decorators.idempotent_id('426b08ef-6394-4d06-9128-965d5a6c38ef')
+ def test_create_volume(self):
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ # Create a volume
+ self._create_volume()
+
+ @rbac_rule_validation.action(component="Volume", 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()
+ 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