Use port's bound host in get_gbp_details RPC

The RPC used by agents to get details about ports is currently
returning a host attribute that is set to the requesting agent's
host ID. The host is changed to pass the host that the port is
bound to, so that agents can qualify whether or not the port
returned in the RPC is managed by them.

Change-Id: I1c30d040b0d6699bd1f59cc49e040896f666e9b6
This commit is contained in:
Thomas Bachman 2018-01-31 17:09:20 +00:00
parent 6c2ac9b022
commit 727595a86f
2 changed files with 42 additions and 1 deletions

View File

@ -18,6 +18,7 @@ from neutron.db import db_base_plugin_common
from neutron.objects import base as objects_base
from neutron.objects import trunk as trunk_objects
from neutron.plugins.ml2 import rpc as ml2_rpc
from neutron_lib.api.definitions import portbindings
from opflexagent import rpc as o_rpc
from oslo_log import log
@ -198,7 +199,7 @@ class AIMMappingRPCMixin(ha_ip_db.HAIPOwnerDbMixin):
'mac_address': port['mac_address'],
'app_profile_name': epg.app_profile_name,
'tenant_id': port['tenant_id'],
'host': host,
'host': port[portbindings.HOST_ID],
# TODO(ivar): scope names, possibly through AIM or the
# name mapper
'ptg_tenant': epg.tenant_name,

View File

@ -5199,6 +5199,46 @@ class TestNeutronPortOperation(AIMBaseTestCase):
expected_calls,
self.driver.aim_mech_driver._notify_port_update.call_args_list)
def test_port_bound_other_agent(self):
self._register_agent('h1', test_aim_md.AGENT_CONF_OPFLEX)
self._register_agent('h2', test_aim_md.AGENT_CONF_OPFLEX)
net = self._make_network(self.fmt, 'net1', True)
self._make_subnet(self.fmt, net, '10.0.1.1', '10.0.1.0/24')
# First test an unbound port
p1 = self._make_port(self.fmt, net['network']['id'],
device_owner='compute:')['port']
details = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % p1['id'],
host='h1')
self.assertEqual('', details['host'])
details = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % p1['id'],
host='h2')
self.assertEqual('', details['host'])
# Test port bound to h1, queries from h1 and h2
p1 = self._bind_port_to_host(p1['id'], 'h2')['port']
details = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % p1['id'],
host='h1')
self.assertEqual('h2', details['host'])
details = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % p1['id'],
host='h2')
self.assertEqual('h2', details['host'])
# Test rebind of port to h2, queries from h1 and h2
p1 = self._bind_port_to_host(p1['id'], 'h1')['port']
details = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % p1['id'],
host='h1')
self.assertEqual('h1', details['host'])
details = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % p1['id'],
host='h2')
self.assertEqual('h1', details['host'])
class TestPerL3PImplicitContractsConfig(TestL2PolicyWithAutoPTG):