Skip to content

Commit 1bd2bf6

Browse files
Imtiaz Chowdhurystevemar
authored andcommitted
Fixes image api URL endpoint for certain scenario
openstackclient fails to get image list when the image api endpoint has 'v2' substring in the URL. Instead of checking whether the api endpoint URL terminates with '/v2', the current logic is checking whether 'v2' appears anywhere in the endpoint string. This issue was discovered on a production setup where certain server names had 'v2' in their names. For example, when a hostname is gopher.dev20.com, the image list APIs fail. This commit updates the unit test to reflect this scenario. Without the change in openstackclient/api/image_v2.py, all the unit tests fail. Co-Authored-By: sergio.carvalho@workday.com Change-Id: I26b85afd646938272dbabe8e045b337b7df58c7d Closes-Bug: 1652827
1 parent e6e3cd2 commit 1bd2bf6

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

openstackclient/api/image_v1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class APIv1(api.BaseAPI):
2020
"""Image v1 API"""
2121

22-
_endpoint_suffix = 'v1'
22+
_endpoint_suffix = '/v1'
2323

2424
def __init__(self, endpoint=None, **kwargs):
2525
super(APIv1, self).__init__(endpoint=endpoint, **kwargs)
@@ -29,8 +29,8 @@ def __init__(self, endpoint=None, **kwargs):
2929

3030
def _munge_url(self):
3131
# Hack this until discovery is up
32-
if self._endpoint_suffix not in self.endpoint.split('/')[-1]:
33-
self.endpoint = '/'.join([self.endpoint, self._endpoint_suffix])
32+
if not self.endpoint.endswith(self._endpoint_suffix):
33+
self.endpoint = self.endpoint + self._endpoint_suffix
3434

3535
def image_list(
3636
self,

openstackclient/api/image_v2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
class APIv2(image_v1.APIv1):
2020
"""Image v2 API"""
2121

22-
_endpoint_suffix = 'v2'
22+
_endpoint_suffix = '/v2'
2323

2424
def _munge_url(self):
2525
# Hack this until discovery is up, and ignore parent endpoint setting
26-
if 'v2' not in self.endpoint.split('/')[-1]:
27-
self.endpoint = '/'.join([self.endpoint, 'v2'])
26+
if not self.endpoint.endswith(self._endpoint_suffix):
27+
self.endpoint = self.endpoint + self._endpoint_suffix
2828

2929
def image_list(
3030
self,

openstackclient/tests/unit/api/test_image_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
FAKE_PROJECT = 'xyzpdq'
24-
FAKE_URL = 'http://gopher.com'
24+
FAKE_URL = 'http://gopher.dev10.com'
2525

2626

2727
class TestImageAPIv1(utils.TestCase):

openstackclient/tests/unit/api/test_image_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
FAKE_PROJECT = 'xyzpdq'
24-
FAKE_URL = 'http://gopher.com'
24+
FAKE_URL = 'http://gopher.dev20.com'
2525

2626

2727
class TestImageAPIv2(utils.TestCase):

0 commit comments

Comments
 (0)