def test_get_connection(mock_mongo_client): """Test get_connection() creates a new MongoClient.""" mongo.get_connection('host1') mock_mongo_client.assert_called_with(['host1'], replicaset=None) mongo.get_connection(['host1', 'host2'], replica_set='replica_set_name') mock_mongo_client.assert_called_with(['host1', 'host2'], replicaset='replica_set_name')
def connection(self): if not self.__connection: if self.use_asyncio: self.__connection = asyncio_mongo.get_connection( self.servers, self.replica_name ) else: self.__connection = common_mongo.get_connection( self.servers, self.replica_name) return self.__connection
def main(): config = options() logging.basicConfig(level=logging.getLevelName(config.log_level), format=config.log_format) db_connection = get_connection(config.log_service.db.servers, config.log_service.db.replica_name) collection = get_collection(config.log_service.db.name, config.log_service.db.collection, db_connection) agent_log_service = AgentLogService(config.log_service.bind_address, collection) LOG.info('Starting logging service on {}'.format( config.log_service.bind_address)) agent_log_service.start()
# if not self.validate_message(message): # raise MercuryGeneralException('Logging controller recieved invalid message') message.update({'time_created': time.time()}) self.set_job_info_from_thread(message) LOG.debug(message) self.log_collection.insert(message) return {'message': 'ok'} if __name__ == '__main__': logging.basicConfig( level=logging.DEBUG, format='%(asctime)s : %(levelname)s - %(name)s - %(message)s') configuration = get_configuration(__defaults['configuration_file']) db_connection = get_connection( configuration['db']['servers'], replica_set=configuration['db']['replica_set']) _log_collection = get_collection(configuration['db']['database'], configuration['db']['collection'], db_connection) _bind_address = configuration['service']['url'] agent_log_service = AgentLogService(_bind_address, _log_collection) LOG.info('Starting logging service on {}'.format(_bind_address)) agent_log_service.start()