NSX|P: Support different mac format in address pairs
Change-Id: I33b161a67c7eed0f13405e508919650ebc9a31f1
This commit is contained in:
parent
09b74c9265
commit
6d89e45016
|
@ -306,6 +306,18 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||
context.elevated(), router_db.id, gw_network_id,
|
||||
interface_subnet['id'], subnet=interface_subnet)
|
||||
|
||||
def _format_mac_address(self, mac):
|
||||
# The NSX backend does not support mac format MMM.MMM.SSS.SSS
|
||||
# Translate it to MM:MM:MM:SS:SS:SS instead
|
||||
if '.' in mac:
|
||||
fixed = mac.replace('.', '')
|
||||
if len(fixed) == 12:
|
||||
fixed = "%s:%s:%s:%s:%s:%s" % (fixed[0:2], fixed[2:4],
|
||||
fixed[4:6], fixed[6:8],
|
||||
fixed[8:10], fixed[10:12])
|
||||
return fixed
|
||||
return mac
|
||||
|
||||
def _validate_address_pairs(self, address_pairs):
|
||||
for pair in address_pairs:
|
||||
ip = pair.get('ip_address')
|
||||
|
|
|
@ -1514,7 +1514,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
|
|||
address_bindings = []
|
||||
for fixed_ip in port_data['fixed_ips']:
|
||||
ip_addr = fixed_ip['ip_address']
|
||||
mac_addr = port_data['mac_address']
|
||||
mac_addr = self._format_mac_address(port_data['mac_address'])
|
||||
binding = self.nsxpolicy.segment_port.build_address_binding(
|
||||
ip_addr, mac_addr)
|
||||
address_bindings.append(binding)
|
||||
|
@ -1530,7 +1530,8 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
|
|||
|
||||
for pair in port_data.get(addr_apidef.ADDRESS_PAIRS):
|
||||
binding = self.nsxpolicy.segment_port.build_address_binding(
|
||||
pair['ip_address'], pair['mac_address'])
|
||||
pair['ip_address'],
|
||||
self._format_mac_address(pair['mac_address']))
|
||||
address_bindings.append(binding)
|
||||
|
||||
return address_bindings
|
||||
|
|
|
@ -19,6 +19,7 @@ from oslo_config import cfg
|
|||
|
||||
from neutron.tests.unit.db import test_allowedaddresspairs_db as ext_pairs
|
||||
|
||||
from vmware_nsx.tests.unit.nsx_p import test_plugin as test_p_plugin
|
||||
from vmware_nsx.tests.unit.nsx_v import test_plugin as test_nsx_v_plugin
|
||||
from vmware_nsx.tests.unit.nsx_v3 import test_constants as v3_constants
|
||||
from vmware_nsx.tests.unit.nsx_v3 import test_plugin as test_v3_plugin
|
||||
|
@ -39,6 +40,65 @@ class TestAllowedAddressPairsNSXv2(test_v3_plugin.NsxV3PluginTestCaseMixin,
|
|||
def test_create_port_security_false_allowed_address_pairs(self):
|
||||
self.skipTest('TBD')
|
||||
|
||||
def test_create_overlap_with_fixed_ip(self):
|
||||
self.skipTest('Not supported')
|
||||
|
||||
|
||||
class TestAllowedAddressPairsNSXp(test_p_plugin.NsxPPluginTestCaseMixin,
|
||||
ext_pairs.TestAllowedAddressPairs):
|
||||
|
||||
def setUp(self, plugin=test_p_plugin.PLUGIN_NAME,
|
||||
ext_mgr=None,
|
||||
service_plugins=None):
|
||||
super(TestAllowedAddressPairsNSXp, self).setUp(
|
||||
plugin=plugin, ext_mgr=ext_mgr, service_plugins=service_plugins)
|
||||
|
||||
def test_create_bad_address_pairs_with_cidr(self):
|
||||
address_pairs = [{'mac_address': '00:00:00:00:00:01',
|
||||
'ip_address': '10.0.0.1/24'}]
|
||||
self._create_port_with_address_pairs(address_pairs, 400)
|
||||
|
||||
def test_create_port_allowed_address_pairs_v6(self):
|
||||
with self.network() as net:
|
||||
address_pairs = [{'ip_address': '1001::12'}]
|
||||
res = self._create_port(self.fmt, net['network']['id'],
|
||||
arg_list=(addr_apidef.ADDRESS_PAIRS,),
|
||||
allowed_address_pairs=address_pairs)
|
||||
port = self.deserialize(self.fmt, res)
|
||||
address_pairs[0]['mac_address'] = port['port']['mac_address']
|
||||
self.assertEqual(port['port'][addr_apidef.ADDRESS_PAIRS],
|
||||
address_pairs)
|
||||
self._delete('ports', port['port']['id'])
|
||||
|
||||
def test_update_add_bad_address_pairs_with_cidr(self):
|
||||
with self.network() as net:
|
||||
res = self._create_port(self.fmt, net['network']['id'])
|
||||
port = self.deserialize(self.fmt, res)
|
||||
address_pairs = [{'mac_address': '00:00:00:00:00:01',
|
||||
'ip_address': '10.0.0.1/24'}]
|
||||
update_port = {'port': {addr_apidef.ADDRESS_PAIRS:
|
||||
address_pairs}}
|
||||
req = self.new_update_request('ports', update_port,
|
||||
port['port']['id'])
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
self._delete('ports', port['port']['id'])
|
||||
|
||||
def test_mac_configuration(self):
|
||||
address_pairs = [{'mac_address': 'fa16.3e3e.3d01',
|
||||
'ip_address': '10.0.0.1'}]
|
||||
self._create_port_with_address_pairs(address_pairs, 201)
|
||||
|
||||
address_pairs = [{'mac_address': 'fa-16-3e-3e-3d-c4',
|
||||
'ip_address': '10.0.0.1'}]
|
||||
self._create_port_with_address_pairs(address_pairs, 201)
|
||||
|
||||
def test_create_port_security_false_allowed_address_pairs(self):
|
||||
self.skipTest('TBD')
|
||||
|
||||
def test_create_overlap_with_fixed_ip(self):
|
||||
self.skipTest('Not supported')
|
||||
|
||||
|
||||
class TestAllowedAddressPairsNSXv3(test_v3_plugin.NsxV3PluginTestCaseMixin,
|
||||
ext_pairs.TestAllowedAddressPairs):
|
||||
|
|
Loading…
Reference in New Issue