def test_glance_version_by_arg(self, _mockglanceclient): """Test glance version set by arg to GlanceClientWrapper""" ctx = mock.MagicMock() glance.GlanceClientWrapper(ctx, 'fake_host', 9292, version=1) self.assertEqual('1', _mockglanceclient.call_args[0][0]) glance.GlanceClientWrapper(ctx, 'fake_host', 9292, version=2) self.assertEqual('2', _mockglanceclient.call_args[0][0])
def test_glance_version_by_flag(self, _mockglanceclient): """Test glance version set by flag is honoured.""" glance.GlanceClientWrapper('fake', 'fake_host', 9292) self.assertEqual('1', _mockglanceclient.call_args[0][0]) self.flags(glance_api_version=2) glance.GlanceClientWrapper('fake', 'fake_host', 9292) self.assertEqual('2', _mockglanceclient.call_args[0][0]) CONF.reset()
def test_glance_version_by_arg(self): """Test glance version set by arg to GlanceClientWrapper""" client_wrapper_v1 = glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=1) self.assertEquals(client_wrapper_v1.client.__module__, 'glanceclient.v1.client') client_wrapper_v2 = glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=2) self.assertEquals(client_wrapper_v2.client.__module__, 'glanceclient.v2.client')
def test_glance_version_by_flag(self): """Test glance version set by flag is honoured.""" client_wrapper_v1 = glance.GlanceClientWrapper('fake', 'fake_host', 9292) self.assertEquals(client_wrapper_v1.client.__module__, 'glanceclient.v1.client') self.flags(glance_api_version=2) client_wrapper_v2 = glance.GlanceClientWrapper('fake', 'fake_host', 9292) self.assertEquals(client_wrapper_v2.client.__module__, 'glanceclient.v2.client') CONF.reset()
def test_call_glance_version_by_arg(self, api_servers, _mockglanceclient): """Test glance version set by arg to GlanceClientWrapper""" glance_wrapper = glance.GlanceClientWrapper() ctx = mock.MagicMock() glance_wrapper.call(ctx, 'method', version=2) self.assertEqual('2', _mockglanceclient.call_args[0][0])
def test_call_glance_over_quota(self, api_servers, _mockglanceclient): """Test glance version set by arg to GlanceClientWrapper""" glance_wrapper = glance.GlanceClientWrapper() fake_client = mock.Mock() fake_client.images.method = mock.Mock( side_effect=glanceclient.exc.HTTPOverLimit) self.mock_object(glance_wrapper, 'client', fake_client) self.assertRaises(exception.ImageLimitExceeded, glance_wrapper.call, 'fake_context', 'method')
def _create_image_service(self, client): def _fake_create_glance_client(context, netloc, use_ssl): return client self.mock_object(glance, '_create_glance_client', _fake_create_glance_client) client_wrapper = glance.GlanceClientWrapper('fake', 'fake_host', 9292) return glance.GlanceImageService(client=client_wrapper)
def _create_image_service(self, client): def _fake_create_glance_client(context, host, port, use_ssl, version): return client self.stubs.Set(glance, '_create_glance_client', _fake_create_glance_client) client_wrapper = glance.GlanceClientWrapper('fake', 'fake_host', 9292) return glance.GlanceImageService(client=client_wrapper)
def test_call_with_additional_headers(self): glance_wrapper = glance.GlanceClientWrapper() fake_client = mock.Mock() self.mock_object(glance_wrapper, 'client', fake_client) glance_wrapper.call(self.context, 'upload', {}, store_id='xyz', base_image_ref=123) self.assertDictEqual( { 'x-image-meta-store': 'xyz', 'x-openstack-base-image-ref': 123 }, fake_client.http_client.additional_headers)
def test_call_glance_version_by_arg(self, _mockglanceclient): """Test glance version set by arg to GlanceClientWrapper""" glance_wrapper = glance.GlanceClientWrapper() glance_wrapper.call('fake_context', 'method', version=2) self.assertEqual('2', _mockglanceclient.call_args[0][0])
'min_disk': 2, 'min_ram': 2, 'kernel_id': 'foo', 'ramdisk_id': 'bar', 'x_billinginfo': '123', } self.assertEqual(expected, actual) class TestGlanceClientVersion(test.TestCase): """Tests the version of the glance client generated.""" @mock.patch('cinder.image.glance.glanceclient.Client') def test_glance_version_by_flag(self, _mockglanceclient): """Test glance version set by flag is honoured.""" glance.GlanceClientWrapper('fake', 'fake_host', 9292) self.assertEqual('1', _mockglanceclient.call_args[0][0]) self.flags(glance_api_version=2) glance.GlanceClientWrapper('fake', 'fake_host', 9292) self.assertEqual('2', _mockglanceclient.call_args[0][0]) CONF.reset() @mock.patch('cinder.image.glance.glanceclient.Client') def test_glance_version_by_arg(self, _mockglanceclient): """Test glance version set by arg to GlanceClientWrapper""" glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=1) self.assertEqual('1', _mockglanceclient.call_args[0][0]) glance.GlanceClientWrapper('fake', 'fake_host', 9292, version=2) self.assertEqual('2', _mockglanceclient.call_args[0][0]) @mock.patch('cinder.image.glance.glanceclient.Client')