oflex 1.1 compliance
Closes-Bug: 1547694 Change-Id: Ie5a5869b566a03ed34a98e0e0ea06b246d672bb3
This commit is contained in:
@@ -28,6 +28,7 @@ from neutron import context as nctx
|
|||||||
from neutron.db import db_base_plugin_v2 as n_db
|
from neutron.db import db_base_plugin_v2 as n_db
|
||||||
from neutron.extensions import portbindings
|
from neutron.extensions import portbindings
|
||||||
from neutron import manager
|
from neutron import manager
|
||||||
|
from neutron.plugins.ml2 import rpc as neu_rpc
|
||||||
from opflexagent import constants as ofcst
|
from opflexagent import constants as ofcst
|
||||||
from opflexagent import rpc
|
from opflexagent import rpc
|
||||||
from oslo_concurrency import lockutils
|
from oslo_concurrency import lockutils
|
||||||
@@ -204,8 +205,8 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
|||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
super(ApicMappingDriver, self).initialize()
|
super(ApicMappingDriver, self).initialize()
|
||||||
self._setup_rpc_listeners()
|
|
||||||
self._setup_rpc()
|
self._setup_rpc()
|
||||||
|
self._setup_rpc_listeners()
|
||||||
self.apic_manager = ApicMappingDriver.get_apic_manager()
|
self.apic_manager = ApicMappingDriver.get_apic_manager()
|
||||||
self.name_mapper = name_manager.ApicNameManager(self.apic_manager)
|
self.name_mapper = name_manager.ApicNameManager(self.apic_manager)
|
||||||
self.enable_dhcp_opt = self.apic_manager.enable_optimized_dhcp
|
self.enable_dhcp_opt = self.apic_manager.enable_optimized_dhcp
|
||||||
@@ -213,7 +214,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
|||||||
self._gbp_plugin = None
|
self._gbp_plugin = None
|
||||||
|
|
||||||
def _setup_rpc_listeners(self):
|
def _setup_rpc_listeners(self):
|
||||||
self.endpoints = [rpc.GBPServerRpcCallback(self)]
|
self.endpoints = [rpc.GBPServerRpcCallback(self, self.notifier)]
|
||||||
self.topic = rpc.TOPIC_OPFLEX
|
self.topic = rpc.TOPIC_OPFLEX
|
||||||
self.conn = n_rpc.create_connection(new=True)
|
self.conn = n_rpc.create_connection(new=True)
|
||||||
self.conn.create_consumer(self.topic, self.endpoints,
|
self.conn.create_consumer(self.topic, self.endpoints,
|
||||||
@@ -256,9 +257,11 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
|||||||
self._add_vrf_details(context, details)
|
self._add_vrf_details(context, details)
|
||||||
return details
|
return details
|
||||||
|
|
||||||
|
def request_vrf_details(self, context, **kwargs):
|
||||||
|
return self.get_vrf_details(context, **kwargs)
|
||||||
|
|
||||||
# RPC Method
|
# RPC Method
|
||||||
def get_gbp_details(self, context, **kwargs):
|
def _get_gbp_details(self, context, **kwargs):
|
||||||
try:
|
|
||||||
port_id = self._core_plugin._device_to_port_id(
|
port_id = self._core_plugin._device_to_port_id(
|
||||||
context, kwargs['device'])
|
context, kwargs['device'])
|
||||||
port_context = self._core_plugin.get_bound_port_context(
|
port_context = self._core_plugin.get_bound_port_context(
|
||||||
@@ -268,7 +271,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
|||||||
"%(agent_id)s not found in database"),
|
"%(agent_id)s not found in database"),
|
||||||
{'device': port_id,
|
{'device': port_id,
|
||||||
'agent_id': kwargs.get('agent_id')})
|
'agent_id': kwargs.get('agent_id')})
|
||||||
return
|
return {'device': kwargs.get('device')}
|
||||||
port = port_context.current
|
port = port_context.current
|
||||||
# retrieve PTG from a given Port
|
# retrieve PTG from a given Port
|
||||||
ptg, pt = self._port_id_to_ptg(context, port['id'])
|
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'])
|
l2p = self._network_id_to_l2p(context, port['network_id'])
|
||||||
if not ptg and not l2p:
|
if not ptg and not l2p:
|
||||||
return
|
return None
|
||||||
|
|
||||||
l2_policy_id = l2p['id']
|
l2_policy_id = l2p['id']
|
||||||
if ptg:
|
if ptg:
|
||||||
@@ -387,13 +390,40 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
|||||||
# Active chain head must have changed in a concurrent
|
# Active chain head must have changed in a concurrent
|
||||||
# operation, get out of here
|
# operation, get out of here
|
||||||
pass
|
pass
|
||||||
|
return details
|
||||||
|
|
||||||
|
# RPC Method
|
||||||
|
def get_gbp_details(self, context, **kwargs):
|
||||||
|
try:
|
||||||
|
return self._get_gbp_details(context, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error(_("An exception has occurred while retrieving device "
|
LOG.error(_(
|
||||||
"gbp details for %(device)s with error %(error)s"),
|
"An exception has occurred while retrieving device "
|
||||||
{'device': kwargs.get('device'), 'error': e.message})
|
"gbp details for %s"), kwargs.get('device'))
|
||||||
|
LOG.exception(e)
|
||||||
details = {'device': kwargs.get('device')}
|
details = {'device': kwargs.get('device')}
|
||||||
return details
|
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,
|
def _allocate_snat_ip_for_host_and_ext_net(self, context, host, network,
|
||||||
es_name):
|
es_name):
|
||||||
"""Allocate SNAT IP for a host for an external network."""
|
"""Allocate SNAT IP for a host for an external network."""
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ class ApicMappingTestCase(
|
|||||||
'tenant_network_types': ['opflex']
|
'tenant_network_types': ['opflex']
|
||||||
}
|
}
|
||||||
mock.patch('gbpservice.neutron.services.grouppolicy.drivers.cisco.'
|
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.'
|
host_agents = mock.patch('neutron.plugins.ml2.driver_context.'
|
||||||
'PortContext.host_agents').start()
|
'PortContext.host_agents').start()
|
||||||
host_agents.return_value = [self.agent_conf]
|
host_agents.return_value = [self.agent_conf]
|
||||||
@@ -293,6 +294,11 @@ class TestPolicyTarget(ApicMappingTestCase):
|
|||||||
|
|
||||||
mapping = self.driver.get_gbp_details(context.get_admin_context(),
|
mapping = self.driver.get_gbp_details(context.get_admin_context(),
|
||||||
device='tap%s' % pt1['port_id'], host='h1')
|
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(pt1['port_id'], mapping['port_id'])
|
||||||
self.assertEqual(ptg['id'], mapping['endpoint_group_name'])
|
self.assertEqual(ptg['id'], mapping['endpoint_group_name'])
|
||||||
self.assertEqual('someid', mapping['vm-name'])
|
self.assertEqual('someid', mapping['vm-name'])
|
||||||
@@ -321,6 +327,10 @@ class TestPolicyTarget(ApicMappingTestCase):
|
|||||||
mapping['host_snat_ips'][0]['host_snat_ip'])
|
mapping['host_snat_ips'][0]['host_snat_ip'])
|
||||||
self.assertEqual(24, mapping['host_snat_ips'][0]['prefixlen'])
|
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
|
# Create event on a second host to verify that the SNAT
|
||||||
# port gets created for this second host
|
# port gets created for this second host
|
||||||
pt2 = self.create_policy_target(
|
pt2 = self.create_policy_target(
|
||||||
@@ -612,8 +622,15 @@ class TestPolicyTarget(ApicMappingTestCase):
|
|||||||
details = self.driver.get_gbp_details(
|
details = self.driver.get_gbp_details(
|
||||||
context.get_admin_context(), device='tap%s' % 'randomid',
|
context.get_admin_context(), device='tap%s' % 'randomid',
|
||||||
host='h1')
|
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
|
# 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']
|
ptg = self.create_policy_target_group()['policy_target_group']
|
||||||
pt1 = self.create_policy_target(
|
pt1 = self.create_policy_target(
|
||||||
policy_target_group_id=ptg['id'])['policy_target']
|
policy_target_group_id=ptg['id'])['policy_target']
|
||||||
@@ -622,8 +639,13 @@ class TestPolicyTarget(ApicMappingTestCase):
|
|||||||
details = self.driver.get_gbp_details(
|
details = self.driver.get_gbp_details(
|
||||||
context.get_admin_context(), device='tap%s' % pt1['port_id'],
|
context.get_admin_context(), device='tap%s' % pt1['port_id'],
|
||||||
host='h1')
|
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.assertEqual({'device': 'tap%s' % pt1['port_id']}, details)
|
||||||
|
self.assertIsNone(req_details)
|
||||||
|
|
||||||
def test_get_gbp_proxy_details(self):
|
def test_get_gbp_proxy_details(self):
|
||||||
l3p_fake = self.create_l3_policy(name='myl3')['l3_policy']
|
l3p_fake = self.create_l3_policy(name='myl3')['l3_policy']
|
||||||
|
|||||||
@@ -990,7 +990,16 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
|
|||||||
self._get_object('subnets', proxy['subnets'][0], self.api,
|
self._get_object('subnets', proxy['subnets'][0], self.api,
|
||||||
expected_res_status=404)
|
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(
|
ptg = self.create_policy_target_group(
|
||||||
name="ptg1")['policy_target_group']
|
name="ptg1")['policy_target_group']
|
||||||
pt1 = self.create_policy_target(
|
pt1 = self.create_policy_target(
|
||||||
@@ -1037,7 +1046,7 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
|
|||||||
def echo(name):
|
def echo(name):
|
||||||
return name
|
return name
|
||||||
self.mgr.apic.fvTenant.name = echo
|
self.mgr.apic.fvTenant.name = echo
|
||||||
mapping = self.driver.get_gbp_details(
|
mapping = gbp_details[async](
|
||||||
context.get_admin_context(),
|
context.get_admin_context(),
|
||||||
device='tap%s' % proxy_gw['port_id'], host='h2')
|
device='tap%s' % proxy_gw['port_id'], host='h2')
|
||||||
|
|
||||||
@@ -1054,13 +1063,13 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
|
|||||||
group_default_gateway=True,
|
group_default_gateway=True,
|
||||||
tenant_id=ptg['tenant_id'])['policy_target']
|
tenant_id=ptg['tenant_id'])['policy_target']
|
||||||
self._bind_port_to_host(pt2['port_id'], 'h2')
|
self._bind_port_to_host(pt2['port_id'], 'h2')
|
||||||
mapping = self.driver.get_gbp_details(
|
mapping = gbp_details[async](
|
||||||
context.get_admin_context(),
|
context.get_admin_context(),
|
||||||
device='tap%s' % group_default_gw['port_id'], host='h2')
|
device='tap%s' % group_default_gw['port_id'], host='h2')
|
||||||
self.assertTrue(mapping['promiscuous_mode'])
|
self.assertTrue(mapping['promiscuous_mode'])
|
||||||
|
|
||||||
# No extra IPs for the failover since it doesn't own the master IP
|
# 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(),
|
context.get_admin_context(),
|
||||||
device='tap%s' % proxy_gw_failover['port_id'], host='h2')
|
device='tap%s' % proxy_gw_failover['port_id'], host='h2')
|
||||||
self.assertEqual(0, len(mapping['extra_ips'] or []))
|
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(
|
self.driver.ha_ip_handler.set_port_id_for_ha_ipaddress(
|
||||||
proxy_gw_failover['port_id'], x['ip_address'])
|
proxy_gw_failover['port_id'], x['ip_address'])
|
||||||
|
|
||||||
mapping = self.driver.get_gbp_details(
|
mapping = gbp_details[async](
|
||||||
context.get_admin_context(),
|
context.get_admin_context(),
|
||||||
device='tap%s' % proxy_gw_failover['port_id'], host='h2')
|
device='tap%s' % proxy_gw_failover['port_id'], host='h2')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -1092,6 +1101,12 @@ class TestProxyGroup(ApicMappingStitchingPlumberGBPTestCase):
|
|||||||
def test_get_gbp_details_admin(self):
|
def test_get_gbp_details_admin(self):
|
||||||
self._test_get_gbp_details(True)
|
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):
|
def test_cluster_promiscuous_mode(self):
|
||||||
ptg = self.create_policy_target_group(
|
ptg = self.create_policy_target_group(
|
||||||
name="ptg1")['policy_target_group']
|
name="ptg1")['policy_target_group']
|
||||||
|
|||||||
Reference in New Issue
Block a user