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 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( driver=driver, resource_id=cfg.CONF.router_id, 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 get_by_tenant(self, resource, worker_context, message): tenant_id = resource.tenant_id driver = resource.driver cached_resources = self._tenant_resources.get(driver, {}) if tenant_id not in cached_resources: resource_id = drivers.get(driver).get_resource_id_for_tenant( worker_context, tenant_id, message) if not resource_id: LOG.debug('%s not found for tenant %s.', driver, tenant_id) return None if not cached_resources: self._tenant_resources[driver] = {} self._tenant_resources[driver][tenant_id] = resource_id return self._tenant_resources[driver][tenant_id]
def _load_resource_from_message(self, worker_context, message): if cfg.CONF.enable_byonf: byonf_res = worker_context.neutron.tenant_has_byo_for_function( tenant_id=self.tenant_id.replace('-', ''), function_type=message.resource.driver) if byonf_res: try: return drivers.load_from_byonf(worker_context, byonf_res, message.resource.id) except drivers.InvalidDriverException: LOG.exception( _LE('Could not load BYONF driver, falling back to ' 'configured image')) pass return drivers.get(message.resource.driver)(worker_context, message.resource.id)
def _load_resource_from_message(self, worker_context, message): if cfg.CONF.enable_byonf: byonf_res = worker_context.neutron.tenant_has_byo_for_function( tenant_id=self.tenant_id.replace('-', ''), function_type=message.resource.driver) if byonf_res: try: return drivers.load_from_byonf( worker_context, byonf_res, message.resource.id) except drivers.InvalidDriverException: LOG.exception(_LE( 'Could not load BYONF driver, falling back to ' 'configured image')) pass return drivers.get(message.resource.driver)( worker_context, message.resource.id)
def test_get_driver(self): for k, v in drivers.AVAILABLE_DRIVERS.items(): self.assertEqual(drivers.get(k), v)
def get_state_machines(self, message, worker_context): """Return the state machines and the queue for sending it messages for the logical resource being addressed by the message. """ if (not message.resource or (message.resource and not message.resource.id)): LOG.error(_LE( 'Cannot get state machine for message with ' 'no message.resource')) raise InvalidIncomingMessage() state_machines = [] # Send to all of our resources. if message.resource.id == '*': LOG.debug('routing to all state machines') state_machines = self.state_machines.values() # Ignore messages to deleted resources. elif self.state_machines.has_been_deleted(message.resource.id): LOG.debug('dropping message for deleted resource') return [] # Send to resources that have an ERROR status elif message.resource.id == 'error': state_machines = [ sm for sm in self.state_machines.values() if sm.has_error() ] LOG.debug('routing to %d errored state machines', len(state_machines)) # Create a new state machine for this router. elif message.resource.id not in self.state_machines: LOG.debug('creating state machine for %s', message.resource.id) # load the driver if not message.resource.driver: LOG.error(_LE('cannot create state machine without specifying' 'a driver.')) return [] driver_obj = \ drivers.get(message.resource.driver)(worker_context, message.resource.id) if not driver_obj: # this means the driver didn't load for some reason.. # this might not be needed at all. LOG.debug('for some reason loading the driver failed') return [] def deleter(): self._delete_resource(message.resource) new_state_machine = state.Automaton( driver=driver_obj, resource_id=message.resource.id, tenant_id=self.tenant_id, delete_callback=deleter, bandwidth_callback=self._report_bandwidth, worker_context=worker_context, queue_warning_threshold=self._queue_warning_threshold, reboot_error_threshold=self._reboot_error_threshold, ) self.state_machines[message.resource.id] = new_state_machine state_machines = [new_state_machine] # Send directly to an existing router. elif message.resource.id: state_machines = [self.state_machines[message.resource.id]] # Filter out any deleted state machines. return [ machine for machine in state_machines if (not machine.deleted and not self.state_machines.has_been_deleted(machine.resource_id)) ]
def test_get_driver(self): for k, v in drivers.AVAILABLE_DRIVERS.items(): self.assertEqual(v, drivers.get(k))