From e0f7306011af36e7306242b242b1119836c5d621 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 7 May 2024 11:44:12 +0100 Subject: [PATCH] network: Migrate 'port list' to compute SDK We use the compute client here to look up server IDs when filtering by 'device_id'. Change-Id: I76515eaa4ce4e7c7d0173d2e0a91d7564ba7041a Signed-off-by: Stephen Finucane --- openstackclient/network/v2/port.py | 7 ++++--- .../tests/unit/network/v2/test_port.py | 17 +++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index fb0ecaff25..b1e60df4e8 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -844,9 +844,10 @@ class ListPort(command.Lister): ) filters['device_id'] = _router.id if parsed_args.server: - compute_client = self.app.client_manager.compute - server = utils.find_resource( - compute_client.servers, parsed_args.server + compute_client = self.app.client_manager.sdk_connection.compute + server = compute_client.find_server( + parsed_args.server, + ignore_missing=False, ) filters['device_id'] = server.id if parsed_args.host: diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index d47f866154..7d19636510 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -15,7 +15,6 @@ from unittest.mock import call from osc_lib.cli import format_columns from osc_lib import exceptions -from osc_lib import utils from openstackclient.network.v2 import port from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes @@ -1190,7 +1189,7 @@ class TestDeletePort(TestPort): self.network_client.delete_port.assert_called_once_with(self._ports[0]) -class TestListPort(TestPort): +class TestListPort(compute_fakes.FakeClientMixin, TestPort): _ports = network_fakes.create_ports(count=3) columns = ( @@ -1256,9 +1255,6 @@ class TestListPort(TestPort): self.network_client.find_router = mock.Mock(return_value=fake_router) self.network_client.find_network = mock.Mock(return_value=fake_network) - self.app.client_manager.compute = mock.Mock() - self.compute_client = self.app.client_manager.compute - # Get the command object to test self.cmd = port.ListPort(self.app, None) @@ -1297,10 +1293,9 @@ class TestListPort(TestPort): self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, list(data)) - @mock.patch.object(utils, 'find_resource') - def test_port_list_with_server_option(self, mock_find): - fake_server = compute_fakes.create_one_server() - mock_find.return_value = fake_server + def test_port_list_with_server_option(self): + fake_server = compute_fakes.create_one_sdk_server() + self.compute_sdk_client.find_server.return_value = fake_server arglist = [ '--server', @@ -1315,7 +1310,9 @@ class TestListPort(TestPort): self.network_client.ports.assert_called_once_with( device_id=fake_server.id, fields=LIST_FIELDS_TO_RETRIEVE ) - mock_find.assert_called_once_with(mock.ANY, 'fake-server-name') + self.compute_sdk_client.find_server.aassert_called_once_with( + mock.ANY, 'fake-server-name' + ) self.assertEqual(self.columns, columns) self.assertCountEqual(self.data, list(data))