Merge "Add role-switching validation to Patrole framework."
diff --git a/contrib/post_test_hook.sh b/contrib/post_test_hook.sh
index 2eb494f..085b5b1 100644
--- a/contrib/post_test_hook.sh
+++ b/contrib/post_test_hook.sh
@@ -26,12 +26,9 @@
TEMPEST_CONFIG=$BASE/new/tempest/etc/tempest.conf
TEMPEST_COMMAND="sudo -H -u tempest tox"
-# TODO(felipemonteiro): This regex does a negative lookahead to exclude slow
-# tests that contain the @test.attr(type='slow') decorator above them. Slower
-# tests will execute those tests in a separate gate, which will require
-# future modification of this script.
-DEVSTACK_FAST_GATE_TEMPEST_REGEX="(?!.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api)"
-DEVSTACK_SLOW_GATE_TEMPEST_REGEX="(?=.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api)"
+
+DEVSTACK_GATE_TEMPEST_REGEX="(?!.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api)"
+DEVSTACK_MULTINODE_GATE_TEMPEST_REGEX="(?=.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api)"
# Import devstack function 'iniset'.
source $BASE/new/devstack/functions
@@ -49,8 +46,8 @@
RBAC_ROLE="Member"
fi
-# Second argument is expected to contain value to indicate whether it is
-# a "fast' or "slow test" gate
+# Second argument is expected to contain value indicating whether the
+# environment is "multinode" or not (empty string).
TYPE=$2
# Set enable_rbac=True under [rbac] section in tempest.conf
@@ -73,11 +70,10 @@
# cd into Tempest directory before executing tox.
cd $BASE/new/tempest
-# Select Fast Gate if Type is set to 'fast', else use 'slow' gate
-if [[ "$TYPE" == "fast" ]]; then
- $TEMPEST_COMMAND -eall-plugin -- $DEVSTACK_FAST_GATE_TEMPEST_REGEX --concurrency=$TEMPEST_CONCURRENCY
+if [[ "$TYPE" == "multinode" ]]; then
+ $TEMPEST_COMMAND -eall-plugin -- $DEVSTACK_MULTINODE_GATE_TEMPEST_REGEX --concurrency=$TEMPEST_CONCURRENCY
else
- $TEMPEST_COMMAND -eall-plugin -- $DEVSTACK_SLOW_GATE_TEMPEST_REGEX --concurrency=$TEMPEST_CONCURRENCY
+ $TEMPEST_COMMAND -eall-plugin -- $DEVSTACK_GATE_TEMPEST_REGEX --concurrency=$TEMPEST_CONCURRENCY
fi
sudo -H -u tempest .tox/all-plugin/bin/tempest list-plugins
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
index 96f1c3f..76064f1 100644
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -30,20 +30,11 @@
#. [auth] section updates ::
- # Set tempest role to admin so all APIs are accessible
- tempest_roles = admin
-
- # Allows test cases to create/destroy tenants and users. This
- # option enables isolated test cases and better parallel
- # execution, but also requires that OpenStack Identity API
- # admin credentials are known. (boolean value)
- allow_tenant_isolation = True
-
# Allows test cases to create/destroy projects and users. This option
# requires that OpenStack Identity API admin credentials are known. If
# false, isolated test cases and parallel execution, can still be
# achieved configuring a list of test accounts (boolean value)
- use_dynamic_credentials = False
+ use_dynamic_credentials = True
#. [rbac] section updates ::
diff --git a/patrole_tempest_plugin/tests/api/compute/test_deferred_delete_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_deferred_delete_rbac.py
index eceef12..79d2c52 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_deferred_delete_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_deferred_delete_rbac.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+from tempest.lib import decorators
from tempest import test
from patrole_tempest_plugin import rbac_rule_validation
@@ -39,6 +40,7 @@
super(DeferredDeleteRbacTest, cls).resource_setup()
cls.server = cls.create_test_server(wait_until='ACTIVE')
+ @decorators.idempotent_id('189bfed4-1e6d-475c-bb8c-d57e60895391')
@rbac_rule_validation.action(
service="nova",
rule="os_compute_api:os-deferred-delete")
diff --git a/patrole_tempest_plugin/tests/api/identity/v3/rbac_base.py b/patrole_tempest_plugin/tests/api/identity/v3/rbac_base.py
index 5c1acce..44504cf 100644
--- a/patrole_tempest_plugin/tests/api/identity/v3/rbac_base.py
+++ b/patrole_tempest_plugin/tests/api/identity/v3/rbac_base.py
@@ -43,12 +43,14 @@
cls.rbac_utils.switch_role(cls, switchToRbacRole=False)
cls.creds_client = cls.os.credentials_client
+ cls.consumers_client = cls.os.oauth_consumers_client
cls.domains_client = cls.os.domains_client
cls.endpoints_client = cls.os.endpoints_v3_client
cls.groups_client = cls.os.groups_client
cls.projects_client = cls.os.projects_client
cls.policies_client = cls.os.policies_client
cls.regions_client = cls.os.regions_client
+ cls.role_assignments_client = cls.os.role_assignments_client
cls.roles_client = cls.os.roles_v3_client
cls.services_client = cls.os.identity_services_v3_client
cls.users_client = cls.os.users_v3_client
diff --git a/patrole_tempest_plugin/tests/api/identity/v3/test_oauth_consumers_rbac.py b/patrole_tempest_plugin/tests/api/identity/v3/test_oauth_consumers_rbac.py
new file mode 100644
index 0000000..62a8084
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v3/test_oauth_consumers_rbac.py
@@ -0,0 +1,76 @@
+# 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.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
+from tempest.lib import decorators
+
+from patrole_tempest_plugin import rbac_rule_validation
+from patrole_tempest_plugin.tests.api.identity.v3 import rbac_base
+
+
+class IdentityConsumersV3AdminRbacTest(rbac_base.BaseIdentityV3RbacAdminTest):
+
+ def _create_consumer(self):
+ description = data_utils.rand_name('test_create_consumer')
+ consumer = self.consumers_client.create_consumer(
+ description)['consumer']
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.consumers_client.delete_consumer,
+ consumer['id'])
+ return consumer
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:create_consumer")
+ @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d970')
+ def test_create_consumer(self):
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_consumer()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:delete_consumer")
+ @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d971')
+ def test_delete_consumer(self):
+ consumer = self._create_consumer()
+
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.consumers_client.delete_consumer(consumer['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:update_consumer")
+ @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d972')
+ def test_update_consumer(self):
+ consumer = self._create_consumer()
+ new_description = data_utils.rand_name('test_update_consumer')
+
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.consumers_client.update_consumer(consumer['id'],
+ new_description)
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:get_consumer")
+ @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d973')
+ def test_show_consumer(self):
+ consumer = self._create_consumer()
+
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.consumers_client.show_consumer(consumer['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_consumers")
+ @decorators.idempotent_id('0f148510-63bf-11e6-4522-080044d0d975')
+ def test_list_consumers(self):
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.consumers_client.list_consumers()
diff --git a/patrole_tempest_plugin/tests/api/identity/v3/test_role_assignments_rbac.py b/patrole_tempest_plugin/tests/api/identity/v3/test_role_assignments_rbac.py
new file mode 100644
index 0000000..878edcb
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v3/test_role_assignments_rbac.py
@@ -0,0 +1,47 @@
+# 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.lib import decorators
+
+from patrole_tempest_plugin import rbac_rule_validation
+from patrole_tempest_plugin.tests.api.identity.v3 import rbac_base
+
+
+class IdentityRoleAssignmentsV3AdminRbacTest(
+ rbac_base.BaseIdentityV3RbacAdminTest):
+
+ @classmethod
+ def setup_clients(cls):
+ super(IdentityRoleAssignmentsV3AdminRbacTest, cls).setup_clients()
+ cls.client = cls.role_assignments_client
+
+ @decorators.idempotent_id('afe57adb-1b9c-43d9-84a9-f0cf4c94e416')
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_role_assignments")
+ def test_list_role_assignments(self):
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.client.list_role_assignments()['role_assignments']
+
+ @decorators.idempotent_id('36c7a990-857e-415c-8717-38d7200a9894')
+ @rbac_rule_validation.action(
+ service="keystone",
+ rule="identity:list_role_assignments_for_tree")
+ def test_list_role_assignments_for_tree(self):
+ project = self.setup_test_project()
+
+ self.rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.client.list_role_assignments(
+ include_subtree=True, **{'scope.project.id': project['id']})[
+ 'role_assignments']
diff --git a/tox.ini b/tox.ini
index 85314b6..e123d64 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,10 +19,10 @@
[testenv:pep8]
commands = flake8 {posargs}
- check-uuid
+ check-uuid --package patrole_tempest_plugin.tests.api
[testenv:uuidgen]
-commands = check-uuid --fix
+commands = check-uuid --package patrole_tempest_plugin.tests.api --fix
[testenv:venv]
commands = {posargs}