summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-21 23:05:19 +0000
committerGerrit Code Review <review@openstack.org>2013-01-21 23:05:19 +0000
commita4d608fa33b328d7ed77c7f9c40ffbb43c0ade6b (patch)
treecf59f08d89515cb1f20da8e01de685bd2f8a9e99 /nova/tests
parent07531ad264a4fd21faa89f19ad032bf34a223d38 (diff)
parent20fca1a2d75c2cd813245200c138df6e854b681b (diff)
Merge "Directly copy a file URL from glance."
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/image/test_glance.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index 7c13796a6..9dd9e5121 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -17,7 +17,10 @@
import datetime
+import filecmp
+import os
import random
+import tempfile
import time
import glanceclient.exc
@@ -468,6 +471,40 @@ class TestGlanceImageService(test.TestCase):
self.flags(glance_num_retries=1)
service.download(self.context, image_id, writer)
+ def test_download_file_url(self):
+ class MyGlanceStubClient(glance_stubs.StubGlanceClient):
+ """A client that returns a file url."""
+
+ (outfd, s_tmpfname) = tempfile.mkstemp(prefix='directURLsrc')
+ outf = os.fdopen(outfd, 'w')
+ inf = open('/dev/urandom', 'r')
+ for i in range(10):
+ _data = inf.read(1024)
+ outf.write(_data)
+ outf.close()
+
+ def get(self, image_id):
+ return type('GlanceTestDirectUrlMeta', (object,),
+ {'direct_url': 'file://%s' + self.s_tmpfname})
+
+ client = MyGlanceStubClient()
+ (outfd, tmpfname) = tempfile.mkstemp(prefix='directURLdst')
+ writer = os.fdopen(outfd, 'w')
+
+ service = self._create_image_service(client)
+ image_id = 1 # doesn't matter
+
+ self.flags(allowed_direct_url_schemes=['file'])
+ service.download(self.context, image_id, writer)
+ writer.close()
+
+ # compare the two files
+ rc = filecmp.cmp(tmpfname, client.s_tmpfname)
+ self.assertTrue(rc, "The file %s and %s should be the same" %
+ (tmpfname, client.s_tmpfname))
+ os.remove(client.s_tmpfname)
+ os.remove(tmpfname)
+
def test_client_forbidden_converts_to_imagenotauthed(self):
class MyGlanceStubClient(glance_stubs.StubGlanceClient):
"""A client that raises a Forbidden exception."""