Esempio n. 1
0
    def test_create_glance_client_with_protocol_https(self, mock_load,
                                                      mock_get_auth_plugin):
        glance._SESSION = None
        self.flags(auth_strategy='keystone')
        self.flags(glance_request_timeout=60)
        self.flags(glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('2', version)
                self.assertEqual("https://fake_host:9292", args[0])
                self.assertNotIn('timeout', kwargs)
                self.assertIn("session", kwargs)
                self.assertIn("auth", kwargs)

        config_options = {
            'insecure': False,
            'cacert': '/opt/stack/data/ca-bundle.pem',
            'timeout': 60
        }

        mock_get_auth_plugin.return_value = context._ContextAuthPlugin
        mock_load.return_value = session.Session
        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              True)
        self.assertIsInstance(client, MyGlanceStubClient)
        mock_get_auth_plugin.assert_called_once_with(self.context)
        mock_load.assert_called_once_with(**config_options)
Esempio n. 2
0
    def test_create_glance_client_with_protocol_https(
            self, mock_load, mock_get_auth_plugin):
        glance._SESSION = None
        self.flags(auth_strategy='keystone')
        self.flags(glance_request_timeout=60)
        self.flags(
            glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('2', version)
                self.assertEqual("https://fake_host:9292", args[0])
                self.assertNotIn('timeout', kwargs)
                self.assertIn("session", kwargs)
                self.assertIn("auth", kwargs)

        config_options = {'insecure': False,
                          'cacert': '/opt/stack/data/ca-bundle.pem',
                          'timeout': 60}

        mock_get_auth_plugin.return_value = context._ContextAuthPlugin
        mock_load.return_value = session.Session
        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              True)
        self.assertIsInstance(client, MyGlanceStubClient)
        mock_get_auth_plugin.assert_called_once_with(self.context)
        mock_load.assert_called_once_with(**config_options)
