From 0f4a7a7364fc1e19c26244b60c2f402b81bdb1f9 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Sat, 1 Apr 2017 22:18:49 -0700 Subject: [PATCH] NSX|V3: fix bulk subnet breakage Commit cf34df857273d3be289e00590d80498cc11149ee broke the plugin. Change-Id: I94f7828b6cbb0ca9ee069666fbff77425e4a868c --- vmware_nsx/plugins/nsx_v3/plugin.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index f95a24d361..8c0a0a9164 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -1164,17 +1164,16 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, objects = [] collection = "%ss" % resource items = request_items[collection] - context.session.begin(subtransactions=True) try: - for item in items: - obj_creator = getattr(self, 'create_%s' % resource) - obj = obj_creator(context, item) - objects.append(obj) - if post_create_func: - # The user-provided post_create function is called - # after a new object is created. - post_create_func(obj) - context.session.commit() + with db_api.context_manager.writer.using(context): + for item in items: + obj_creator = getattr(self, 'create_%s' % resource) + obj = obj_creator(context, item) + objects.append(obj) + if post_create_func: + # The user-provided post_create function is called + # after a new object is created. + post_create_func(obj) except Exception: if rollback_func: # The user-provided rollback function is called when an @@ -1725,7 +1724,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, for fixed_ip in fixed_ips: if netaddr.IPNetwork(fixed_ip['ip_address']).version != 4: 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']: ips.append(fixed_ip) return ips