def test_message_enqueued(self): self.w.handle_message(self.tenant_id, self.msg) trm = self.w.tenant_managers[self.tenant_id] sm = trm.get_state_machines(self.msg, worker.WorkerContext( fakes.FAKE_MGT_ADDR))[0] self.assertEqual(len(sm._queue), 1)
def debug_one_router(args=sys.argv[1:]): # Add our extra option for specifying the router-id to debug cfg.CONF.register_cli_opts(DEBUG_OPTS) cfg.CONF.set_override('boot_timeout', 60000) cfg.CONF.import_opt('host', 'astara.main') config.parse_config(args) logging.setup(cfg.CONF, __name__) log = logging.getLogger(__name__) log.debug('Proxy settings: %r', os.getenv('no_proxy')) context = worker.WorkerContext() driver = drivers.get('router')(context, cfg.CONF.router_id) a = state.Automaton( resource=driver, tenant_id=driver._router.tenant_id, delete_callback=delete_callback, bandwidth_callback=bandwidth_callback, worker_context=context, queue_warning_threshold=100, reboot_error_threshold=1, ) a.send_message(Fake('update')) import pdb pdb.set_trace() a.update(context)
def test_worker_context_config(self): self.config(astara_metadata_port=1234) self.config(host='foohost') ctxt = worker.WorkerContext(fakes.FAKE_MGT_ADDR) self.assertEqual( ctxt.config, { 'host': 'foohost', 'metadata_port': 1234, 'address': fakes.FAKE_MGT_ADDR, })
def fake_worker_context(): """Patches client API libs in the worker context. Caller should addCleanup(mock.patch.stopall). """ fake_neutron_obj = mock.patch.object(neutron, 'Neutron', autospec=True).start() mock.patch.object(neutron, 'Neutron', return_value=fake_neutron_obj).start() fake_nova_obj = mock.patch.object(nova, 'Nova', autospec=True).start() mock.patch.object(nova, 'Nova', return_value=fake_nova_obj).start() return worker.WorkerContext(FAKE_MGT_ADDR)
def test_global_debug_no_message_sent(self): self.dbapi.enable_global_debug() tenant_id = '98dd9c41-d3ac-4fd6-8927-567afa0b8fc3' resource_id = 'ac194fc5-f317-412e-8611-fb290629f624' msg = event.Event( resource=event.Resource(router.Router.RESOURCE_NAME, resource_id, tenant_id), crud=event.CREATE, body={'key': 'value'}, ) # Create the router manager and state machine so we can # replace the send_message() method with a mock. trm = self.w._get_trms(tenant_id)[0] sm = trm.get_state_machines(msg, worker.WorkerContext( fakes.FAKE_MGT_ADDR))[0] with mock.patch.object(sm, 'send_message') as meth: # The tenant id is being ignored, so the send_message() # method shouldn't ever be invoked. meth.side_effect = AssertionError('send_message was called') self.w.handle_message(tenant_id, msg)
def setUp(self): super(TestUpdateStateMachine, self).setUp() self.worker_context = worker.WorkerContext(fakes.FAKE_MGT_ADDR) self.w._should_process_message = mock.MagicMock(return_value=self.msg)
def setUp(self): super(TestResourceCache, self).setUp() self.resource_cache = worker.TenantResourceCache() self.worker_context = worker.WorkerContext(fakes.FAKE_MGT_ADDR)