Nova: Remove unused image apis
Currently images are managed by Glance, instead of Nova, and these implementations are no longer used. Change-Id: Iabd4591b6782b135faa137a1e14a1fb760127ee6
This commit is contained in:
parent
205d716bca
commit
39a031e65c
@ -240,26 +240,6 @@ class API(base.Base):
|
||||
def keypair_list(self, context):
|
||||
return novaclient(context).keypairs.list()
|
||||
|
||||
def image_list(self, context):
|
||||
client = novaclient(context)
|
||||
if hasattr(client, 'images'):
|
||||
# Old novaclient with 'images' API proxy
|
||||
return client.images.list()
|
||||
# New novaclient without 'images' API proxy
|
||||
return client.glance.list()
|
||||
|
||||
def image_get(self, context, name):
|
||||
client = novaclient(context)
|
||||
try:
|
||||
# New novaclient without 'images' API proxy
|
||||
return client.glance.find_image(name)
|
||||
except nova_exception.NotFound:
|
||||
raise exception.ServiceInstanceException(
|
||||
_("Image with name '%s' was not found.") % name)
|
||||
except nova_exception.NoUniqueMatch:
|
||||
raise exception.ServiceInstanceException(
|
||||
_("Found more than one image by name '%s'.") % name)
|
||||
|
||||
def add_security_group_to_server(self, context, server, security_group):
|
||||
return novaclient(context).servers.add_security_group(server,
|
||||
security_group)
|
||||
|
@ -190,80 +190,6 @@ class NovaApiTestCase(test.TestCase):
|
||||
self.mock_object(nova, '_untranslate_server_summary_view',
|
||||
lambda server: server)
|
||||
|
||||
def test_image_list_novaclient_has_no_proxy(self):
|
||||
image_list = ['fake', 'image', 'list']
|
||||
|
||||
class FakeGlanceClient(object):
|
||||
def list(self):
|
||||
return image_list
|
||||
|
||||
self.novaclient.glance = FakeGlanceClient()
|
||||
|
||||
result = self.api.image_list(self.ctx)
|
||||
|
||||
self.assertEqual(image_list, result)
|
||||
|
||||
def test_image_list_novaclient_has_proxy(self):
|
||||
image_list1 = ['fake', 'image', 'list1']
|
||||
image_list2 = ['fake', 'image', 'list2']
|
||||
|
||||
class FakeImagesClient(object):
|
||||
def list(self):
|
||||
return image_list1
|
||||
|
||||
class FakeGlanceClient(object):
|
||||
def list(self):
|
||||
return image_list2
|
||||
|
||||
self.novaclient.images = FakeImagesClient()
|
||||
self.novaclient.glance = FakeGlanceClient()
|
||||
|
||||
result = self.api.image_list(self.ctx)
|
||||
|
||||
self.assertEqual(image_list1, result)
|
||||
|
||||
def test_image_get_novaclient_has_no_proxy(self):
|
||||
image = 'fake-image'
|
||||
|
||||
class FakeGlanceClient(object):
|
||||
def find_image(self, name):
|
||||
return image
|
||||
|
||||
self.novaclient.glance = FakeGlanceClient()
|
||||
result = self.api.image_get(self.ctx, 'fake-image')
|
||||
|
||||
self.assertEqual(image, result)
|
||||
|
||||
def test_image_get_novaclient_not_found(self):
|
||||
image = 'fake-image'
|
||||
|
||||
class FakeGlanceClient(object):
|
||||
def find_image(self, image):
|
||||
return image
|
||||
|
||||
self.novaclient.glance = FakeGlanceClient()
|
||||
|
||||
self.mock_object(self.novaclient.glance, 'find_image',
|
||||
mock.Mock(return_value=image,
|
||||
side_effect=nova_exception.NotFound(404)))
|
||||
self.assertRaises(exception.ServiceInstanceException,
|
||||
self.api.image_get, self.ctx, image)
|
||||
|
||||
def test_image_get_novaclient_multi_match(self):
|
||||
image = 'fake-image'
|
||||
|
||||
class FakeGlanceClient(object):
|
||||
def find_image(self, image):
|
||||
return image
|
||||
|
||||
self.novaclient.glance = FakeGlanceClient()
|
||||
|
||||
self.mock_object(self.novaclient.glance, 'find_image',
|
||||
mock.Mock(return_value=image,
|
||||
side_effect=nova_exception.NoUniqueMatch))
|
||||
self.assertRaises(exception.ServiceInstanceException,
|
||||
self.api.image_get, self.ctx, image)
|
||||
|
||||
def test_server_create(self):
|
||||
result = self.api.server_create(self.ctx, 'server_name', 'fake_image',
|
||||
'fake_flavor', None, None, None)
|
||||
|
@ -48,13 +48,6 @@ class FakeKeypair(object):
|
||||
setattr(self, key, value)
|
||||
|
||||
|
||||
class FakeImage(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.id = kwargs.pop('id', 'fake_image_id')
|
||||
for key, value in kwargs.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
|
||||
class API(object):
|
||||
"""Fake Compute API."""
|
||||
def instance_volume_attach(self, ctx, server_id, volume_id, mount_path):
|
||||
@ -90,11 +83,5 @@ class API(object):
|
||||
def keypair_delete(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def image_list(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def image_get(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def add_security_group_to_server(self, *args, **kwargs):
|
||||
pass
|
||||
|
26
manila/tests/fake_image.py
Normal file
26
manila/tests/fake_image.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class FakeImage(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.id = kwargs.pop('id', 'fake_image_id')
|
||||
for key, value in kwargs.items():
|
||||
setattr(self, key, value)
|
@ -31,6 +31,7 @@ from manila.share import driver # noqa
|
||||
from manila.share.drivers import service_instance
|
||||
from manila import test
|
||||
from manila.tests import fake_compute
|
||||
from manila.tests import fake_image
|
||||
from manila.tests import fake_network
|
||||
from manila.tests import utils as test_utils
|
||||
|
||||
@ -735,13 +736,13 @@ class ServiceInstanceManagerTestCase(test.TestCase):
|
||||
self.assertEqual((None, None), result)
|
||||
|
||||
def test_get_service_image(self):
|
||||
fake_image1 = fake_compute.FakeImage(
|
||||
fake_image1 = fake_image.FakeImage(
|
||||
name=self._manager.get_config_option('service_image_name'),
|
||||
status='active')
|
||||
fake_image2 = fake_compute.FakeImage(
|
||||
fake_image2 = fake_image.FakeImage(
|
||||
name='service_image_name',
|
||||
status='error')
|
||||
fake_image3 = fake_compute.FakeImage(
|
||||
fake_image3 = fake_image.FakeImage(
|
||||
name='another-image',
|
||||
status='active')
|
||||
self.mock_object(self._manager.image_api, 'image_list',
|
||||
@ -760,7 +761,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
|
||||
self._manager._get_service_image, self._manager.admin_context)
|
||||
|
||||
def test_get_service_image_not_active(self):
|
||||
fake_error_image = fake_compute.FakeImage(
|
||||
fake_error_image = fake_image.FakeImage(
|
||||
name='service_image_name',
|
||||
status='error')
|
||||
self.mock_object(self._manager.image_api, 'image_list',
|
||||
@ -770,10 +771,10 @@ class ServiceInstanceManagerTestCase(test.TestCase):
|
||||
self._manager._get_service_image, self._manager.admin_context)
|
||||
|
||||
def test_get_service_image_ambiguous(self):
|
||||
fake_image = fake_compute.FakeImage(
|
||||
fake_image1 = fake_image.FakeImage(
|
||||
name=fake_get_config_option('service_image_name'),
|
||||
status='active')
|
||||
fake_images = [fake_image, fake_image]
|
||||
fake_images = [fake_image1, fake_image1]
|
||||
self.mock_object(self._manager.image_api, 'image_list',
|
||||
mock.Mock(return_value=fake_images))
|
||||
self.assertRaises(
|
||||
|
Loading…
x
Reference in New Issue
Block a user