NSXv: locking DHCP

Change-Id: If3aed690dd5607288cbc23faa3809ab59f6f92d0
This commit is contained in:
Kobi Samoray 2017-07-24 10:17:14 +03:00
parent 4b9a162a29
commit 6195f523bf
3 changed files with 28 additions and 33 deletions

View File

@ -1282,13 +1282,6 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self.edge_manager.reconfigure_shared_edge_metadata_port(
context, (vcns_const.DHCP_EDGE_PREFIX + net_id)[:36])
def _update_dhcp_edge_service(self, context, network_id, address_groups):
self.edge_manager.update_dhcp_edge_service(
context, network_id, address_groups=address_groups)
def _delete_dhcp_edge_service(self, context, id):
self.edge_manager.delete_dhcp_edge_service(context, id)
def _is_neutron_spoofguard_policy(self, net_id, moref, policy_id):
# A neutron policy will have the network UUID as the name of the
# policy
@ -1324,7 +1317,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
if len(sids) > 0:
try:
self._cleanup_dhcp_edge_before_deletion(context, id)
self._delete_dhcp_edge_service(context, id)
self.edge_manager.delete_dhcp_edge_service(context, id)
is_dhcp_backend_deleted = True
except Exception:
with excutils.save_and_reraise_exception():
@ -1772,8 +1765,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
with locking.LockManager.get_lock('dhcp-update-%s' % network_id):
address_groups = self._create_network_dhcp_address_group(
context, network_id)
self._update_dhcp_edge_service(context, network_id,
address_groups)
self.edge_manager.update_dhcp_edge_service(
context, network_id, address_groups=address_groups)
def _update_port(self, context, id, port, original_port, is_compute_port,
device_id):
@ -2119,17 +2112,18 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
filters = {'fixed_ips': {'subnet_id': [id]}}
ports = self.get_ports(context, filters=filters)
# Add nsx-edge-pool here is because we first delete the subnet in db.
# if the subnet overlaps with another new creating subnet, there is a
# chance that the new creating subnet select the deleting subnet's edge
# and send update dhcp interface rest call before deleting subnet's
# corresponding dhcp interface rest call and lead to overlap response
# from backend.
# Add nsx-dhcp-edge-pool here is because we first delete the subnet in
# db.locking if the subnet overlaps with another new creating subnet,
# there is a chance that the new creating subnet select the deleting
# subnet's edge and send update dhcp interface rest call before
# deleting subnet's corresponding dhcp interface rest call and lead to
# overlap response from backend.
network_id = subnet['network_id']
with locking.LockManager.get_lock(network_id):
with context.session.begin(subtransactions=True):
self.base_delete_subnet(context, id)
with locking.LockManager.get_lock('nsx-edge-pool'):
with locking.LockManager.get_lock('nsx-dhcp-edge-pool'):
if subnet['enable_dhcp']:
# There is only DHCP port available
if len(ports) == 1:
@ -2147,7 +2141,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
context, network_id)
LOG.debug("Delete the DHCP service for network %s",
network_id)
self._delete_dhcp_edge_service(context, network_id)
self.edge_manager.delete_dhcp_edge_service(context,
network_id)
else:
# Update address group and delete the DHCP port only
self._update_dhcp_adddress(context, network_id)
@ -2476,7 +2471,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
context, network_id)
LOG.debug("Delete the DHCP service for network %s",
network_id)
self._delete_dhcp_edge_service(context, network_id)
self.edge_manager.delete_dhcp_edge_service(context, network_id)
return
self._update_dhcp_adddress(context, network_id)

View File

@ -1259,13 +1259,12 @@ class EdgeManager(object):
availability_zone):
self._allocate_dhcp_edge_appliance(context, resource_id,
availability_zone)
with locking.LockManager.get_lock('nsx-edge-pool'):
new_edge = nsxv_db.get_nsxv_router_binding(context.session,
resource_id)
nsxv_db.allocate_edge_vnic_with_tunnel_index(
context.session, new_edge['edge_id'], network_id,
availability_zone.name)
return new_edge['edge_id']
new_edge = nsxv_db.get_nsxv_router_binding(context.session,
resource_id)
nsxv_db.allocate_edge_vnic_with_tunnel_index(
context.session, new_edge['edge_id'], network_id,
availability_zone.name)
return new_edge['edge_id']
def create_dhcp_edge_service(self, context, network_id,
subnet):
@ -1281,7 +1280,7 @@ class EdgeManager(object):
dhcp_edge_binding = nsxv_db.get_nsxv_router_binding(context.session,
resource_id)
allocate_new_edge = False
with locking.LockManager.get_lock('nsx-edge-pool'):
with locking.LockManager.get_lock('nsx-dhcp-edge-pool'):
(conflict_edge_ids,
available_edge_ids) = self._get_used_edges(context, subnet,
availability_zone)
@ -1326,12 +1325,12 @@ class EdgeManager(object):
else:
allocate_new_edge = True
if allocate_new_edge:
self.allocate_new_dhcp_edge(context, network_id, resource_id,
availability_zone)
if allocate_new_edge:
self.allocate_new_dhcp_edge(context, network_id, resource_id,
availability_zone)
# If a new Edge was allocated, return resource_id
return resource_id
# If a new Edge was allocated, return resource_id
return resource_id
def update_dhcp_edge_service(self, context, network_id,
address_groups=None):

View File

@ -222,7 +222,8 @@ def recreate_network_dhcp(context, plugin, edge_manager, old_edge_id, net_id):
LOG.info(_LI("Creating network %s DHCP address group"), net_id)
address_groups = plugin._create_network_dhcp_address_group(
context, net_id)
plugin._update_dhcp_edge_service(context, net_id, address_groups)
plugin.edge_manager.update_dhcp_edge_service(
context, net_id, address_groups=address_groups)
# find out the id of the new edge:
new_binding = nsxv_db.get_nsxv_router_binding(