Add qos-pps-minimum-rule-alias API extension
Introduce a new API extension to enable GET, PUT and DELETE operations on QoS minimum packet rate rule without specifying policy ID. Partial-Bug: #1922237 See-Also: https://review.opendev.org/785236 Change-Id: Ia083b5ac98c9e18ddbcdd2e0fc46f2f8432a628c
This commit is contained in:
parent
a88a8ab413
commit
084bb163f2
@ -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}/',
|
||||
},
|
||||
]
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
35
neutron/extensions/qos_pps_minimum_rule_alias.py
Normal file
35
neutron/extensions/qos_pps_minimum_rule_alias.py
Normal 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)
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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'
|
||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user