summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorNaveed Massjouni <naveedm9@gmail.com>2011-10-26 14:32:48 -0400
committerDan Prince <dan.prince@rackspace.com>2011-10-26 14:48:46 -0400
commit1b7fba648aa3eb4cdda345237c9f77dc0b229329 (patch)
tree2903b2cb0e77879fed81d4fec8f06df7dd76133f /nova/tests
parent5e9e3873e5ee3cf87b8aec801705ee24cedcd1aa (diff)
Adding support for retrying glance image downloads.
Change-Id: Ifff40d90f7dc61a6d41ae2d6908d6e1e6f0aea7e
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/image/test_glance.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index 0934eb5eb..1ab40f5f6 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -508,6 +508,35 @@ 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_with_retries(self):
+ tries = [0]
+
+ class GlanceBusyException(Exception):
+ pass
+
+ class MyGlanceStubClient(glance_stubs.StubGlanceClient):
+ """A client that fails the first time, then succeeds."""
+ def get_image(self, image_id):
+ if tries[0] == 0:
+ tries[0] = 1
+ raise GlanceBusyException()
+ else:
+ return {}, []
+
+ client = MyGlanceStubClient()
+ service = glance.GlanceImageService(client=client)
+ image_id = 1 # doesn't matter
+ writer = NullWriter()
+
+ # When retries are disabled, we should get an exception
+ self.flags(glance_num_retries=0)
+ self.assertRaises(GlanceBusyException, service.get, 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)
+
def test_glance_client_image_id(self):
fixture = self._make_fixture(name='test image')
image_id = self.service.create(self.context, fixture)['id']