From 0a185354a16d2bbd87bea4371933032d0f349e60 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 14 Jun 2017 15:46:28 +0100 Subject: [PATCH] TC doesn't rise exception if device doesn't exist If device doesn't exit, TC doesn't need to raise an exception during the deletion of the qdisc. In iproute2 source code [1], the error code used is "1". [1] https://kernel.googlesource.com/pub/scm/linux/kernel/git/shemminger/iproute2/+/master/tc/tc_qdisc.c#188 Change-Id: I9abecd6ef9d74abff27fb0ed0f5f4535c0622fd6 Closes-Bug: #1697937 --- neutron/agent/linux/tc_lib.py | 4 +++- neutron/tests/unit/agent/linux/test_tc_lib.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/neutron/agent/linux/tc_lib.py b/neutron/agent/linux/tc_lib.py index df6de290b04..aefc41f2aa6 100644 --- a/neutron/agent/linux/tc_lib.py +++ b/neutron/agent/linux/tc_lib.py @@ -200,7 +200,9 @@ class TcCommand(ip_lib.IPDevice): # Return_code=2 is fine because it means # "RTNETLINK answers: No such file or directory" what is fine when we # are trying to delete qdisc - return self._execute_tc_cmd(cmd, extra_ok_codes=[2]) + # Return_code=1 means "RTNETLINK answers: Cannot find device ". + # If the device doesn't exist, the qdisc is already deleted. + return self._execute_tc_cmd(cmd, extra_ok_codes=[1, 2]) def _get_tbf_burst_value(self, bw_limit, burst_limit): min_burst_value = float(bw_limit) / float(self.kernel_hz) diff --git a/neutron/tests/unit/agent/linux/test_tc_lib.py b/neutron/tests/unit/agent/linux/test_tc_lib.py index 4a3fcf726ba..851d276ea42 100644 --- a/neutron/tests/unit/agent/linux/test_tc_lib.py +++ b/neutron/tests/unit/agent/linux/test_tc_lib.py @@ -218,7 +218,7 @@ class TestTcCommand(base.BaseTestCase): run_as_root=True, check_exit_code=True, log_fail_as_error=True, - extra_ok_codes=[2] + extra_ok_codes=[1, 2] ), mock.call( ['tc', 'qdisc', 'add', 'dev', DEVICE_NAME, "ingress", @@ -263,7 +263,7 @@ class TestTcCommand(base.BaseTestCase): run_as_root=True, check_exit_code=True, log_fail_as_error=True, - extra_ok_codes=[2] + extra_ok_codes=[1, 2] ) def test_delete_tbf_bw_limit(self): @@ -273,7 +273,7 @@ class TestTcCommand(base.BaseTestCase): run_as_root=True, check_exit_code=True, log_fail_as_error=True, - extra_ok_codes=[2] + extra_ok_codes=[1, 2] ) def test_get_ingress_qdisc_burst_value_burst_not_none(self):