def test_discover_fail(self, mock_url_for, mock___init__): mock___init__.return_value = None mock_url_for.side_effect = ks_exc.DiscoveryFailure() ks = keystone.Keystone('http://server.test:5000/v2.0', 'auser', 'apassword', 'aproject', test_heat.FakeKeystoneClient(self)) self.assertEqual(ks.auth_url, 'http://server.test:5000/v3')
def test_cache_is_created(self, mock_url_for, mock___init__): mock___init__.return_value = None mock_url_for.return_value = 'http://server.test:5000/' ks = keystone.Keystone('http://server.test:5000/', 'auser', 'apassword', 'aproject', test_heat.FakeKeystoneClient(self)) self.assertIsNotNone(ks.cache)
def test_discover_v3_unsupported(self, mock_url_for, mock___init__): mock___init__.return_value = None mock_url_for.return_value = None ks = keystone.Keystone('http://server.test:5000/v2.0', 'auser', 'apassword', 'aproject', test_heat.FakeKeystoneClient(self)) self.assertEqual(ks.auth_url, 'http://server.test:5000/v2.0') mock___init__.assert_called_with(auth_url='http://server.test:5000/')
def collect(self): if CONF.zaqar.auth_url is None: logger.warn('No auth_url configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.password is None: logger.warn('No password configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.project_id is None: logger.warn('No project_id configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.user_id is None: logger.warn('No user_id configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.queue_id is None: logger.warn('No queue_id configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.ssl_certificate_validation is True and ( CONF.zaqar.ca_file is None): logger.warn('No CA file configured when flag ssl certificate ' 'validation is on.') raise exc.ZaqarMetadataNotConfigured() # NOTE(flwang): To be compatible with old versions, we won't throw # error here if there is no region name. try: ks = keystone.Keystone(auth_url=CONF.zaqar.auth_url, user_id=CONF.zaqar.user_id, password=CONF.zaqar.password, project_id=CONF.zaqar.project_id, keystoneclient=self.keystoneclient, discover_class=self.discover_class).client conf = { 'auth_opts': { 'backend': 'keystone', 'options': { 'os_auth_token': ks.auth_token, 'os_project_id': CONF.zaqar.project_id, 'insecure': not CONF.zaqar.ssl_certificate_validation, 'cacert': CONF.zaqar.ca_file } } } if CONF.zaqar.use_websockets: data = self.get_data_websocket(ks, conf) else: data = self.get_data_wsgi(ks, conf) final_list = merger.merged_list_from_content( data, cfg.CONF.deployment_key, name) return final_list except Exception as e: logger.warn(str(e)) raise exc.ZaqarMetadataNotAvailable()
def _make_ks(self, client): class Configs(object): auth_url = 'http://192.0.2.1:5000/' user_id = 'auser' password = '******' project_id = 'aproject' return keystone.Keystone('http://192.0.2.1:5000/', 'auser', 'apassword', 'aproject', client(self, Configs), FakeKeystoneDiscoverBase)
def _make_ks(self, client, mock_url_for, mock___init__): class Configs(object): auth_url = 'http://server.test:5000/' user_id = 'auser' password = '******' project_id = 'aproject' mock___init__.return_value = None mock_url_for.return_value = Configs.auth_url return keystone.Keystone('http://server.test:5000/', 'auser', 'apassword', 'aproject', client(self, Configs))
def collect(self): if CONF.heat.auth_url is None: logger.info('No auth_url configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.password is None: logger.info('No password configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.project_id is None: logger.info('No project_id configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.user_id is None: logger.info('No user_id configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.stack_id is None: logger.info('No stack_id configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.resource_name is None: logger.info('No resource_name configured.') raise exc.HeatMetadataNotConfigured # NOTE(flwang): To be compatible with old versions, we won't throw # error here if there is no region name. try: ks = keystone.Keystone(auth_url=CONF.heat.auth_url, user_id=CONF.heat.user_id, password=CONF.heat.password, project_id=CONF.heat.project_id, keystoneclient=self.keystoneclient, discover_class=self.discover_class).client kwargs = { 'service_type': 'orchestration', 'endpoint_type': 'publicURL' } if CONF.heat.region_name: kwargs['region_name'] = CONF.heat.region_name endpoint = ks.service_catalog.url_for(**kwargs) logger.debug('Fetching metadata from %s' % endpoint) heat = self.heatclient.Client('1', endpoint, token=ks.auth_token) r = heat.resources.metadata(CONF.heat.stack_id, CONF.heat.resource_name) final_list = merger.merged_list_from_content( r, cfg.CONF.deployment_key, name) return final_list except Exception as e: logger.warn(str(e)) raise exc.HeatMetadataNotAvailable
def collect(self): if CONF.zaqar.auth_url is None: logger.warn('No auth_url configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.password is None: logger.warn('No password configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.project_id is None: logger.warn('No project_id configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.user_id is None: logger.warn('No user_id configured.') raise exc.ZaqarMetadataNotConfigured() if CONF.zaqar.queue_id is None: logger.warn('No queue_id configured.') raise exc.ZaqarMetadataNotConfigured() try: ks = keystone.Keystone( auth_url=CONF.zaqar.auth_url, user_id=CONF.zaqar.user_id, password=CONF.zaqar.password, project_id=CONF.zaqar.project_id, keystoneclient=self.keystoneclient).client endpoint = ks.service_catalog.url_for( service_type='messaging', endpoint_type='publicURL') logger.debug('Fetching metadata from %s' % endpoint) conf = { 'auth_opts': { 'backend': 'keystone', 'options': { 'os_auth_token': ks.auth_token, 'os_project_id': CONF.zaqar.project_id } } } zaqar = self.zaqarclient.Client(endpoint, conf=conf, version=1.1) queue = zaqar.queue(CONF.zaqar.queue_id) r = six.next(queue.pop()) return [('zaqar', r.body)] except Exception as e: logger.warn(str(e)) raise exc.ZaqarMetadataNotAvailable()
def collect(self): if CONF.heat.auth_url is None: logger.info('No auth_url configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.password is None: logger.info('No password configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.project_id is None: logger.info('No project_id configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.user_id is None: logger.info('No user_id configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.stack_id is None: logger.info('No stack_id configured.') raise exc.HeatMetadataNotConfigured if CONF.heat.resource_name is None: logger.info('No resource_name configured.') raise exc.HeatMetadataNotConfigured try: ks = keystone.Keystone(auth_url=CONF.heat.auth_url, user_id=CONF.heat.user_id, password=CONF.heat.password, project_id=CONF.heat.project_id, keystoneclient=self.keystoneclient).client endpoint = ks.service_catalog.url_for(service_type='orchestration', endpoint_type='publicURL') logger.debug('Fetching metadata from %s' % endpoint) heat = self.heatclient.Client('1', endpoint, token=ks.auth_token) r = heat.resources.metadata(CONF.heat.stack_id, CONF.heat.resource_name) final_list = merger.merged_list_from_content( r, cfg.CONF.deployment_key, name) return final_list except Exception as e: logger.warn(str(e)) raise exc.HeatMetadataNotAvailable
def test_cache_is_created(self): ks = keystone.Keystone('http://192.0.2.1:5000/', 'auser', 'apassword', 'aproject', test_heat.FakeKeystoneClient(self), test_heat.FakeKeystoneDiscover) self.assertIsNotNone(ks.cache)
def test_discover_v3_unsupported(self): ks = keystone.Keystone('http://192.0.2.1:5000/v2.0', 'auser', 'apassword', 'aproject', test_heat.FakeKeystoneClient(self), FakeKeystoneDiscoverNone) self.assertEqual(ks.auth_url, 'http://192.0.2.1:5000/v2.0')
def test_discover_fail(self): ks = keystone.Keystone('http://192.0.2.1:5000/v2.0', 'auser', 'apassword', 'aproject', test_heat.FakeKeystoneClient(self), FakeKeystoneDiscoverError) self.assertEqual(ks.auth_url, 'http://192.0.2.1:5000/v3')