Example #1
0
    def test_should_call_service_catalog_for_endpoint(self):
        keystone.Keystone.instance = None
        with mock.patch('keystoneauth1.identity.Password') as password, \
                mock.patch('keystoneauth1.session.Session') as session, \
                mock.patch('keystoneclient.discover.Discover') as discover:
            client = mock.Mock()
            discover.return_value = d = mock.Mock()
            d.create_client = mock.Mock(return_value=client)

            config = base_config.get_config('Api')
            config.update({
                'url': None,
                'service_type': self.default_service_type,
                'endpoint_type': self.default_endpoint_type,
                'region_name': self.default_region_name
            })

            k = keystone.Keystone(config)
            k.get_monasca_url()

            password.assert_called_once()
            session.assert_called_once()
            discover.assert_called_once()

            client.auth_ref.service_catalog.url_for.assert_called_once_with(
                **{
                    'service_type': self.default_service_type,
                    'interface': self.default_endpoint_type,
                    'region_name': self.default_region_name
                })
Example #2
0
    def test_should_use_url_from_config_if_catalog_config_missing(self):
        keystone.Keystone.instance = None
        with mock.patch('keystoneauth1.identity.Password') as password, \
                mock.patch('keystoneauth1.session.Session') as session, \
                mock.patch('keystoneclient.discover.Discover') as discover:
            client = mock.Mock()
            discover.return_value = d = mock.Mock()
            d.create_client = mock.Mock(return_value=client)

            monasca_url = mock.NonCallableMock()

            config = base_config.get_config('Api')
            config.update({
                'url': monasca_url,
                'service_type': None,
                'endpoint_type': None,
                'region_name': None
            })
            k = keystone.Keystone(config)
            k.get_monasca_url()

            password.assert_not_called()
            session.assert_not_called()
            discover.assert_not_called()
            client.auth_ref.service_catalog.url_for.assert_not_called()
Example #3
0
    def test_should_call_service_catalog_for_endpoint(self):
        keystone.Keystone.instance = None
        with mock.patch('keystoneauth1.identity.Password') as password, \
                mock.patch('keystoneauth1.session.Session') as session, \
                mock.patch('keystoneclient.discover.Discover') as discover:
            client = mock.Mock()
            discover.return_value = d = mock.Mock()
            d.create_client = mock.Mock(return_value=client)

            config = base_config.get_config('Api')
            config.update({
                'url': None,
                'service_type': self.default_service_type,
                'endpoint_type': self.default_endpoint_type,
                'region_name': self.default_region_name
            })

            k = keystone.Keystone(config)
            k.get_monasca_url()

            password.assert_called_once()
            session.assert_called_once()
            discover.assert_called_once()

            client.auth_ref.service_catalog.url_for.assert_called_once_with(**{
                'service_type': self.default_service_type,
                'interface': self.default_endpoint_type,
                'region_name': self.default_region_name
            })
Example #4
0
    def test_should_use_url_from_config_if_catalog_config_missing(self):
        keystone.Keystone.instance = None
        with mock.patch('keystoneauth1.identity.Password') as password, \
                mock.patch('keystoneauth1.session.Session') as session, \
                mock.patch('keystoneclient.discover.Discover') as discover:
            client = mock.Mock()
            discover.return_value = d = mock.Mock()
            d.create_client = mock.Mock(return_value=client)

            monasca_url = mock.NonCallableMock()

            config = base_config.get_config('Api')
            config.update({
                'url': monasca_url,
                'service_type': None,
                'endpoint_type': None,
                'region_name': None
            })
            k = keystone.Keystone(config)
            k.get_monasca_url()

            password.assert_not_called()
            session.assert_not_called()
            discover.assert_not_called()
            client.auth_ref.service_catalog.url_for.assert_not_called()
Example #5
0
 def testServiceCatalogMonascaUrlUsingDefaults(self):
     Keystone.instance = None
     with mock.patch('keystoneclient.v3.client.Client') as client:
         config = base_config.get_config('Api')
         keystone = Keystone(config)
         keystone.get_monasca_url()
         self.assertTrue(client.called)
         self.assertIn('auth_url', client.call_args[client.call_count])
         self.assertNotIn('service_type', client.call_args[client.call_count])
         self.assertNotIn('endpoint_type', client.call_args[client.call_count])
         self.assertNotIn('region_name', client.call_args[client.call_count])
         client.return_value.service_catalog.url_for.assert_has_calls([
             mock.call(endpoint_type=self.default_endpoint_type, service_type=self.default_service_type)
         ])
Example #6
0
    def test_should_init_client_just_once(self):
        keystone.Keystone.instance = None

        k = keystone.Keystone(config=base_config.get_config('Api'))
        client = mock.Mock()

        with mock.patch('monasca_agent.common.keystone.get_client') as gc:
            gc.return_value = client

            for _ in range(random.randint(5, 50)):
                k._init_client()

            self.assertIsNotNone(k._keystone_client)
            self.assertEqual(client, k._keystone_client)

            gc.assert_called_once()
Example #7
0
    def test_should_init_client_just_once(self):
        keystone.Keystone.instance = None

        k = keystone.Keystone(config=base_config.get_config('Api'))
        client = mock.Mock()

        with mock.patch('monasca_agent.common.keystone.get_client') as gc:
            gc.return_value = client

            for _ in range(random.randint(5, 50)):
                k._init_client()

            self.assertIsNotNone(k._keystone_client)
            self.assertEqual(client, k._keystone_client)

            gc.assert_called_once()
Example #8
0
 def testServiceCatalogMonascaUrlWithCustomRegionName(self):
     Keystone.instance = None
     region_name = 'my_region'
     with mock.patch('keystoneclient.v3.client.Client') as client:
         config = base_config.get_config('Api')
         config.update({'region_name': region_name})
         keystone = Keystone(config)
         keystone.get_monasca_url()
         self.assertTrue(client.called)
         self.assertIn('auth_url', client.call_args[client.call_count])
         self.assertNotIn('service_type', client.call_args[client.call_count])
         self.assertNotIn('endpoint_type', client.call_args[client.call_count])
         self.assertNotIn('region_name', client.call_args[client.call_count])
         client.return_value.service_catalog.url_for.assert_has_calls([
             mock.call(endpoint_type=self.default_endpoint_type, service_type=self.default_service_type,
                       attr='region', filter_value=region_name)
         ])