def test_client_retry(self): glance.glanceclient = MockRetryGlanceClient conf = LunrConfig() glance_urls = ['url1:9292', 'url2:9292', 'url3:9292'] urls_string = ', '.join(glance_urls) self.conf = LunrConfig({'glance': {'glance_urls': urls_string}}) glance1 = glance.GlanceClient(self.conf) self.assertRaises(glance.GlanceError, glance1.head, 'junk') self.assertEquals(glance1._glance_url_index, 3) glance2 = glance.GlanceClient(self.conf) self.assertRaises(glance.GlanceError, glance2.get, 'junk') self.assertEquals(glance2._glance_url_index, 3)
def test_shuffle_glance_url(self): glance.glanceclient = MockGlanceClient conf = LunrConfig() glance_urls = ['url1:9292', 'url2:9292', 'url3:9292'] urls_string = ', '.join(glance_urls) self.conf = LunrConfig({'glance': {'glance_urls': urls_string}}) glance1 = glance.GlanceClient(self.conf) self.assertItemsEqual(glance1.glance_urls, glance_urls) shuffled = False for i in range(10): glance2 = glance.GlanceClient(self.conf) self.assertItemsEqual(glance2.glance_urls, glance_urls) if glance1.glance_urls != glance2.glance_urls: shuffled = True break self.assertTrue(shuffled)
def test_success(self): token = {'access': {'token': {'id': 1, 'tenant': {'id': 'foo'}}}} responses = [token] def success(*args, **kwargs): return responses.pop(0) glance.request = success self.client = glance.GlanceClient(self.conf) self.assertEquals(self.client._token, 1) self.assertEquals(self.client.tenant_id, 'foo') self.assertEquals(responses, [])
def test_401_retry(self): token = {'access': {'token': {'id': 1, 'tenant': {'id': 'foo'}}}} responses = [FakeHTTPException(401), token] def reauth(*args, **kwargs): resp = responses.pop(0) if isinstance(resp, dict): return resp raise resp glance.request = reauth self.client = glance.GlanceClient(self.conf) self.assertEquals(self.client._token, 1) self.assertEquals(self.client.tenant_id, 'foo') self.assertEquals(responses, [])