From dfa79b3cf6e0b29225242df5d96a83b5871f9705 Mon Sep 17 00:00:00 2001 From: vikas Date: Thu, 10 Mar 2016 01:46:18 -0800 Subject: [PATCH] check for ovs agent is running on a host while retreving the information from port details which belongs to specific host, we are checking whether ovs agent is running on that host or not. if not, exception is raised saying ovs agent not found in the host. Closes-Bug:1515877 Change-Id: I23fccd8751ce791e1c6fd6920a0510c943714126 --- networking_l2gw/services/l2gateway/exceptions.py | 5 +++++ .../services/l2gateway/service_drivers/rpc_l2gw.py | 13 ++++++++----- .../l2gateway/service_drivers/test_rpc_l2gw.py | 11 +++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/networking_l2gw/services/l2gateway/exceptions.py b/networking_l2gw/services/l2gateway/exceptions.py index 0f024030..7bcce243 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 9a4c9219..d463fe96 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 e8856d95..5e16597c 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',