Browse Source

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

tags/1.5.0^0
Zuul 4 weeks ago
committed by Gerrit Code Review
parent
commit
051940c8dc
4 changed files with 25 additions and 5 deletions
  1. +4
    -1
      ovsdbapp/schema/ovn_northbound/api.py
  2. +10
    -2
      ovsdbapp/schema/ovn_northbound/commands.py
  3. +4
    -2
      ovsdbapp/schema/ovn_northbound/impl_idl.py
  4. +7
    -0
      ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py

+ 4
- 1
ovsdbapp/schema/ovn_northbound/api.py View File

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



+ 10
- 2
ovsdbapp/schema/ovn_northbound/commands.py View File

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


+ 4
- 2
ovsdbapp/schema/ovn_northbound/impl_idl.py View File

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


+ 7
- 0
ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py View File

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


Loading…
Cancel
Save