summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <bcwaldon@gmail.com>2012-06-27 12:24:17 -0700
committerBrian Waldon <bcwaldon@gmail.com>2012-06-27 21:35:48 -0700
commit95dd69d6eba3352b63495b8746281dd2e2476508 (patch)
treed4134437a2eb7ca2c13642b0efdb350284f79478
parentd537f641c71fba1acd10a617eb804c15ac1cbd3b (diff)
Rename GlanceImageService.get to download
In preparation for integration with the new Glance client, this drops the return of image metadata from GlanceImageService.get in addition to renaming it to 'download'. Change-Id: I75ca3a0a909335e74cd521da6f894c163e773e94
-rw-r--r--nova/image/glance.py5
-rw-r--r--nova/tests/image/fake.py5
-rw-r--r--nova/tests/image/test_fake.py2
-rw-r--r--nova/tests/image/test_glance.py16
-rw-r--r--nova/tests/test_xenapi.py19
-rw-r--r--nova/tests/xenapi/stubs.py7
-rw-r--r--nova/virt/images.py3
-rw-r--r--nova/virt/vmwareapi/vmware_images.py5
-rw-r--r--nova/virt/xenapi/vm_utils.py3
9 files changed, 27 insertions, 38 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py
index c01a7b957..6691afeb0 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -235,7 +235,7 @@ class GlanceImageService(object):
base_image_meta = self._translate_from_glance(image_meta)
return base_image_meta
- def get(self, context, image_id, data):
+ def download(self, context, image_id, data):
"""Calls out to Glance for metadata and data and writes data."""
try:
image_meta, image_chunks = self._call_retry(context, 'get_image',
@@ -246,9 +246,6 @@ class GlanceImageService(object):
for chunk in image_chunks:
data.write(chunk)
- base_image_meta = self._translate_from_glance(image_meta)
- return base_image_meta
-
def create(self, context, image_meta, data=None):
"""Store the image data and return the new image id.
diff --git a/nova/tests/image/fake.py b/nova/tests/image/fake.py
index ffb2e050b..99b1a6175 100644
--- a/nova/tests/image/fake.py
+++ b/nova/tests/image/fake.py
@@ -155,10 +155,9 @@ class _FakeImageService(object):
"""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)
+ def download(self, context, image_id, data):
+ 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.
diff --git a/nova/tests/image/test_fake.py b/nova/tests/image/test_fake.py
index 1361b984c..bd7ae7d5b 100644
--- a/nova/tests/image/test_fake.py
+++ b/nova/tests/image/test_fake.py
@@ -123,5 +123,5 @@ class FakeImageServiceTestCase(test.TestCase):
{'id': '32', 'foo': 'bar'},
data=s1)
s2 = StringIO.StringIO()
- self.image_service.get(self.context, '32', data=s2)
+ self.image_service.download(self.context, '32', data=s2)
self.assertEquals(s2.getvalue(), blob, 'Did not get blob back intact')
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index f8d2c2d9d..0518007c9 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -453,15 +453,7 @@ class TestGlanceImageService(test.TestCase):
self.assertEqual(image_meta['created_at'], self.NOW_DATETIME)
self.assertEqual(image_meta['updated_at'], self.NOW_DATETIME)
- def test_get_makes_datetimes(self):
- fixture = self._make_datetime_fixture()
- image_id = self.service.create(self.context, fixture)['id']
- writer = NullWriter()
- image_meta = self.service.get(self.context, image_id, writer)
- self.assertEqual(image_meta['created_at'], self.NOW_DATETIME)
- self.assertEqual(image_meta['updated_at'], self.NOW_DATETIME)
-
- def test_get_with_retries(self):
+ def test_download_with_retries(self):
tries = [0]
class GlanceBusyException(Exception):
@@ -483,12 +475,12 @@ class TestGlanceImageService(test.TestCase):
# When retries are disabled, we should get an exception
self.flags(glance_num_retries=0)
- self.assertRaises(GlanceBusyException, service.get, self.context,
+ self.assertRaises(GlanceBusyException, service.download, self.context,
image_id, writer)
# Now lets enable retries. No exception should happen now.
self.flags(glance_num_retries=1)
- service.get(self.context, image_id, writer)
+ service.download(self.context, image_id, writer)
def test_client_raises_forbidden(self):
class MyGlanceStubClient(glance_stubs.StubGlanceClient):
@@ -500,7 +492,7 @@ class TestGlanceImageService(test.TestCase):
service = glance.GlanceImageService(client=client)
image_id = 1 # doesn't matter
writer = NullWriter()
- self.assertRaises(exception.ImageNotAuthorized, service.get,
+ self.assertRaises(exception.ImageNotAuthorized, service.download,
self.context, image_id, writer)
def test_glance_client_image_id(self):
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index ca3fb3263..668172a92 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -33,11 +33,10 @@ from nova import log as logging
from nova.openstack.common import importutils
from nova.openstack.common import timeutils
from nova import test
-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
+import nova.tests.image.fake as fake_image
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 +91,7 @@ IMAGE_FIXTURES = {
def set_image_fixtures():
- image_service = nova.tests.image.fake.FakeImageService()
+ image_service = fake_image.FakeImageService()
image_service.delete_all()
for image_id, image_meta in IMAGE_FIXTURES.items():
image_meta = image_meta['image_meta']
@@ -113,23 +112,23 @@ def stub_vm_utils_with_vdi_attached_here(function, should_return=True):
fake_dev = 'fakedev'
yield fake_dev
- def fake_image_get(*args, **kwargs):
+ def fake_image_download(*args, **kwargs):
pass
def fake_is_vdi_pv(*args, **kwargs):
return should_return
orig_vdi_attached_here = vm_utils.vdi_attached_here
- orig_image_get = nova.tests.image.fake._FakeImageService.get
+ orig_image_download = fake_image._FakeImageService.download
orig_is_vdi_pv = vm_utils._is_vdi_pv
try:
vm_utils.vdi_attached_here = fake_vdi_attached_here
- nova.tests.image.fake._FakeImageService.get = fake_image_get
+ fake_image._FakeImageService.download = fake_image_download
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.tests.image.fake._FakeImageService.get = orig_image_get
+ fake_image._FakeImageService.download = orig_image_download
vm_utils.vdi_attached_here = orig_vdi_attached_here
return decorated_function
@@ -278,14 +277,14 @@ class XenAPIVMTestCase(test.TestCase):
self.context = context.RequestContext(self.user_id, self.project_id)
self.conn = xenapi_conn.XenAPIDriver(False)
- nova.tests.image.fake.stub_out_image_service(self.stubs)
+ fake_image.stub_out_image_service(self.stubs)
set_image_fixtures()
- stubs.stubout_image_service_get(self.stubs)
+ stubs.stubout_image_service_download(self.stubs)
stubs.stubout_stream_disk(self.stubs)
def tearDown(self):
super(XenAPIVMTestCase, self).tearDown()
- nova.tests.image.fake.FakeImageService_reset()
+ fake_image.FakeImageService_reset()
def test_init_host(self):
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 0116c4d99..47b950e01 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -82,10 +82,11 @@ def stubout_get_this_vm_uuid(stubs):
stubs.Set(vm_utils, 'get_this_vm_uuid', f)
-def stubout_image_service_get(stubs):
- def fake_get(*args, **kwargs):
+def stubout_image_service_download(stubs):
+ def fake_download(*args, **kwargs):
pass
- stubs.Set(nova.tests.image.fake._FakeImageService, 'get', fake_get)
+ stubs.Set(nova.tests.image.fake._FakeImageService,
+ 'download', fake_download)
def stubout_stream_disk(stubs):
diff --git a/nova/virt/images.py b/nova/virt/images.py
index ffb2e8e36..78bd8aebc 100644
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -52,8 +52,7 @@ def fetch(context, image_href, path, _user_id, _project_id):
image_href)
with utils.remove_path_on_error(path):
with open(path, "wb") as image_file:
- metadata = image_service.get(context, image_id, image_file)
- return metadata
+ image_service.download(context, image_id, image_file)
def fetch_to_raw(context, image_href, path, user_id, project_id):
diff --git a/nova/virt/vmwareapi/vmware_images.py b/nova/virt/vmwareapi/vmware_images.py
index 56088acb7..c1ab77fa5 100644
--- a/nova/virt/vmwareapi/vmware_images.py
+++ b/nova/virt/vmwareapi/vmware_images.py
@@ -91,10 +91,11 @@ def fetch_image(context, image, instance, **kwargs):
LOG.debug(_("Downloading image %s from glance image server") % image,
instance=instance)
(image_service, image_id) = glance.get_remote_image_service(context, image)
+ metadata = image_service.show(context, image_id)
+ file_size = int(metadata['size'])
f = StringIO.StringIO()
- metadata = image_service.get(context, image_id, f)
+ image_service.download(context, image_id, f)
read_file_handle = read_write_util.GlanceFileRead(f)
- file_size = int(metadata['size'])
write_file_handle = read_write_util.VMWareHTTPWriteFile(
kwargs.get("host"),
kwargs.get("data_center_name"),
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index afde16894..b0f617e48 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -893,7 +893,8 @@ def _fetch_image_glance_disk(context, session, instance, image_id, image_type):
vdi_uuid = session.call_xenapi("VDI.get_uuid", vdi_ref)
with vdi_attached_here(session, vdi_ref, read_only=False) as dev:
- stream_func = lambda f: image_service.get(context, image_id, f)
+ stream_func = lambda f: image_service.download(
+ context, image_id, f)
_stream_disk(stream_func, image_type, virtual_size, dev)
if image_type in (ImageType.KERNEL, ImageType.RAMDISK):