NSX|V3: fix bulk subnet breakage

Commit cf34df857273d3be289e00590d80498cc11149ee broke the plugin.

Change-Id: I94f7828b6cbb0ca9ee069666fbff77425e4a868c
This commit is contained in:
Gary Kotton 2017-04-01 22:18:49 -07:00
parent 7b64469d32
commit 0f4a7a7364

View File

@ -1164,17 +1164,16 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
objects = [] objects = []
collection = "%ss" % resource collection = "%ss" % resource
items = request_items[collection] items = request_items[collection]
context.session.begin(subtransactions=True)
try: try:
for item in items: with db_api.context_manager.writer.using(context):
obj_creator = getattr(self, 'create_%s' % resource) for item in items:
obj = obj_creator(context, item) obj_creator = getattr(self, 'create_%s' % resource)
objects.append(obj) obj = obj_creator(context, item)
if post_create_func: objects.append(obj)
# The user-provided post_create function is called if post_create_func:
# after a new object is created. # The user-provided post_create function is called
post_create_func(obj) # after a new object is created.
context.session.commit() post_create_func(obj)
except Exception: except Exception:
if rollback_func: if rollback_func:
# The user-provided rollback function is called when an # The user-provided rollback function is called when an
@ -1725,7 +1724,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
for fixed_ip in fixed_ips: for fixed_ip in fixed_ips:
if netaddr.IPNetwork(fixed_ip['ip_address']).version != 4: if netaddr.IPNetwork(fixed_ip['ip_address']).version != 4:
continue continue
subnet = self.get_subnet(context, fixed_ip['subnet_id']) with db_api.context_manager.reader.using(context):
subnet = self.get_subnet(context, fixed_ip['subnet_id'])
if subnet['enable_dhcp']: if subnet['enable_dhcp']:
ips.append(fixed_ip) ips.append(fixed_ip)
return ips return ips