From 25ec686c5b096e7980d60079c86ff5deaa28fd8c Mon Sep 17 00:00:00 2001 From: Rafael Castillo Date: Thu, 15 Sep 2022 17:08:02 -0700 Subject: [PATCH] Use /servers/detail endpoint in find_server proxy method Currently, find_server will return the objects with different fields filled in depending on whether the term provided is an id or a name. This patch, in the same vein of [0], changes the find_server method so it uses the /servers/detail endpoint to find servers in the case of a name being provided. This ensures that the method fills in all fields in every case. [0] https://review.opendev.org/c/openstack/openstacksdk/+/854293 Change-Id: If8306f879361f872a1a87d589c756d9ae2435449 --- openstack/compute/v2/_proxy.py | 3 ++- .../tests/unit/cloud/test_delete_server.py | 18 +++++++++--------- .../tests/unit/cloud/test_update_server.py | 4 ++-- openstack/tests/unit/compute/v2/test_proxy.py | 6 +++++- ...nd_server-use-details-9a22e83ec6540c98.yaml | 4 ++++ 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 releasenotes/notes/find_server-use-details-9a22e83ec6540c98.yaml diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index 3f0373d1f..9f8b34d03 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -660,7 +660,8 @@ class Proxy(proxy.Proxy): :returns: One :class:`~openstack.compute.v2.server.Server` or None """ return self._find(_server.Server, name_or_id, - ignore_missing=ignore_missing) + ignore_missing=ignore_missing, + list_base_path='/servers/detail') def get_server(self, server): """Get a single server diff --git a/openstack/tests/unit/cloud/test_delete_server.py b/openstack/tests/unit/cloud/test_delete_server.py index 67c6306e6..562e7ffbe 100644 --- a/openstack/tests/unit/cloud/test_delete_server.py +++ b/openstack/tests/unit/cloud/test_delete_server.py @@ -38,7 +38,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=daffy']), json={'servers': [server]}), dict(method='DELETE', @@ -61,7 +61,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=tweety']), json={'servers': []}), ]) @@ -78,7 +78,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=speedy']), json={'servers': []}), ]) @@ -98,7 +98,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=wily']), json={'servers': [server]}), dict(method='DELETE', @@ -130,7 +130,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=speedy']), json={'servers': [server]}), dict(method='DELETE', @@ -167,7 +167,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=porky']), json={'servers': [server]}), dict(method='DELETE', @@ -193,7 +193,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=porky']), json={'servers': [server]}), dict(method='GET', @@ -246,7 +246,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=porky']), json={'servers': [server]}), dict(method='GET', @@ -283,7 +283,7 @@ class TestDeleteServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=porky']), json={'servers': [server]}), dict(method='GET', diff --git a/openstack/tests/unit/cloud/test_update_server.py b/openstack/tests/unit/cloud/test_update_server.py index e25ec2e36..7af7db1d5 100644 --- a/openstack/tests/unit/cloud/test_update_server.py +++ b/openstack/tests/unit/cloud/test_update_server.py @@ -48,7 +48,7 @@ class TestUpdateServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=%s' % self.server_name]), json={'servers': [self.fake_server]}), dict(method='PUT', @@ -80,7 +80,7 @@ class TestUpdateServer(base.TestCase): status_code=404), dict(method='GET', uri=self.get_mock_url( - 'compute', 'public', append=['servers'], + 'compute', 'public', append=['servers', 'detail'], qs_elements=['name=%s' % self.server_name]), json={'servers': [self.fake_server]}), dict(method='PUT', diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index 4f6a4f60c..6e797a0c0 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -668,7 +668,11 @@ class TestCompute(TestComputeProxy): expected_args=[self.proxy]) def test_server_find(self): - self.verify_find(self.proxy.find_server, server.Server) + self.verify_find( + self.proxy.find_server, + server.Server, + expected_kwargs={'list_base_path': '/servers/detail'}, + ) def test_server_get(self): self.verify_get(self.proxy.get_server, server.Server) diff --git a/releasenotes/notes/find_server-use-details-9a22e83ec6540c98.yaml b/releasenotes/notes/find_server-use-details-9a22e83ec6540c98.yaml new file mode 100644 index 000000000..79cd7c2fa --- /dev/null +++ b/releasenotes/notes/find_server-use-details-9a22e83ec6540c98.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Make sure find_server returns server details when looking up by name.