diff --git a/neutron/conf/policies/qos.py b/neutron/conf/policies/qos.py index 8f250c78a6c..05586b38fcc 100644 --- a/neutron/conf/policies/qos.py +++ b/neutron/conf/policies/qos.py @@ -556,6 +556,39 @@ rules = [ deprecated_reason=DEPRECATED_REASON, deprecated_since=versionutils.deprecated.WALLABY) ), + policy.DocumentedRuleDefault( + name='get_alias_minimum_packet_rate_rule', + check_str='rule:get_policy_minimum_packet_rate_rule', + description='Get a QoS minimum packet rate rule through alias', + operations=[ + { + 'method': 'GET', + 'path': '/qos/alias_minimum_packet_rate_rules/{rule_id}/', + }, + ] + ), + policy.DocumentedRuleDefault( + name='update_alias_minimum_packet_rate_rule', + check_str='rule:update_policy_minimum_packet_rate_rule', + description='Update a QoS minimum packet rate rule through alias', + operations=[ + { + 'method': 'PUT', + 'path': '/qos/alias_minimum_packet_rate_rules/{rule_id}/', + }, + ] + ), + policy.DocumentedRuleDefault( + name='delete_alias_minimum_packet_rate_rule', + check_str='rule:delete_policy_minimum_packet_rate_rule', + description='Delete a QoS minimum packet rate rule through alias', + operations=[ + { + 'method': 'DELETE', + 'path': '/qos/alias_minimum_packet_rate_rules/{rule_id}/', + }, + ] + ), ] diff --git a/neutron/extensions/qos_pps_minimum_rule_alias.py b/neutron/extensions/qos_pps_minimum_rule_alias.py new file mode 100644 index 00000000000..37f2cee0643 --- /dev/null +++ b/neutron/extensions/qos_pps_minimum_rule_alias.py @@ -0,0 +1,35 @@ +# Copyright (c) 2021 Ericsson Software Technology +# +# 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 neutron_lib.api.definitions import qos_pps_minimum_rule_alias as apidef +from neutron_lib.api import extensions as api_extensions +from neutron_lib.plugins import constants as nl_pl_const + +from neutron.api.v2 import resource_helper + + +class Qos_pps_minimum_rule_alias(api_extensions.APIExtensionDescriptor): + api_definition = apidef + + @classmethod + def get_resources(cls): + plural_mappings = resource_helper.build_plural_mappings( + {}, apidef.RESOURCE_ATTRIBUTE_MAP) + + return resource_helper.build_resource_info( + plural_mappings, + apidef.RESOURCE_ATTRIBUTE_MAP, + nl_pl_const.QOS, + translate_name=True, + allow_bulk=True) diff --git a/neutron/services/qos/qos_plugin.py b/neutron/services/qos/qos_plugin.py index 4d544037392..21deb88b0d8 100644 --- a/neutron/services/qos/qos_plugin.py +++ b/neutron/services/qos/qos_plugin.py @@ -28,6 +28,7 @@ from neutron_lib.api.definitions import qos_bw_minimum_ingress from neutron_lib.api.definitions import qos_default from neutron_lib.api.definitions import qos_port_network_policy from neutron_lib.api.definitions import qos_pps_minimum_rule +from neutron_lib.api.definitions import qos_pps_minimum_rule_alias from neutron_lib.api.definitions import qos_pps_rule from neutron_lib.api.definitions import qos_rule_type_details from neutron_lib.api.definitions import qos_rules_alias @@ -132,6 +133,7 @@ class QoSPlugin(qos.QoSPluginBase): qos_port_network_policy.ALIAS, qos_pps_rule.ALIAS, qos_pps_minimum_rule.ALIAS, + qos_pps_minimum_rule_alias.ALIAS, ] __native_pagination_support = True diff --git a/neutron/tests/unit/conf/policies/test_qos.py b/neutron/tests/unit/conf/policies/test_qos.py index f87ad95366e..bc2b79e05aa 100644 --- a/neutron/tests/unit/conf/policies/test_qos.py +++ b/neutron/tests/unit/conf/policies/test_qos.py @@ -1059,6 +1059,18 @@ class SystemAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase): self.context, 'get_policy_minimum_packet_rate_rule', self.alt_target) + # And the same for aliases + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'get_alias_minimum_packet_rate_rule', + self.target) + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'get_alias_minimum_packet_rate_rule', + self.alt_target) + def test_create_policy_minimum_packet_rate_rule(self): self.assertRaises( base_policy.InvalidScope, @@ -1083,6 +1095,18 @@ class SystemAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase): self.context, 'update_policy_minimum_packet_rate_rule', self.alt_target) + # And the same for aliases + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'get_alias_minimum_packet_rate_rule', + self.target) + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'get_alias_minimum_packet_rate_rule', + self.alt_target) + def test_delete_policy_minimum_packet_rate_rule(self): self.assertRaises( base_policy.InvalidScope, @@ -1095,6 +1119,18 @@ class SystemAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase): self.context, 'delete_policy_minimum_packet_rate_rule', self.alt_target) + # And the same for aliases + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'delete_alias_minimum_packet_rate_rule', + self.target) + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'delete_alias_minimum_packet_rate_rule', + self.alt_target) + class SystemMemberQosMinimumPacketRateRuleTests( SystemAdminQosMinimumPacketRateRuleTests): @@ -1129,6 +1165,17 @@ class ProjectAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase): self.context, 'get_policy_minimum_packet_rate_rule', self.alt_target) + # And the same for aliases + self.assertTrue( + policy.enforce(self.context, + 'get_alias_minimum_packet_rate_rule', + self.target)) + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'get_alias_minimum_packet_rate_rule', + self.alt_target) + def test_create_policy_minimum_packet_rate_rule(self): self.assertTrue( policy.enforce(self.context, @@ -1151,6 +1198,17 @@ class ProjectAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase): self.context, 'update_policy_minimum_packet_rate_rule', self.alt_target) + # And the same for aliases + self.assertTrue( + policy.enforce(self.context, + 'update_alias_minimum_packet_rate_rule', + self.target)) + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'update_alias_minimum_packet_rate_rule', + self.alt_target) + def test_delete_policy_minimum_packet_rate_rule(self): self.assertTrue( policy.enforce(self.context, @@ -1194,6 +1252,18 @@ class ProjectMemberQosMinimumPacketRateRuleTests( self.context, 'update_policy_minimum_packet_rate_rule', self.alt_target) + # And the same for aliases + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'update_alias_minimum_packet_rate_rule', + self.target) + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'update_alias_minimum_packet_rate_rule', + self.alt_target) + def test_delete_policy_minimum_packet_rate_rule(self): self.assertRaises( base_policy.PolicyNotAuthorized, @@ -1206,6 +1276,18 @@ class ProjectMemberQosMinimumPacketRateRuleTests( self.context, 'delete_policy_minimum_packet_rate_rule', self.alt_target) + # And the same for aliases + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'delete_alias_minimum_packet_rate_rule', + self.target) + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'delete_alias_minimum_packet_rate_rule', + self.alt_target) + class ProjectReaderQosMinimumPacketRateRuleTests( ProjectMemberQosMinimumPacketRateRuleTests): diff --git a/neutron/tests/unit/services/qos/test_qos_plugin.py b/neutron/tests/unit/services/qos/test_qos_plugin.py index 777f8bc7310..eb0cc83ee43 100644 --- a/neutron/tests/unit/services/qos/test_qos_plugin.py +++ b/neutron/tests/unit/services/qos/test_qos_plugin.py @@ -33,6 +33,7 @@ from oslo_utils import uuidutils import webob.exc from neutron.exceptions import qos as neutron_qos_exc +from neutron.extensions import qos_pps_minimum_rule_alias from neutron.extensions import qos_rules_alias from neutron import manager from neutron.objects import network as network_object @@ -1858,6 +1859,19 @@ class QoSRuleAliasTestExtensionManager(object): return [] +class QoSRuleAliasMinimumPacketRateTestExtensionManager(object): + + def get_resources(self): + return qos_pps_minimum_rule_alias.Qos_pps_minimum_rule_alias.\ + get_resources() + + def get_actions(self): + return [] + + def get_request_extensions(self): + return [] + + class TestQoSRuleAlias(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): def setUp(self): @@ -1983,6 +1997,30 @@ class TestQoSRuleAlias(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): self.assertEqual(webob.exc.HTTPNotFound.code, res.status_int) +class TestQoSRuleAliasMinimumPacketRate(TestQoSRuleAlias): + def setUp(self): + # Remove MissingAuthPlugin exception from logs + self.patch_notifier = mock.patch( + 'neutron.notifiers.batch_notifier.BatchNotifier._notify') + self.patch_notifier.start() + plugin = 'ml2' + service_plugins = {'qos_plugin_name': SERVICE_PLUGIN_KLASS} + ext_mgr = QoSRuleAliasMinimumPacketRateTestExtensionManager() + super(TestQoSRuleAlias, self).setUp(plugin=plugin, ext_mgr=ext_mgr, + service_plugins=service_plugins) + self.qos_plugin = directory.get_plugin(plugins_constants.QOS) + + self.ctxt = context.Context('fake_user', 'fake_tenant') + self.rule_objects = { + 'minimum_packet_rate': rule_object.QosMinimumPacketRateRule + } + + self.qos_policy_id = uuidutils.generate_uuid() + self.rule_data = { + 'minimum_packet_rate_rule': {'min_kpps': 10, 'direction': 'any'} + } + + class TestQosPluginDB(base.BaseQosTestCase): PORT_ID = 'f02f160e-1612-11ec-b2b8-bf60ab98186c' diff --git a/releasenotes/notes/qos-pps-minimum-rule-alias-dbd652445a033f31.yaml b/releasenotes/notes/qos-pps-minimum-rule-alias-dbd652445a033f31.yaml new file mode 100644 index 00000000000..5e56ad7462c --- /dev/null +++ b/releasenotes/notes/qos-pps-minimum-rule-alias-dbd652445a033f31.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Added ``qos-pps-minimum-rule-alias`` API extension to enable GET, PUT and + DELETE operations on QoS minimum packet rate rule without specifying + policy ID.