def test_client_options(self): repl_set = ReplicaSet().start() try: config_def = { 'mainAddress': repl_set.uri, 'oplogFile': from_here('lib', 'dummy.timestamp'), 'docManagers': [ { 'docManager': 'solr_doc_manager', 'targetURL': solr_url, 'args': { 'clientOptions': { 'timeout': 100 } } } ] } config_obj = config.Config(get_config_options()) config_obj.load_json(json.dumps(config_def)) config_obj.parse_args(argv=[]) conn = connector.Connector.from_config(config_obj) self.assertEqual(100, conn.doc_managers[0].solr.timeout) finally: repl_set.stop()
def main(): """ Starts the mongo connector (assuming CLI) """ conf = config.Config(get_config_options()) conf.parse_args() setup_logging(conf) log_startup_info() connector = Connector.from_config(conf) # Catch SIGTERM and SIGINT to cleanup the connector gracefully def signame_handler(signal_name): def sig_handler(signum, frame): # Save the signal so it can be printed later connector.signal = (signal_name, signum) connector.can_run = False return sig_handler signal.signal(signal.SIGTERM, signame_handler('SIGTERM')) signal.signal(signal.SIGINT, signame_handler('SIGINT')) connector.start() while True: if not connector.is_alive(): break time.sleep(3)
def main(): """ Starts the mongo connector (assuming CLI) """ conf = config.Config(get_config_options()) conf.parse_args() root_logger = logging.getLogger() formatter = logging.Formatter( "%(asctime)s [%(levelname)s] %(name)s:%(lineno)d - %(message)s") loglevel = logging.INFO if conf['verbosity'] > 0: loglevel = logging.DEBUG root_logger.setLevel(loglevel) if conf['logging.type'] == 'file': log_out = logging.handlers.TimedRotatingFileHandler( conf['logging.filename'], when=conf['logging.rotationWhen'], interval=conf['logging.rotationInterval'], backupCount=conf['logging.rotationBackups']) print("Logging to %s." % conf['logging.filename']) elif conf['logging.type'] == 'syslog': syslog_info = conf['logging.host'] if ':' in syslog_info: log_host, log_port = syslog_info.split(':') syslog_info = (log_host, int(log_port)) log_out = logging.handlers.SysLogHandler( address=syslog_info, facility=conf['logging.facility']) print("Logging to system log at %s" % conf['logging.host']) elif conf['logging.type'] is None: log_out = logging.StreamHandler() log_out.setLevel(loglevel) log_out.setFormatter(formatter) root_logger.addHandler(log_out) LOG.info('Beginning Mongo Connector') connector = Connector.from_config(conf) connector.start() while True: try: time.sleep(3) if not connector.is_alive(): break except KeyboardInterrupt: LOG.info("Caught keyboard interrupt, exiting!") connector.join() break
def main(): """ Starts the mongo connector (assuming CLI) """ # Setup an initial logging handler that buffers log messages before # applying the final logging configuration. initial_handler = logging.handlers.MemoryHandler(100) root_logger = logging.getLogger() root_logger.addHandler(initial_handler) # Parse configuration and setup logging. conf = config.Config(get_config_options()) conf.parse_args() setup_logging(conf) # Flush the buffered log messages to the final logging handler. initial_handler.setTarget(root_logger.handlers[-1]) initial_handler.flush() root_logger.removeHandler(initial_handler) log_startup_info() connector = Connector.from_config(conf) # Catch SIGTERM and SIGINT to cleanup the connector gracefully def signame_handler(signal_name): def sig_handler(signum, frame): # Save the signal so it can be printed later connector.signal = (signal_name, signum) connector.can_run = False return sig_handler signal.signal(signal.SIGTERM, signame_handler('SIGTERM')) signal.signal(signal.SIGINT, signame_handler('SIGINT')) connector.start() while True: if not connector.is_alive(): break time.sleep(3)
def main(): """ Starts the mongo connector (assuming CLI) """ conf = config.Config(get_config_options()) conf.parse_args() setup_logging(conf) LOG.info('Beginning Mongo Connector') connector = Connector.from_config(conf) connector.start() while True: try: time.sleep(3) if not connector.is_alive(): break except KeyboardInterrupt: LOG.info("Caught keyboard interrupt, exiting!") connector.join() break
def test_client_options(self): config_def = { 'mainAddress': 'localhost:27017', 'oplogFile': from_here('lib', 'dummy.timestamp'), 'docManagers': [{ 'docManager': 'mongo_doc_manager', 'targetURL': 'dummyhost:27017', 'args': { 'clientOptions': { 'maxPoolSize': 50, 'connect': False } } }] } config_obj = config.Config(get_config_options()) config_obj.load_json(json.dumps(config_def)) config_obj.parse_args(argv=[]) conn = connector.Connector.from_config(config_obj) self.assertEqual(50, conn.doc_managers[0].mongo.max_pool_size)
def test_ssl_options(self): config_def = { 'mainAddress': 'localhost:27017', 'oplogFile': from_here('lib', 'dummy.timestamp'), 'ssl': { 'sslCertfile': 'certfile.pem', 'sslKeyfile': 'certfile.key', 'sslCACerts': 'ca.pem' }, } for cert_policy, expected_ssl_cert_req in [ ('ignored', ssl.CERT_NONE), ('optional', ssl.CERT_OPTIONAL), ('required', ssl.CERT_REQUIRED), (None, None) ]: config_def['ssl']['sslCertificatePolicy'] = cert_policy config_obj = config.Config(get_config_options()) config_obj.load_json(json.dumps(config_def)) config_obj.parse_args(argv=[]) mc = connector.Connector.from_config(config_obj) self.assertEqual('certfile.pem', mc.ssl_kwargs.get('ssl_certfile')) self.assertEqual('ca.pem', mc.ssl_kwargs.get('ssl_ca_certs')) self.assertEqual('certfile.key', mc.ssl_kwargs.get('ssl_keyfile')) self.assertEqual(expected_ssl_cert_req, mc.ssl_kwargs.get('ssl_cert_reqs'))
def reset_config(self): self.options = get_config_options() self.conf = config.Config(self.options)
def setUp(self): self.config = config.Config(get_config_options()) # Remove all logging Handlers, since tests may create Handlers. logger = logging.getLogger() for handler in logger.handlers: logger.removeHandler(handler)