From: Swaminathan Vasudevan Date: Wed, 23 Dec 2015 18:36:35 +0000 (-0800) Subject: Rename _get_vm_port_hostid in dvr to reflect the right functionality X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3a6951befee21f5113449d551adb7c9243c6159c;p=openstack-build%2Fneutron-build.git Rename _get_vm_port_hostid in dvr to reflect the right functionality _get_vm_port_hostid returns the host id associated with the dvr service ports. It not only returns the VM port hostid, but also returns the host id associated with LBaaS vip port and dhcp. So to be in sync with other function names let us rename the function to _get_dvr_service_port_hostid. Change-Id: Idc69d3b35a371b987aa34597ed6e1de7b96ff2e5 --- diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index e77d665f0..2576aa427 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -218,9 +218,9 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, # Check if distributed router and then create the # FloatingIP agent gateway port if router_dict.get('distributed'): - vm_hostid = self._get_vm_port_hostid( + hostid = self._get_dvr_service_port_hostid( context, fip_port) - if vm_hostid: + if hostid: # FIXME (Swami): This FIP Agent Gateway port should be # created only once and there should not be a duplicate # for the same host. Until we find a good solution for @@ -229,7 +229,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, fip_agent_port = ( self.create_fip_agent_gw_port_if_not_exists( admin_ctx, external_port['network_id'], - vm_hostid)) + hostid)) LOG.debug("FIP Agent gateway port: %s", fip_agent_port) def _get_floatingip_on_port(self, context, port_id=None): @@ -512,9 +512,8 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, for fip in floating_ips: vm_port = port_dict.get(fip['port_id'], None) if vm_port: - fip['host'] = self._get_vm_port_hostid(context, - fip['port_id'], - port=vm_port) + fip['host'] = self._get_dvr_service_port_hostid( + context, fip['port_id'], port=vm_port) routers_dict = self._process_routers(context, routers) self._process_floating_ips_dvr(context, routers_dict, floating_ips, host, agent) @@ -531,13 +530,13 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, self._process_interfaces(routers_dict, interfaces) return list(routers_dict.values()) - def _get_vm_port_hostid(self, context, port_id, port=None): - """Return the portbinding host_id.""" - vm_port_db = port or self._core_plugin.get_port(context, port_id) - device_owner = vm_port_db['device_owner'] if vm_port_db else "" + def _get_dvr_service_port_hostid(self, context, port_id, port=None): + """Returns the portbinding host_id for dvr service port.""" + port_db = port or self._core_plugin.get_port(context, port_id) + device_owner = port_db['device_owner'] if port_db else "" if (n_utils.is_dvr_serviced(device_owner) or device_owner == l3_const.DEVICE_OWNER_AGENT_GW): - return vm_port_db[portbindings.HOST_ID] + return port_db[portbindings.HOST_ID] def _get_agent_gw_ports_exist_for_network( self, context, network_id, host, agent_id): @@ -772,7 +771,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, return if is_distributed_router(router): - host = self._get_vm_port_hostid(context, fixed_port_id) + host = self._get_dvr_service_port_hostid(context, fixed_port_id) self.l3_rpc_notifier.routers_updated_on_host( context, [router_id], host) else: diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py index 6954f8e70..611dcab67 100644 --- a/neutron/tests/unit/db/test_l3_dvr_db.py +++ b/neutron/tests/unit/db/test_l3_dvr_db.py @@ -397,7 +397,8 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): # NOTE: mock.patch is not needed here since self.mixin is created fresh # for each test. It doesn't work with some methods since the mixin is # tested in isolation (e.g. _get_agent_by_type_and_host). - self.mixin._get_vm_port_hostid = mock.Mock(return_value=hostid) + self.mixin._get_dvr_service_port_hostid = mock.Mock( + return_value=hostid) self.mixin._get_agent_by_type_and_host = mock.Mock( return_value=fipagent) self.mixin._get_fip_sync_interfaces = mock.Mock( @@ -435,7 +436,8 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): } with mock.patch.object(self.mixin, 'get_router') as grtr,\ - mock.patch.object(self.mixin, '_get_vm_port_hostid') as vmp,\ + mock.patch.object(self.mixin, + '_get_dvr_service_port_hostid') as vmp,\ mock.patch.object( self.mixin, 'create_fip_agent_gw_port_if_not_exists') as c_fip,\