From d9a8cc7b51df8b9f3d5fd8162f7f4c6c7aa94ec6 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Mon, 17 Mar 2014 15:43:53 +0100 Subject: [PATCH] NSX: Ensure gateway devices are usable after upgrade The gateway device database migration upon an upgrade creates gateway devices objects from references in network gateway objects. While these gateway devices are perfectly usable in network gateways, they are not directly visible to tenants and also cannot be updated to change details such as name, connector type or ip as well as the client certificate. This patch fixes the DB migration in order to ensure tenant have access to gateway devices created after an upgrade. This patch also modifies the l2 gateway nsxlib module to ensure request bodies are correctly created even when not all the attributes of a gateway device are specified. Change-Id: I7077e9884adc739fb75e64a6e9a17a124d79fb6b Closes-Bug: 1293617 --- .../versions/19180cf98af6_nsx_gw_devices.py | 7 +++++-- neutron/plugins/vmware/nsxlib/l2gateway.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/neutron/db/migration/alembic_migrations/versions/19180cf98af6_nsx_gw_devices.py b/neutron/db/migration/alembic_migrations/versions/19180cf98af6_nsx_gw_devices.py index 2eabc150a1..fafb85a511 100644 --- a/neutron/db/migration/alembic_migrations/versions/19180cf98af6_nsx_gw_devices.py +++ b/neutron/db/migration/alembic_migrations/versions/19180cf98af6_nsx_gw_devices.py @@ -73,8 +73,11 @@ def upgrade(active_plugins=None, options=None): # Create a networkgatewaydevice for each existing reference. # For existing references nsx_id == neutron_id # Do not fill conenctor info as they would be unknown - op.execute("INSERT INTO networkgatewaydevices (id, nsx_id) SELECT " - "id, id as nsx_id FROM networkgatewaydevicereferences") + op.execute("INSERT INTO networkgatewaydevices (id, nsx_id, tenant_id) " + "SELECT gw_dev_ref.id, gw_dev_ref.id as nsx_id, tenant_id " + "FROM networkgatewaydevicereferences AS gw_dev_ref " + "INNER JOIN networkgateways AS net_gw ON " + "gw_dev_ref.network_gateway_id=net_gw.id") def downgrade(active_plugins=None, options=None): diff --git a/neutron/plugins/vmware/nsxlib/l2gateway.py b/neutron/plugins/vmware/nsxlib/l2gateway.py index 80397d51d7..9d34a988a7 100644 --- a/neutron/plugins/vmware/nsxlib/l2gateway.py +++ b/neutron/plugins/vmware/nsxlib/l2gateway.py @@ -120,15 +120,18 @@ def _build_gateway_device_body(tenant_id, display_name, neutron_id, utils.NetworkTypes.BRIDGE: "BridgeConnector", 'ipsec%s' % utils.NetworkTypes.STT: "IPsecSTT", 'ipsec%s' % utils.NetworkTypes.GRE: "IPsecGRE"} - nsx_connector_type = connector_type_mappings[connector_type] + nsx_connector_type = connector_type_mappings.get(connector_type) body = {"display_name": utils.check_and_truncate(display_name), "tags": utils.get_tags(os_tid=tenant_id, q_gw_dev_id=neutron_id), - "transport_connectors": [ - {"transport_zone_uuid": tz_uuid, - "ip_address": connector_ip, - "type": nsx_connector_type}], "admin_status_enabled": True} + + if connector_ip and nsx_connector_type: + body["transport_connectors"] = [ + {"transport_zone_uuid": tz_uuid, + "ip_address": connector_ip, + "type": nsx_connector_type}] + if client_certificate: body["credential"] = {"client_certificate": {"pem_encoded": client_certificate},