Merge "Add "if_exists" parameter to "QoSDelCommand""

This commit is contained in:
Zuul 2020-09-01 10:38:33 +00:00 committed by Gerrit Code Review
commit 051940c8dc
4 changed files with 25 additions and 5 deletions

View File

@ -220,7 +220,8 @@ class API(api.API, metaclass=abc.ABCMeta):
""" """
@abc.abstractmethod @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' """Remove Qos rules from 'switch'
If only switch is supplied, all the QoS rules from the logical 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 :type priority: int
:param match: The match rule :param match: The match rule
:type match: string :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 :returns: :class:`Command` with no result
""" """

View File

@ -270,7 +270,7 @@ class QoSAddCommand(cmd.AddCommand):
class QoSDelCommand(cmd.BaseCommand): class QoSDelCommand(cmd.BaseCommand):
def __init__(self, api, switch, direction=None, 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): if (priority is None) != (match is None):
raise TypeError("Must specify priority and match together") raise TypeError("Must specify priority and match together")
if priority is not None and not direction: if priority is not None and not direction:
@ -278,6 +278,7 @@ class QoSDelCommand(cmd.BaseCommand):
super(QoSDelCommand, self).__init__(api) super(QoSDelCommand, self).__init__(api)
self.switch = switch self.switch = switch
self.conditions = [] self.conditions = []
self.if_exists = if_exists
if direction: if direction:
self.conditions.append(('direction', '=', direction)) self.conditions.append(('direction', '=', direction))
# priority can be 0 # priority can be 0
@ -286,7 +287,14 @@ class QoSDelCommand(cmd.BaseCommand):
('match', '=', match)] ('match', '=', match)]
def run_idl(self, txn): 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: for row in ls.qos_rules:
if idlutils.row_match(row, self.conditions): if idlutils.row_match(row, self.conditions):
ls.delvalue('qos_rules', row) ls.delvalue('qos_rules', row)

View File

@ -83,8 +83,10 @@ class OvnNbApiIdlImpl(ovs_idl.Backend, api.API):
return cmd.QoSAddCommand(self, switch, direction, priority, match, return cmd.QoSAddCommand(self, switch, direction, priority, match,
rate, burst, dscp, may_exist, **columns) rate, burst, dscp, may_exist, **columns)
def qos_del(self, switch, direction=None, priority=None, match=None): def qos_del(self, switch, direction=None, priority=None, match=None,
return cmd.QoSDelCommand(self, switch, direction, priority, match) if_exists=True):
return cmd.QoSDelCommand(self, switch, direction, priority, match,
if_exists)
def qos_list(self, switch): def qos_list(self, switch):
return cmd.QoSListCommand(self, switch) return cmd.QoSListCommand(self, switch)

View File

@ -310,6 +310,13 @@ class TestQoSOps(OvnNorthboundTest):
self.assertRaises(TypeError, self.api.qos_del, self.switch.uuid, self.assertRaises(TypeError, self.api.qos_del, self.switch.uuid,
priority=0) 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): def test_qos_list(self):
r1 = self._qos_add('from-lport', 0, 'output == "fake_port"', 1000) r1 = self._qos_add('from-lport', 0, 'output == "fake_port"', 1000)
r2 = self._qos_add('from-lport', 1, 'output == "fake_port2"', 1000) r2 = self._qos_add('from-lport', 1, 'output == "fake_port2"', 1000)