Пример #1
0
 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')
Пример #2
0
 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')
Пример #3
0
    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)
Пример #4
0
    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)