Merge "remove glance usage inside compute"

This commit is contained in:
Zuul 2017-12-12 00:09:59 +00:00 committed by Gerrit Code Review
commit 32c8ac6b7d
3 changed files with 18 additions and 7 deletions

View File

@ -74,7 +74,6 @@ from nova import exception_wrapper
from nova import hooks
from nova.i18n import _
from nova import image
from nova.image import glance
from nova import manager
from nova import network
from nova.network import base_api as base_net_api
@ -2974,8 +2973,8 @@ class ComputeManager(manager.Manager):
# This instance.exists message should contain the original
# image_ref, not the new one. Since the DB has been updated
# to point to the new one... we have to override it.
# TODO(jaypipes): Move generate_image_url() into the nova.image.api
orig_image_ref_url = glance.generate_image_url(orig_image_ref, context)
orig_image_ref_url = self.image_api.generate_image_url(orig_image_ref,
context)
extra_usage_info = {'image_ref_url': orig_image_ref_url}
compute_utils.notify_usage_exists(
self.notifier, context, instance,
@ -3322,10 +3321,9 @@ class ComputeManager(manager.Manager):
msg = 'Instance disappeared during snapshot'
LOG.debug(msg, instance=instance)
try:
image_service = glance.get_default_image_service()
image = image_service.show(context, image_id)
image = self.image_api.get(context, image_id)
if image['status'] != 'active':
image_service.delete(context, image_id)
self.image_api.delete(context, image_id)
except Exception:
LOG.warning("Error while trying to clean up image %s",
image_id, instance=instance)

View File

@ -55,6 +55,16 @@ class API(object):
# the context alive...
return glance.get_default_image_service()
@staticmethod
def generate_image_url(image_ref, context):
"""Generate an image URL from an image_ref.
:param image_ref: The image ref to generate URL
:param context: The `nova.context.Context` object for the request
"""
return "%s/images/%s" % (next(glance.get_api_servers(context)),
image_ref)
def get_all(self, context, **kwargs):
"""Retrieves all information records about all disk images available
to show to the requesting user. If the requesting user is an admin,

View File

@ -6593,13 +6593,16 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
migration.status = 'running'
migration.id = 0
# TODO(jichenjc): will be removed when remove glance.generate_image_url
@mock.patch('nova.image.glance.generate_image_url',
return_value='fake-url')
@mock.patch('nova.image.api.API.generate_image_url',
return_value='fake-url')
@mock.patch.object(objects.Migration, 'get_by_id',
return_value=migration)
@mock.patch.object(self.compute.driver,
'live_migration_force_complete')
def _do_test(force_complete, get_by_id, gen_img_url):
def _do_test(force_complete, get_by_id, gen_img_url, glance_image_url):
self.compute.live_migration_force_complete(
self.context, self.instance, migration.id)