NSX|P: Support different mac format in address pairs

Change-Id: I33b161a67c7eed0f13405e508919650ebc9a31f1
This commit is contained in:
asarfaty 2020-05-24 11:14:42 +02:00 committed by Adit Sarfaty
parent e86d1bd19d
commit e78fab9507
3 changed files with 24 additions and 2 deletions

View File

@ -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, fixed_ips=None):
port_ips = []
if fixed_ips:

View File

@ -1500,7 +1500,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)
@ -1516,7 +1516,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

View File

@ -84,6 +84,15 @@ class TestAllowedAddressPairsNSXp(test_p_plugin.NsxPPluginTestCaseMixin,
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')