Merge "Removes test_access_ips_rbac test because it cannot be tested."
diff --git a/patrole_tempest_plugin/tests/api/compute/rbac_base.py b/patrole_tempest_plugin/tests/api/compute/rbac_base.py
index ca24204..6fd8f30 100644
--- a/patrole_tempest_plugin/tests/api/compute/rbac_base.py
+++ b/patrole_tempest_plugin/tests/api/compute/rbac_base.py
@@ -11,6 +11,9 @@
# 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.api.compute import base as compute_base
from tempest import config
@@ -56,3 +59,34 @@
super(BaseV2ComputeAdminRbacTest, cls).setup_clients()
cls.admin_client = cls.os_admin.agents_client
cls.auth_provider = cls.os.auth_provider
+
+ @classmethod
+ def resource_setup(cls):
+ super(BaseV2ComputeAdminRbacTest, cls).resource_setup()
+ cls.flavors = []
+
+ @classmethod
+ def resource_cleanup(cls):
+ cls.clear_flavors()
+ super(BaseV2ComputeAdminRbacTest, cls).resource_cleanup()
+
+ @classmethod
+ def clear_flavors(cls):
+ for flavor in cls.flavors:
+ test_utils.call_and_ignore_notfound_exc(
+ cls.flavors_client.delete_flavor, flavor['id'])
+
+ @classmethod
+ def _create_flavor(cls, **kwargs):
+ flavor_kwargs = {
+ "name": data_utils.rand_name('flavor'),
+ "ram": data_utils.rand_int_id(1, 10),
+ "vcpus": data_utils.rand_int_id(1, 10),
+ "disk": data_utils.rand_int_id(1, 10),
+ "id": data_utils.rand_uuid(),
+ }
+ if kwargs:
+ flavor_kwargs.update(kwargs)
+ flavor = cls.flavors_client.create_flavor(**flavor_kwargs)['flavor']
+ cls.flavors.append(flavor)
+ return flavor
diff --git a/patrole_tempest_plugin/tests/api/compute/test_flavor_access_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_flavor_access_rbac.py
new file mode 100644
index 0000000..32ec91a
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/compute/test_flavor_access_rbac.py
@@ -0,0 +1,93 @@
+# 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
+
+from tempest import config
+from tempest.lib.common.utils import test_utils
+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.compute import rbac_base
+
+CONF = config.CONF
+LOG = log.getLogger(__name__)
+
+
+class FlavorAccessAdminRbacTest(rbac_base.BaseV2ComputeAdminRbacTest):
+
+ @classmethod
+ def setup_clients(cls):
+ super(FlavorAccessAdminRbacTest, cls).setup_clients()
+ cls.client = cls.flavors_client
+
+ @classmethod
+ def skip_checks(cls):
+ super(FlavorAccessAdminRbacTest, cls).skip_checks()
+ if not CONF.compute_feature_enabled.api_extensions:
+ raise cls.skipException(
+ '%s skipped as no compute extensions enabled' % cls.__name__)
+
+ @classmethod
+ def resource_setup(cls):
+ super(FlavorAccessAdminRbacTest, cls).resource_setup()
+ cls.flavor_id = cls._create_flavor(is_public=False)['id']
+ cls.tenant_id = cls.auth_provider.credentials.tenant_id
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(FlavorAccessAdminRbacTest, self).tearDown()
+
+ @decorators.idempotent_id('a2bd3740-765d-4c95-ac98-9e027378c75e')
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:os-flavor-access")
+ def test_list_flavor_access(self):
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ try:
+ self.client.list_flavor_access(self.flavor_id)
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @decorators.idempotent_id('39cb5c8f-9990-436f-9282-fc76a41d9bac')
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:os-flavor-access:add_tenant_access")
+ def test_add_flavor_access(self):
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.client.add_flavor_access(
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
+ self.addCleanup(self.client.remove_flavor_access,
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
+
+ @decorators.idempotent_id('61b8621f-52e4-473a-8d07-e228af8853d1')
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:os-flavor-access:remove_tenant_access")
+ def test_remove_flavor_access(self):
+ self.client.add_flavor_access(
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.client.remove_flavor_access,
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.client.remove_flavor_access(
+ flavor_id=self.flavor_id, tenant_id=self.tenant_id)
diff --git a/patrole_tempest_plugin/tests/api/compute/test_hypervisor_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_hypervisor_rbac.py
new file mode 100644
index 0000000..5f571a5
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/compute/test_hypervisor_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 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.compute import rbac_base
+
+CONF = config.CONF
+
+
+class HypervisorRbacTest(rbac_base.BaseV2ComputeRbacTest):
+
+ @classmethod
+ def setup_clients(cls):
+ super(HypervisorRbacTest, cls).setup_clients()
+ cls.client = cls.hypervisor_client
+
+ @classmethod
+ def skip_checks(cls):
+ super(HypervisorRbacTest, cls).skip_checks()
+ if not CONF.compute_feature_enabled.api_extensions:
+ raise cls.skipException(
+ '%s skipped as no compute extensions enabled' % cls.__name__)
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(HypervisorRbacTest, self).tearDown()
+
+ @decorators.idempotent_id('afe5d5ed-c9b9-4e9b-bdc6-20ef9fe86ad8')
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:limits:discoverable")
+ def test_hypervisor_discoverable(self):
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.extensions_client.list_extensions()
+
+
+class HypervisorAdminRbacTest(rbac_base.BaseV2ComputeAdminRbacTest):
+
+ @classmethod
+ def setup_clients(cls):
+ super(HypervisorAdminRbacTest, cls).setup_clients()
+ cls.client = cls.hypervisor_client
+
+ @classmethod
+ def skip_checks(cls):
+ super(HypervisorAdminRbacTest, cls).skip_checks()
+ if not CONF.compute_feature_enabled.api_extensions:
+ raise cls.skipException(
+ '%s skipped as no compute extensions enabled' % cls.__name__)
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(HypervisorAdminRbacTest, self).tearDown()
+
+ @decorators.idempotent_id('17bbeb9a-e73e-445f-a771-c794448ef562')
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:os-hypervisors")
+ def test_list_hypervisors(self):
+ self.client.list_hypervisors()['hypervisors']
diff --git a/patrole_tempest_plugin/tests/api/compute/test_instance_actions.py b/patrole_tempest_plugin/tests/api/compute/test_instance_actions.py
new file mode 100644
index 0000000..5bcb18e
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/compute/test_instance_actions.py
@@ -0,0 +1,63 @@
+# 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 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.compute import rbac_base
+
+CONF = config.CONF
+
+
+class InstanceActionsRbacTest(rbac_base.BaseV2ComputeRbacTest):
+
+ @classmethod
+ def setup_clients(cls):
+ super(InstanceActionsRbacTest, cls).setup_clients()
+ cls.client = cls.servers_client
+
+ @classmethod
+ def skip_checks(cls):
+ super(InstanceActionsRbacTest, cls).skip_checks()
+ if not CONF.compute_feature_enabled.api_extensions:
+ raise cls.skipException(
+ '%s skipped as no compute extensions enabled' % cls.__name__)
+
+ @classmethod
+ def resource_setup(cls):
+ super(InstanceActionsRbacTest, cls).resource_setup()
+ cls.server = cls.create_test_server(wait_until='ACTIVE')
+ cls.request_id = cls.server.response['x-compute-request-id']
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(InstanceActionsRbacTest, self).tearDown()
+
+ @decorators.idempotent_id('9d1b131d-407e-4fa3-8eef-eb2c4526f1da')
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:os-instance-actions")
+ def test_list_instance_actions(self):
+ self.client.list_instance_actions(self.server['id'])
+
+ @decorators.idempotent_id('eb04c439-4215-4029-9ccb-5b3c041bfc25')
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:os-instance-actions:events")
+ def test_get_instance_action(self):
+ self.client.show_instance_action(
+ self.server['id'], self.request_id)['instanceAction']
diff --git a/patrole_tempest_plugin/tests/api/compute/test_absolute_limits_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_limits_rbac.py
similarity index 73%
rename from patrole_tempest_plugin/tests/api/compute/test_absolute_limits_rbac.py
rename to patrole_tempest_plugin/tests/api/compute/test_limits_rbac.py
index 8e1f6ee..ae52fe5 100644
--- a/patrole_tempest_plugin/tests/api/compute/test_absolute_limits_rbac.py
+++ b/patrole_tempest_plugin/tests/api/compute/test_limits_rbac.py
@@ -21,28 +21,27 @@
CONF = config.CONF
-class AbsoluteLimitsRbacTest(rbac_base.BaseV2ComputeRbacTest):
+class LimitsRbacTest(rbac_base.BaseV2ComputeRbacTest):
def tearDown(self):
rbac_utils.switch_role(self, switchToRbacRole=False)
- super(AbsoluteLimitsRbacTest, self).tearDown()
+ super(LimitsRbacTest, self).tearDown()
@classmethod
def setup_clients(cls):
- super(AbsoluteLimitsRbacTest, cls).setup_clients()
- cls.identity_client = cls.os_adm.identity_client
- cls.tenants_client = cls.os_adm.tenants_client
+ super(LimitsRbacTest, cls).setup_clients()
+ cls.client = cls.limits_client
@classmethod
def skip_checks(cls):
- super(AbsoluteLimitsRbacTest, cls).skip_checks()
+ super(LimitsRbacTest, cls).skip_checks()
if not CONF.compute_feature_enabled.api_extensions:
raise cls.skipException(
'%s skipped as no compute extensions enabled' % cls.__name__)
@rbac_rule_validation.action(service="nova",
- rule="os_compute_api:os-used-limits")
+ rule="os_compute_api:limits")
@decorators.idempotent_id('3fb60f83-9a5f-4fdd-89d9-26c3710844a1')
- def test_used_limits_for_admin_rbac(self):
+ def test_show_limits(self):
rbac_utils.switch_role(self, switchToRbacRole=True)
- self.limits_client.show_limits()
+ self.client.show_limits()
diff --git a/patrole_tempest_plugin/tests/api/compute/test_security_groups_rbac.py b/patrole_tempest_plugin/tests/api/compute/test_security_groups_rbac.py
new file mode 100644
index 0000000..7cbf012
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/compute/test_security_groups_rbac.py
@@ -0,0 +1,35 @@
+# 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.rbac_utils import rbac_utils
+from patrole_tempest_plugin.tests.api.compute import rbac_base
+
+
+class SecurityGroupsRbacTest(rbac_base.BaseV2ComputeRbacTest):
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(SecurityGroupsRbacTest, self).tearDown()
+
+ @rbac_rule_validation.action(
+ service="nova",
+ rule="os_compute_api:os-security-groups")
+ @decorators.idempotent_id('4ac58e49-48c1-4fca-a6c3-3f95fb99eb77')
+ def test_server_security_groups(self):
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.security_groups_client.list_security_groups()
diff --git a/patrole_tempest_plugin/tests/api/identity/v2/__init__.py b/patrole_tempest_plugin/tests/api/identity/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v2/__init__.py
diff --git a/patrole_tempest_plugin/tests/api/identity/v2/rbac_base.py b/patrole_tempest_plugin/tests/api/identity/v2/rbac_base.py
new file mode 100644
index 0000000..e379873
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v2/rbac_base.py
@@ -0,0 +1,54 @@
+# 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.api.identity import base
+from tempest import config
+from tempest.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
+
+CONF = config.CONF
+
+
+class BaseIdentityV2AdminRbacTest(base.BaseIdentityV2AdminTest):
+
+ credentials = ['primary', 'admin']
+
+ @classmethod
+ def skip_checks(cls):
+ super(BaseIdentityV2AdminRbacTest, 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(BaseIdentityV2AdminRbacTest, cls).setup_clients()
+ cls.auth_provider = cls.os.auth_provider
+ cls.admin_client = cls.os_adm.identity_client
+
+ def _create_service(self):
+ name = data_utils.rand_name('service')
+ type = data_utils.rand_name('type')
+
+ self.service = self.services_client.create_service(
+ name=name, type=type,
+ description="description")
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.services_client.delete_service,
+ self.service['OS-KSADM:service']['id'])
+ return self.service
diff --git a/patrole_tempest_plugin/tests/api/identity/v2/test_endpoints_rbac.py b/patrole_tempest_plugin/tests/api/identity/v2/test_endpoints_rbac.py
new file mode 100644
index 0000000..b448976
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v2/test_endpoints_rbac.py
@@ -0,0 +1,99 @@
+# 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.common.utils import test_utils
+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.identity.v2 import rbac_base
+
+CONF = config.CONF
+
+
+class IdentityEndpointsV2AdminRbacTest(rbac_base.BaseIdentityV2AdminRbacTest):
+
+ @classmethod
+ def setup_clients(cls):
+ super(IdentityEndpointsV2AdminRbacTest, cls).setup_clients()
+ cls.endpoints_client = cls.os.endpoints_client
+
+ @classmethod
+ def resource_setup(cls):
+ super(IdentityEndpointsV2AdminRbacTest, cls).resource_setup()
+ cls.region = data_utils.rand_name('region')
+ cls.public_url = data_utils.rand_url()
+ cls.admin_url = data_utils.rand_url()
+ cls.internal_url = data_utils.rand_url()
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(IdentityEndpointsV2AdminRbacTest, self).tearDown()
+
+ def _create_endpoint(self):
+ self._create_service()
+ endpoint = self.endpoints_client.create_endpoint(
+ service_id=self.service['OS-KSADM:service']['id'],
+ region=self.region,
+ publicurl=self.public_url,
+ adminurl=self.admin_url,
+ internalurl=self.internal_url
+ )
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.endpoints_client.delete_endpoint,
+ endpoint['endpoint']['id'])
+ return endpoint
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:create_endpoint")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd124')
+ def test_create_endpoint(self):
+
+ """Create Endpoint Test
+
+ RBAC test for Identity Admin 2.0 create_endpoint
+ """
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_endpoint()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:delete_endpoint")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd125')
+ def test_delete_endpoint(self):
+
+ """Delete Endpoint Test
+
+ RBAC test for Identity Admin 2.0 delete_endpoint
+ """
+
+ endpoint = self._create_endpoint()
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.endpoints_client.delete_endpoint(endpoint['endpoint']['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_endpoints")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd126')
+ def test_list_endpoints(self):
+
+ """List Endpoints Test
+
+ RBAC test for Identity Admin 2.0 list_endpoint
+ """
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.endpoints_client.list_endpoints()
diff --git a/patrole_tempest_plugin/tests/api/identity/v2/test_projects_rbac.py b/patrole_tempest_plugin/tests/api/identity/v2/test_projects_rbac.py
new file mode 100644
index 0000000..0c2eb96
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v2/test_projects_rbac.py
@@ -0,0 +1,136 @@
+# 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.common.utils import test_utils
+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.identity.v2 import rbac_base
+
+CONF = config.CONF
+
+
+class IdentityProjectV2AdminRbacTest(rbac_base.BaseIdentityV2AdminRbacTest):
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(IdentityProjectV2AdminRbacTest, self).tearDown()
+
+ @classmethod
+ def setup_clients(cls):
+ super(IdentityProjectV2AdminRbacTest, cls).setup_clients()
+ cls.tenants_client = cls.os.tenants_client
+
+ def _create_tenant(self, name):
+ self.tenant = self.tenants_client.create_tenant(name=name)
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.tenants_client.delete_tenant,
+ self.tenant['tenant']['id'])
+ return self.tenant
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:create_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d904')
+ def test_create_project(self):
+
+ """Create Project Test
+
+ RBAC test for Identity 2.0 create_tenant
+ """
+
+ tenant_name = data_utils.rand_name('test_create_project')
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_tenant(tenant_name)
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:update_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d905')
+ def test_update_project(self):
+
+ """Update Project Test
+
+ RBAC test for Identity 2.0 update_tenant
+ """
+
+ tenant_name = data_utils.rand_name('test_update_project')
+ tenant = self._create_tenant(tenant_name)
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.tenants_client.update_tenant(tenant['tenant']['id'],
+ description="Changed description")
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:delete_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d906')
+ def test_delete_project(self):
+
+ """Delete Project Test
+
+ RBAC test for Identity 2.0 delete_tenant
+ """
+
+ tenant_name = data_utils.rand_name('test_delete_project')
+ tenant = self._create_tenant(tenant_name)
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.tenants_client.delete_tenant(tenant['tenant']['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:get_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d907')
+ def test_get_project(self):
+
+ """Get Project Test
+
+ RBAC test for Identity 2.0 show_tenant
+ """
+
+ tenant_name = data_utils.rand_name('test_get_project')
+ tenant = self._create_tenant(tenant_name)
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.tenants_client.show_tenant(tenant['tenant']['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_projects")
+ @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d908')
+ def test_get_all_projects(self):
+
+ """List All Projects Test
+
+ RBAC test for Identity 2.0 list_tenants
+ """
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.tenants_client.list_tenants()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_user_projects")
+ @decorators.idempotent_id('0f148510-63bf-11e6-b348-080044d0d909')
+ def test_list_users_for_tenant(self):
+
+ """Get Users of a Project Test
+
+ RBAC test for Identity 2.0 list_tenant_users
+ """
+
+ tenant_name = data_utils.rand_name('test_list_users_for_tenant')
+ tenant = self._create_tenant(tenant_name)
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.tenants_client.list_tenant_users(tenant['tenant']['id'])
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 3d53df4..3639caa 100644
--- a/patrole_tempest_plugin/tests/api/identity/v3/rbac_base.py
+++ b/patrole_tempest_plugin/tests/api/identity/v3/rbac_base.py
@@ -15,6 +15,8 @@
from tempest.api.identity import base
from tempest import config
+from tempest.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
CONF = config.CONF
@@ -34,8 +36,23 @@
"%s skipped because tempest roles is not admin" % cls.__name__)
@classmethod
- def resource_setup(cls):
- super(BaseIdentityV3RbacAdminTest, cls).resource_setup()
+ def setup_clients(cls):
+ super(BaseIdentityV3RbacAdminTest, cls).setup_clients()
cls.auth_provider = cls.os.auth_provider
cls.admin_client = cls.os_adm.identity_v3_client
cls.creds_client = cls.os.credentials_client
+ cls.services_client = cls.os.identity_services_v3_client
+ cls.endpoints_client = cls.os.endpoints_v3_client
+
+ def _create_service(self):
+ """Creates a service for test."""
+ name = data_utils.rand_name('service')
+ serv_type = data_utils.rand_name('type')
+ desc = data_utils.rand_name('description')
+ service = self.services_client \
+ .create_service(name=name,
+ type=serv_type,
+ description=desc)['service']
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.services_client.delete_service, service['id'])
+ return service
diff --git a/patrole_tempest_plugin/tests/api/identity/v3/test_endpoints_rbac.py b/patrole_tempest_plugin/tests/api/identity/v3/test_endpoints_rbac.py
new file mode 100644
index 0000000..b60c3e8
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v3/test_endpoints_rbac.py
@@ -0,0 +1,111 @@
+# 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.common.utils import data_utils
+from tempest import config
+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.rbac_utils import rbac_utils
+from patrole_tempest_plugin.tests.api.identity.v3 import rbac_base
+
+CONF = config.CONF
+
+
+class IdentityEndpointsV3AdminRbacTest(
+ rbac_base.BaseIdentityV3RbacAdminTest):
+
+ def _create_endpoint(self):
+ """Creates a service and an endpoint for test."""
+ interface = 'public'
+ url = data_utils.rand_url()
+ service = self._create_service()
+ endpoint = self.endpoints_client \
+ .create_endpoint(service_id=service['id'],
+ interface=interface,
+ url=url)['endpoint']
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.endpoints_client.delete_endpoint, endpoint['id'])
+ return (service, endpoint)
+
+ def tearDown(self):
+ """Reverts user back to admin for cleanup."""
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(IdentityEndpointsV3AdminRbacTest, self).tearDown()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:create_endpoint")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd127')
+ def test_create_endpoint(self):
+ """Create an endpoint.
+
+ RBAC test for Keystone: identity:create_endpoint
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_endpoint()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:update_endpoint")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd128')
+ def test_update_endpoint(self):
+ """Update an endpoint.
+
+ RBAC test for Keystone: identity:update_endpoint
+ """
+ service, endpoint = self._create_endpoint()
+ new_url = data_utils.rand_url()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.endpoints_client.update_endpoint(endpoint["id"],
+ service_id=service['id'],
+ url=new_url)
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:delete_endpoint")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd129')
+ def test_delete_endpoint(self):
+ """Delete an endpoint.
+
+ RBAC test for Keystone: identity:delete_endpoint
+ """
+ _, endpoint = self._create_endpoint()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.endpoints_client.delete_endpoint(endpoint['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:get_endpoint")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd130')
+ def test_show_endpoint(self):
+ """Show/Get an endpoint.
+
+ RBAC test for Keystone: identity:get_endpoint
+ """
+ _, endpoint = self._create_endpoint()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.endpoints_client.show_endpoint(endpoint['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_endpoints")
+ @decorators.idempotent_id('6bdaecd4-0843-4ed6-ab64-3a57ab0cd131')
+ def test_list_endpoints(self):
+ """Create a Domain.
+
+ RBAC test for Keystone: identity:create_domain
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.endpoints_client.list_endpoints()
diff --git a/patrole_tempest_plugin/tests/api/identity/v3/test_projects_rbac.py b/patrole_tempest_plugin/tests/api/identity/v3/test_projects_rbac.py
new file mode 100644
index 0000000..9af2ccf
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v3/test_projects_rbac.py
@@ -0,0 +1,99 @@
+# 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.common.utils import data_utils
+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.identity.v3 import rbac_base
+
+CONF = config.CONF
+
+
+class IdentityProjectV3AdminRbacTest(
+ rbac_base.BaseIdentityV3RbacAdminTest):
+
+ def tearDown(self):
+ """Reverts user back to admin for cleanup."""
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(IdentityProjectV3AdminRbacTest, self).tearDown()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:create_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-1564-080044d0d904')
+ def test_create_project(self):
+ """Create a Project.
+
+ RBAC test for Keystone: identity:create_project
+ """
+ name = data_utils.rand_name('project')
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ project = self.non_admin_projects_client \
+ .create_project(name)['project']
+ self.addCleanup(self.projects_client.delete_project, project['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:update_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-1564-080044d0d905')
+ def test_update_project(self):
+ """Update a Project.
+
+ RBAC test for Keystone: identity:update_project
+ """
+ project = self.setup_test_project()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.non_admin_projects_client \
+ .update_project(project['id'],
+ description="Changed description")
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:delete_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-1564-080044d0d906')
+ def test_delete_project(self):
+ """Delete a Project.
+
+ RBAC test for Keystone: identity:delete_project
+ """
+ project = self.setup_test_project()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.non_admin_projects_client.delete_project(project['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:get_project")
+ @decorators.idempotent_id('0f148510-63bf-11e6-1564-080044d0d907')
+ def test_show_project(self):
+ """Show a project.
+
+ RBAC test for Keystone: identity:get_project
+ """
+ project = self.setup_test_project()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.non_admin_projects_client.show_project(project['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_projects")
+ @decorators.idempotent_id('0f148510-63bf-11e6-1564-080044d0d908')
+ def test_list_projects(self):
+ """List all projects.
+
+ RBAC test for Keystone: identity:list_projects
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.non_admin_projects_client.list_projects()
diff --git a/patrole_tempest_plugin/tests/api/identity/v3/test_services_rbac.py b/patrole_tempest_plugin/tests/api/identity/v3/test_services_rbac.py
new file mode 100644
index 0000000..f5a0a3e
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/identity/v3/test_services_rbac.py
@@ -0,0 +1,97 @@
+# 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.common.utils import data_utils
+from tempest import config
+from tempest import test
+
+from patrole_tempest_plugin import rbac_rule_validation
+from patrole_tempest_plugin.rbac_utils import rbac_utils
+from patrole_tempest_plugin.tests.api.identity.v3 import rbac_base
+
+CONF = config.CONF
+
+
+class IdentitySericesV3AdminRbacTest(rbac_base.BaseIdentityV3RbacAdminTest):
+
+ def tearDown(self):
+ """Reverts user back to admin for cleanup."""
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(IdentitySericesV3AdminRbacTest, self).tearDown()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:create_service")
+ @test.idempotent_id('9a4bb317-f0bb-4005-8df0-4b672885b7c8')
+ def test_create_service(self):
+ """Create a service.
+
+ RBAC test for Keystone: identity:create_service
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_service()
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:update_service")
+ @test.idempotent_id('b39447d1-2cf6-40e5-a899-46f287f2ecf0')
+ def test_update_service(self):
+ """Update a service.
+
+ RBAC test for Keystone: identity:update_service
+ """
+ service = self._create_service()
+ new_name = data_utils.rand_name('new_test_name')
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.services_client.update_service(service['id'],
+ service=service,
+ name=new_name,
+ type=service['type'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:delete_service")
+ @test.idempotent_id('177b991a-438d-4bef-8e9f-9c6cc5a1c9e8')
+ def test_delete_service(self):
+ """Delete a service.
+
+ RBAC test for Keystone: identity:delete_service
+ """
+ service = self._create_service()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.services_client.delete_service(service['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:get_service")
+ @test.idempotent_id('d89a9ac6-cd53-428d-84c0-5bc71f4a432d')
+ def test_show_service(self):
+ """Show/Get a service.
+
+ RBAC test for Keystone: identity:get_service
+ """
+ service = self._create_service()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.services_client.show_service(service['id'])
+
+ @rbac_rule_validation.action(service="keystone",
+ rule="identity:list_services")
+ @test.idempotent_id('706e6bea-3385-4718-919c-0b5121395806')
+ def test_list_services(self):
+ """list all services.
+
+ RBAC test for Keystone: identity:list_services
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.services_client.list_services()
diff --git a/patrole_tempest_plugin/tests/api/network/test_ports_rbac.py b/patrole_tempest_plugin/tests/api/network/test_ports_rbac.py
new file mode 100644
index 0000000..207ae54
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/network/test_ports_rbac.py
@@ -0,0 +1,358 @@
+# 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.
+#
+import netaddr
+import random
+
+from oslo_log import log
+from tempest import config
+from tempest.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
+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.network import rbac_base as base
+
+CONF = config.CONF
+LOG = log.getLogger(__name__)
+
+
+class PortsRbacTest(base.BaseNetworkRbacTest):
+
+ @classmethod
+ def resource_setup(cls):
+ super(PortsRbacTest, cls).resource_setup()
+ cls.admin_network = cls.create_network()
+
+ # Create a subnet by admin user
+ cls.cidr = netaddr.IPNetwork(CONF.network.project_network_cidr)
+
+ cls.admin_subnet = cls.create_subnet(cls.admin_network,
+ cidr=cls.cidr,
+ mask_bits=24)
+ cls.admin_ip_range = netaddr.IPRange(
+ cls.admin_subnet['allocation_pools'][0]['start'],
+ cls.admin_subnet['allocation_pools'][0]['end'])
+
+ # Create a port by admin user
+ body = cls.ports_client.create_port(network_id=cls.admin_network['id'])
+ cls.admin_port = body['port']
+ cls.ports.append(cls.admin_port)
+ ipaddr = cls.admin_port['fixed_ips'][0]['ip_address']
+ cls.admin_port_ip_address = ipaddr
+ cls.admin_port_mac_address = cls.admin_port['mac_address']
+
+ def _create_port(self, **post_body):
+
+ body = self.ports_client.create_port(**post_body)
+ port = body['port']
+
+ # Schedule port deletion with verification upon test completion
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.ports_client.delete_port,
+ port['id'])
+
+ return port
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(PortsRbacTest, self).tearDown()
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="create_port")
+ @decorators.idempotent_id('0ec8c551-625c-4864-8a52-85baa7c40f22')
+ def test_create_port(self):
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ post_body = {'network_id': self.admin_network['id']}
+ self._create_port(**post_body)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="create_port:binding:host_id")
+ @decorators.idempotent_id('a54bd6b8-a7eb-4101-bfe8-093930b0d660')
+ def test_create_port_binding_host_id(self):
+
+ post_body = {'network_id': self.admin_network['id'],
+ 'binding:host_id': "rbac_test_host"}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_port(**post_body)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="create_port:fixed_ips")
+ @decorators.idempotent_id('2551e10d-006a-413c-925a-8c6f834c09ac')
+ def test_create_port_fixed_ips(self):
+ # Pick an ip address within the allocation_pools range
+ ip_address = random.choice(list(self.admin_ip_range))
+
+ fixed_ips = [{'ip_address': ip_address},
+ {'subnet_id': self.admin_subnet['id']}]
+
+ post_body = {'network_id': self.admin_network['id'],
+ 'fixed_ips': fixed_ips}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_port(**post_body)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="create_port:mac_address")
+ @decorators.idempotent_id('aee6d0be-a7f3-452f-aefc-796b4eb9c9a8')
+ def test_create_port_mac_address(self):
+
+ post_body = {'network_id': self.admin_network['id'],
+ 'mac_address': data_utils.rand_mac_address()}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_port(**post_body)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="create_port:binding:profile")
+ @decorators.idempotent_id('98fa38ab-c2ed-46a0-99f0-59f18cbd257a')
+ def test_create_port_binding_profile(self):
+
+ binding_profile = {"foo": "1"}
+
+ post_body = {'network_id': self.admin_network['id'],
+ 'binding:profile': binding_profile}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_port(**post_body)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="create_port:allowed_address_pairs")
+ @decorators.idempotent_id('b638d1f4-d903-4ca8-aa2a-6fd603c5ec3a')
+ def test_create_port_allowed_address_pairs(self):
+
+ # Create port with allowed address pair attribute
+ allowed_address_pairs = [{'ip_address': self.admin_port_ip_address,
+ 'mac_address': self.admin_port_mac_address}]
+
+ post_body = {'network_id': self.admin_network['id'],
+ 'allowed_address_pairs': allowed_address_pairs}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self._create_port(**post_body)
+
+ @rbac_rule_validation.action(service="neutron", rule="get_port")
+ @decorators.idempotent_id('a9d41cb8-78a2-4b97-985c-44e4064416f4')
+ def test_show_port(self):
+
+ try:
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+
+ self.ports_client.show_port(self.admin_port['id'])
+
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="get_port:binding:vif_type")
+ @decorators.idempotent_id('125aff0b-8fed-4f8e-8410-338616594b06')
+ def test_show_port_binding_vif_type(self):
+
+ # Verify specific fields of a port
+ fields = ['binding:vif_type']
+
+ try:
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.show_port(self.admin_port['id'],
+ fields=fields)
+
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="get_port:binding:vif_details")
+ @decorators.idempotent_id('e42bfd77-fcce-45ee-9728-3424300f0d6f')
+ def test_show_port_binding_vif_details(self):
+
+ # Verify specific fields of a port
+ fields = ['binding:vif_details']
+
+ try:
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.show_port(self.admin_port['id'],
+ fields=fields)
+
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="get_port:binding:host_id")
+ @decorators.idempotent_id('8e61bcdc-6f81-443c-833e-44410266551e')
+ def test_show_port_binding_host_id(self):
+
+ # Verify specific fields of a port
+ fields = ['binding:host_id']
+ post_body = {'network_id': self.admin_network['id'],
+ 'binding:host_id': data_utils.rand_name('host-id')}
+ port = self._create_port(**post_body)
+
+ try:
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.show_port(port['id'],
+ fields=fields)
+
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="get_port:binding:profile")
+ @decorators.idempotent_id('d497cea9-c4ad-42e0-acc9-8d257d6b01fc')
+ def test_show_port_binding_profile(self):
+
+ # Verify specific fields of a port
+ fields = ['binding:profile']
+ binding_profile = {"foo": "1"}
+ post_body = {'network_id': self.admin_network['id'],
+ 'binding:profile': binding_profile}
+ port = self._create_port(**post_body)
+
+ try:
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.show_port(port['id'],
+ fields=fields)
+
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="update_port")
+ @decorators.idempotent_id('afa80981-3c59-42fd-9531-3bcb2cd03711')
+ def test_update_port(self):
+
+ port = self.create_port(self.admin_network)
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.update_port(port['id'],
+ admin_state_up=False)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="update_port:mac_address")
+ @decorators.idempotent_id('507140c8-7b14-4d63-b627-2103691d887e')
+ def test_update_port_mac_address(self):
+
+ port = self.create_port(self.admin_network)
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.update_port(
+ port['id'],
+ mac_address=data_utils.rand_mac_address())
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="update_port:fixed_ips")
+ @decorators.idempotent_id('c091c825-532b-4c6f-a14f-affd3259c1c3')
+ def test_update_port_fixed_ips(self):
+
+ # Pick an ip address within the allocation_pools range
+ ip_address = random.choice(list(self.admin_ip_range))
+ fixed_ips = [{'ip_address': ip_address}]
+ post_body = {'network_id': self.admin_network['id']}
+ port = self._create_port(**post_body)
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.update_port(port['id'],
+ fixed_ips=fixed_ips)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="update_port:port_security_enabled")
+ @decorators.idempotent_id('795541af-6652-4e35-9581-fd58224f7545')
+ def test_update_port_security_enabled(self):
+
+ port = self.create_port(self.admin_network)
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.update_port(port['id'],
+ security_groups=[])
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="update_port:binding:host_id")
+ @decorators.idempotent_id('24206a72-0d90-4712-918c-5c9a1ebef64d')
+ def test_update_port_binding_host_id(self):
+
+ post_body = {'network_id': self.admin_network['id'],
+ 'binding:host_id': 'rbac_test_host'}
+ port = self._create_port(**post_body)
+
+ updated_body = {'port_id': port['id'],
+ 'binding:host_id': 'rbac_test_host_updated'}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.update_port(**updated_body)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="update_port:binding:profile")
+ @decorators.idempotent_id('990ea8d1-9257-4f71-a3bf-d6d0914625c5')
+ def test_update_port_binding_profile(self):
+
+ binding_profile = {"foo": "1"}
+ post_body = {'network_id': self.admin_network['id'],
+ 'binding:profile': binding_profile}
+
+ port = self._create_port(**post_body)
+
+ new_binding_profile = {"foo": "2"}
+ updated_body = {'port_id': port['id'],
+ 'binding:profile': new_binding_profile}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.update_port(**updated_body)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="update_port:allowed_address_pairs")
+ @decorators.idempotent_id('729c2151-bb49-4f4f-9d58-3ed8819b7582')
+ def test_update_port_allowed_address_pairs(self):
+
+ ip_address = random.choice(list(self.admin_ip_range))
+ # Update allowed address pair attribute of port
+ address_pairs = [{'ip_address': ip_address,
+ 'mac_address': data_utils.rand_mac_address()}]
+ post_body = {'network_id': self.admin_network['id']}
+ port = self._create_port(**post_body)
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.update_port(port['id'],
+ allowed_address_pairs=address_pairs)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="delete_port")
+ @decorators.idempotent_id('1cf8e582-bc09-46cb-b32a-82bf991ad56f')
+ def test_delete_port(self):
+
+ try:
+ port = self._create_port(network_id=self.admin_network['id'])
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.ports_client.delete_port(port['id'])
+
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
diff --git a/patrole_tempest_plugin/tests/api/network/test_routers_rbac.py b/patrole_tempest_plugin/tests/api/network/test_routers_rbac.py
new file mode 100644
index 0000000..662eb41
--- /dev/null
+++ b/patrole_tempest_plugin/tests/api/network/test_routers_rbac.py
@@ -0,0 +1,292 @@
+# 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.
+
+import netaddr
+import random
+
+from oslo_log import log
+from tempest import config
+from tempest.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
+from tempest.lib import decorators
+from tempest.lib import exceptions
+from tempest import test
+
+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.network import rbac_base as base
+
+CONF = config.CONF
+LOG = log.getLogger(__name__)
+
+
+class RouterRbacTest(base.BaseNetworkRbacTest):
+ @classmethod
+ def skip_checks(cls):
+ super(RouterRbacTest, cls).skip_checks()
+ if not test.is_extension_enabled('router', 'network'):
+ msg = "router extension not enabled."
+ raise cls.skipException(msg)
+
+ @classmethod
+ def resource_setup(cls):
+ super(RouterRbacTest, cls).resource_setup()
+ post_body = {}
+ post_body['router:external'] = True
+ cls.admin_network = cls.create_network(**post_body)
+ cls.admin_subnet = cls.create_subnet(cls.admin_network)
+ cls.admin_ip_range = netaddr.IPRange(
+ cls.admin_subnet['allocation_pools'][0]['start'],
+ cls.admin_subnet['allocation_pools'][0]['end'])
+ cls.admin_router = cls.create_router()
+
+ def tearDown(self):
+ rbac_utils.switch_role(self, switchToRbacRole=False)
+ super(RouterRbacTest, self).tearDown()
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="create_router")
+ @decorators.idempotent_id('acc5005c-bdb6-4192-bc9f-ece9035bb488')
+ def test_create_router(self):
+ """Create Router
+
+ RBAC test for the neutron create_router policy
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ router = self.routers_client.create_router()
+ self.addCleanup(self.routers_client.delete_router,
+ router['router']['id'])
+
+ @rbac_rule_validation.action(
+ service="neutron",
+ rule="create_router:external_gateway_info:enable_snat")
+ @decorators.idempotent_id('3c5acd49-0ec7-4109-ab51-640557b48ebc')
+ def test_create_router_enable_snat(self):
+ """Create Router Snat
+
+ RBAC test for the neutron
+ create_router:external_gateway_info:enable_snat policy
+ """
+ name = data_utils.rand_name('snat-router')
+ external_gateway_info = {'network_id': self.admin_network['id'],
+ 'enable_snat': True}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ router = self.routers_client.create_router(
+ name=name, external_gateway_info=external_gateway_info)
+ self.addCleanup(self.routers_client.delete_router,
+ router['router']['id'])
+
+ @rbac_rule_validation.action(
+ service="neutron",
+ rule="create_router:external_gateway_info:external_fixed_ips")
+ @decorators.idempotent_id('d0354369-a040-4349-b869-645c8aed13cd')
+ def test_create_router_external_fixed_ips(self):
+ """Create Router Fixed IPs
+
+ RBAC test for the neutron
+ create_router:external_gateway_info:external_fixed_ips policy
+ """
+ name = data_utils.rand_name('snat-router')
+ # Pick an ip address within the allocation_pools range
+ ip_address = random.choice(list(self.admin_ip_range))
+ external_fixed_ips = {'subnet_id': self.admin_subnet['id'],
+ 'ip_address': ip_address}
+
+ external_gateway_info = {'network_id': self.admin_network['id'],
+ 'enable_snat': False,
+ 'external_fixed_ips': [external_fixed_ips]}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ router = self.routers_client.create_router(
+ name=name, external_gateway_info=external_gateway_info)
+ self.addCleanup(self.routers_client.delete_router,
+ router['router']['id'])
+
+ @rbac_rule_validation.action(service="neutron", rule="get_router")
+ @decorators.idempotent_id('bfbdbcff-f115-4d3e-8cd5-6ada33fd0e21')
+ def test_show_router(self):
+ """Get Router
+
+ RBAC test for the neutron get_router policy
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ try:
+ self.routers_client.show_router(self.admin_router['id'])
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(
+ service="neutron", rule="update_router")
+ @decorators.idempotent_id('3d182f4e-0023-4218-9aa0-ea2b0ae0bd7a')
+ def test_update_router(self):
+ """Update Router
+
+ RBAC test for the neutron update_router policy
+ """
+ new_name = data_utils.rand_name('new-router-name')
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.routers_client.update_router(self.admin_router['id'],
+ name=new_name)
+
+ @rbac_rule_validation.action(
+ service="neutron", rule="update_router:external_gateway_info")
+ @decorators.idempotent_id('5a6ae104-a9c3-4b56-8622-e1a0a0194474')
+ def test_update_router_external_gateway_info(self):
+ """Update Router External Gateway Info
+
+ RBAC test for the neutron
+ update_router:external_gateway_info policy
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.routers_client.update_router(self.admin_router['id'],
+ external_gateway_info={})
+
+ @rbac_rule_validation.action(
+ service="neutron",
+ rule="update_router:external_gateway_info:network_id")
+ @decorators.idempotent_id('f1fc5a23-e3d8-44f0-b7bc-47006ad9d3d4')
+ def test_update_router_external_gateway_info_network_id(self):
+ """Update Router External Gateway Info Network Id
+
+ RBAC test for the neutron
+ update_router:external_gateway_info:network_id policy
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.routers_client.update_router(
+ self.admin_router['id'],
+ external_gateway_info={'network_id': self.admin_network['id']})
+
+ @rbac_rule_validation.action(
+ service="neutron",
+ rule="update_router:external_gateway_info:enable_snat")
+ @decorators.idempotent_id('515a2954-3d79-4695-aeb9-d1c222765840')
+ def test_update_router_enable_snat(self):
+ """Update Router External Gateway Info Enable Snat
+
+ RBAC test for the neutron
+ update_router:external_gateway_info:enable_snat policy
+ """
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.routers_client.update_router(
+ self.admin_router['id'],
+ external_gateway_info={'network_id': self.admin_network['id'],
+ 'enable_snat': True})
+
+ @rbac_rule_validation.action(
+ service="neutron",
+ rule="update_router:external_gateway_info:external_fixed_ips")
+ @decorators.idempotent_id('f429e5ee-8f0a-4667-963e-72dd95d5adee')
+ def test_update_router_external_fixed_ips(self):
+ """Update Router External Gateway Info External Fixed Ips
+
+ RBAC test for the neutron
+ update_router:external_gateway_info:external_fixed_ips policy
+ """
+ # Pick an ip address within the allocation_pools range
+ ip_address = random.choice(list(self.admin_ip_range))
+ external_fixed_ips = {'subnet_id': self.admin_subnet['id'],
+ 'ip_address': ip_address}
+ external_gateway_info = {'network_id': self.admin_network['id'],
+ 'external_fixed_ips': [external_fixed_ips]}
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.routers_client.update_router(
+ self.admin_router['id'],
+ external_gateway_info=external_gateway_info)
+ self.addCleanup(
+ self.routers_client.update_router,
+ self.admin_router['id'],
+ external_gateway_info=None)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="delete_router")
+ @decorators.idempotent_id('c0634dd5-0467-48f7-a4ae-1014d8edb2a7')
+ def test_delete_router(self):
+ """Delete Router
+
+ RBAC test for the neutron delete_router policy
+ """
+ router = self.create_router()
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ try:
+ self.routers_client.delete_router(router['id'])
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="add_router_interface")
+ @decorators.idempotent_id('a0627778-d68d-4913-881b-e345360cca19')
+ def test_add_router_interfaces(self):
+ """Add Router Interface
+
+ RBAC test for the neutron add_router_interface policy
+ """
+ network = self.create_network()
+ subnet = self.create_subnet(network)
+ router = self.create_router()
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ try:
+ self.routers_client.add_router_interface(
+ router['id'], subnet_id=subnet['id'])
+ self.addCleanup(
+ test_utils.call_and_ignore_notfound_exc,
+ self.routers_client.remove_router_interface,
+ router['id'],
+ subnet_id=subnet['id'])
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
+
+ @rbac_rule_validation.action(service="neutron",
+ rule="remove_router_interface")
+ @decorators.idempotent_id('ff2593a4-2bff-4c27-97d3-dd3702b27dfb')
+ def test_remove_router_interfaces(self):
+ """Remove Router Interface
+
+ RBAC test for the neutron remove_router_interface policy
+ """
+ network = self.create_network()
+ subnet = self.create_subnet(network)
+ router = self.create_router()
+
+ self.routers_client.add_router_interface(
+ router['id'], subnet_id=subnet['id'])
+
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.routers_client.remove_router_interface,
+ router['id'],
+ subnet_id=subnet['id'])
+
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ try:
+ self.routers_client.remove_router_interface(
+ router['id'],
+ subnet_id=subnet['id'])
+ except exceptions.NotFound as e:
+ LOG.info("NotFound exception caught. Exception is thrown when "
+ "role doesn't have access to the endpoint."
+ "This is irregular and should be fixed.")
+ raise rbac_exceptions.RbacActionFailed(e)
diff --git a/patrole_tempest_plugin/tests/api/volume/test_volume_transfers_rbac.py b/patrole_tempest_plugin/tests/api/volume/test_volume_transfers_rbac.py
index f88d44f..485844f 100644
--- a/patrole_tempest_plugin/tests/api/volume/test_volume_transfers_rbac.py
+++ b/patrole_tempest_plugin/tests/api/volume/test_volume_transfers_rbac.py
@@ -54,22 +54,24 @@
waiters.wait_for_volume_status(self.client, self.volume['id'],
'available')
+ def _create_transfer(self):
+ transfer = self.client.create_volume_transfer(
+ volume_id=self.volume['id'])['transfer']
+ self.addCleanup(self._delete_transfer, transfer)
+ return transfer
+
@rbac_rule_validation.action(service="cinder",
rule="volume:create_transfer")
@decorators.idempotent_id('25413af4-468d-48ff-94ca-4436f8526b3e')
def test_create_volume_transfer(self):
rbac_utils.switch_role(self, switchToRbacRole=True)
- transfer = self.client.create_volume_transfer(
- volume_id=self.volume['id'])['transfer']
- self.addCleanup(self._delete_transfer, transfer)
+ self._create_transfer()
@rbac_rule_validation.action(service="cinder",
- rule="volume:get_all_transfers")
+ rule="volume:get_transfer")
@decorators.idempotent_id('7a0925d3-ed97-4c25-8299-e5cdabe2eb55')
def test_get_volume_transfer(self):
- transfer = self.client.create_volume_transfer(
- volume_id=self.volume['id'])['transfer']
- self.addCleanup(self._delete_transfer, transfer)
+ transfer = self._create_transfer()
rbac_utils.switch_role(self, switchToRbacRole=True)
self.client.show_volume_transfer(transfer['id'])
@@ -84,13 +86,19 @@
rule="volume:accept_transfer")
@decorators.idempotent_id('987f2a11-d657-4984-a6c9-28f06c1cd014')
def test_accept_volume_transfer(self):
- transfer = self.client.create_volume_transfer(
- volume_id=self.volume['id'])['transfer']
- self.addCleanup(self._delete_transfer, transfer)
+ transfer = self._create_transfer()
rbac_utils.switch_role(self, switchToRbacRole=True)
self.client.accept_volume_transfer(transfer['id'],
auth_key=transfer['auth_key'])
+ @rbac_rule_validation.action(service="cinder",
+ rule="volume:delete_transfer")
+ @decorators.idempotent_id('4672187e-7fff-454b-832a-5c8865dda868')
+ def test_delete_volume_transfer(self):
+ transfer = self._create_transfer()
+ rbac_utils.switch_role(self, switchToRbacRole=True)
+ self.client.delete_volume_transfer(transfer['id'])
+
class VolumesTransfersV3RbacTest(VolumesTransfersRbacTest):
_api_version = 3