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