Add QoS packet rate limit rule object and CRUD operations

Related-Bug: #2099747
Change-Id: I061772cc7fd45ba137ceab7a2f90c3dce15d5c9d
This commit is contained in:
Rodolfo Alonso Hernandez
2025-03-17 16:06:22 +00:00
parent de7fa8725f
commit cbf29120bd
8 changed files with 449 additions and 1 deletions

View File

@@ -152,7 +152,12 @@ QoS Operations
qos_bandwidth_limit_rules,
create_qos_dscp_marking_rule, update_qos_dscp_marking_rule,
delete_qos_dscp_marking_rule, get_qos_dscp_marking_rule,
find_qos_dscp_marking_rule, qos_dscp_marking_rules
find_qos_dscp_marking_rule, qos_dscp_marking_rules,
create_qos_packet_rate_limit_rule,
update_qos_packet_rate_limit_rule,
delete_qos_packet_rate_limit_rule,
get_qos_packet_rate_limit_rule,
find_qos_packet_rate_limit_rule,
Agent Operations
^^^^^^^^^^^^^^^^

View File

@@ -0,0 +1,13 @@
openstack.network.v2.qos_packet_rate_limit_rule
===============================================
.. automodule:: openstack.network.v2.qos_packet_rate_limit_rule
The QoSPacketRateLimitRule Class
----------------------------------
The ``QoSPacketRateLimitRule`` class inherits from
:class:`~openstack.resource.Resource`.
.. autoclass:: openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule
:members:

View File

