Merge "Add commands to set and get LRP options"

This commit is contained in:
Zuul 2019-08-05 13:05:49 +00:00 committed by Gerrit Code Review
commit 68d462d355
4 changed files with 48 additions and 2 deletions

View File

@ -542,6 +542,26 @@ class API(api.API):
:returns:
"""
@abc.abstractmethod
def lrp_set_options(self, port, **options):
"""Set options related to the type of 'port'
:param port: The name or uuid of the port
:type port: string or uuid.UUID
:param options: keys and values for the port 'options' dict
:type options: key: string, value: string
:returns: :class:`Command` with no result
"""
@abc.abstractmethod
def lrp_get_options(self, port):
"""Get the type-specific options for 'port'
:param port: The name or uuid of the port
:type port: string or uuid.UUID
:returns: :class:`Command` with dict result
"""
@abc.abstractmethod
def lr_route_add(self, router, prefix, nexthop, port=None,
policy='dst-ip', may_exist=False):

View File

@ -542,23 +542,27 @@ class LspGetTypeCommand(cmd.ReadOnlyCommand):
class LspSetOptionsCommand(cmd.BaseCommand):
table = 'Logical_Switch_Port'
def __init__(self, api, port, **options):
super(LspSetOptionsCommand, self).__init__(api)
self.port = port
self.options = options
def run_idl(self, txn):
lsp = self.api.lookup('Logical_Switch_Port', self.port)
lsp = self.api.lookup(self.table, self.port)
lsp.options = self.options
class LspGetOptionsCommand(cmd.ReadOnlyCommand):
table = 'Logical_Switch_Port'
def __init__(self, api, port):
super(LspGetOptionsCommand, self).__init__(api)
self.port = port
def run_idl(self, txn):
lsp = self.api.lookup('Logical_Switch_Port', self.port)
lsp = self.api.lookup(self.table, self.port)
self.result = lsp.options
@ -795,6 +799,14 @@ class LrpGetEnabledCommand(cmd.ReadOnlyCommand):
self.result = next(iter(lrp.enabled), True)
class LrpSetOptionsCommand(LspSetOptionsCommand):
table = 'Logical_Router_Port'
class LrpGetOptionsCommand(LspGetOptionsCommand):
table = 'Logical_Router_Port'
class LrRouteAddCommand(cmd.BaseCommand):
def __init__(self, api, router, prefix, nexthop, port=None,
policy='dst-ip', may_exist=False):

View File

@ -178,6 +178,12 @@ class OvnNbApiIdlImpl(ovs_idl.Backend, api.API):
def lrp_get_enabled(self, port):
return cmd.LrpGetEnabledCommand(self, port)
def lrp_set_options(self, port, **options):
return cmd.LrpSetOptionsCommand(self, port, **options)
def lrp_get_options(self, port):
return cmd.LrpGetOptionsCommand(self, port)
def lr_route_add(self, router, prefix, nexthop, port=None,
policy='dst-ip', may_exist=False):
return cmd.LrRouteAddCommand(self, router, prefix, nexthop, port,

View File

@ -1032,6 +1032,14 @@ class TestLogicalRouterPortOps(OvnNorthboundTest):
self.assertTrue(self.api.lrp_get_enabled(lrp.name).execute(
check_error=True))
def test_lrp_get_set_options(self):
options = {'one': 'two', 'three': 'four'}
lrp = self._lrp_add(None)
self.api.lrp_set_options(lrp.uuid, **options).execute(
check_error=True)
self.assertEqual(options, self.api.lrp_get_options(lrp.uuid).execute(
check_error=True))
class TestLoadBalancerOps(OvnNorthboundTest):