def setUp(self): super(TestAdvancedService, self).setUp() self.agent = mock.Mock() self.test_observers = event_observers.L3EventObservers() # Ensure no instances for each test FakeServiceA._instance = None FakeServiceB._instance = None
def test_unique_observers_for_different_services(self): """Test different service types with different observer lists. The services are unique instances, shared the same agent, but are using different observer lists. """ a = FakeServiceA(self.agent) self.test_observers.add(a) other_observers = event_observers.L3EventObservers() b = FakeServiceB(self.agent) other_observers.add(b) self.assertNotEqual(a, b) self.assertEqual(self.agent, a.l3_agent) self.assertIn(a, self.test_observers.observers) self.assertEqual(1, len(self.test_observers.observers)) self.assertEqual(self.agent, b.l3_agent) self.assertIn(b, other_observers.observers) self.assertEqual(1, len(other_observers.observers))
def setUp(self): super(TestL3EventObservers, self).setUp() self.event_observers = event_observers.L3EventObservers()
def __init__(self, host, conf=None): if conf: self.conf = conf else: self.conf = cfg.CONF self.router_info = {} self._check_config_params() self.process_monitor = external_process.ProcessMonitor( config=self.conf, resource_type='router') try: self.driver = importutils.import_object(self.conf.interface_driver, self.conf) except Exception: LOG.error(_LE("Error importing interface driver " "'%s'"), self.conf.interface_driver) raise SystemExit(1) self.context = n_context.get_admin_context_without_session() self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host) self.fullsync = True # Get the list of service plugins from Neutron Server # This is the first place where we contact neutron-server on startup # so retry in case its not ready to respond. retry_count = 5 while True: retry_count = retry_count - 1 try: self.neutron_service_plugins = ( self.plugin_rpc.get_service_plugin_list(self.context)) except oslo_messaging.RemoteError as e: with excutils.save_and_reraise_exception() as ctx: ctx.reraise = False LOG.warning( _LW('l3-agent cannot check service plugins ' 'enabled at the neutron server when ' 'startup due to RPC error. It happens ' 'when the server does not support this ' 'RPC API. If the error is ' 'UnsupportedVersion you can ignore this ' 'warning. Detail message: %s'), e) self.neutron_service_plugins = None except oslo_messaging.MessagingTimeout as e: with excutils.save_and_reraise_exception() as ctx: if retry_count > 0: ctx.reraise = False LOG.warning( _LW('l3-agent cannot check service ' 'plugins enabled on the neutron ' 'server. Retrying. ' 'Detail message: %s'), e) continue break self.namespaces_manager = namespace_manager.NamespaceManager( self.conf, self.driver, self.conf.use_namespaces) self._queue = queue.RouterProcessingQueue() self.event_observers = event_observers.L3EventObservers() super(L3NATAgent, self).__init__(conf=self.conf) self.target_ex_net_id = None self.use_ipv6 = ipv6_utils.is_enabled() if self.conf.enable_metadata_proxy: self.metadata_driver = metadata_driver.MetadataDriver(self) self.event_observers.add(self.metadata_driver)
def setUp(self): super(TestAdvancedService, self).setUp() self.agent = mock.Mock() self.test_observers = event_observers.L3EventObservers()