Cinder tests - Volume Quotas

Volume RBAC admin base and tests for
cinder volume quota admin policies

Implements bp: initial-tests-volume
Co-Authored-By: Anthony Bellino <ab2434@att.com>

Change-Id: If67a77371c9d2b9d500fc2c6e21117f85269c31f
diff --git a/patrole_tempest_plugin/tests/api/rbac_base.py b/patrole_tempest_plugin/tests/api/rbac_base.py
index 1e6de8e..fee24b8 100644
--- a/patrole_tempest_plugin/tests/api/rbac_base.py
+++ b/patrole_tempest_plugin/tests/api/rbac_base.py
@@ -59,3 +59,24 @@
         super(BaseVolumeRbacTest, cls).setup_clients()
         cls.auth_provider = cls.os.auth_provider
         cls.admin_client = cls.os_adm.volumes_client
+
+
+class BaseVolumeAdminRbacTest(vol_base.BaseVolumeAdminTest):
+
+    credentials = ['primary', 'admin']
+
+    @classmethod
+    def skip_checks(cls):
+        super(BaseVolumeAdminRbacTest, 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(BaseVolumeAdminRbacTest, 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/admin/__init__.py b/patrole_tempest_plugin/tests/api/volume/admin/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/volume/admin/__init__.py
diff --git a/patrole_tempest_plugin/tests/api/volume/admin/test_volume_quotas_rbac.py b/patrole_tempest_plugin/tests/api/volume/admin/test_volume_quotas_rbac.py
new file mode 100644
index 0000000..1595eac
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/volume/admin/test_volume_quotas_rbac.py
@@ -0,0 +1,70 @@
+# 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.
+
+import logging
+
+from tempest import config
+from tempest.lib import decorators
+
+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
+
+QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes']
+QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use']
+CONF = config.CONF
+LOG = logging.getLogger(__name__)
+
+
+class VolumeQuotasAdminRbacTest(rbac_base.BaseVolumeAdminRbacTest):
+
+    @classmethod
+    def setup_credentials(cls):
+        super(VolumeQuotasAdminRbacTest, cls).setup_credentials()
+        cls.demo_tenant_id = cls.os.credentials.tenant_id
+
+    @classmethod
+    def setup_clients(cls):
+        super(VolumeQuotasAdminRbacTest, cls).setup_clients()
+        cls.client = cls.os.volume_quotas_client
+
+    def tearDown(self):
+        rbac_utils.switch_role(self, switchToRbacRole=False)
+        super(VolumeQuotasAdminRbacTest, self).tearDown()
+
+    @rbac_rule_validation.action(component="Volume", service="cinder",
+                                 rule="volume_extension:quotas:show")
+    @decorators.idempotent_id('b3c7177e-b6b1-4d0f-810a-fc95606964dd')
+    def test_list_default_quotas(self):
+        rbac_utils.switch_role(self, switchToRbacRole=True)
+        self.client.show_default_quota_set(
+            self.demo_tenant_id)['quota_set']
+
+    @rbac_rule_validation.action(component="Volume", service="cinder",
+                                 rule="volume_extension:quotas:update")
+    @decorators.idempotent_id('60f8f421-1630-4953-b449-b22af32265c7')
+    def test_update_all_quota_resources_for_tenant(self):
+        new_quota_set = {'gigabytes': 1009,
+                         'volumes': 11,
+                         'snapshots': 11}
+        # Update limits for all quota resources
+        rbac_utils.switch_role(self, switchToRbacRole=True)
+        self.client.update_quota_set(
+            self.demo_tenant_id,
+            **new_quota_set)['quota_set']
+
+
+class VolumeQuotasAdminV3RbacTest(VolumeQuotasAdminRbacTest):
+    _api_version = 3