Return None image client when no glance endpoint

Glance will soon be switched off by default, so the baremetal
management code needs to handle the glance endpoint not existing.

This change returns None from get_image_client when there is no glance
endpoint.

The only callers of get_image_client use the result to call
create_or_find_kernel_and_ramdisk[2]. This function only requires a an
image client when the image reference is not a valid URL, and handles
a None client with image URLs just fine.

[1] https://review.opendev.org/711364
[2] https://opendev.org/openstack/tripleo-common/src/branch/master/tripleo_common/utils/glance.py#L22
Blueprint: nova-less-deploy

Change-Id: I703660e72a934e8b0925d63a19cb78f603bff5ba
This commit is contained in:
Steve Baker 2020-03-30 12:14:47 +13:00
parent 93c53c21cc
commit ce52e8b7e6
2 changed files with 13 additions and 3 deletions

View File

@ -113,8 +113,12 @@ class TripleOAction(actions.Action):
def get_image_client(self, context):
security_ctx = context.security
glance_endpoint = keystone_utils.get_endpoint_for_project(
security_ctx, 'glance')
try:
glance_endpoint = keystone_utils.get_endpoint_for_project(
security_ctx, 'glance')
except Exception:
return None
return glanceclient.Client(
glance_endpoint.url,
token=security_ctx.auth_token,

View File

@ -59,7 +59,7 @@ class GlanceTest(base.TestCase):
client = mock.MagicMock()
expected = {'kernel': 'file:///kernel', 'ramdisk': 'file:///ramdisk'}
ids = glance.create_or_find_kernel_and_ramdisk(
client, 'file:///kernel', 'file:///ramdisk')
None, 'file:///kernel', 'file:///ramdisk')
client.images.assert_not_called()
self.assertEqual(expected, ids)
@ -70,3 +70,9 @@ class GlanceTest(base.TestCase):
client, 'http://kernel', 'http://ramdisk')
client.images.assert_not_called()
self.assertEqual(expected, ids)
def test_return_https_urls_no_client(self):
expected = {'kernel': 'https://kernel', 'ramdisk': 'https://ramdisk'}
ids = glance.create_or_find_kernel_and_ramdisk(
None, 'https://kernel', 'https://ramdisk')
self.assertEqual(expected, ids)