Esempio n. 3
0
    def test_create_glance_client_glance_request_default_timeout(self):
        self.flags(auth_strategy="keystone")
        self.flags(glance_request_timeout=None)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual("1", version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertTrue(kwargs["token"])
                self.assertNotIn("timeout", kwargs)

        self.stubs.Set(glance.glanceclient, "Client", MyGlanceStubClient)
        client = glance._create_glance_client(self.context, "fake_host:9292", False)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 4
0
    def test_create_glance_client_auth_strategy_is_not_keystone(self):
        self.flags(auth_strategy="noauth")
        self.flags(glance_request_timeout=60)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual("1", version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertFalse("token" in kwargs)
                self.assertEqual(60, kwargs["timeout"])

        self.stubs.Set(glance.glanceclient, "Client", MyGlanceStubClient)
        client = glance._create_glance_client(self.context, "fake_host:9292", False)
        self.assertTrue(isinstance(client, MyGlanceStubClient))
Esempio n. 5
0
    def test_create_glance_client_glance_request_default_timeout(self):
        self.flags(auth_strategy='keystone')
        self.flags(glance_request_timeout=None)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual("1", version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertEqual(True, kwargs['token'])
                self.assertFalse('timeout' in kwargs)

        self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertTrue(isinstance(client, MyGlanceStubClient))
Esempio n. 6
0
    def test_create_glance_client_auth_strategy_is_not_keystone(self):
        self.flags(auth_strategy='noauth')
        self.flags(glance_request_timeout=60)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('1', version)
                self.assertEqual('http://fake_host:9292', args[0])
                self.assertFalse('token' in kwargs)
                self.assertEqual(60, kwargs['timeout'])

        self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertTrue(isinstance(client, MyGlanceStubClient))
Esempio n. 7
0
    def test_create_glance_client_auth_strategy_is_not_keystone(self):
        self.flags(auth_strategy='noauth')
        self.flags(glance_request_timeout=60)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('1', version)
                self.assertEqual('http://fake_host:9292', args[0])
                self.assertNotIn('token', kwargs)
                self.assertEqual(60, kwargs['timeout'])

        self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 8
0
    def test_create_glance_client(self):
        self.flags(auth_strategy='keystone')
        self.flags(glance_request_timeout=60)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('1', version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertTrue(kwargs['token'])
                self.assertEqual(60, kwargs['timeout'])

        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 9
0
    def test_create_glance_client_glance_request_default_timeout(self):
        self.flags(auth_strategy='keystone')
        self.flags(glance_request_timeout=None)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual("1", version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertTrue(kwargs['token'])
                self.assertNotIn('timeout', kwargs)

        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 10
0
    def test_create_glance_client_auth_strategy_noauth_with_protocol_http(
            self):
        self.flags(auth_strategy='noauth')
        self.flags(glance_request_timeout=None)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('2', version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertNotIn('timeout', kwargs)
                self.assertNotIn("session", kwargs)
                self.assertNotIn("auth", kwargs)

        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 11
0
    def test_create_glance_client_auth_strategy_noauth_with_protocol_http(
            self):
        self.flags(auth_strategy='noauth')
        self.flags(glance_request_timeout=None)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('2', version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertNotIn('timeout', kwargs)
                self.assertNotIn("session", kwargs)
                self.assertNotIn("auth", kwargs)

        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 12
0
    def test_create_glance_client_auth_strategy_noauth_with_protocol_https(
            self):
        self.flags(auth_strategy='noauth')
        self.flags(glance_request_timeout=60)
        self.flags(glance_api_insecure=False)
        self.flags(glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('2', version)
                self.assertEqual('https://fake_host:9292', args[0])
                self.assertEqual(60, kwargs['timeout'])
                self.assertNotIn("session", kwargs)
                self.assertNotIn("auth", kwargs)
                self.assertEqual('/opt/stack/data/ca-bundle.pem',
                                 kwargs['cacert'])
                self.assertEqual(False, kwargs['insecure'])

        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              True)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 13
0
    def test_create_glance_client_auth_strategy_noauth_with_protocol_https(
            self):
        self.flags(auth_strategy='noauth')
        self.flags(glance_request_timeout=60)
        self.flags(glance_api_insecure=False)
        self.flags(
            glance_ca_certificates_file='/opt/stack/data/ca-bundle.pem')

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('2', version)
                self.assertEqual('https://fake_host:9292', args[0])
                self.assertEqual(60, kwargs['timeout'])
                self.assertNotIn("session", kwargs)
                self.assertNotIn("auth", kwargs)
                self.assertEqual(
                    '/opt/stack/data/ca-bundle.pem', kwargs['cacert'])
                self.assertEqual(False, kwargs['insecure'])

        self.mock_object(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              True)
        self.assertIsInstance(client, MyGlanceStubClient)
Esempio n. 14
0
        self.context = context.RequestContext('fake', 'fake', auth_token=True)
        self.stubs.Set(glance.time, 'sleep', lambda s: None)

    def test_create_glance_client(self):
        self.flags(auth_strategy='keystone')
        self.flags(glance_request_timeout=60)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('1', version)
                self.assertEqual("http://fake_host:9292", args[0])
                self.assertTrue(kwargs['token'])
                self.assertEqual(60, kwargs['timeout'])

        self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',
                                              False)
        self.assertIsInstance(client, MyGlanceStubClient)

    def test_create_glance_client_auth_strategy_is_not_keystone(self):
        self.flags(auth_strategy='noauth')
        self.flags(glance_request_timeout=60)

        class MyGlanceStubClient(object):
            def __init__(inst, version, *args, **kwargs):
                self.assertEqual('1', version)
                self.assertEqual('http://fake_host:9292', args[0])
                self.assertNotIn('token', kwargs)
                self.assertEqual(60, kwargs['timeout'])

        self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient)
        client = glance._create_glance_client(self.context, 'fake_host:9292',