@@ -73,6 +73,9 @@ from openstack.network.v2 import (
from openstack.network.v2 import (
qos_minimum_packet_rate_rule as _qos_minimum_packet_rate_rule,
)
from openstack.network.v2 import (
qos_packet_rate_limit_rule as _qos_packet_rate_limit_rule,
)
from openstack.network.v2 import qos_policy as _qos_policy
from openstack.network.v2 import qos_rule_type as _qos_rule_type
from openstack.network.v2 import quota as _quota
@@ -3702,6 +3705,148 @@ class Proxy(proxy.Proxy):
**attrs,
)
def create_qos_packet_rate_limit_rule(self, qos_policy, **attrs):
"""Create a new packet rate limit rule
:param attrs: Keyword arguments which will be used to create a
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`,
comprised of the properties on the QoSPacketRateLimitRule class.
:param qos_policy: The value can be the ID of the QoS policy that the
rule belongs or a
:class:`~openstack.network.v2.qos_policy.QoSPolicy` instance.
:returns: The results of resource creation
:rtype:
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
"""
policy = self._get_resource(_qos_policy.QoSPolicy, qos_policy)
return self._create(
_qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
qos_policy_id=policy.id,
**attrs,
)
def delete_qos_packet_rate_limit_rule(
self, qos_rule, qos_policy, ignore_missing=True
):
"""Delete a packet rate limit rule
:param qos_rule: The value can be either the ID of a packet rate limit
rule or a
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
instance.
:param qos_policy: The value can be the ID of the QoS policy that the
rule belongs or a
:class:`~openstack.network.v2.qos_policy.QoSPolicy` instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.NotFoundException` will be raised when
the resource does not exist. When set to ``True``, no exception
will be set when attempting to delete a nonexistent minimum packet
rate rule.
:returns: ``None``
"""
policy = self._get_resource(_qos_policy.QoSPolicy, qos_policy)
self._delete(
_qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
qos_rule,
ignore_missing=ignore_missing,
qos_policy_id=policy.id,
)
def find_qos_packet_rate_limit_rule(
self, qos_rule_id, qos_policy, ignore_missing=True, **query
):
"""Find a packet rate limit rule
:param qos_rule_id: The ID of a packet rate limit rule.
:param qos_policy: The value can be the ID of the QoS policy that the
rule belongs or a
:class:`~openstack.network.v2.qos_policy.QoSPolicy` instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.NotFoundException` will be raised when
the resource does not exist. When set to ``True``, None will be
returned when attempting to find a nonexistent resource.
:param dict query: Any additional parameters to be passed into
underlying methods. such as query filters.
:returns: One
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
or None
"""
policy = self._get_resource(_qos_policy.QoSPolicy, qos_policy)
return self._find(
_qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
qos_rule_id,
ignore_missing=ignore_missing,
qos_policy_id=policy.id,
**query,
)
def get_qos_packet_rate_limit_rule(self, qos_rule, qos_policy):
"""Get a single packet rate limit rule
:param qos_rule: The value can be the ID of a packet rate limit rule
or a
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
instance.
:param qos_policy: The value can be the ID of the QoS policy that the
rule belongs or a
:class:`~openstack.network.v2.qos_policy.QoSPolicy` instance.
:returns: One
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
:raises: :class:`~openstack.exceptions.NotFoundException` when no
resource can be found.
"""
policy = self._get_resource(_qos_policy.QoSPolicy, qos_policy)
return self._get(
_qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
qos_rule,
qos_policy_id=policy.id,
)
def qos_packet_rate_limit_rules(self, qos_policy, **query):
"""Return a generator of packet rate limit rules
:param qos_policy: The value can be the ID of the QoS policy that the
rule belongs or a
:class:`~openstack.network.v2.qos_policy.QoSPolicy` instance.
:param kwargs query: Optional query parameters to be sent to limit the
resources being returned.
:returns: A generator of minimum packet rate rule objects
:rtype:
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
"""
policy = self._get_resource(_qos_policy.QoSPolicy, qos_policy)
return self._list(
_qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
qos_policy_id=policy.id,
**query,
)
def update_qos_packet_rate_limit_rule(self, qos_rule, qos_policy, **attrs):
"""Update a minimum packet rate rule
:param qos_rule: Either the id of a minimum packet rate rule or a
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
instance.
:param qos_policy: The value can be the ID of the QoS policy that the
rule belongs or a
:class:`~openstack.network.v2.qos_policy.QoSPolicy` instance.
:param attrs: The attributes to update on the minimum packet rate rule
represented by ``qos_rule``.
:returns: The updated minimum packet rate rule
:rtype:
:class:`~openstack.network.v2.qos_packet_rate_limit_rule.QoSPacketRateLimitRule`
"""
policy = self._get_resource(_qos_policy.QoSPolicy, qos_policy)
return self._update(
_qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
qos_rule,
qos_policy_id=policy.id,
**attrs,
)
def create_qos_policy(self, **attrs):
"""Create a new QoS policy from attributes

View File

@@ -0,0 +1,39 @@
# 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 openstack import resource
class QoSPacketRateLimitRule(resource.Resource):
resource_key = 'packet_rate_limit_rule'
resources_key = resource_key + 's'
base_path = '/qos/policies/%(qos_policy_id)s/' + resources_key
_allow_unknown_attrs_in_body = True
# capabilities
allow_create = True
allow_fetch = True
allow_commit = True
allow_delete = True
allow_list = True
# Properties
#: The ID of the QoS policy who owns rule.
qos_policy_id = resource.URI('qos_policy_id')
#: Maximum packet rare in kpps.
max_kpps = resource.Body('max_kpps')
#: Maximum burst packet rate in kpps.
max_burst_kpps = resource.Body('max_burst_kpps')
#: Traffic direction from the tenant point of view ('egress', 'ingress',
# 'any').
direction = resource.Body('direction')

View File

@@ -0,0 +1,115 @@
# 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 openstack.network.v2 import (
qos_packet_rate_limit_rule as _qos_packet_rate_limit_rule,
)
from openstack.tests.functional import base
class TestQoSPacketRateLimitRule(base.BaseFunctionalTest):
QOS_POLICY_ID = None
QOS_IS_SHARED = False
QOS_POLICY_DESCRIPTION = 'QoS policy description'
RULE_MAX_KPPS = 1500
RULE_MAX_KPPS_NEW = 1800
RULE_MAX_BURST_KPPS = 1100
RULE_MAX_BURST_KPPS_NEW = 1300
RULE_DIRECTION = 'egress'
RULE_DIRECTION_NEW = 'ingress'
RULE_DIRECTION_NEW_2 = 'any'
def setUp(self):
super().setUp()
if not self.operator_cloud:
self.skipTest('Operator cloud required for this test')
# Skip the tests if qos-bw-limit-direction extension is not enabled.
if not self.operator_cloud.network.find_extension('qos-pps'):
self.skipTest("Network qos-pps extension disabled")
self.QOS_POLICY_NAME = self.getUniqueString()
self.RULE_ID = self.getUniqueString()
qos_policy = self.operator_cloud.network.create_qos_policy(
description=self.QOS_POLICY_DESCRIPTION,
name=self.QOS_POLICY_NAME,
shared=self.QOS_IS_SHARED,
)
self.QOS_POLICY_ID = qos_policy.id
qos_rule = (
self.operator_cloud.network.create_qos_packet_rate_limit_rule(
self.QOS_POLICY_ID,
max_kpps=self.RULE_MAX_KPPS,
max_burst_kpps=self.RULE_MAX_BURST_KPPS,
direction=self.RULE_DIRECTION,
)
)
assert isinstance(
qos_rule, _qos_packet_rate_limit_rule.QoSPacketRateLimitRule
)
self.assertEqual(self.RULE_MAX_KPPS, qos_rule.max_kpps)
self.assertEqual(self.RULE_MAX_BURST_KPPS, qos_rule.max_burst_kpps)
self.assertEqual(self.RULE_DIRECTION, qos_rule.direction)
self.RULE_ID = qos_rule.id
def tearDown(self):
rule = self.operator_cloud.network.delete_qos_packet_rate_limit_rule(
self.RULE_ID, self.QOS_POLICY_ID
)
qos_policy = self.operator_cloud.network.delete_qos_policy(
self.QOS_POLICY_ID
)
self.assertIsNone(rule)
self.assertIsNone(qos_policy)
super().tearDown()
def test_find(self):
sot = self.operator_cloud.network.find_qos_packet_rate_limit_rule(
self.RULE_ID, self.QOS_POLICY_ID
)
self.assertEqual(self.RULE_ID, sot.id)
self.assertEqual(self.RULE_MAX_KPPS, sot.max_kpps)
self.assertEqual(self.RULE_MAX_BURST_KPPS, sot.max_burst_kpps)
self.assertEqual(self.RULE_DIRECTION, sot.direction)
def test_get(self):
sot = self.operator_cloud.network.get_qos_packet_rate_limit_rule(
self.RULE_ID, self.QOS_POLICY_ID
)
self.assertEqual(self.RULE_ID, sot.id)
self.assertEqual(self.QOS_POLICY_ID, sot.qos_policy_id)
self.assertEqual(self.RULE_MAX_KPPS, sot.max_kpps)
self.assertEqual(self.RULE_MAX_BURST_KPPS, sot.max_burst_kpps)
self.assertEqual(self.RULE_DIRECTION, sot.direction)
def test_list(self):
rule_ids = [
o.id
for o in self.operator_cloud.network.qos_packet_rate_limit_rules(
self.QOS_POLICY_ID
)
]
self.assertIn(self.RULE_ID, rule_ids)
def test_update(self):
sot = self.operator_cloud.network.update_qos_packet_rate_limit_rule(
self.RULE_ID,
self.QOS_POLICY_ID,
max_kpps=self.RULE_MAX_KPPS_NEW,
max_burst_kpps=self.RULE_MAX_BURST_KPPS_NEW,
direction=self.RULE_DIRECTION_NEW,
)
self.assertEqual(self.RULE_MAX_KPPS_NEW, sot.max_kpps)
self.assertEqual(self.RULE_MAX_BURST_KPPS_NEW, sot.max_burst_kpps)
self.assertEqual(self.RULE_DIRECTION_NEW, sot.direction)

View File

@@ -53,6 +53,7 @@ from openstack.network.v2 import qos_bandwidth_limit_rule
from openstack.network.v2 import qos_dscp_marking_rule
from openstack.network.v2 import qos_minimum_bandwidth_rule
from openstack.network.v2 import qos_minimum_packet_rate_rule
from openstack.network.v2 import qos_packet_rate_limit_rule
from openstack.network.v2 import qos_policy
from openstack.network.v2 import qos_rule_type
from openstack.network.v2 import quota
@@ -1232,6 +1233,82 @@ class TestNetworkQosMinimumPacketRate(TestNetworkProxy):
)
class TestNetworkQosPacketRateLimitRule(TestNetworkProxy):
def test_qos_packet_rate_limit_rule_create_attrs(self):
self.verify_create(
self.proxy.create_qos_packet_rate_limit_rule,
qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
method_kwargs={'qos_policy': QOS_POLICY_ID},
expected_kwargs={'qos_policy_id': QOS_POLICY_ID},
)
def test_qos_packet_rate_limit_rule_delete(self):
self.verify_delete(
self.proxy.delete_qos_packet_rate_limit_rule,
qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
ignore_missing=False,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID},
)
def test_qos_packet_rate_limit_rule_delete_ignore(self):
self.verify_delete(
self.proxy.delete_qos_packet_rate_limit_rule,
qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
ignore_missing=True,
method_args=["resource_or_id", QOS_POLICY_ID],
expected_args=["resource_or_id"],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID},
)
def test_qos_packet_rate_limit_rule_find(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify(
'openstack.proxy.Proxy._find',
self.proxy.find_qos_packet_rate_limit_rule,
method_args=['rule_id', policy],
expected_args=[
qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
'rule_id',
],
expected_kwargs={
'ignore_missing': True,
'qos_policy_id': QOS_POLICY_ID,
},
)
def test_qos_packet_rate_limit_rule_get(self):
self.verify_get(
self.proxy.get_qos_packet_rate_limit_rule,
qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
method_kwargs={'qos_policy': QOS_POLICY_ID},
expected_kwargs={'qos_policy_id': QOS_POLICY_ID},
)
def test_qos_packet_rate_limit_rules(self):
self.verify_list(
self.proxy.qos_packet_rate_limit_rules,
qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
method_kwargs={'qos_policy': QOS_POLICY_ID},
expected_kwargs={'qos_policy_id': QOS_POLICY_ID},
)
def test_qos_packet_rate_limit_rule_update(self):
policy = qos_policy.QoSPolicy.new(id=QOS_POLICY_ID)
self._verify(
'openstack.network.v2._proxy.Proxy._update',
self.proxy.update_qos_packet_rate_limit_rule,
method_args=['rule_id', policy],
method_kwargs={'foo': 'bar'},
expected_args=[
qos_packet_rate_limit_rule.QoSPacketRateLimitRule,
'rule_id',
],
expected_kwargs={'qos_policy_id': QOS_POLICY_ID, 'foo': 'bar'},
)
class TestNetworkQosRuleType(TestNetworkProxy):
def test_qos_rule_type_find(self):
self.verify_find(

View File

@@ -0,0 +1,49 @@
# 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.
import uuid
from openstack.network.v2 import qos_packet_rate_limit_rule
from openstack.tests.unit import base
EXAMPLE = {
'id': 'IDENTIFIER',
'qos_policy_id': 'qos-policy-' + uuid.uuid4().hex,
'max_kpps': 1600,
'max_burst_kpps': 1300,
'direction': 'any',
}
class TestQoSBandwidthLimitRule(base.TestCase):
def test_basic(self):
sot = qos_packet_rate_limit_rule.QoSPacketRateLimitRule()
self.assertEqual('packet_rate_limit_rule', sot.resource_key)
self.assertEqual('packet_rate_limit_rules', sot.resources_key)
self.assertEqual(
'/qos/policies/%(qos_policy_id)s/packet_rate_limit_rules',
sot.base_path,
)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_fetch)
self.assertTrue(sot.allow_commit)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = qos_packet_rate_limit_rule.QoSPacketRateLimitRule(**EXAMPLE)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['qos_policy_id'], sot.qos_policy_id)
self.assertEqual(EXAMPLE['max_kpps'], sot.max_kpps)
self.assertEqual(EXAMPLE['max_burst_kpps'], sot.max_burst_kpps)
self.assertEqual(EXAMPLE['direction'], sot.direction)

View File

@@ -0,0 +1,5 @@
---
features:
- |
Added Neutron QoS packet rate limit rule object and introduced support for
CRUD operations.