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()
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()
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()
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()