Fix cleaning QoS rules for not existing port.

If port update event is received by L2 agent and there is
no QoS policy assigned to such port, agent tries to delete
any existing QoS rules from port.
For bandwidth limit rules OVS qos driver tries to update
port in OVS database.
In case if port not exists in OVS database agent raised
exception.

This patch fixes that by checking if port really exists and
removing QoS bandwidth limit rules only for existing ports.

Change-Id: I3775ee7b383ada6e4e4ace53b5405aa3c7c22027
Closes-Bug: 1712913
This commit is contained in:
Sławek Kapłoński 2017-08-28 20:59:12 +00:00 committed by Slawek Kaplonski
parent 7f25845041
commit 46289c3c74
2 changed files with 47 additions and 0 deletions

View File

@ -664,6 +664,8 @@ class OVSBridge(BaseOVS):
return max_kbps, max_burst_kbps
def delete_egress_bw_limit_for_port(self, port_name):
if not self.port_exists(port_name):
return
self._set_egress_bw_limit_for_port(
port_name, 0, 0)
@ -753,6 +755,11 @@ class OVSBridge(BaseOVS):
return max_kbps, max_burst_kbit
def delete_ingress_bw_limit_for_port(self, port_name):
if not self.port_exists(port_name):
return
self._delete_ingress_bw_limit_for_port(port_name)
def _delete_ingress_bw_limit_for_port(self, port_name):
qos = self._find_qos(port_name)
queue = self._find_queue(port_name, QOS_DEFAULT_QUEUE)
with self.ovsdb.transaction(check_error=True) as txn:

View File

@ -762,6 +762,46 @@ class OVS_Lib_Test(base.BaseTestCase):
with testtools.ExpectedException(Exception):
self.br.get_local_port_mac()
def test_delete_egress_bw_limit_for_port(self):
with mock.patch.object(
self.br, "_set_egress_bw_limit_for_port"
) as set_egress_mock, mock.patch.object(
self.br, "port_exists", return_value=True
) as port_exists_mock:
self.br.delete_egress_bw_limit_for_port("test_port")
port_exists_mock.assert_called_once_with("test_port")
set_egress_mock.assert_called_once_with("test_port", 0, 0)
def test_delete_egress_bw_limit_for_port_port_not_exists(self):
with mock.patch.object(
self.br, "_set_egress_bw_limit_for_port"
) as set_egress_mock, mock.patch.object(
self.br, "port_exists", return_value=False
) as port_exists_mock:
self.br.delete_egress_bw_limit_for_port("test_port")
port_exists_mock.assert_called_once_with("test_port")
set_egress_mock.assert_not_called()
def test_delete_ingress_bw_limit_for_port(self):
with mock.patch.object(
self.br, "_delete_ingress_bw_limit_for_port"
) as delete_ingress_mock, mock.patch.object(
self.br, "port_exists", return_value=True
) as port_exists_mock:
self.br.delete_ingress_bw_limit_for_port("test_port")
port_exists_mock.assert_called_once_with("test_port")
delete_ingress_mock.assert_called_once_with("test_port")
def test_delete_ingress_bw_limit_for_port_port_not_exists(self):
with mock.patch.object(
self.br, "_delete_ingress_bw_limit_for_port"
) as delete_ingress_mock, mock.patch.object(
self.br, "port_exists", return_value=False
) as port_exists_mock:
self.br.delete_ingress_bw_limit_for_port("test_port")
port_exists_mock.assert_called_once_with("test_port")
delete_ingress_mock.assert_not_called()
def test_get_vifs_by_ids(self):
db_list_res = [
{'name': 'qvo1', 'ofport': 1,