From 3a4db946fdb0114b5c02f283b55c8679c159848e Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 26 Apr 2019 15:10:56 +0000 Subject: [PATCH] "add_tc_policy_class" must always assign a default value to "min_kbps" This method calls Pyroute2 library. This library needs always a defined value for "rate" (minimum bandwidth). The default value assigned should be 1 (kbps). Change-Id: I07a8e70248892b7fb4590fdec232fa24d8a937e6 Closes-Bug: #1826565 --- neutron/agent/linux/tc_lib.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/neutron/agent/linux/tc_lib.py b/neutron/agent/linux/tc_lib.py index 20bccb4a7bc..3cf38145890 100644 --- a/neutron/agent/linux/tc_lib.py +++ b/neutron/agent/linux/tc_lib.py @@ -68,6 +68,10 @@ class InvalidUnit(exceptions.NeutronException): message = _("Unit name '%(unit)s' is not valid.") +class TcLibPolicyClassInvalidMinKbpsValue(exceptions.NeutronException): + message = _("'min_kbps' is mandatory in a TC class and must be >= 1.") + + def convert_to_kilobits(value, base): value = value.lower() if "bit" in value: @@ -376,7 +380,7 @@ def delete_tc_qdisc(device, parent=None, is_ingress=False, raise_qdisc_not_found=raise_qdisc_not_found, namespace=namespace) -def add_tc_policy_class(device, parent, classid, min_kbps=None, max_kbps=None, +def add_tc_policy_class(device, parent, classid, min_kbps=1, max_kbps=None, burst_kb=None, namespace=None): """Add a TC policy class @@ -390,14 +394,14 @@ def add_tc_policy_class(device, parent, classid, min_kbps=None, max_kbps=None, :return: """ parent = TC_QDISC_PARENT.get(parent, parent) - args = {} # NOTE(ralonsoh): pyroute2 input parameters and units [1]: # - rate (min bw): bytes/second # - ceil (max bw): bytes/second # - burst: bytes # [1] https://www.systutorials.com/docs/linux/man/8-tc/ - if min_kbps: - args['rate'] = int(min_kbps * 1024 / 8) + if int(min_kbps) < 1: + raise TcLibPolicyClassInvalidMinKbpsValue() + args = {'rate': int(min_kbps * 1024 / 8)} if max_kbps: args['ceil'] = int(max_kbps * 1024 / 8) if burst_kb: