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
This commit is contained in:
Rodolfo Alonso Hernandez 2017-06-14 15:46:28 +01:00
parent 044a06383b
commit 0a185354a1
2 changed files with 6 additions and 4 deletions

View File

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

View File

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