From a31609cb69bc7625443d8ce8eba4405c2094243b Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Mon, 27 Jul 2020 11:26:45 +0000 Subject: [PATCH] Add "if_exists" parameter to "QoSDelCommand" If the flag is set and the Logical Switch does not exist, the command will exist without raising any exception. Change-Id: Id97af258f1f7158c0593241a196dc506db7f8d9c Related-Bug: #1888828 --- ovsdbapp/schema/ovn_northbound/api.py | 5 ++++- ovsdbapp/schema/ovn_northbound/commands.py | 12 ++++++++++-- ovsdbapp/schema/ovn_northbound/impl_idl.py | 6 ++++-- .../schema/ovn_northbound/test_impl_idl.py | 7 +++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ovsdbapp/schema/ovn_northbound/api.py b/ovsdbapp/schema/ovn_northbound/api.py index f5e7b706..65e9b276 100644 --- a/ovsdbapp/schema/ovn_northbound/api.py +++ b/ovsdbapp/schema/ovn_northbound/api.py @@ -220,7 +220,8 @@ class API(api.API, metaclass=abc.ABCMeta): """ @abc.abstractmethod - def qos_del(self, switch, direction=None, priority=None, match=None): + def qos_del(self, switch, direction=None, priority=None, match=None, + if_exists=True): """Remove Qos rules from 'switch' If only switch is supplied, all the QoS rules from the logical switch @@ -237,6 +238,8 @@ class API(api.API, metaclass=abc.ABCMeta): :type priority: int :param match: The match rule :type match: string + :param if_exists: Do not fail if the Logical_Switch row does not exist + :type if_exists: bool :returns: :class:`Command` with no result """ diff --git a/ovsdbapp/schema/ovn_northbound/commands.py b/ovsdbapp/schema/ovn_northbound/commands.py index dee9d102..7c1808c0 100644 --- a/ovsdbapp/schema/ovn_northbound/commands.py +++ b/ovsdbapp/schema/ovn_northbound/commands.py @@ -270,7 +270,7 @@ class QoSAddCommand(cmd.AddCommand): class QoSDelCommand(cmd.BaseCommand): def __init__(self, api, switch, direction=None, - priority=None, match=None): + priority=None, match=None, if_exists=True): if (priority is None) != (match is None): raise TypeError("Must specify priority and match together") if priority is not None and not direction: @@ -278,6 +278,7 @@ class QoSDelCommand(cmd.BaseCommand): super(QoSDelCommand, self).__init__(api) self.switch = switch self.conditions = [] + self.if_exists = if_exists if direction: self.conditions.append(('direction', '=', direction)) # priority can be 0 @@ -286,7 +287,14 @@ class QoSDelCommand(cmd.BaseCommand): ('match', '=', match)] def run_idl(self, txn): - ls = self.api.lookup('Logical_Switch', self.switch) + try: + ls = self.api.lookup('Logical_Switch', self.switch) + except idlutils.RowNotFound: + if self.if_exists: + return + msg = 'Logical Switch %s does not exist' % self.switch + raise RuntimeError(msg) + for row in ls.qos_rules: if idlutils.row_match(row, self.conditions): ls.delvalue('qos_rules', row) diff --git a/ovsdbapp/schema/ovn_northbound/impl_idl.py b/ovsdbapp/schema/ovn_northbound/impl_idl.py index a1bc7919..bcb07233 100644 --- a/ovsdbapp/schema/ovn_northbound/impl_idl.py +++ b/ovsdbapp/schema/ovn_northbound/impl_idl.py @@ -83,8 +83,10 @@ class OvnNbApiIdlImpl(ovs_idl.Backend, api.API): return cmd.QoSAddCommand(self, switch, direction, priority, match, rate, burst, dscp, may_exist, **columns) - def qos_del(self, switch, direction=None, priority=None, match=None): - return cmd.QoSDelCommand(self, switch, direction, priority, match) + def qos_del(self, switch, direction=None, priority=None, match=None, + if_exists=True): + return cmd.QoSDelCommand(self, switch, direction, priority, match, + if_exists) def qos_list(self, switch): return cmd.QoSListCommand(self, switch) diff --git a/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py b/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py index 08222b83..d1df5437 100644 --- a/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py +++ b/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py @@ -310,6 +310,13 @@ class TestQoSOps(OvnNorthboundTest): self.assertRaises(TypeError, self.api.qos_del, self.switch.uuid, priority=0) + def test_qos_del_ls_not_present_if_exists_true(self): + self.api.qos_del('some_other_ls').execute(check_error=True) + + def test_qos_del_ls_not_present_if_exists_false(self): + cmd = self.api.qos_del('some_other_ls', if_exists=False) + self.assertRaises(RuntimeError, cmd.execute, check_error=True) + def test_qos_list(self): r1 = self._qos_add('from-lport', 0, 'output == "fake_port"', 1000) r2 = self._qos_add('from-lport', 1, 'output == "fake_port2"', 1000)