From 3c1de67be7509d1c16c2ed2414fe2ae6d1fb7957 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Fri, 26 May 2017 23:48:47 +0100 Subject: [PATCH] Subnet rbac tests Add rbac tests for subnet-related network policy actions. This commit adds coverage for the following policy actions: * create_subnet * get_subnet * update_subnet * delete_subnet Note that policy actions like create_subnet:segment_id and get_subnet:segment_id have not been included because it is not clear how to enforce them (same with create_subnet:service_types: service_types is not even an attribute exposed in the subnet v2.0 documentation). Change-Id: I982fde3e065cbf966a03754e99dae8c3fe8715b9 --- .../tests/api/network/test_subnets_rbac.py | 96 +++++++++++++++++++ .../subnet-rbac-tests-6d3cf54e39a7b486.yaml | 10 ++ 2 files changed, 106 insertions(+) create mode 100644 patrole_tempest_plugin/tests/api/network/test_subnets_rbac.py create mode 100644 releasenotes/notes/subnet-rbac-tests-6d3cf54e39a7b486.yaml diff --git a/patrole_tempest_plugin/tests/api/network/test_subnets_rbac.py b/patrole_tempest_plugin/tests/api/network/test_subnets_rbac.py new file mode 100644 index 00000000..68f51565 --- /dev/null +++ b/patrole_tempest_plugin/tests/api/network/test_subnets_rbac.py @@ -0,0 +1,96 @@ +# 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 import decorators +from tempest import test + +from patrole_tempest_plugin import rbac_rule_validation +from patrole_tempest_plugin.tests.api.network import rbac_base as base + + +class SubnetsRbacTest(base.BaseNetworkRbacTest): + + @classmethod + def skip_checks(cls): + super(SubnetsRbacTest, cls).skip_checks() + if not test.is_extension_enabled('subnet_allocation', 'network'): + msg = "subnet_allocation extension not enabled." + raise cls.skipException(msg) + + @classmethod + def resource_setup(cls): + super(SubnetsRbacTest, cls).resource_setup() + cls.network = cls.create_network() + cls.subnet = cls.create_subnet(cls.network) + + @decorators.idempotent_id('0481adeb-4301-44d5-851c-35910cc18a6b') + @rbac_rule_validation.action(service="neutron", + rule="create_subnet") + def test_create_subnet(self): + """Create subnet. + + RBAC test for the neutron "create_subnet" policy + """ + self.rbac_utils.switch_role(self, toggle_rbac_role=True) + self.create_subnet(self.network) + + @decorators.idempotent_id('c02618e7-bb20-4abd-83c8-6eec2af08752') + @rbac_rule_validation.action(service="neutron", + rule="get_subnet") + def test_show_subnet(self): + """Show subnet. + + RBAC test for the neutron "get_subnet" policy + """ + self.rbac_utils.switch_role(self, toggle_rbac_role=True) + self.subnets_client.show_subnet(self.subnet['id']) + + @decorators.idempotent_id('e2ddc415-5cab-43f4-9b61-166aed65d637') + @rbac_rule_validation.action(service="neutron", + rule="get_subnet") + def test_list_subnets(self): + """List subnets. + + RBAC test for the neutron "get_subnet" policy + """ + self.rbac_utils.switch_role(self, toggle_rbac_role=True) + self.subnets_client.list_subnets() + + @decorators.idempotent_id('f36cd821-dd22-4bd0-b43d-110fc4b553eb') + @rbac_rule_validation.action(service="neutron", + rule="update_subnet") + def test_update_subnet(self): + """Update subnet. + + RBAC test for the neutron "update_subnet" policy + """ + update_name = data_utils.rand_name(self.__class__.__name__ + '-Subnet') + + self.rbac_utils.switch_role(self, toggle_rbac_role=True) + self.subnets_client.update_subnet(self.subnet['id'], name=update_name) + + @decorators.idempotent_id('bcfc7153-bbd1-43a4-a908-b3e1b0cde0dc') + @rbac_rule_validation.action(service="neutron", + rule="delete_subnet") + def test_delete_subnet(self): + """Delete subnet. + + RBAC test for the neutron "delete_subnet" policy + """ + subnet = self.create_subnet(self.network) + + self.rbac_utils.switch_role(self, toggle_rbac_role=True) + self.subnets_client.delete_subnet(subnet['id']) diff --git a/releasenotes/notes/subnet-rbac-tests-6d3cf54e39a7b486.yaml b/releasenotes/notes/subnet-rbac-tests-6d3cf54e39a7b486.yaml new file mode 100644 index 00000000..8d3d22ac --- /dev/null +++ b/releasenotes/notes/subnet-rbac-tests-6d3cf54e39a7b486.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + Add RBAC tests for network subnet endpoints, providing coverage for the + following policy actions: + + * create_subnet + * get_subnet + * update_subnet + * delete_subnet