NVP: Correct NVP router port mac to match neutron

Previously when router ports were created the mac_address from neutron
was not passed to nvp so nvp generated it's own mac_address for the port.
This patch fixes this by passing the mac_address on the port to nvp.

Fixes bug: 1244481

Change-Id: I0d0e068923497a13915749f3781d54194cfcfe89
This commit is contained in:
Aaron Rosen 2013-10-24 17:22:56 -07:00
parent 32a8d5c3a7
commit 4ac05465cc
3 changed files with 27 additions and 17 deletions

View File

@ -271,7 +271,8 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin,
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
cluster, router_id, port_data.get('tenant_id', 'fake'), cluster, router_id, port_data.get('tenant_id', 'fake'),
port_data.get('id', 'fake'), port_data.get('name', 'fake'), port_data.get('id', 'fake'), port_data.get('name', 'fake'),
port_data.get('admin_state_up', True), ip_addresses) port_data.get('admin_state_up', True), ip_addresses,
port_data.get('mac_address'))
LOG.debug(_("Created NVP router port:%s"), lrouter_port['uuid']) LOG.debug(_("Created NVP router port:%s"), lrouter_port['uuid'])
except NvpApiClient.NvpApiException: except NvpApiClient.NvpApiException:
LOG.exception(_("Unable to create port on NVP logical router %s"), LOG.exception(_("Unable to create port on NVP logical router %s"),

View File

@ -855,7 +855,8 @@ def create_lport(cluster, lswitch_uuid, tenant_id, neutron_port_id,
def create_router_lport(cluster, lrouter_uuid, tenant_id, neutron_port_id, def create_router_lport(cluster, lrouter_uuid, tenant_id, neutron_port_id,
display_name, admin_status_enabled, ip_addresses): display_name, admin_status_enabled, ip_addresses,
mac_address=None):
"""Creates a logical port on the assigned logical router.""" """Creates a logical port on the assigned logical router."""
tags = [dict(scope='os_tid', tag=tenant_id), tags = [dict(scope='os_tid', tag=tenant_id),
dict(scope='q_port_id', tag=neutron_port_id), dict(scope='q_port_id', tag=neutron_port_id),
@ -868,6 +869,10 @@ def create_router_lport(cluster, lrouter_uuid, tenant_id, neutron_port_id,
ip_addresses=ip_addresses, ip_addresses=ip_addresses,
type="LogicalRouterPortConfig" type="LogicalRouterPortConfig"
) )
# Only add the mac_address to lport_obj if present. This is because
# when creating the fake_ext_gw there is no mac_address present.
if mac_address:
lport_obj['mac_address'] = mac_address
path = _build_uri_path(LROUTERPORT_RESOURCE, path = _build_uri_path(LROUTERPORT_RESOURCE,
parent_resource_id=lrouter_uuid) parent_resource_id=lrouter_uuid)
result = do_request(HTTP_POST, path, json.dumps(lport_obj), result = do_request(HTTP_POST, path, json.dumps(lport_obj),

View File

@ -690,7 +690,8 @@ class TestNvplibLogicalRouters(NvplibTestCase):
router_port_uuids = [nvplib.create_router_lport( router_port_uuids = [nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', self.fake_cluster, lrouter['uuid'], 'pippo',
'qp_id_%s' % k, 'port-%s' % k, True, 'qp_id_%s' % k, 'port-%s' % k, True,
['192.168.0.%s' % k])['uuid'] for k in range(0, 3)] ['192.168.0.%s' % k], '00:11:22:33:44:55')['uuid']
for k in range(0, 3)]
ports = nvplib.query_lrouter_lports(self.fake_cluster, lrouter['uuid']) ports = nvplib.query_lrouter_lports(self.fake_cluster, lrouter['uuid'])
self.assertEqual(len(ports), 3) self.assertEqual(len(ports), 3)
for res_port in ports: for res_port in ports:
@ -700,7 +701,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
self.assertRaises( self.assertRaises(
exceptions.NotFound, nvplib.create_router_lport, exceptions.NotFound, nvplib.create_router_lport,
self.fake_cluster, 'booo', 'pippo', 'neutron_port_id', self.fake_cluster, 'booo', 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
def test_create_and_get_lrouter_port(self): def test_create_and_get_lrouter_port(self):
lrouter = nvplib.create_lrouter(self.fake_cluster, lrouter = nvplib.create_lrouter(self.fake_cluster,
@ -709,7 +710,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
nvplib.create_router_lport( nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
ports = nvplib.query_lrouter_lports(self.fake_cluster, lrouter['uuid']) ports = nvplib.query_lrouter_lports(self.fake_cluster, lrouter['uuid'])
self.assertEqual(len(ports), 1) self.assertEqual(len(ports), 1)
res_port = ports[0] res_port = ports[0]
@ -724,7 +725,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
self.assertRaises( self.assertRaises(
exceptions.NotFound, nvplib.create_router_lport, exceptions.NotFound, nvplib.create_router_lport,
self.fake_cluster, 'booo', 'pippo', 'neutron_port_id', self.fake_cluster, 'booo', 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
def test_update_lrouter_port(self): def test_update_lrouter_port(self):
lrouter = nvplib.create_lrouter(self.fake_cluster, lrouter = nvplib.create_lrouter(self.fake_cluster,
@ -733,7 +734,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
nvplib.update_router_lport( nvplib.update_router_lport(
self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'], self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'],
'pippo', 'another_port_id', 'name', False, 'pippo', 'another_port_id', 'name', False,
@ -773,7 +774,8 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'fake-lrouter', 'fake-lrouter',
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'x', 'y', True, []) self.fake_cluster, lrouter['uuid'], 'pippo', 'x', 'y', True, [],
'00:11:22:33:44:55')
ports = nvplib.query_lrouter_lports(self.fake_cluster, lrouter['uuid']) ports = nvplib.query_lrouter_lports(self.fake_cluster, lrouter['uuid'])
self.assertEqual(len(ports), 1) self.assertEqual(len(ports), 1)
nvplib.delete_router_lport(self.fake_cluster, lrouter['uuid'], nvplib.delete_router_lport(self.fake_cluster, lrouter['uuid'],
@ -801,7 +803,8 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'fake-lrouter', 'fake-lrouter',
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'x', 'y', True, []) self.fake_cluster, lrouter['uuid'], 'pippo', 'x', 'y', True, [],
'00:11:22:33:44:55')
def fakegetport(*args, **kwargs): def fakegetport(*args, **kwargs):
return {'_relations': {'LogicalPortAttachment': return {'_relations': {'LogicalPortAttachment':
@ -819,7 +822,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
nvplib.update_lrouter_port_ips( nvplib.update_lrouter_port_ips(
self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'], self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'],
['10.10.10.254'], []) ['10.10.10.254'], [])
@ -836,7 +839,8 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1', '10.10.10.254']) 'name', True, ['192.168.0.1', '10.10.10.254'],
'00:11:22:33:44:55')
nvplib.update_lrouter_port_ips( nvplib.update_lrouter_port_ips(
self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'], self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'],
[], ['10.10.10.254']) [], ['10.10.10.254'])
@ -852,7 +856,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
nvplib.update_lrouter_port_ips( nvplib.update_lrouter_port_ips(
self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'], self.fake_cluster, lrouter['uuid'], lrouter_port['uuid'],
['10.10.10.254'], ['192.168.0.1']) ['10.10.10.254'], ['192.168.0.1'])
@ -873,7 +877,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
def raise_nvp_exc(*args, **kwargs): def raise_nvp_exc(*args, **kwargs):
raise NvpApiClient.NvpApiException() raise NvpApiClient.NvpApiException()
@ -900,7 +904,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55:66')
result = nvplib.plug_router_port_attachment( result = nvplib.plug_router_port_attachment(
self.fake_cluster, lrouter['uuid'], self.fake_cluster, lrouter['uuid'],
lrouter_port['uuid'], lrouter_port['uuid'],
@ -915,7 +919,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55:66')
result = nvplib.plug_router_port_attachment( result = nvplib.plug_router_port_attachment(
self.fake_cluster, lrouter['uuid'], self.fake_cluster, lrouter['uuid'],
lrouter_port['uuid'], lrouter_port['uuid'],
@ -931,7 +935,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
result = nvplib.plug_router_port_attachment( result = nvplib.plug_router_port_attachment(
self.fake_cluster, lrouter['uuid'], self.fake_cluster, lrouter['uuid'],
lrouter_port['uuid'], lrouter_port['uuid'],
@ -950,7 +954,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
'10.0.0.1') '10.0.0.1')
lrouter_port = nvplib.create_router_lport( lrouter_port = nvplib.create_router_lport(
self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id', self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
'name', True, ['192.168.0.1']) 'name', True, ['192.168.0.1'], '00:11:22:33:44:55')
self.assertRaises(nvp_exc.NvpInvalidAttachmentType, self.assertRaises(nvp_exc.NvpInvalidAttachmentType,
nvplib.plug_router_port_attachment, nvplib.plug_router_port_attachment,
self.fake_cluster, lrouter['uuid'], self.fake_cluster, lrouter['uuid'],