oflex 1.1 compliance

Closes-Bug: 1547694
Change-Id: Ie5a5869b566a03ed34a98e0e0ea06b246d672bb3
This commit is contained in:
Ivar Lazzaro
2016-02-18 15:07:59 -08:00
parent c9c581abdd
commit d282835e51
3 changed files with 208 additions and 141 deletions

View File

@@ -28,6 +28,7 @@ from neutron import context as nctx
from neutron.db import db_base_plugin_v2 as n_db
from neutron.extensions import portbindings
from neutron import manager
from neutron.plugins.ml2 import rpc as neu_rpc
from opflexagent import constants as ofcst
from opflexagent import rpc
from oslo_concurrency import lockutils
@@ -204,8 +205,8 @@ class ApicMappingDriver(api.ResourceMappingDriver,
def initialize(self):
super(ApicMappingDriver, self).initialize()
self._setup_rpc_listeners()
self._setup_rpc()
self._setup_rpc_listeners()
self.apic_manager = ApicMappingDriver.get_apic_manager()
self.name_mapper = name_manager.ApicNameManager(self.apic_manager)
self.enable_dhcp_opt = self.apic_manager.enable_optimized_dhcp
@@ -213,7 +214,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
self._gbp_plugin = None
def _setup_rpc_listeners(self):
self.endpoints = [rpc.GBPServerRpcCallback(self)]
self.endpoints = [rpc.GBPServerRpcCallback(self, self.notifier)]
self.topic = rpc.TOPIC_OPFLEX
self.conn = n_rpc.create_connection(new=True)
self.conn.create_consumer(self.topic, self.endpoints,
@@ -256,9 +257,11 @@ class ApicMappingDriver(api.ResourceMappingDriver,
self._add_vrf_details(context, details)
return details
def request_vrf_details(self, context, **kwargs):
return self.get_vrf_details(context, **kwargs)
# RPC Method
def get_gbp_details(self, context, **kwargs):
try:
def _get_gbp_details(self, context, **kwargs):
port_id = self._core_plugin._device_to_port_id(
context, kwargs['device'])
port_context = self._core_plugin.get_bound_port_context(
@@ -268,7 +271,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
"%(agent_id)s not found in database"),
{'device': port_id,
'agent_id': kwargs.get('agent_id')})
return
return {'device': kwargs.get('device')}
port = port_context.current
# retrieve PTG from a given Port
ptg, pt = self._port_id_to_ptg(context, port['id'])
@@ -289,7 +292,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
l2p = self._network_id_to_l2p(context, port['network_id'])
if not ptg and not l2p:
return
return None
l2_policy_id = l2p['id']
if ptg:
@@ -387,13 +390,40 @@ class ApicMappingDriver(api.ResourceMappingDriver,
# Active chain head must have changed in a concurrent
# operation, get out of here
pass
return details
# RPC Method
def get_gbp_details(self, context, **kwargs):
try:
return self._get_gbp_details(context, **kwargs)
except Exception as e:
LOG.error(_("An exception has occurred while retrieving device "
"gbp details for %(device)s with error %(error)s"),
{'device': kwargs.get('device'), 'error': e.message})
LOG.error(_(
"An exception has occurred while retrieving device "
"gbp details for %s"), kwargs.get('device'))
LOG.exception(e)
details = {'device': kwargs.get('device')}
return details
# RPC Method
def request_gbp_details(self, context, **kwargs):
try:
LOG.debug("Request GBP details: %s", kwargs)
kwargs.update(kwargs['request'])
result = {'device': kwargs['device'],
'timestamp': kwargs['timestamp'],
'request_id': kwargs['request_id'],
'gbp_details': None,
'neutron_details': None}
result['gbp_details'] = self._get_gbp_details(context, **kwargs)
result['neutron_details'] = neu_rpc.RpcCallbacks(
None, None).get_device_details(context, **kwargs)
return result
except Exception as e:
LOG.error(_("An exception has occurred while requesting device "
"gbp details for %s"), kwargs.get('device'))
LOG.exception(e)
return None
def _allocate_snat_ip_for_host_and_ext_net(self, context, host, network,
es_name):
"""Allocate SNAT IP for a host for an external network."""

View File

@@ -97,7 +97,8 @@ class ApicMappingTestCase(
'tenant_network_types': ['opflex']
}
mock.patch('gbpservice.neutron.services.grouppolicy.drivers.cisco.'
'apic.apic_mapping.ApicMappingDriver._setup_rpc').start()
'apic.apic_mapping.ApicMappingDriver.'
'_setup_rpc_listeners').start()
host_agents = mock.patch('neutron.plugins.ml2.driver_context.'
'PortContext.host_agents').start()
host_agents.return_value = [self.agent_conf]
@@ -293,6 +294,11 @@ class TestPolicyTarget(ApicMappingTestCase):
mapping = self.driver.get_gbp_details(context.get_admin_context(),
device='tap%s' % pt1['port_id'], host='h1')
req_mapping = self.driver.request_gbp_details(
context.get_admin_context(),
request={'device': 'tap%s' % pt1['port_id'], 'host': 'h1',
'timestamp': 0, 'request_id': 'request_id'})
self.assertEqual(mapping, req_mapping['gbp_details'])
self.assertEqual(pt1['port_id'], mapping['port_id'])
self.assertEqual(ptg['id'], mapping['endpoint_group_name'])
self.assertEqual('someid', mapping['vm-name'])
@@ -321,6 +327,10 @@ class TestPolicyTarget(ApicMappingTestCase):
mapping['host_snat_ips'][0]['host_snat_ip'])
self.assertEqual(24, mapping['host_snat_ips'][0]['prefixlen'])
# Verify Neutron details
self.assertEqual(pt1['port_id'],
req_mapping['neutron_details']['port_id'])
# Create event on a second host to verify that the SNAT
# port gets created for this second host
pt2 = self.create_policy_target(
@@ -612,8 +622,15 @@ class TestPolicyTarget(ApicMappingTestCase):
details = self.driver.get_gbp_details(
context.get_admin_context(), device='tap%s' % 'randomid',
host='h1')
req_details = self.driver.request_gbp_details(
context.get_admin_context(),
request={'device': 'tap%s' % 'randomid', 'host': 'h1',
'timestamp': 0, 'request_id': 'request_id'})
# device was not found
self.assertEqual(None, details)
self.assertTrue('port_id' not in details)
self.assertEqual(details, req_details['gbp_details'])
self.assertTrue('port_id' not in req_details['neutron_details'])
ptg = self.create_policy_target_group()['policy_target_group']
pt1 = self.create_policy_target(
policy_target_group_id=ptg['id'])['policy_target']
@@ -622,8 +639,13 @@ class TestPolicyTarget(ApicMappingTestCase):
details = self.driver.get_gbp_details(
context.get_admin_context(), device='tap%s' % pt1['port_id'],
host='h1')
# device was not found
req_details = self.driver.request_gbp_details(
context.get_admin_context(),
request={'device': 'tap%s' % pt1['port_id'], 'host': 'h1',
'timestamp': 0, 'request_id': 'request_id'})
# An exception occurred
self.assertEqual({'device': 'tap%s' % pt1['port_id']}, details)
self.assertIsNone(req_details)
def test_get_gbp_proxy_details(self):
l3p_fake = self.create_l3_policy(name='myl3')['l3_policy']

View File

@@ -990,7 +990,16 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
self._get_object('subnets', proxy['subnets'][0], self.api,
expected_res_status=404)
def _test_get_gbp_details(self, admin_proxy=False):
def _test_get_gbp_details(self, admin_proxy=False, async=False):
def request_wrapper(*args, **kwargs):
kwargs['timestamp'] = 0
kwargs['request_id'] = 'some_id'
result = self.driver.request_gbp_details(*args, request=kwargs)
if result:
return result.get('gbp_details')
gbp_details = {False: self.driver.get_gbp_details,
True: request_wrapper}
ptg = self.create_policy_target_group(
name="ptg1")['policy_target_group']
pt1 = self.create_policy_target(
@@ -1037,7 +1046,7 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
def echo(name):
return name
self.mgr.apic.fvTenant.name = echo
mapping = self.driver.get_gbp_details(
mapping = gbp_details[async](
context.get_admin_context(),
device='tap%s' % proxy_gw['port_id'], host='h2')
@@ -1054,13 +1063,13 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
group_default_gateway=True,
tenant_id=ptg['tenant_id'])['policy_target']
self._bind_port_to_host(pt2['port_id'], 'h2')
mapping = self.driver.get_gbp_details(
mapping = gbp_details[async](
context.get_admin_context(),
device='tap%s' % group_default_gw['port_id'], host='h2')
self.assertTrue(mapping['promiscuous_mode'])
# No extra IPs for the failover since it doesn't own the master IP
mapping = self.driver.get_gbp_details(
mapping = gbp_details[async](
context.get_admin_context(),
device='tap%s' % proxy_gw_failover['port_id'], host='h2')
self.assertEqual(0, len(mapping['extra_ips'] or []))
@@ -1074,7 +1083,7 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
self.driver.ha_ip_handler.set_port_id_for_ha_ipaddress(
proxy_gw_failover['port_id'], x['ip_address'])
mapping = self.driver.get_gbp_details(
mapping = gbp_details[async](
context.get_admin_context(),
device='tap%s' % proxy_gw_failover['port_id'], host='h2')
self.assertEqual(
@@ -1092,6 +1101,12 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
def test_get_gbp_details_admin(self):
self._test_get_gbp_details(True)
def test_get_gbp_details_async(self):
self._test_get_gbp_details(False, True)
def test_get_gbp_details_admin_async(self):
self._test_get_gbp_details(True, True)
def test_cluster_promiscuous_mode(self):
ptg = self.create_policy_target_group(
name="ptg1")['policy_target_group']