def _agent_notification(self, context, method, router_id, version=None, **kwargs): """Notify update for the agent. Find the host for the router being notified and then dispatches a notification for the VPN device driver. """ admin_context = context.is_admin and context or context.elevated() if not version: version = self.RPC_API_VERSION host = via_cfg_file.get_host_for_router(admin_context, router_id) if not host: # NOTE: This is a config error for workaround. At this point we # can't set state of resource to error. return LOG.debug(_('Notify agent at %(topic)s.%(host)s the message ' '%(method)s %(args)s for router %(router)s'), {'topic': self.topic, 'host': host, 'method': method, 'args': kwargs, 'router': router_id}) self.cast(context, self.make_msg(method, **kwargs), version=version, topic='%s.%s' % (self.topic, host))
def _agent_notification(self, context, method, router_id, version=None, **kwargs): """Notify update for the agent. Find the host for the router being notified and then dispatches a notification for the VPN device driver. """ admin_context = context.is_admin and context or context.elevated() if not version: version = self.RPC_API_VERSION host = via_cfg_file.get_host_for_router(admin_context, router_id) if not host: # NOTE: This is a config error for workaround. At this point we # can't set state of resource to error. return LOG.debug( _('Notify agent at %(topic)s.%(host)s the message ' '%(method)s %(args)s for router %(router)s'), { 'topic': self.topic, 'host': host, 'method': method, 'args': kwargs, 'router': router_id }) self.cast(context, self.make_msg(method, **kwargs), version=version, topic='%s.%s' % (self.topic, host))
def test_failed_to_find_host_as_no_routers_in_ini(self): """Fail to find host, as no router info in INI file.""" cfg_file = create_tempfile('\n') cfg.CONF.set_override('config_file', [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value='5.5.5.5').start() self.assertEqual( '', cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))
def test_failed_to_find_host_as_no_routers_in_ini(self): """Fail to find host, as no router info in INI file.""" cfg_file = create_tempfile('\n') cfg.CONF.set_override('config_file', [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value='5.5.5.5').start() self.assertEqual('', cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))
def test_failed_to_find_router_ip(self): """Fail to lookup router IP, preventing search in INI file.""" cfg_file = create_tempfile('[CISCO_CSR_REST:3.2.1.1]\n' 'rest_mgmt = 10.20.30.1\n' 'tunnel_ip = 3.2.1.3\n' 'username = me\n' 'password = secret\n' 'host = ubuntu\n' 'tunnel_if = GigabitEthernet3\n' 'timeout = 5.0\n') cfg.CONF.set_override('config_file', [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value=None).start() self.assertEqual( '', cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))
def test_failed_no_matching_router_to_obtain_host(self): """Fail to find INI info for router provided.""" cfg_file = create_tempfile('[CISCO_CSR_REST:3.2.1.1]\n' 'rest_mgmt = 10.20.30.1\n' 'tunnel_ip = 3.2.1.3\n' 'username = me\n' 'password = secret\n' 'host = ubuntu\n' 'tunnel_if = GigabitEthernet3\n' 'timeout = 5.0\n') cfg.CONF.set_override('config_file', [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value='5.5.5.5').start() self.assertEqual( '', cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))
def test_failed_to_find_router_ip(self): """Fail to lookup router IP, preventing search in INI file.""" cfg_file = create_tempfile( "[CISCO_CSR_REST:3.2.1.1]\n" "rest_mgmt = 10.20.30.1\n" "tunnel_ip = 3.2.1.3\n" "username = me\n" "password = secret\n" "host = ubuntu\n" "tunnel_if = GigabitEthernet3\n" "timeout = 5.0\n" ) cfg.CONF.set_override("config_file", [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value=None).start() self.assertEqual("", cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))
def test_failed_no_matching_router_to_obtain_host(self): """Fail to find INI info for router provided.""" cfg_file = create_tempfile( "[CISCO_CSR_REST:3.2.1.1]\n" "rest_mgmt = 10.20.30.1\n" "tunnel_ip = 3.2.1.3\n" "username = me\n" "password = secret\n" "host = ubuntu\n" "tunnel_if = GigabitEthernet3\n" "timeout = 5.0\n" ) cfg.CONF.set_override("config_file", [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value="5.5.5.5").start() self.assertEqual("", cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))
def test_find_host_for_router(self): """Look up host in INI file for a router.""" cfg_file = create_tempfile('[CISCO_CSR_REST:3.2.1.1]\n' 'rest_mgmt = 10.20.30.1\n' 'tunnel_ip = 3.2.1.3\n' 'username = me\n' 'password = secret\n' 'host = ubuntu\n' 'tunnel_if = GigabitEthernet1\n' 'mgmt_vlan = 100\n' 'timeout = 5.0\n') cfg.CONF.set_override('config_file', [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value='3.2.1.1').start() self.assertEqual( 'ubuntu', cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))
def test_find_host_for_router(self): """Look up host in INI file for a router.""" cfg_file = create_tempfile( "[CISCO_CSR_REST:3.2.1.1]\n" "rest_mgmt = 10.20.30.1\n" "tunnel_ip = 3.2.1.3\n" "username = me\n" "password = secret\n" "host = ubuntu\n" "tunnel_if = GigabitEthernet1\n" "mgmt_vlan = 100\n" "timeout = 5.0\n" ) cfg.CONF.set_override("config_file", [cfg_file]) mock.patch(CISCO_GET_ROUTER_IP, return_value="3.2.1.1").start() self.assertEqual("ubuntu", cfg_loader.get_host_for_router(self.context, FAKE_ROUTER_ID))