Skip to content

Commit 92a64a3

Browse files
committed
Add leak-routes related options for subnets
The patch adds --leak-routes/--no-leak-routes for the 'subnet set' operation to configure OVN BGP route leaking. Assisted-By: Claude Opus 4.6 High Related-Bug: #2161353 Change-Id: I0cead57c3db621d25e257e4bc572aff544f9cbb7 Signed-off-by: Jakub Libosvar <jlibosva@redhat.com>
1 parent 9726a4d commit 92a64a3

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

openstackclient/network/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'dns_domain': 'dns-integration',
3434
'dns_name': 'dns-integration',
3535
'extra_dhcp_opts': 'extra_dhcp_opt',
36+
'leak_routes': 'ovn-bgp',
3637
'qos_policy_id': 'qos',
3738
'security_groups': 'security-groups',
3839
}

openstackclient/network/v2/subnet.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,26 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
730730
metavar='<description>',
731731
help=_("Set subnet description"),
732732
)
733+
leak_routes_grp = parser.add_mutually_exclusive_group()
734+
leak_routes_grp.add_argument(
735+
'--leak-routes',
736+
action='store_true',
737+
dest='leak_routes',
738+
default=None,
739+
help=_(
740+
"Leak subnet routes to the underlay BGP fabric "
741+
"(ovn-bgp extension required)"
742+
),
743+
)
744+
leak_routes_grp.add_argument(
745+
'--no-leak-routes',
746+
action='store_false',
747+
dest='leak_routes',
748+
help=_(
749+
"Do not leak subnet routes to the underlay "
750+
"BGP fabric (ovn-bgp extension required)"
751+
),
752+
)
733753
_tag.add_tag_option_to_parser_for_set(parser, _('subnet'))
734754
_get_common_parse_arguments(parser, is_create=False)
735755
return parser
@@ -757,11 +777,14 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
757777
attrs['allocation_pools'] = []
758778
if 'service_types' in attrs:
759779
attrs['service_types'] += obj.service_types
780+
if parsed_args.leak_routes is not None:
781+
attrs['leak_routes'] = parsed_args.leak_routes
760782
attrs.update(
761783
self._parse_extra_properties(parsed_args.extra_properties)
762784
)
763785
if attrs:
764-
client.update_subnet(obj, **attrs)
786+
with common.check_missing_extension_if_error(client, attrs):
787+
client.update_subnet(obj, **attrs)
765788
# tags is a subresource and it needs to be updated separately.
766789
_tag.update_tags_for_set(client, obj, parsed_args)
767790
return

openstackclient/tests/unit/network/v2/test_subnet.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,48 @@ def test_set_segment(self):
14721472
self.network_client.update_subnet.assert_called_with(_subnet, **attrs)
14731473
self.assertIsNone(result)
14741474

1475+
def test_set_leak_routes(self):
1476+
arglist = [
1477+
self._subnet.name,
1478+
'--leak-routes',
1479+
]
1480+
verifylist = [
1481+
('subnet', self._subnet.name),
1482+
('leak_routes', True),
1483+
]
1484+
1485+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1486+
result = self.cmd.take_action(parsed_args)
1487+
1488+
attrs = {
1489+
'leak_routes': True,
1490+
}
1491+
self.network_client.update_subnet.assert_called_once_with(
1492+
self._subnet, **attrs
1493+
)
1494+
self.assertIsNone(result)
1495+
1496+
def test_set_no_leak_routes(self):
1497+
arglist = [
1498+
self._subnet.name,
1499+
'--no-leak-routes',
1500+
]
1501+
verifylist = [
1502+
('subnet', self._subnet.name),
1503+
('leak_routes', False),
1504+
]
1505+
1506+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1507+
result = self.cmd.take_action(parsed_args)
1508+
1509+
attrs = {
1510+
'leak_routes': False,
1511+
}
1512+
self.network_client.update_subnet.assert_called_once_with(
1513+
self._subnet, **attrs
1514+
)
1515+
self.assertIsNone(result)
1516+
14751517

14761518
class TestShowSubnet(TestSubnet):
14771519
# The subnets to be shown

0 commit comments

Comments
 (0)