remove glance usage inside compute
refactor compute code to remove glance direct usage, 1) use image_api.get instead of get glance code then show the image detail information 2) according to TODO, create a new api in image.api and use it Change-Id: I0c8dee5d0d18adeaa83183da81c85f378ae5f8fd
This commit is contained in:
parent
9f46043f2f
commit
2ea2f0d705
@ -74,7 +74,6 @@ from nova import exception_wrapper
|
|||||||
from nova import hooks
|
from nova import hooks
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova import image
|
from nova import image
|
||||||
from nova.image import glance
|
|
||||||
from nova import manager
|
from nova import manager
|
||||||
from nova import network
|
from nova import network
|
||||||
from nova.network import base_api as base_net_api
|
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
|
# This instance.exists message should contain the original
|
||||||
# image_ref, not the new one. Since the DB has been updated
|
# image_ref, not the new one. Since the DB has been updated
|
||||||
# to point to the new one... we have to override it.
|
# 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 = self.image_api.generate_image_url(orig_image_ref,
|
||||||
orig_image_ref_url = glance.generate_image_url(orig_image_ref, context)
|
context)
|
||||||
extra_usage_info = {'image_ref_url': orig_image_ref_url}
|
extra_usage_info = {'image_ref_url': orig_image_ref_url}
|
||||||
compute_utils.notify_usage_exists(
|
compute_utils.notify_usage_exists(
|
||||||
self.notifier, context, instance,
|
self.notifier, context, instance,
|
||||||
@ -3307,10 +3306,9 @@ class ComputeManager(manager.Manager):
|
|||||||
msg = 'Instance disappeared during snapshot'
|
msg = 'Instance disappeared during snapshot'
|
||||||
LOG.debug(msg, instance=instance)
|
LOG.debug(msg, instance=instance)
|
||||||
try:
|
try:
|
||||||
image_service = glance.get_default_image_service()
|
image = self.image_api.get(context, image_id)
|
||||||
image = image_service.show(context, image_id)
|
|
||||||
if image['status'] != 'active':
|
if image['status'] != 'active':
|
||||||
image_service.delete(context, image_id)
|
self.image_api.delete(context, image_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.warning("Error while trying to clean up image %s",
|
LOG.warning("Error while trying to clean up image %s",
|
||||||
image_id, instance=instance)
|
image_id, instance=instance)
|
||||||
|
@ -55,6 +55,16 @@ class API(object):
|
|||||||
# the context alive...
|
# the context alive...
|
||||||
return glance.get_default_image_service()
|
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):
|
def get_all(self, context, **kwargs):
|
||||||
"""Retrieves all information records about all disk images available
|
"""Retrieves all information records about all disk images available
|
||||||
to show to the requesting user. If the requesting user is an admin,
|
to show to the requesting user. If the requesting user is an admin,
|
||||||
|
@ -6574,13 +6574,16 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||||||
migration.status = 'running'
|
migration.status = 'running'
|
||||||
migration.id = 0
|
migration.id = 0
|
||||||
|
|
||||||
|
# TODO(jichenjc): will be removed when remove glance.generate_image_url
|
||||||
@mock.patch('nova.image.glance.generate_image_url',
|
@mock.patch('nova.image.glance.generate_image_url',
|
||||||
return_value='fake-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',
|
@mock.patch.object(objects.Migration, 'get_by_id',
|
||||||
return_value=migration)
|
return_value=migration)
|
||||||
@mock.patch.object(self.compute.driver,
|
@mock.patch.object(self.compute.driver,
|
||||||
'live_migration_force_complete')
|
'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.compute.live_migration_force_complete(
|
||||||
self.context, self.instance, migration.id)
|
self.context, self.instance, migration.id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user