Merge "Add qos-pps-minimum-rule-alias API extension"

This commit is contained in:
Zuul 2022-02-14 11:55:48 +00:00 committed by Gerrit Code Review
commit b6e606a909
6 changed files with 196 additions and 0 deletions

View File

@ -556,6 +556,39 @@ rules = [
deprecated_reason=DEPRECATED_REASON, deprecated_reason=DEPRECATED_REASON,
deprecated_since=versionutils.deprecated.WALLABY) 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}/',
},
]
),
] ]

View File

@ -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)

View File

@ -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_default
from neutron_lib.api.definitions import qos_port_network_policy 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
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_pps_rule
from neutron_lib.api.definitions import qos_rule_type_details from neutron_lib.api.definitions import qos_rule_type_details
from neutron_lib.api.definitions import qos_rules_alias from neutron_lib.api.definitions import qos_rules_alias
@ -132,6 +133,7 @@ class QoSPlugin(qos.QoSPluginBase):
qos_port_network_policy.ALIAS, qos_port_network_policy.ALIAS,
qos_pps_rule.ALIAS, qos_pps_rule.ALIAS,
qos_pps_minimum_rule.ALIAS, qos_pps_minimum_rule.ALIAS,
qos_pps_minimum_rule_alias.ALIAS,
] ]
__native_pagination_support = True __native_pagination_support = True

View File

@ -1059,6 +1059,18 @@ class SystemAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase):
self.context, 'get_policy_minimum_packet_rate_rule', self.context, 'get_policy_minimum_packet_rate_rule',
self.alt_target) 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): def test_create_policy_minimum_packet_rate_rule(self):
self.assertRaises( self.assertRaises(
base_policy.InvalidScope, base_policy.InvalidScope,
@ -1083,6 +1095,18 @@ class SystemAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase):
self.context, 'update_policy_minimum_packet_rate_rule', self.context, 'update_policy_minimum_packet_rate_rule',
self.alt_target) 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): def test_delete_policy_minimum_packet_rate_rule(self):
self.assertRaises( self.assertRaises(
base_policy.InvalidScope, base_policy.InvalidScope,
@ -1095,6 +1119,18 @@ class SystemAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase):
self.context, 'delete_policy_minimum_packet_rate_rule', self.context, 'delete_policy_minimum_packet_rate_rule',
self.alt_target) 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( class SystemMemberQosMinimumPacketRateRuleTests(
SystemAdminQosMinimumPacketRateRuleTests): SystemAdminQosMinimumPacketRateRuleTests):
@ -1129,6 +1165,17 @@ class ProjectAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase):
self.context, 'get_policy_minimum_packet_rate_rule', self.context, 'get_policy_minimum_packet_rate_rule',
self.alt_target) 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): def test_create_policy_minimum_packet_rate_rule(self):
self.assertTrue( self.assertTrue(
policy.enforce(self.context, policy.enforce(self.context,
@ -1151,6 +1198,17 @@ class ProjectAdminQosMinimumPacketRateRuleTests(QosRulesAPITestCase):
self.context, 'update_policy_minimum_packet_rate_rule', self.context, 'update_policy_minimum_packet_rate_rule',
self.alt_target) 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): def test_delete_policy_minimum_packet_rate_rule(self):
self.assertTrue( self.assertTrue(
policy.enforce(self.context, policy.enforce(self.context,
@ -1194,6 +1252,18 @@ class ProjectMemberQosMinimumPacketRateRuleTests(
self.context, 'update_policy_minimum_packet_rate_rule', self.context, 'update_policy_minimum_packet_rate_rule',
self.alt_target) 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): def test_delete_policy_minimum_packet_rate_rule(self):
self.assertRaises( self.assertRaises(
base_policy.PolicyNotAuthorized, base_policy.PolicyNotAuthorized,
@ -1206,6 +1276,18 @@ class ProjectMemberQosMinimumPacketRateRuleTests(
self.context, 'delete_policy_minimum_packet_rate_rule', self.context, 'delete_policy_minimum_packet_rate_rule',
self.alt_target) 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( class ProjectReaderQosMinimumPacketRateRuleTests(
ProjectMemberQosMinimumPacketRateRuleTests): ProjectMemberQosMinimumPacketRateRuleTests):

View File

@ -33,6 +33,7 @@ from oslo_utils import uuidutils
import webob.exc import webob.exc
from neutron.exceptions import qos as neutron_qos_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.extensions import qos_rules_alias
from neutron import manager from neutron import manager
from neutron.objects import network as network_object from neutron.objects import network as network_object
@ -1858,6 +1859,19 @@ class QoSRuleAliasTestExtensionManager(object):
return [] 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): class TestQoSRuleAlias(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
def setUp(self): def setUp(self):
@ -1983,6 +1997,30 @@ class TestQoSRuleAlias(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
self.assertEqual(webob.exc.HTTPNotFound.code, res.status_int) 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): class TestQosPluginDB(base.BaseQosTestCase):
PORT_ID = 'f02f160e-1612-11ec-b2b8-bf60ab98186c' PORT_ID = 'f02f160e-1612-11ec-b2b8-bf60ab98186c'

View File

@ -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.