def test_headers_passed_glanceclient(self): auth_token = 'auth_token' ctxt = context.RequestContext('fake', 'fake', auth_token=auth_token) fake_host = 'host4' fake_port = 9295 fake_use_ssl = False def _get_fake_glanceclient(version, endpoint, **params): fake_client = glance_stubs.StubGlanceClient(version, endpoint, **params) self.assertTrue(fake_client.auth_token is not None) self.assertTrue(fake_client.identity_headers is not None) self.assertEquals(fake_client.identity_header['X-Auth_Token'], auth_token) self.assertEquals(fake_client.identity_header['X-User-Id'], 'fake') self.assertEquals(fake_client.identity_header['X-Roles'], None) self.assertEquals(fake_client.identity_header['X-Tenant-Id'], None) self.assertEquals(fake_client. identity_header['X-Service-Catalog'], None) self.assertEquals(fake_client. identity_header['X-Identity-Status'], 'Confirmed') self.stubs.Set(glanceclient.Client, '__init__', _get_fake_glanceclient) glance._create_glance_client(ctxt, fake_host, fake_port, fake_use_ssl)
def test_create_glance_client_with_ssl(self, client_mock): self.flags(ca_file='foo.cert', cert_file='bar.cert', key_file='wut.key', group='ssl') ctxt = mock.sentinel.ctx glance._create_glance_client(ctxt, 'host4', 9295, use_ssl=True) client_mock.assert_called_once_with( '1', 'https://host4:9295', insecure=False, ssl_compression=False, cert_file='bar.cert', key_file='wut.key', cacert='foo.cert')
def test_create_glance_client_with_ssl(self, client_mock, ssl_enable_mock): self.flags(ca_file="foo.cert", cert_file="bar.cert", key_file="wut.key", group="ssl") ctxt = mock.sentinel.ctx glance._create_glance_client(ctxt, "host4", 9295, use_ssl=True) client_mock.assert_called_once_with( "1", "https://host4:9295", insecure=False, ssl_compression=False, cert_file="bar.cert", key_file="wut.key", cacert="foo.cert", )
def test_headers_passed_glanceclient(self): auth_token = "auth_token" ctxt = context.RequestContext("fake", "fake", auth_token=auth_token) fake_host = "host4" fake_port = 9295 fake_use_ssl = False def _get_fake_glanceclient(version, endpoint, **params): fake_client = glance_stubs.StubGlanceClient(version, endpoint, **params) self.assertIsNotNone(fake_client.auth_token) self.assertIsNotNone(fake_client.identity_headers) self.assertEqual(fake_client.identity_header["X-Auth_Token"], auth_token) self.assertEqual(fake_client.identity_header["X-User-Id"], "fake") self.assertIsNone(fake_client.identity_header["X-Roles"]) self.assertIsNone(fake_client.identity_header["X-Tenant-Id"]) self.assertIsNone(fake_client.identity_header["X-Service-Catalog"]) self.assertEqual(fake_client.identity_header["X-Identity-Status"], "Confirmed") self.stubs.Set(glanceclient.Client, "__init__", _get_fake_glanceclient) glance._create_glance_client(ctxt, fake_host, fake_port, fake_use_ssl)
def test_headers_passed_glanceclient(self, init_mock, ipv6_mock): self.flags(auth_strategy='keystone') ipv6_mock.return_value = False auth_token = 'token' ctx = context.RequestContext('fake', 'fake', auth_token=auth_token) host = 'host4' port = 9295 use_ssl = False expected_endpoint = 'http://host4:9295' expected_params = { 'identity_headers': { 'X-Auth-Token': 'token', 'X-User-Id': 'fake', 'X-Roles': '', 'X-Tenant-Id': 'fake', 'X-Service-Catalog': '[]', 'X-Identity-Status': 'Confirmed' }, 'token': 'token' } glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with('1', expected_endpoint, **expected_params) # Test the version is properly passed to glanceclient. ipv6_mock.reset_mock() init_mock.reset_mock() expected_endpoint = 'http://host4:9295' expected_params = { 'identity_headers': { 'X-Auth-Token': 'token', 'X-User-Id': 'fake', 'X-Roles': '', 'X-Tenant-Id': 'fake', 'X-Service-Catalog': '[]', 'X-Identity-Status': 'Confirmed' }, 'token': 'token' } glance._create_glance_client(ctx, host, port, use_ssl, version=2) init_mock.assert_called_once_with('2', expected_endpoint, **expected_params) # Test that non-keystone auth strategy doesn't bother to pass # glanceclient all the Keystone-related headers. ipv6_mock.reset_mock() init_mock.reset_mock() self.flags(auth_strategy='non-keystone') expected_endpoint = 'http://host4:9295' expected_params = {} glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with('1', expected_endpoint, **expected_params) # Test that the IPv6 bracketization adapts the endpoint properly. ipv6_mock.reset_mock() init_mock.reset_mock() ipv6_mock.return_value = True expected_endpoint = 'http://[host4]:9295' expected_params = {} glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with('1', expected_endpoint, **expected_params)
def test_headers_passed_glanceclient(self, init_mock, ipv6_mock): self.flags(auth_strategy='keystone') ipv6_mock.return_value = False auth_token = 'token' ctx = context.RequestContext('fake', 'fake', auth_token=auth_token) host = 'host4' port = 9295 use_ssl = False expected_endpoint = 'http://host4:9295' expected_params = { 'identity_headers': { 'X-Auth-Token': 'token', 'X-User-Id': 'fake', 'X-Roles': '', 'X-Tenant-Id': 'fake', 'X-Service-Catalog': '[]', 'X-Identity-Status': 'Confirmed' }, 'token': 'token' } glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with('1', expected_endpoint, **expected_params) # Test the version is properly passed to glanceclient. ipv6_mock.reset_mock() init_mock.reset_mock() expected_endpoint = 'http://host4:9295' expected_params = { 'identity_headers': { 'X-Auth-Token': 'token', 'X-User-Id': 'fake', 'X-Roles': '', 'X-Tenant-Id': 'fake', 'X-Service-Catalog': '[]', 'X-Identity-Status': 'Confirmed' }, 'token': 'token' } glance._create_glance_client(ctx, host, port, use_ssl, version=2) init_mock.assert_called_once_with('2', expected_endpoint, **expected_params) # Test that non-keystone auth strategy doesn't bother to pass # glanceclient all the Keystone-related headers. ipv6_mock.reset_mock() init_mock.reset_mock() self.flags(auth_strategy='non-keystone') expected_endpoint = 'http://host4:9295' expected_params = { } glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with('1', expected_endpoint, **expected_params) # Test that the IPv6 bracketization adapts the endpoint properly. ipv6_mock.reset_mock() init_mock.reset_mock() ipv6_mock.return_value = True expected_endpoint = 'http://[host4]:9295' expected_params = { } glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with('1', expected_endpoint, **expected_params)
def test_headers_passed_glanceclient(self, init_mock, ipv6_mock): self.flags(auth_strategy="keystone") ipv6_mock.return_value = False auth_token = "token" ctx = context.RequestContext("fake", "fake", auth_token=auth_token) host = "host4" port = 9295 use_ssl = False expected_endpoint = "http://host4:9295" expected_params = { "identity_headers": { "X-Auth-Token": "token", "X-User-Id": "fake", "X-Roles": "", "X-Tenant-Id": "fake", "X-Identity-Status": "Confirmed", }, "token": "token", } glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with("1", expected_endpoint, **expected_params) # Test the version is properly passed to glanceclient. ipv6_mock.reset_mock() init_mock.reset_mock() expected_endpoint = "http://host4:9295" expected_params = { "identity_headers": { "X-Auth-Token": "token", "X-User-Id": "fake", "X-Roles": "", "X-Tenant-Id": "fake", "X-Identity-Status": "Confirmed", }, "token": "token", } glance._create_glance_client(ctx, host, port, use_ssl, version=2) init_mock.assert_called_once_with("2", expected_endpoint, **expected_params) # Test that non-keystone auth strategy doesn't bother to pass # glanceclient all the Keystone-related headers. ipv6_mock.reset_mock() init_mock.reset_mock() self.flags(auth_strategy="non-keystone") expected_endpoint = "http://host4:9295" expected_params = {} glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with("1", expected_endpoint, **expected_params) # Test that the IPv6 bracketization adapts the endpoint properly. ipv6_mock.reset_mock() init_mock.reset_mock() ipv6_mock.return_value = True expected_endpoint = "http://[host4]:9295" expected_params = {} glance._create_glance_client(ctx, host, port, use_ssl) init_mock.assert_called_once_with("1", expected_endpoint, **expected_params)