From faea17101b3816566d449ed4801702dce8c9e566 Mon Sep 17 00:00:00 2001 From: Anton Vazhnetsov Date: Tue, 26 Oct 2021 17:02:22 +0300 Subject: [PATCH] nb: provide lrp_get method This change adds function and command to get only one logical router port by name or uuid. Closes-Bug: #1948947 Change-Id: I8395cc22d7143a53bb507876a62d923ea3874602 --- ovsdbapp/schema/ovn_northbound/api.py | 9 +++++++++ ovsdbapp/schema/ovn_northbound/commands.py | 4 ++++ ovsdbapp/schema/ovn_northbound/impl_idl.py | 3 +++ .../schema/ovn_northbound/test_impl_idl.py | 12 ++++++++++++ .../provide-lrp-get-method-a33a99a7f86b827e.yaml | 4 ++++ 5 files changed, 32 insertions(+) create mode 100644 releasenotes/notes/provide-lrp-get-method-a33a99a7f86b827e.yaml diff --git a/ovsdbapp/schema/ovn_northbound/api.py b/ovsdbapp/schema/ovn_northbound/api.py index 6a6f4b6b..22d1ff83 100644 --- a/ovsdbapp/schema/ovn_northbound/api.py +++ b/ovsdbapp/schema/ovn_northbound/api.py @@ -547,6 +547,15 @@ class API(api.API, metaclass=abc.ABCMeta): :returns: :class:`Command` with RowView list result """ + @abc.abstractmethod + def lrp_get(self, port): + """Get logical router port for 'port' + + :param port: The name or uuid of the port + :type port: string or uuid.UUID + :returns: :class:`Command` with RowView result + """ + @abc.abstractmethod def lrp_set_enabled(self, port, is_enabled): """Set administrative state of 'port' diff --git a/ovsdbapp/schema/ovn_northbound/commands.py b/ovsdbapp/schema/ovn_northbound/commands.py index 979c593d..2dc68eba 100644 --- a/ovsdbapp/schema/ovn_northbound/commands.py +++ b/ovsdbapp/schema/ovn_northbound/commands.py @@ -815,6 +815,10 @@ class LrpListCommand(cmd.ReadOnlyCommand): self.result = [rowview.RowView(r) for r in router.ports] +class LrpGetCommand(cmd.BaseGetRowCommand): + table = 'Logical_Router_Port' + + class LrpSetEnabledCommand(cmd.BaseCommand): def __init__(self, api, port, is_enabled): super().__init__(api) diff --git a/ovsdbapp/schema/ovn_northbound/impl_idl.py b/ovsdbapp/schema/ovn_northbound/impl_idl.py index 1254df5f..4ff3764e 100644 --- a/ovsdbapp/schema/ovn_northbound/impl_idl.py +++ b/ovsdbapp/schema/ovn_northbound/impl_idl.py @@ -180,6 +180,9 @@ class OvnNbApiIdlImpl(ovs_idl.Backend, api.API): def lrp_list(self, router): return cmd.LrpListCommand(self, router) + def lrp_get(self, port): + return cmd.LrpGetCommand(self, port) + def lrp_set_enabled(self, port, is_enabled): return cmd.LrpSetEnabledCommand(self, port, is_enabled) 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 d4562a40..df14a3d7 100644 --- a/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py +++ b/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py @@ -1136,6 +1136,18 @@ class TestLogicalRouterPortOps(OvnNorthboundTest): self.assertEqual(set(networks), set(lrp.networks)) return lrp + def _test_lrp_get(self, col): + lrp = self._lrp_add(None) + val = getattr(lrp, col) + found = self.api.lrp_get(val).execute(check_error=True) + self.assertEqual(lrp, found) + + def test_lrp_get_uuid(self): + self._test_lrp_get('uuid') + + def test_lrp_get_name(self): + self._test_lrp_get('name') + def test_lrp_add(self): self._lrp_add(None, 'de:ad:be:ef:4d:ad', ['192.0.2.0/24']) diff --git a/releasenotes/notes/provide-lrp-get-method-a33a99a7f86b827e.yaml b/releasenotes/notes/provide-lrp-get-method-a33a99a7f86b827e.yaml new file mode 100644 index 00000000..9848d2ed --- /dev/null +++ b/releasenotes/notes/provide-lrp-get-method-a33a99a7f86b827e.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Added function and command to get one logical router port by name or uuid.