diff --git a/networking_l2gw/services/l2gateway/exceptions.py b/networking_l2gw/services/l2gateway/exceptions.py index 0f02403..7bcce24 100644 --- a/networking_l2gw/services/l2gateway/exceptions.py +++ b/networking_l2gw/services/l2gateway/exceptions.py @@ -28,6 +28,10 @@ class L2GatewayNotFound(exceptions.NotFound): message = _("L2 Gateway %(gateway_id)s could not be found") +class OvsAgentNotFound(exceptions.NotFound): + message = _("ovs agent not found in host %(host)s") + + class L2GatewayDeviceInUse(exceptions.InUse): message = _("L2 Gateway Device '%(device_id)s' is still used by " "one or more network gateways.") @@ -119,4 +123,5 @@ base.FAULT_MAP.update({L2GatewayInUse: web_exc.HTTPConflict, L2GatewaySegmentationRequired: web_exc.HTTPConflict, L2MultipleGatewayConnections: web_exc.HTTPConflict, L2GatewayDuplicateSegmentationID: web_exc.HTTPConflict, + OvsAgentNotFound: web_exc.HTTPNotFound, OVSDBError: web_exc.HTTPConflict}) diff --git a/networking_l2gw/services/l2gateway/service_drivers/rpc_l2gw.py b/networking_l2gw/services/l2gateway/service_drivers/rpc_l2gw.py index 9a4c921..d463fe9 100644 --- a/networking_l2gw/services/l2gateway/service_drivers/rpc_l2gw.py +++ b/networking_l2gw/services/l2gateway/service_drivers/rpc_l2gw.py @@ -470,11 +470,14 @@ class L2gwRpcDriver(service_drivers.L2gwDriver): def _get_ip_details(self, context, port): host = port[portbindings.HOST_ID] agent = self._get_agent_details(context, host) - conf_dict = agent[0].get("configurations") - dst_ip = conf_dict.get("tunneling_ip") - fixed_ip_list = port.get('fixed_ips') - fixed_ip_list = fixed_ip_list[0] - return dst_ip, fixed_ip_list.get('ip_address') + if agent: + conf_dict = agent[0].get("configurations") + dst_ip = conf_dict.get("tunneling_ip") + fixed_ip_list = port.get('fixed_ips') + fixed_ip_list = fixed_ip_list[0] + return dst_ip, fixed_ip_list.get('ip_address') + else: + raise l2gw_exc.OvsAgentNotFound(host=host) def _get_network_details(self, context, network_id): network = self.service_plugin._core_plugin.get_network(context, diff --git a/networking_l2gw/tests/unit/services/l2gateway/service_drivers/test_rpc_l2gw.py b/networking_l2gw/tests/unit/services/l2gateway/service_drivers/test_rpc_l2gw.py index e8856d9..5e16597 100644 --- a/networking_l2gw/tests/unit/services/l2gateway/service_drivers/test_rpc_l2gw.py +++ b/networking_l2gw/tests/unit/services/l2gateway/service_drivers/test_rpc_l2gw.py @@ -272,6 +272,17 @@ class TestL2gwRpcDriver(base.BaseTestCase): self.assertEqual(ret_dst_ip, 'fake_tun_ip') self.assertEqual(ret_ip_add, 'fake_ip') + def test_get_ip_details_for_no_ovs_agent(self): + fake_port = {'binding:host_id': 'fake_host', + 'fixed_ips': [{'ip_address': 'fake_ip'}]} + with mock.patch.object(self.plugin, + '_get_agent_details', + return_value=None): + self.assertRaises(l2gw_exc.OvsAgentNotFound, + self.plugin._get_ip_details, + self.context, + fake_port) + def test_get_network_details(self): fake_network = {'id': 'fake_network_id', 'name': 'fake_network_name',