~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/tests/image/test_glance.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from cinder import exception
27
27
from cinder.image import glance
28
28
from cinder import test
29
 
from cinder.tests.api.openstack import fakes
30
29
from cinder.tests.glance import stubs as glance_stubs
31
30
 
32
31
 
33
32
class NullWriter(object):
34
 
    """Used to test ImageService.get which takes a writer object"""
 
33
    """Used to test ImageService.get which takes a writer object."""
35
34
 
36
35
    def write(self, *arg, **kwargs):
37
36
        pass
106
105
        self.stubs.Set(glance.time, 'sleep', lambda s: None)
107
106
 
108
107
    def _create_image_service(self, client):
109
 
        def _fake_create_glance_client(context, host, port, version):
 
108
        def _fake_create_glance_client(context, host, port, use_ssl, version):
110
109
            return client
111
110
 
112
 
        self.stubs.Set(glance, '_create_glance_client',
113
 
                _fake_create_glance_client)
 
111
        self.stubs.Set(glance,
 
112
                       '_create_glance_client',
 
113
                       _fake_create_glance_client)
114
114
 
115
 
        client_wrapper = glance.GlanceClientWrapper(
116
 
                'fake', 'fake_host', 9292)
 
115
        client_wrapper = glance.GlanceClientWrapper('fake', 'fake_host', 9292)
117
116
        return glance.GlanceImageService(client=client_wrapper)
118
117
 
119
118
    @staticmethod
131
130
                                  deleted_at=self.NOW_GLANCE_FORMAT)
132
131
 
133
132
    def test_create_with_instance_id(self):
134
 
        """Ensure instance_id is persisted as an image-property"""
 
133
        """Ensure instance_id is persisted as an image-property."""
135
134
        fixture = {'name': 'test image',
136
135
                   'is_public': False,
137
136
                   'properties': {'instance_id': '42', 'user_id': 'fake'}}
458
457
        # When retries are disabled, we should get an exception
459
458
        self.flags(glance_num_retries=0)
460
459
        self.assertRaises(exception.GlanceConnectionFailed,
461
 
                service.download, self.context, image_id, writer)
 
460
                          service.download,
 
461
                          self.context,
 
462
                          image_id,
 
463
                          writer)
462
464
 
463
465
        # Now lets enable retries. No exception should happen now.
464
466
        tries = [0]
520
522
    def test_glance_client_image_id(self):
521
523
        fixture = self._make_fixture(name='test image')
522
524
        image_id = self.service.create(self.context, fixture)['id']
523
 
        (service, same_id) = glance.get_remote_image_service(
524
 
                self.context, image_id)
 
525
        (service, same_id) = glance.get_remote_image_service(self.context,
 
526
                                                             image_id)
525
527
        self.assertEquals(same_id, image_id)
526
528
 
527
529
    def test_glance_client_image_ref(self):
528
530
        fixture = self._make_fixture(name='test image')
529
531
        image_id = self.service.create(self.context, fixture)['id']
530
532
        image_url = 'http://something-less-likely/%s' % image_id
531
 
        (service, same_id) = glance.get_remote_image_service(
532
 
                self.context, image_url)
 
533
        (service, same_id) = glance.get_remote_image_service(self.context,
 
534
                                                             image_url)
533
535
        self.assertEquals(same_id, image_id)
534
536
        self.assertEquals(service._client.host,
535
 
                'something-less-likely')
 
537
                          'something-less-likely')
536
538
 
537
539
 
538
540
def _create_failing_glance_client(info):