From 73d9f957b36eb68525655730fab48dc653f950cf Mon Sep 17 00:00:00 2001 From: Mykola Yakovliev Date: Sat, 28 Jul 2018 11:03:32 -0500 Subject: [PATCH] Add tests to cover flavors This patch set adds tests to cver the flavors API [0]. Test lists, gets, creates, updates, and deletes flavors. Part of "Increase Neutron RBAC Coverage" initiative [1] [0] https://developer.openstack.org/api-ref/network/v2/index.html#networking-flavors-framework-v2-0-current-flavor-service-profile [1] https://storyboard.openstack.org/#!/story/2002641 Change-Id: I526d1567b715c0a57e73fa6645d8a98b9b45c62e Story: 2002641 Task: 22316 --- .../tests/api/network/test_flavors_rbac.py | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 patrole_tempest_plugin/tests/api/network/test_flavors_rbac.py diff --git a/patrole_tempest_plugin/tests/api/network/test_flavors_rbac.py b/patrole_tempest_plugin/tests/api/network/test_flavors_rbac.py new file mode 100644 index 00000000..cdc98524 --- /dev/null +++ b/patrole_tempest_plugin/tests/api/network/test_flavors_rbac.py @@ -0,0 +1,118 @@ +# Copyright 2018 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.network import rbac_base as base + + +class FlavorsPluginRbacTest(base.BaseNetworkPluginRbacTest): + + @classmethod + def resource_setup(cls): + super(FlavorsPluginRbacTest, cls).resource_setup() + providers = cls.ntp_client.list_service_providers() + if not providers["service_providers"]: + raise cls.skipException("No service_providers available.") + cls.service_type = providers["service_providers"][0]["service_type"] + + @decorators.idempotent_id('2632a61b-831e-4da5-82c8-a5f7d448589b') + @rbac_rule_validation.action(service="neutron", + rules=["create_flavor"]) + def test_create_flavor(self): + """Create flavor. + + RBAC test for the neutron "create_flavor" policy + """ + with self.rbac_utils.override_role(self): + flavor = self.ntp_client.create_flavor( + service_type=self.service_type) + + self.addCleanup( + test_utils.call_and_ignore_notfound_exc, + self.ntp_client.delete_flavor, flavor["flavor"]["id"]) + + @decorators.idempotent_id('9c53164c-117d-4b44-a5cb-96f08386513f') + @rbac_rule_validation.action(service="neutron", + rules=["get_flavor", + "update_flavor"], + expected_error_codes=[404, 403]) + def test_update_flavor(self): + """Update flavor. + + RBAC test for the neutron "update_flavor" policy + """ + flavor = self.ntp_client.create_flavor(service_type=self.service_type) + self.addCleanup( + test_utils.call_and_ignore_notfound_exc, + self.ntp_client.delete_flavor, flavor["flavor"]["id"]) + + name = data_utils.rand_name(self.__class__.__name__ + '-Flavor') + with self.rbac_utils.override_role(self): + self.ntp_client.update_flavor(flavor["flavor"]["id"], name=name) + + @decorators.idempotent_id('1de15f9e-5080-4259-ab41-e230bb312de8') + @rbac_rule_validation.action(service="neutron", + rules=["get_flavor", + "delete_flavor"], + expected_error_codes=[404, 403]) + def test_delete_flavor(self): + """Delete flavor. + + RBAC test for the neutron "delete_flavor" policy + """ + flavor = self.ntp_client.create_flavor(service_type=self.service_type) + self.addCleanup( + test_utils.call_and_ignore_notfound_exc, + self.ntp_client.delete_flavor, flavor["flavor"]["id"]) + + with self.rbac_utils.override_role(self): + self.ntp_client.delete_flavor(flavor["flavor"]["id"]) + + @decorators.idempotent_id('c2baf35f-e6c1-4833-9114-aadd9b1f6aaa') + @rbac_rule_validation.action(service="neutron", + rules=["get_flavor"], + expected_error_codes=[404]) + def test_show_flavor(self): + """Show flavor. + + RBAC test for the neutron "get_flavor" policy + """ + flavor = self.ntp_client.create_flavor(service_type=self.service_type) + self.addCleanup( + test_utils.call_and_ignore_notfound_exc, + self.ntp_client.delete_flavor, flavor["flavor"]["id"]) + + with self.rbac_utils.override_role(self): + self.ntp_client.show_flavor(flavor["flavor"]["id"]) + + @decorators.idempotent_id('ab10bd5d-987e-4255-966f-947670ffd0fa') + @rbac_rule_validation.action(service="neutron", + rules=["get_flavors"]) + def test_list_flavors(self): + """List flavors. + + RBAC test for the neutron "get_flavors" policy + """ + flavor = self.ntp_client.create_flavor(service_type=self.service_type) + self.addCleanup( + test_utils.call_and_ignore_notfound_exc, + self.ntp_client.delete_flavor, flavor["flavor"]["id"]) + + with self.rbac_utils.override_role(self): + self.ntp_client.list_flavors()