Exemplo n.º 1
0
 def test_run(self):
     config = {
         'name': 'east_coast.prod.global',
         'durable_queue': False,
         'rabbit_host': '10.0.0.1',
         'rabbit_port': 5672,
         'rabbit_userid': 'rabbit',
         'rabbit_password': '******',
         'rabbit_virtual_host': '/'
     }
     self.mox.StubOutWithMock(db, 'get_or_create_deployment')
     deployment = self.mox.CreateMockAnything()
     db.get_or_create_deployment(config['name'])\
       .AndReturn((deployment, True))
     self.mox.StubOutWithMock(kombu.connection, 'BrokerConnection')
     params = dict(hostname=config['rabbit_host'],
                   port=config['rabbit_port'],
                   userid=config['rabbit_userid'],
                   password=config['rabbit_password'],
                   transport="librabbitmq",
                   virtual_host=config['rabbit_virtual_host'])
     self.mox.StubOutWithMock(worker, "continue_running")
     worker.continue_running().AndReturn(True)
     conn = self.mox.CreateMockAnything()
     kombu.connection.BrokerConnection(**params).AndReturn(conn)
     conn.__enter__().AndReturn(conn)
     conn.__exit__(None, None, None).AndReturn(None)
     self.mox.StubOutClassWithMocks(worker, 'NovaConsumer')
     consumer = worker.NovaConsumer(config['name'], conn, deployment,
                                    config['durable_queue'], {})
     consumer.run()
     worker.continue_running().AndReturn(False)
     self.mox.ReplayAll()
     worker.run(config)
     self.mox.VerifyAll()
Exemplo n.º 2
0
 def test_run(self):
     config = {
         'name': 'east_coast.prod.global',
         'durable_queue': False,
         'rabbit_host': '10.0.0.1',
         'rabbit_port': 5672,
         'rabbit_userid': 'rabbit',
         'rabbit_password': '******',
         'rabbit_virtual_host': '/'
     }
     self.mox.StubOutWithMock(db, 'get_or_create_deployment')
     deployment = self.mox.CreateMockAnything()
     db.get_or_create_deployment(config['name'])\
       .AndReturn((deployment, True))
     self.mox.StubOutWithMock(kombu.connection, 'BrokerConnection')
     params = dict(hostname=config['rabbit_host'],
                   port=config['rabbit_port'],
                   userid=config['rabbit_userid'],
                   password=config['rabbit_password'],
                   transport="librabbitmq",
                   virtual_host=config['rabbit_virtual_host'])
     self.mox.StubOutWithMock(worker, "continue_running")
     worker.continue_running().AndReturn(True)
     conn = self.mox.CreateMockAnything()
     kombu.connection.BrokerConnection(**params).AndReturn(conn)
     conn.__enter__().AndReturn(conn)
     conn.__exit__(None, None, None).AndReturn(None)
     self.mox.StubOutClassWithMocks(worker, 'NovaConsumer')
     consumer = worker.NovaConsumer(config['name'], conn, deployment,
                                    config['durable_queue'], {})
     consumer.run()
     worker.continue_running().AndReturn(False)
     self.mox.ReplayAll()
     worker.run(config)
     self.mox.VerifyAll()
Exemplo n.º 3
0
    def test_run_queue_args(self):
        mock_logger = self._setup_mock_logger()
        self.mox.StubOutWithMock(mock_logger, 'info')
        mock_logger.info("east_coast.prod.global: nova 10.0.0.1 5672 rabbit /")
        self.mox.StubOutWithMock(mock_logger, 'debug')
        mock_logger.debug("Processing on 'east_coast.prod.global nova'")
        mock_logger.debug("Completed processing on "
                          "'east_coast.prod.global nova'")
        mock_logger.info("Worker exiting.")

        config = {
            'name': 'east_coast.prod.global',
            'durable_queue': False,
            'rabbit_host': '10.0.0.1',
            'rabbit_port': 5672,
            'rabbit_userid': 'rabbit',
            'rabbit_password': '******',
            'rabbit_virtual_host': '/',
            'queue_arguments': {
                'x-ha-policy': 'all'
            },
            'queue_name_prefix': "test_name_",
            "services": ["nova"],
            "topics": {
                "nova": self._test_topics()
            }
        }
        self.mox.StubOutWithMock(db, 'get_deployment')
        deployment = self.mox.CreateMockAnything()
        deployment.id = 1
        db.get_deployment(deployment.id).AndReturn(deployment)
        self.mox.StubOutWithMock(kombu.connection, 'BrokerConnection')
        params = dict(hostname=config['rabbit_host'],
                      port=config['rabbit_port'],
                      userid=config['rabbit_userid'],
                      password=config['rabbit_password'],
                      transport="librabbitmq",
                      virtual_host=config['rabbit_virtual_host'])
        self.mox.StubOutWithMock(worker, "continue_running")
        worker.continue_running().AndReturn(True)
        conn = self.mox.CreateMockAnything()
        kombu.connection.BrokerConnection(**params).AndReturn(conn)
        conn.__enter__().AndReturn(conn)
        conn.__exit__(None, None, None).AndReturn(None)
        self.mox.StubOutClassWithMocks(worker, 'Consumer')
        exchange = 'nova'
        consumer = worker.Consumer(config['name'], conn, deployment,
                                   config['durable_queue'],
                                   config['queue_arguments'], exchange,
                                   self._test_topics())
        consumer.run()
        worker.continue_running().AndReturn(False)
        self.mox.ReplayAll()
        worker.run(config, deployment.id, exchange)
        self.mox.VerifyAll()
