diff options
| author | Brian Waldon <bcwaldon@gmail.com> | 2012-06-25 14:06:08 -0700 |
|---|---|---|
| committer | Brian Waldon <bcwaldon@gmail.com> | 2012-06-27 14:31:35 -0700 |
| commit | 3aaa0b103447d56f8d3b259c693cd9a3a8dcbe36 (patch) | |
| tree | 00a15f76716fd9e43ce7c24dfc8b45e38a1b4866 /nova/tests | |
| parent | 7e658bd45db6c14b4cd7e3a976caf769873d4ca1 (diff) | |
Cleanup of image service code
* Remove image_service flag
* Move nova.image.fake to nova.tests.image.fake
* Move nova.image.get_default_image_service to
nova.image.glance.get_default_image_service
* Move nova.image.get_image_service to
nova.image.glance.get_remote_image_service
* Related to bp integrate-python-glanceclient
Change-Id: Iea6db7898328a9060fb88586e042efbc0a4351fc
Diffstat (limited to 'nova/tests')
23 files changed, 378 insertions, 99 deletions
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 6dd6fe916..180faeeaa 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -36,12 +36,12 @@ from nova import context from nova import db from nova import exception from nova import flags -from nova.image import fake from nova.image import s3 from nova import log as logging from nova.network import api as network_api from nova.openstack.common import rpc from nova import test +from nova.tests.image import fake from nova import utils @@ -94,6 +94,19 @@ class CloudTestCase(test.TestCase): self.flags(compute_driver='nova.virt.fake.FakeDriver', stub_network=True) + def fake_show(meh, context, id): + return {'id': id, + 'container_format': 'ami', + 'properties': { + 'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175', + 'ramdisk_id': 'cedef40a-ed67-4d10-800e-17455edce175', + 'type': 'machine', + 'image_state': 'available'}} + + self.stubs.Set(fake._FakeImageService, 'show', fake_show) + self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) + fake.stub_out_image_service(self.stubs) + def dumb(*args, **kwargs): pass @@ -115,18 +128,6 @@ class CloudTestCase(test.TestCase): self.project_id, is_admin=True) - def fake_show(meh, context, id): - return {'id': id, - 'container_format': 'ami', - 'properties': { - 'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175', - 'ramdisk_id': 'cedef40a-ed67-4d10-800e-17455edce175', - 'type': 'machine', - 'image_state': 'available'}} - - self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) - # NOTE(comstud): Make 'cast' behave like a 'call' which will # ensure that operations complete self.stubs.Set(rpc, 'cast', rpc.call) @@ -137,6 +138,10 @@ class CloudTestCase(test.TestCase): db.api.s3_image_create(self.context, '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6') + def tearDown(self): + super(CloudTestCase, self).tearDown() + fake.FakeImageService_reset() + def _stub_instance_get_with_fixed_ips(self, func_name): orig_func = getattr(self.cloud.compute_api, func_name) @@ -1618,7 +1623,6 @@ class CloudTestCase(test.TestCase): 'container_format': 'ami', 'status': 'active'} - self.stubs.UnsetAll() self.stubs.Set(fake._FakeImageService, 'show', fake_show) def dumb(*args, **kwargs): @@ -2352,7 +2356,6 @@ class CloudTestCase(test.TestCase): for i in range(3, 7): db.api.s3_image_create(self.context, 'ami-%d' % i) - self.stubs.UnsetAll() self.stubs.Set(fake._FakeImageService, 'show', fake_show) test_dia_iisb('stop', image_id='ami-3') diff --git a/nova/tests/api/ec2/test_ec2_validate.py b/nova/tests/api/ec2/test_ec2_validate.py index d917c3352..ad0de2ca0 100644 --- a/nova/tests/api/ec2/test_ec2_validate.py +++ b/nova/tests/api/ec2/test_ec2_validate.py @@ -22,7 +22,7 @@ from nova import context from nova import db from nova import exception from nova import flags -from nova.image import fake +from nova.tests.image import fake from nova import log as logging from nova.openstack.common import importutils from nova.openstack.common import rpc @@ -50,7 +50,7 @@ class EC2ValidateTestCase(test.TestCase): self.scheduter = self.start_service('scheduler') self.network = self.start_service('network') self.volume = self.start_service('volume') - self.image_service = importutils.import_object(FLAGS.image_service) + self.image_service = fake.FakeImageService() self.user_id = 'fake' self.project_id = 'fake' @@ -80,6 +80,7 @@ class EC2ValidateTestCase(test.TestCase): 'type': 'machine', 'image_state': 'available'}} + fake.stub_out_image_service(self.stubs) self.stubs.Set(fake._FakeImageService, 'show', fake_show) self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) @@ -93,6 +94,10 @@ class EC2ValidateTestCase(test.TestCase): db.api.s3_image_create(self.context, '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6') + def tearDown(self): + super(EC2ValidateTestCase, self).tearDown() + fake.FakeImageService_reset() + #EC2_API tests (InvalidInstanceID.Malformed) def test_console_output(self): for ec2_id, e in self.ec2_id_exception_map: diff --git a/nova/tests/api/openstack/compute/contrib/test_disk_config.py b/nova/tests/api/openstack/compute/contrib/test_disk_config.py index e63c28080..9999d94da 100644 --- a/nova/tests/api/openstack/compute/contrib/test_disk_config.py +++ b/nova/tests/api/openstack/compute/contrib/test_disk_config.py @@ -24,6 +24,7 @@ from nova.openstack.common import jsonutils import nova.openstack.common.rpc from nova import test from nova.tests.api.openstack import fakes +import nova.tests.image.fake MANUAL_INSTANCE_UUID = fakes.FAKE_UUID @@ -45,6 +46,8 @@ class DiskConfigTestCase(test.TestCase): def setUp(self): super(DiskConfigTestCase, self).setUp() self.flags(verbose=True) + nova.tests.image.fake.stub_out_image_service(self.stubs) + fakes.stub_out_nw_api(self.stubs) FAKE_INSTANCES = [ @@ -120,6 +123,10 @@ class DiskConfigTestCase(test.TestCase): self.app = compute.APIRouter() + def tearDown(self): + super(DiskConfigTestCase, self).tearDown() + nova.tests.image.fake.FakeImageService_reset() + def assertDiskConfig(self, dict_, value): self.assert_(API_DISK_CONFIG in dict_) self.assertEqual(dict_[API_DISK_CONFIG], value) diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py index 3e3b4eafc..19d752a9f 100644 --- a/nova/tests/api/openstack/compute/test_server_actions.py +++ b/nova/tests/api/openstack/compute/test_server_actions.py @@ -27,6 +27,7 @@ from nova import flags from nova.openstack.common import importutils from nova import test from nova.tests.api.openstack import fakes +import nova.tests.image.fake from nova import utils @@ -69,7 +70,7 @@ class ServerActionsControllerTest(test.TestCase): fakes.stub_out_nw_api(self.stubs) fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_compute_api_snapshot(self.stubs) - fakes.stub_out_image_service(self.stubs) + nova.tests.image.fake.stub_out_image_service(self.stubs) service_class = 'nova.image.glance.GlanceImageService' self.service = importutils.import_object(service_class) self.service.delete_all() diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index e1d898aeb..91a3ef68d 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -35,12 +35,12 @@ from nova.compute import vm_states import nova.db from nova.db.sqlalchemy import models from nova import flags -import nova.image.fake from nova.openstack.common import jsonutils import nova.openstack.common.rpc from nova import test from nova.tests.api.openstack import fakes from nova.tests import fake_network +import nova.tests.image.fake from nova import utils @@ -99,7 +99,7 @@ class ServersControllerTest(test.TestCase): self.flags(verbose=True, use_ipv6=False) fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) - fakes.stub_out_image_service(self.stubs) + nova.tests.image.fake.stub_out_image_service(self.stubs) return_server = fakes.fake_instance_get() return_servers = fakes.fake_instance_get_all_by_filters() self.stubs.Set(nova.db, 'instance_get_all_by_filters', @@ -1484,7 +1484,7 @@ class ServersControllerCreateTest(test.TestCase): fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) - fakes.stub_out_image_service(self.stubs) + nova.tests.image.fake.stub_out_image_service(self.stubs) fakes.stub_out_nw_api(self.stubs) self.stubs.Set(utils, 'gen_uuid', fake_gen_uuid) self.stubs.Set(nova.db, 'instance_add_security_group', diff --git a/nova/tests/api/openstack/compute/test_urlmap.py b/nova/tests/api/openstack/compute/test_urlmap.py index 67524bcf5..780879e3c 100644 --- a/nova/tests/api/openstack/compute/test_urlmap.py +++ b/nova/tests/api/openstack/compute/test_urlmap.py @@ -19,6 +19,7 @@ from nova import log as logging from nova.openstack.common import jsonutils from nova import test from nova.tests.api.openstack import fakes +import nova.tests.image.fake LOG = logging.getLogger(__name__) @@ -27,6 +28,11 @@ class UrlmapTest(test.TestCase): def setUp(self): super(UrlmapTest, self).setUp() fakes.stub_out_rate_limiting(self.stubs) + nova.tests.image.fake.stub_out_image_service(self.stubs) + + def tearDown(self): + super(UrlmapTest, self).tearDown() + nova.tests.image.fake.FakeImageService_reset() def test_path_version_v1_1(self): """Test URL path specifying v1.1 returns v2 content.""" diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index ca6b25c67..a6dcd4d2f 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -37,7 +37,7 @@ from nova.compute import vm_states from nova import context from nova.db.sqlalchemy import models from nova import exception as exc -import nova.image.fake +import nova.image.glance from nova.openstack.common import jsonutils from nova.openstack.common import timeutils from nova import quota @@ -125,14 +125,6 @@ def stub_out_key_pair_funcs(stubs, have_key_pair=True): stubs.Set(nova.db, 'key_pair_get_all_by_user', no_key_pair) -def stub_out_image_service(stubs): - def fake_get_image_service(context, image_href): - return (nova.image.fake.FakeImageService(), image_href) - stubs.Set(nova.image, 'get_image_service', fake_get_image_service) - stubs.Set(nova.image, 'get_default_image_service', - lambda: nova.image.fake.FakeImageService()) - - def stub_out_rate_limiting(stubs): def fake_rate_init(self, app): super(limits.RateLimitingMiddleware, self).__init__(app) @@ -276,10 +268,12 @@ def stub_out_glance_add_image(stubs, sent_to_glance): def stub_out_glance(stubs): - def fake_get_image_service(): + def fake_get_remote_image_service(): client = glance_stubs.StubGlanceClient(_make_image_fixtures()) return nova.image.glance.GlanceImageService(client) - stubs.Set(nova.image, 'get_default_image_service', fake_get_image_service) + stubs.Set(nova.image.glance, + 'get_default_image_service', + fake_get_remote_image_service) class FakeToken(object): diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index e77b0fcdb..9ae099b60 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -39,7 +39,7 @@ from nova import context from nova import db from nova import exception from nova import flags -from nova.image import fake as fake_image +from nova.tests.image import fake as fake_image from nova import log as logging from nova.notifier import test_notifier from nova.openstack.common import importutils @@ -125,11 +125,13 @@ class BaseTestCase(test.TestCase): 'ramdisk_id': 'fake_ramdisk_id', 'something_else': 'meow'}} + fake_image.stub_out_image_service(self.stubs) self.stubs.Set(fake_image._FakeImageService, 'show', fake_show) self.stubs.Set(rpc, 'call', rpc_call_wrapper) self.stubs.Set(rpc, 'cast', rpc_cast_wrapper) def tearDown(self): + fake_image.FakeImageService_reset() instances = db.instance_get_all(self.context.elevated()) for instance in instances: db.instance_destroy(self.context.elevated(), instance['uuid']) diff --git a/nova/tests/fake_flags.py b/nova/tests/fake_flags.py index 3d05d7605..5bcfb4c71 100644 --- a/nova/tests/fake_flags.py +++ b/nova/tests/fake_flags.py @@ -38,7 +38,6 @@ def set_defaults(conf): conf.set_default('fake_network', True) conf.set_default('fake_rabbit', True) conf.set_default('flat_network_bridge', 'br100') - conf.set_default('image_service', 'nova.image.fake.FakeImageService') conf.set_default('iscsi_num_targets', 8) conf.set_default('network_size', 8) conf.set_default('num_networks', 2) diff --git a/nova/tests/image/fake.py b/nova/tests/image/fake.py new file mode 100644 index 000000000..017611aa9 --- /dev/null +++ b/nova/tests/image/fake.py @@ -0,0 +1,264 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 Justin Santa Barbara +# Copyright 2012 OpenStack LLC +# 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. + +"""Implementation of a fake image service""" + +import copy +import datetime + +from nova import exception +from nova import flags +import nova.image.glance +from nova import log as logging +from nova import utils + + +LOG = logging.getLogger(__name__) + + +FLAGS = flags.FLAGS + + +class _FakeImageService(object): + """Mock (fake) image service for unit testing.""" + + def __init__(self): + self.images = {} + # NOTE(justinsb): The OpenStack API can't upload an image? + # So, make sure we've got one.. + timestamp = datetime.datetime(2011, 01, 01, 01, 02, 03) + + image1 = {'id': '155d900f-4e14-4e4c-a73d-069cbf4541e6', + 'name': 'fakeimage123456', + 'created_at': timestamp, + 'updated_at': timestamp, + 'deleted_at': None, + 'deleted': False, + 'status': 'active', + 'is_public': False, + 'container_format': 'raw', + 'disk_format': 'raw', + 'properties': {'kernel_id': FLAGS.null_kernel, + 'ramdisk_id': FLAGS.null_kernel, + 'architecture': 'x86_64'}} + + image2 = {'id': 'a2459075-d96c-40d5-893e-577ff92e721c', + 'name': 'fakeimage123456', + 'created_at': timestamp, + 'updated_at': timestamp, + 'deleted_at': None, + 'deleted': False, + 'status': 'active', + 'is_public': True, + 'container_format': 'ami', + 'disk_format': 'ami', + 'properties': {'kernel_id': FLAGS.null_kernel, + 'ramdisk_id': FLAGS.null_kernel}} + + image3 = {'id': '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6', + 'name': 'fakeimage123456', + 'created_at': timestamp, + 'updated_at': timestamp, + 'deleted_at': None, + 'deleted': False, + 'status': 'active', + 'is_public': True, + 'container_format': None, + 'disk_format': None, + 'properties': {'kernel_id': FLAGS.null_kernel, + 'ramdisk_id': FLAGS.null_kernel}} + + image4 = {'id': 'cedef40a-ed67-4d10-800e-17455edce175', + 'name': 'fakeimage123456', + 'created_at': timestamp, + 'updated_at': timestamp, + 'deleted_at': None, + 'deleted': False, + 'status': 'active', + 'is_public': True, + 'container_format': 'ami', + 'disk_format': 'ami', + 'properties': {'kernel_id': FLAGS.null_kernel, + 'ramdisk_id': FLAGS.null_kernel}} + + image5 = {'id': 'c905cedb-7281-47e4-8a62-f26bc5fc4c77', + 'name': 'fakeimage123456', + 'created_at': timestamp, + 'updated_at': timestamp, + 'deleted_at': None, + 'deleted': False, + 'status': 'active', + 'is_public': True, + 'container_format': 'ami', + 'disk_format': 'ami', + 'properties': {'kernel_id': + '155d900f-4e14-4e4c-a73d-069cbf4541e6', + 'ramdisk_id': None}} + + image6 = {'id': 'a440c04b-79fa-479c-bed1-0b816eaec379', + 'name': 'fakeimage6', + 'created_at': timestamp, + 'updated_at': timestamp, + 'deleted_at': None, + 'deleted': False, + 'status': 'active', + 'is_public': False, + 'container_format': 'ova', + 'disk_format': 'vhd', + 'properties': {'kernel_id': FLAGS.null_kernel, + 'ramdisk_id': FLAGS.null_kernel, + 'architecture': 'x86_64', + 'auto_disk_config': 'False'}} + + image7 = {'id': '70a599e0-31e7-49b7-b260-868f441e862b', + 'name': 'fakeimage7', + 'created_at': timestamp, + 'updated_at': timestamp, + 'deleted_at': None, + 'deleted': False, + 'status': 'active', + 'is_public': False, + 'container_format': 'ova', + 'disk_format': 'vhd', + 'properties': {'kernel_id': FLAGS.null_kernel, + 'ramdisk_id': FLAGS.null_kernel, + 'architecture': 'x86_64', + 'auto_disk_config': 'True'}} + + self.create(None, image1) + self.create(None, image2) + self.create(None, image3) + self.create(None, image4) + self.create(None, image5) + self.create(None, image6) + self.create(None, image7) + self._imagedata = {} + super(_FakeImageService, self).__init__() + + #TODO(bcwaldon): implement optional kwargs such as limit, sort_dir + def index(self, context, **kwargs): + """Returns list of images.""" + retval = [] + for img in self.images.values(): + retval += [dict([(k, v) for k, v in img.iteritems() + if k in ['id', 'name']])] + return retval + + #TODO(bcwaldon): implement optional kwargs such as limit, sort_dir + def detail(self, context, **kwargs): + """Return list of detailed image information.""" + return copy.deepcopy(self.images.values()) + + def get(self, context, image_id, data): + metadata = self.show(context, image_id) + data.write(self._imagedata.get(image_id, '')) + return metadata + + def show(self, context, image_id): + """Get data about specified image. + + Returns a dict containing image data for the given opaque image id. + + """ + image = self.images.get(str(image_id)) + if image: + return copy.deepcopy(image) + LOG.warn('Unable to find image id %s. Have images: %s', + image_id, self.images) + raise exception.ImageNotFound(image_id=image_id) + + def show_by_name(self, context, name): + """Returns a dict containing image data for the given name.""" + images = copy.deepcopy(self.images.values()) + for image in images: + if name == image.get('name'): + return image + raise exception.ImageNotFound(image_id=name) + + def create(self, context, metadata, data=None): + """Store the image data and return the new image id. + + :raises: Duplicate if the image already exist. + + """ + image_id = str(metadata.get('id', utils.gen_uuid())) + metadata['id'] = image_id + if image_id in self.images: + raise exception.Duplicate() + self.images[image_id] = copy.deepcopy(metadata) + if data: + self._imagedata[image_id] = data.read() + return self.images[image_id] + + def update(self, context, image_id, metadata, data=None, + headers=None): + """Replace the contents of the given image with the new data. + + :raises: ImageNotFound if the image does not exist. + + """ + if not self.images.get(image_id): + raise exception.ImageNotFound(image_id=image_id) + try: + purge = headers['x-glance-registry-purge-props'] + except Exception: + purge = True + if purge: + self.images[image_id] = copy.deepcopy(metadata) + else: + image = self.images[image_id] + try: + image['properties'].update(metadata.pop('properties')) + except Exception: + pass + image.update(metadata) + return self.images[image_id] + + def delete(self, context, image_id): + """Delete the given image. + + :raises: ImageNotFound if the image does not exist. + + """ + removed = self.images.pop(image_id, None) + if not removed: + raise exception.ImageNotFound(image_id=image_id) + + def delete_all(self): + """Clears out all images.""" + self.images.clear() + +_fakeImageService = _FakeImageService() + + +def FakeImageService(): + return _fakeImageService + + +def FakeImageService_reset(): + global _fakeImageService + _fakeImageService = _FakeImageService() + + +def stub_out_image_service(stubs): + def fake_get_remote_image_service(context, image_href): + return (FakeImageService(), image_href) + stubs.Set(nova.image.glance, 'get_remote_image_service', + lambda x, y: (FakeImageService(), y)) + stubs.Set(nova.image.glance, 'get_default_image_service', + lambda: FakeImageService()) diff --git a/nova/tests/test_image.py b/nova/tests/image/test_fake.py index 6482d779b..eb1136894 100644 --- a/nova/tests/test_image.py +++ b/nova/tests/image/test_fake.py @@ -20,15 +20,20 @@ import StringIO from nova import context from nova import exception -import nova.image +import nova.tests.image.fake from nova import test -class _ImageTestCase(test.TestCase): +class FakeImageServiceTestCase(test.TestCase): def setUp(self): - super(_ImageTestCase, self).setUp() + super(FakeImageServiceTestCase, self).setUp() + self.image_service = nova.tests.image.fake.FakeImageService() self.context = context.get_admin_context() + def tearDown(self): + super(FakeImageServiceTestCase, self).setUp() + nova.tests.image.fake.FakeImageService_reset() + def test_index(self): res = self.image_service.index(self.context) for image in res: @@ -138,9 +143,3 @@ class _ImageTestCase(test.TestCase): s2 = StringIO.StringIO() self.image_service.get(self.context, '32', data=s2) self.assertEquals(s2.getvalue(), blob, 'Did not get blob back intact') - - -class FakeImageTestCase(_ImageTestCase): - def setUp(self): - super(FakeImageTestCase, self).setUp() - self.image_service = nova.image.fake.FakeImageService() diff --git a/nova/tests/image/test_s3.py b/nova/tests/image/test_s3.py index 9f078fc49..9b4b5757f 100644 --- a/nova/tests/image/test_s3.py +++ b/nova/tests/image/test_s3.py @@ -24,6 +24,7 @@ import tempfile from nova import context import nova.db.api from nova import exception +from nova.tests.image import fake from nova.image import s3 from nova import test @@ -81,14 +82,19 @@ file_manifest_xml = """<?xml version="1.0" ?> class TestS3ImageService(test.TestCase): def setUp(self): super(TestS3ImageService, self).setUp() - self.flags(image_service='nova.image.fake.FakeImageService') - self.image_service = s3.S3ImageService() self.context = context.RequestContext(None, None) # set up one fixture to test shows, should have id '1' nova.db.api.s3_image_create(self.context, '155d900f-4e14-4e4c-a73d-069cbf4541e6') + fake.stub_out_image_service(self.stubs) + self.image_service = s3.S3ImageService() + + def tearDown(self): + super(TestS3ImageService, self).tearDown() + fake.FakeImageService_reset() + def _assertEqualList(self, list0, list1, keys): self.assertEqual(len(list0), len(list1)) key = keys[0] @@ -183,8 +189,8 @@ class TestS3ImageService(test.TestCase): eventlet.sleep() translated = self.image_service._translate_id_to_uuid(context, img) uuid = translated['id'] - self.glance_service = nova.image.get_default_image_service() - updated_image = self.glance_service.update(self.context, uuid, + image_service = fake.FakeImageService() + updated_image = image_service.update(self.context, uuid, {'is_public': True}, None, {'x-glance-registry-purge-props': False}) self.assertTrue(updated_image['is_public']) diff --git a/nova/tests/integrated/integrated_helpers.py b/nova/tests/integrated/integrated_helpers.py index e205dfb18..a514de677 100644 --- a/nova/tests/integrated/integrated_helpers.py +++ b/nova/tests/integrated/integrated_helpers.py @@ -22,10 +22,10 @@ Provides common functionality for integrated unit tests import random import string -import nova.image.glance from nova.log import logging from nova import service from nova import test # For the flags +import nova.tests.image.fake from nova.tests.integrated.api import client from nova import utils @@ -65,10 +65,7 @@ class _IntegratedTestBase(test.TestCase): self.flags(**f) self.flags(verbose=True) - def fake_get_image_service(context, image_href): - image_id = str(image_href).split('/')[-1] - return (nova.image.fake.FakeImageService(), image_id) - self.stubs.Set(nova.image, 'get_image_service', fake_get_image_service) + nova.tests.image.fake.stub_out_image_service(self.stubs) self.flags(compute_scheduler_driver='nova.scheduler.' 'chance.ChanceScheduler') @@ -84,6 +81,7 @@ class _IntegratedTestBase(test.TestCase): def tearDown(self): self.osapi.stop() + nova.tests.image.fake.FakeImageService_reset() super(_IntegratedTestBase, self).tearDown() def _start_api_service(self): @@ -108,7 +106,6 @@ class _IntegratedTestBase(test.TestCase): f['osapi_volume_listen_port'] = 0 f['metadata_listen_port'] = 0 - f['image_service'] = 'nova.image.fake.FakeImageService' f['fake_network'] = True return f diff --git a/nova/tests/test_compute_utils.py b/nova/tests/test_compute_utils.py index 50c85073f..0955134ba 100644 --- a/nova/tests/test_compute_utils.py +++ b/nova/tests/test_compute_utils.py @@ -22,12 +22,12 @@ from nova.compute import utils as compute_utils from nova import context from nova import db from nova import flags -import nova.image.fake from nova import log as logging from nova.notifier import test_notifier from nova.openstack.common import importutils from nova import test from nova.tests import fake_network +import nova.tests.image.fake from nova import utils @@ -61,7 +61,8 @@ class UsageInfoTestCase(test.TestCase): def fake_show(meh, context, id): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} - self.stubs.Set(nova.image.fake._FakeImageService, 'show', fake_show) + self.stubs.Set(nova.tests.image.fake._FakeImageService, + 'show', fake_show) def _create_instance(self, params={}): """Create a test instance""" diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 75ab99383..510bcad7c 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -40,6 +40,7 @@ from nova.openstack.common import jsonutils from nova import test from nova.tests import fake_libvirt_utils from nova.tests import fake_network +import nova.tests.image.fake from nova import utils from nova.virt import driver from nova.virt import firewall as base_firewall @@ -427,8 +428,11 @@ class LibvirtConnTestCase(test.TestCase): self.stubs.Set(libvirt_driver.disk, 'extend', fake_extend) + nova.tests.image.fake.stub_out_image_service(self.stubs) + def tearDown(self): libvirt_driver.libvirt_utils = libvirt_utils + nova.tests.image.fake.FakeImageService_reset() super(LibvirtConnTestCase, self).tearDown() test_instance = {'memory_kb': '1024000', @@ -458,7 +462,6 @@ class LibvirtConnTestCase(test.TestCase): for key, val in kwargs.items(): fake.__setattr__(key, val) - self.flags(image_service='nova.image.fake.FakeImageService') self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver") self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, '_conn') @@ -807,10 +810,8 @@ class LibvirtConnTestCase(test.TestCase): @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_snapshot_in_ami_format(self): - self.flags(image_service='nova.image.fake.FakeImageService') - # Start test - image_service = importutils.import_object(FLAGS.image_service) + image_service = nova.tests.image.fake.FakeImageService() # Assign different image_ref from nova/images/fakes for testing ami test_instance = copy.deepcopy(self.test_instance) @@ -845,10 +846,8 @@ class LibvirtConnTestCase(test.TestCase): @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_snapshot_in_raw_format(self): - self.flags(image_service='nova.image.fake.FakeImageService') - # Start test - image_service = importutils.import_object(FLAGS.image_service) + image_service = nova.tests.image.fake.FakeImageService() # Assuming that base image already exists in image_service instance_ref = db.instance_create(self.context, self.test_instance) @@ -879,11 +878,10 @@ class LibvirtConnTestCase(test.TestCase): @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_snapshot_in_qcow2_format(self): - self.flags(image_service='nova.image.fake.FakeImageService') self.flags(snapshot_image_format='qcow2') # Start test - image_service = importutils.import_object(FLAGS.image_service) + image_service = nova.tests.image.fake.FakeImageService() # Assuming that base image already exists in image_service instance_ref = db.instance_create(self.context, self.test_instance) @@ -914,10 +912,8 @@ class LibvirtConnTestCase(test.TestCase): @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_snapshot_no_image_architecture(self): - self.flags(image_service='nova.image.fake.FakeImageService') - # Start test - image_service = importutils.import_object(FLAGS.image_service) + image_service = nova.tests.image.fake.FakeImageService() # Assign different image_ref from nova/images/fakes for # testing different base image @@ -952,10 +948,8 @@ class LibvirtConnTestCase(test.TestCase): @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_snapshot_no_original_image(self): - self.flags(image_service='nova.image.fake.FakeImageService') - # Start test - image_service = importutils.import_object(FLAGS.image_service) + image_service = nova.tests.image.fake.FakeImageService() # Assign a non-existent image test_instance = copy.deepcopy(self.test_instance) diff --git a/nova/tests/test_notifications.py b/nova/tests/test_notifications.py index 5ce45d777..ff6acb155 100644 --- a/nova/tests/test_notifications.py +++ b/nova/tests/test_notifications.py @@ -25,9 +25,9 @@ from nova.compute import vm_states from nova import context from nova import db from nova import flags -import nova.image.fake from nova import log as logging from nova import notifications +import nova.network from nova.notifier import test_notifier from nova import test from nova.tests import fake_network diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py index 54489918b..eefde358e 100644 --- a/nova/tests/test_quota.py +++ b/nova/tests/test_quota.py @@ -31,6 +31,7 @@ from nova.openstack.common import timeutils from nova import quota from nova.scheduler import driver as scheduler_driver from nova import test +import nova.tests.image.fake from nova import volume @@ -39,11 +40,6 @@ FLAGS = flags.FLAGS class QuotaIntegrationTestCase(test.TestCase): - class StubImageService(object): - - def show(self, *args, **kwargs): - return {"properties": {}} - def setUp(self): super(QuotaIntegrationTestCase, self).setUp() self.flags(compute_driver='nova.virt.fake.FakeDriver', @@ -78,6 +74,11 @@ class QuotaIntegrationTestCase(test.TestCase): return orig_rpc_call(context, topic, msg) self.stubs.Set(rpc, 'call', rpc_call_wrapper) + nova.tests.image.fake.stub_out_image_service(self.stubs) + + def tearDown(self): + super(QuotaIntegrationTestCase, self).tearDown() + nova.tests.image.fake.FakeImageService_reset() def _create_instance(self, cores=2): """Create a test instance""" @@ -173,8 +174,7 @@ class QuotaIntegrationTestCase(test.TestCase): metadata=metadata) def _create_with_injected_files(self, files): - self.flags(image_service='nova.image.fake.FakeImageService') - api = compute.API(image_service=self.StubImageService()) + api = compute.API() inst_type = instance_types.get_instance_type_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' api.create(self.context, min_count=1, max_count=1, @@ -182,8 +182,7 @@ class QuotaIntegrationTestCase(test.TestCase): injected_files=files) def test_no_injected_files(self): - self.flags(image_service='nova.image.fake.FakeImageService') - api = compute.API(image_service=self.StubImageService()) + api = compute.API() inst_type = instance_types.get_instance_type_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' api.create(self.context, diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 9f54089bf..6443c6721 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -21,10 +21,10 @@ import traceback from nova.compute.manager import ComputeManager from nova import exception -from nova import image from nova import log as logging from nova.openstack.common import importutils from nova import test +from nova.tests.image import fake as fake_image from nova.tests import utils as test_utils LOG = logging.getLogger(__name__) @@ -102,9 +102,11 @@ class _FakeDriverBackendTestCase(test.TestCase): # TODO(sdague): it would be nice to do this in a way that only # the relevant backends where replaced for tests, though this # should not harm anything by doing it for all backends + fake_image.stub_out_image_service(self.stubs) self._setup_fakelibvirt() def tearDown(self): + fake_image.FakeImageService_reset() self._teardown_fakelibvirt() super(_FakeDriverBackendTestCase, self).tearDown() @@ -177,7 +179,7 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): super(_VirtDriverTestCase, self).setUp() self.connection = importutils.import_object(self.driver_module, '') self.ctxt = test_utils.get_test_admin_context() - self.image_service = image.get_default_image_service() + self.image_service = fake_image.FakeImageService() def _get_running_instance(self): instance_ref = test_utils.get_test_instance() diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py index 7c2653f84..647a9d0a0 100644 --- a/nova/tests/test_vmwareapi.py +++ b/nova/tests/test_vmwareapi.py @@ -24,9 +24,8 @@ from nova import context from nova import db from nova import exception from nova import flags -import nova.image.fake from nova import test -import nova.tests.api.openstack.fakes as api_fakes +import nova.tests.image.fake from nova.tests.vmwareapi import db_fakes from nova.tests.vmwareapi import stubs from nova.virt.vmwareapi import fake as vmwareapi_fake @@ -78,12 +77,12 @@ class VMWareAPIVMTestCase(test.TestCase): 'disk_format': 'vhd', 'size': 512, } - api_fakes.stub_out_image_service(self.stubs) + nova.tests.image.fake.stub_out_image_service(self.stubs) def tearDown(self): super(VMWareAPIVMTestCase, self).tearDown() vmwareapi_fake.cleanup() - nova.image.fake.FakeImageService_reset() + nova.tests.image.fake.FakeImageService_reset() def _create_instance_in_the_db(self): values = {'name': 1, diff --git a/nova/tests/test_volume_utils.py b/nova/tests/test_volume_utils.py index 222f12266..b2ccb41b8 100644 --- a/nova/tests/test_volume_utils.py +++ b/nova/tests/test_volume_utils.py @@ -20,7 +20,6 @@ from nova import context from nova import db from nova import flags -import nova.image.fake from nova import log as logging from nova.notifier import test_notifier from nova.openstack.common import importutils @@ -39,7 +38,7 @@ class UsageInfoTestCase(test.TestCase): self.flags(compute_driver='nova.virt.fake.FakeDriver', stub_network=True, host='fake') - self.stubs.Set(nova.flags.FLAGS, 'notification_driver', + self.stubs.Set(flags.FLAGS, 'notification_driver', 'nova.notifier.test_notifier') self.volume = importutils.import_object(FLAGS.volume_manager) self.user_id = 'fake' diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index bdef5c6d4..ca3fb3263 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -29,7 +29,6 @@ from nova import context from nova import db from nova import exception from nova import flags -import nova.image.fake from nova import log as logging from nova.openstack.common import importutils from nova.openstack.common import timeutils @@ -38,6 +37,7 @@ import nova.tests.api.openstack.fakes as api_fakes from nova.tests.db import fakes as db_fakes from nova.tests import fake_network from nova.tests import fake_utils +import nova.tests.image.fake from nova.tests.xenapi import stubs from nova.virt.xenapi import connection as xenapi_conn from nova.virt.xenapi import fake as xenapi_fake @@ -92,7 +92,7 @@ IMAGE_FIXTURES = { def set_image_fixtures(): - image_service = nova.image.fake.FakeImageService() + image_service = nova.tests.image.fake.FakeImageService() image_service.delete_all() for image_id, image_meta in IMAGE_FIXTURES.items(): image_meta = image_meta['image_meta'] @@ -113,23 +113,23 @@ def stub_vm_utils_with_vdi_attached_here(function, should_return=True): fake_dev = 'fakedev' yield fake_dev - def fake_image_service_get(*args, **kwargs): + def fake_image_get(*args, **kwargs): pass def fake_is_vdi_pv(*args, **kwargs): return should_return orig_vdi_attached_here = vm_utils.vdi_attached_here - orig_image_service_get = nova.image.fake._FakeImageService.get + orig_image_get = nova.tests.image.fake._FakeImageService.get orig_is_vdi_pv = vm_utils._is_vdi_pv try: vm_utils.vdi_attached_here = fake_vdi_attached_here - nova.image.fake._FakeImageService.get = fake_image_service_get + nova.tests.image.fake._FakeImageService.get = fake_image_get vm_utils._is_vdi_pv = fake_is_vdi_pv return function(self, *args, **kwargs) finally: vm_utils._is_vdi_pv = orig_is_vdi_pv - nova.image.fake._FakeImageService.get = orig_image_service_get + nova.tests.image.fake._FakeImageService.get = orig_image_get vm_utils.vdi_attached_here = orig_vdi_attached_here return decorated_function @@ -278,14 +278,14 @@ class XenAPIVMTestCase(test.TestCase): self.context = context.RequestContext(self.user_id, self.project_id) self.conn = xenapi_conn.XenAPIDriver(False) - api_fakes.stub_out_image_service(self.stubs) + nova.tests.image.fake.stub_out_image_service(self.stubs) set_image_fixtures() stubs.stubout_image_service_get(self.stubs) stubs.stubout_stream_disk(self.stubs) def tearDown(self): super(XenAPIVMTestCase, self).tearDown() - nova.image.fake.FakeImageService_reset() + nova.tests.image.fake.FakeImageService_reset() def test_init_host(self): session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass') diff --git a/nova/tests/utils.py b/nova/tests/utils.py index 17fa2a049..46feca99e 100644 --- a/nova/tests/utils.py +++ b/nova/tests/utils.py @@ -17,6 +17,7 @@ import nova.context import nova.db import nova.flags +from nova.image import glance FLAGS = nova.flags.FLAGS @@ -30,7 +31,8 @@ def get_test_image_info(context, instance_ref): context = get_test_admin_context() image_ref = instance_ref['image_ref'] - image_service, image_id = nova.image.get_image_service(context, image_ref) + image_service, image_id = glance.get_remote_image_service(context, + image_ref) return image_service.show(context, image_id) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 7f32e96fb..0116c4d99 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -19,8 +19,8 @@ import random from eventlet import tpool -import nova.image.fake from nova.openstack.common import jsonutils +import nova.tests.image.fake from nova.virt.xenapi import connection as xenapi_conn from nova.virt.xenapi import fake from nova.virt.xenapi import vm_utils @@ -85,7 +85,7 @@ def stubout_get_this_vm_uuid(stubs): def stubout_image_service_get(stubs): def fake_get(*args, **kwargs): pass - stubs.Set(nova.image.fake._FakeImageService, 'get', fake_get) + stubs.Set(nova.tests.image.fake._FakeImageService, 'get', fake_get) def stubout_stream_disk(stubs): |
