From a42e56079613df611aaab19018b540aee8649041 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Wed, 22 Apr 2026 11:26:05 +0200 Subject: [PATCH 1/2] tests: Move assert helpers to utils.TestCommand Move assertItemEqual() and assertListItemEqual() from fwaas/test_rule.py to openstackclient.tests.unit.utils.TestCommand so network tests can use them without inheriting from both utils.TestCommand and osc_lib.test.base.TestCommand. Add a TODO to eventually replace utils.TestCommand with osc_lib.test.base.TestCommand once osc-lib provides the same functionality as current openstackclient.tests.unit.utils.TestCommand class and once current one will be replaced with osc_lib one. Assisted-by: Cursor Composer 2.5 Change-Id: I88fdab495a486c1166023287936764f5cf2bc918 Signed-off-by: Slawek Kaplonski --- .../tests/unit/network/v2/fwaas/test_rule.py | 21 ----------------- openstackclient/tests/unit/utils.py | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/openstackclient/tests/unit/network/v2/fwaas/test_rule.py b/openstackclient/tests/unit/network/v2/fwaas/test_rule.py index 0ae78c515..e04ad6418 100644 --- a/openstackclient/tests/unit/network/v2/fwaas/test_rule.py +++ b/openstackclient/tests/unit/network/v2/fwaas/test_rule.py @@ -17,7 +17,6 @@ import re from unittest import mock -from cliff import columns as cliff_columns from openstack.network.v2 import firewall_rule from openstack.test import fakes as sdk_fakes from osc_lib import exceptions @@ -79,26 +78,6 @@ def check_results(self, headers, data, exp_req=None, is_list=False): self.mocked.assert_called_once_with(**req_body) self.assertEqual(self.ordered_headers, headers) - # TODO(slaweq): remove this method once network_fakes.TestNetworkV2 will - # inherit from the osc_lib.test.base.TestCommand - def assertListItemEqual(self, expected, actual): - self.assertEqual(len(expected), len(actual)) - for item_expected, item_actual in zip(expected, actual): - self.assertItemEqual(item_expected, item_actual) - - # TODO(slaweq): remove this method once network_fakes.TestNetworkV2 will - # inherit from the osc_lib.test.base.TestCommand - def assertItemEqual(self, expected, actual): - self.assertEqual(len(expected), len(actual)) - for col_expected, col_actual in zip(expected, actual): - if isinstance(col_expected, cliff_columns.FormattableColumn): - self.assertIsInstance(col_actual, col_expected.__class__) - self.assertEqual( - col_expected.human_readable(), col_actual.human_readable() - ) - else: - self.assertEqual(col_expected, col_actual) - def setUp(self): super().setUp() diff --git a/openstackclient/tests/unit/utils.py b/openstackclient/tests/unit/utils.py index 607047f14..f742c46e7 100644 --- a/openstackclient/tests/unit/utils.py +++ b/openstackclient/tests/unit/utils.py @@ -17,6 +17,7 @@ import io import os +from cliff import columns as cliff_columns import fixtures import testtools @@ -69,6 +70,28 @@ def assertNotCalled(self, m, msg=None): class TestCommand(TestCase): """Test cliff command classes""" + # TODO(slaweq): Remove those methods in favour of the ones in + # osc_lib.test.base.TestCommand once osc-lib TestCommand + # provides all of the same functionality as this TestCommand + # like e.g. the monkey patching for sys.stderr and this one can be + # removed. + + def assertListItemEqual(self, expected, actual): + self.assertEqual(len(expected), len(actual)) + for item_expected, item_actual in zip(expected, actual): + self.assertItemEqual(item_expected, item_actual) + + def assertItemEqual(self, expected, actual): + self.assertEqual(len(expected), len(actual)) + for col_expected, col_actual in zip(expected, actual): + if isinstance(col_expected, cliff_columns.FormattableColumn): + self.assertIsInstance(col_actual, col_expected.__class__) + self.assertEqual( + col_expected.human_readable(), col_actual.human_readable() + ) + else: + self.assertEqual(col_expected, col_actual) + def setUp(self): super().setUp() # Build up a fake app From 95a376a84f2e942442452c270daa0cd265f37347 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Thu, 4 Jun 2026 13:00:53 -0400 Subject: [PATCH 2/2] network: Remove the workaround for SDK for advertise_host attribute The patch removes the workaround for advertise_host attribute support. Related-Bug: #2144617 Change-Id: I7bff6a6c5382b386f58ad163d4115b962f80e6a5 Signed-off-by: Jakub Libosvar --- openstackclient/network/v2/router.py | 19 +++++-------------- .../tests/unit/network/v2/test_router.py | 12 ++++-------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index 38e17b267..8c68d5a83 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -402,20 +402,11 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser: def take_action(self, parsed_args: argparse.Namespace) -> None: client = self.app.client_manager.network subnet = client.find_subnet(parsed_args.subnet, ignore_missing=False) - if parsed_args.advertise_host: - # TODO(evpn): switch to client.add_interface_to_router() once - # openstacksdk supports the advertise_host parameter. - router = client.find_router( - parsed_args.router, ignore_missing=False - ) - router.add_interface( - client, subnet_id=subnet.id, advertise_host=True - ) - else: - client.add_interface_to_router( - client.find_router(parsed_args.router, ignore_missing=False), - subnet=subnet.id, - ) + client.add_interface_to_router( + client.find_router(parsed_args.router, ignore_missing=False), + subnet=subnet.id, + advertise_host=parsed_args.advertise_host, + ) class AddExtraRoutesToRouter(command.ShowOne): diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py index 4f70fc5ca..db2057a7a 100644 --- a/openstackclient/tests/unit/network/v2/test_router.py +++ b/openstackclient/tests/unit/network/v2/test_router.py @@ -108,7 +108,7 @@ def test_add_subnet_required_options(self): result = self.cmd.take_action(parsed_args) self.network_client.add_interface_to_router.assert_called_with( - self._router, subnet=self._router.subnet + self._router, subnet=self._router.subnet, advertise_host=False ) self.assertIsNone(result) @@ -127,12 +127,9 @@ def test_add_subnet_with_advertise_host(self): parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self._router.add_interface.assert_called_once_with( - self.network_client, - subnet_id=self._subnet.id, - advertise_host=True, + self.network_client.add_interface_to_router.assert_called_once_with( + self._router, subnet=self._router.subnet, advertise_host=True ) - self.network_client.add_interface_to_router.assert_not_called() self.assertIsNone(result) @@ -150,9 +147,8 @@ def test_add_subnet_without_advertise_host(self): result = self.cmd.take_action(parsed_args) self.network_client.add_interface_to_router.assert_called_once_with( - self._router, subnet=self._subnet.id + self._router, subnet=self._subnet.id, advertise_host=False ) - self._router.add_interface.assert_not_called() self.assertIsNone(result)