Exemplo n.º 4
0
    def test_run_queue_args(self):
        mock_logger = self._setup_mock_logger()
        self.mox.StubOutWithMock(mock_logger, 'info')
        mock_logger.info("east_coast.prod.global: nova 10.0.0.1 5672 rabbit /")
        self.mox.StubOutWithMock(mock_logger, 'debug')
        mock_logger.debug("Processing on 'east_coast.prod.global nova'")
        mock_logger.debug("Completed processing on "
                          "'east_coast.prod.global nova'")
        mock_logger.info("Worker exiting.")

        config = {
            'name': 'east_coast.prod.global',
            'durable_queue': False,
            'rabbit_host': '10.0.0.1',
            'rabbit_port': 5672,
            'rabbit_userid': 'rabbit',
            'rabbit_password': '******',
            'rabbit_virtual_host': '/',
            'queue_arguments': {'x-ha-policy': 'all'},
            'queue_name_prefix': "test_name_",
            "services": ["nova"],
            "topics": {"nova": self._test_topics()}
        }
        self.mox.StubOutWithMock(db, 'get_deployment')
        deployment = self.mox.CreateMockAnything()
        deployment.id = 1
        db.get_deployment(deployment.id).AndReturn(deployment)
        stats = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(kombu.connection, 'BrokerConnection')
        params = dict(hostname=config['rabbit_host'],
                      port=config['rabbit_port'],
                      userid=config['rabbit_userid'],
                      password=config['rabbit_password'],
                      transport="librabbitmq",
                      virtual_host=config['rabbit_virtual_host'])
        self.mox.StubOutWithMock(worker, "continue_running")
        worker.continue_running().AndReturn(True)
        conn = self.mox.CreateMockAnything()
        kombu.connection.BrokerConnection(**params).AndReturn(conn)
        conn.__enter__().AndReturn(conn)
        conn.__exit__(None, None, None).AndReturn(None)
        self.mox.StubOutClassWithMocks(worker, 'Consumer')
        exchange = 'nova'
        consumer = worker.Consumer(config['name'], conn, deployment,
                                   config['durable_queue'],
                                   config['queue_arguments'], exchange,
                                   self._test_topics(), stats=stats)
        consumer.run()
        worker.continue_running().AndReturn(False)
        self.mox.ReplayAll()
        worker.run(config, deployment.id, exchange, stats)
        self.mox.VerifyAll()
Exemplo n.º 5
0
 def test_run_queue_args(self):
     config = {
         'name': 'east_coast.prod.global',
         'durable_queue': False,
         'rabbit_host': '10.0.0.1',
         'rabbit_port': 5672,
         'rabbit_userid': 'rabbit',
         'rabbit_password': '******',
         'rabbit_virtual_host': '/',
         'queue_arguments': {'x-ha-policy': 'all'},
         'queue_name_prefix': "test_name_",
         "services": ["nova"],
         "topics": {"nova": ["monitor.info", "monitor.error"]}
     }
     self.mox.StubOutWithMock(db, 'get_or_create_deployment')
     deployment = self.mox.CreateMockAnything()
     db.get_or_create_deployment(config['name'])\
       .AndReturn((deployment, True))
     self.mox.StubOutWithMock(kombu.connection, 'BrokerConnection')
     params = dict(hostname=config['rabbit_host'],
                   port=config['rabbit_port'],
                   userid=config['rabbit_userid'],
                   password=config['rabbit_password'],
                   transport="librabbitmq",
                   virtual_host=config['rabbit_virtual_host'])
     self.mox.StubOutWithMock(worker, "continue_running")
     worker.continue_running().AndReturn(True)
     conn = self.mox.CreateMockAnything()
     kombu.connection.BrokerConnection(**params).AndReturn(conn)
     conn.__enter__().AndReturn(conn)
     conn.__exit__(None, None, None).AndReturn(None)
     self.mox.StubOutClassWithMocks(worker, 'Consumer')
     exchange = 'nova'
     consumer = worker.Consumer(config['name'], conn, deployment,
                                config['durable_queue'],
                                config['queue_arguments'], exchange,
                                ["monitor.info", "monitor.error"],
                                "test_name_")
     consumer.run()
     worker.continue_running().AndReturn(False)
     self.mox.ReplayAll()
     worker.run(config, exchange)
     self.mox.VerifyAll()
Exemplo n.º 6
0
def start_handler(config, handler_name):

    logUtils.setup_logging(config)
    logger = logUtils.get_logger(__name__)
    logger.info('starting handler ' + handler_name)
    worker.run(config, handler_name)
Exemplo n.º 7
0
    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')

    keep_fds = None
    if args.log:
        handler = logging.FileHandler(args.log, 'a')
        keep_fds = [handler.stream.fileno()]
    else:
        handler = logging.StreamHandler()

    handler.setFormatter(formatter)
    config.logger.addHandler(handler)

    chdir = Path(__file__).parent

    if args.daemon:
        if not args.pidfile:
            print('PID file is required for daemon mode!')
            exit(1)

        d = daemonize.Daemonize(app='speech_tools_worker',
                                pid=args.pidfile,
                                action=worker.run,
                                keep_fds=keep_fds,
                                user=args.user,
                                group=args.group,
                                chdir=chdir)
        d.start()

    else:
        worker.run()
Exemplo n.º 8
0
import logging

from worker.config import logger
from worker.worker import run

if __name__ == '__main__':
    logger.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    run()