From f513b6326fecda4d9221db191fa3ae3e8ca35131 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Tue, 25 Dec 2012 15:11:35 +0000 Subject: [PATCH] Provide "atomic" database access for networks Fixes bug 1093637 In the OVS and LB plugins there are cases when accessing the network has an additional database query. The patch enables this to occur without accessing an invalid database entry. Change-Id: I7d4944cf3240819f23dd7b4993d6ae3cefab9dc2 --- .../plugins/linuxbridge/lb_quantum_plugin.py | 26 ++++++++++++------- .../plugins/openvswitch/ovs_quantum_plugin.py | 26 ++++++++++++------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/quantum/plugins/linuxbridge/lb_quantum_plugin.py b/quantum/plugins/linuxbridge/lb_quantum_plugin.py index 86a05a2019..7c946d000f 100644 --- a/quantum/plugins/linuxbridge/lb_quantum_plugin.py +++ b/quantum/plugins/linuxbridge/lb_quantum_plugin.py @@ -383,20 +383,26 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2, self.notifier.network_delete(context, id) def get_network(self, context, id, fields=None): - net = super(LinuxBridgePluginV2, self).get_network(context, id, None) - self._extend_network_dict_provider(context, net) - self._extend_network_dict_l3(context, net) + session = context.session + with session.begin(subtransactions=True): + net = super(LinuxBridgePluginV2, self).get_network(context, + id, None) + self._extend_network_dict_provider(context, net) + self._extend_network_dict_l3(context, net) return self._fields(net, fields) def get_networks(self, context, filters=None, fields=None): - nets = super(LinuxBridgePluginV2, self).get_networks(context, filters, - None) - for net in nets: - self._extend_network_dict_provider(context, net) - self._extend_network_dict_l3(context, net) + session = context.session + with session.begin(subtransactions=True): + nets = super(LinuxBridgePluginV2, self).get_networks(context, + filters, + None) + for net in nets: + self._extend_network_dict_provider(context, net) + self._extend_network_dict_l3(context, net) - # TODO(rkukura): Filter on extended provider attributes. - nets = self._filter_nets_l3(context, nets, filters) + # TODO(rkukura): Filter on extended provider attributes. + nets = self._filter_nets_l3(context, nets, filters) return [self._fields(net, fields) for net in nets] diff --git a/quantum/plugins/openvswitch/ovs_quantum_plugin.py b/quantum/plugins/openvswitch/ovs_quantum_plugin.py index 195bac2f89..9ce325d6ad 100644 --- a/quantum/plugins/openvswitch/ovs_quantum_plugin.py +++ b/quantum/plugins/openvswitch/ovs_quantum_plugin.py @@ -468,20 +468,26 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2, self.notifier.network_delete(context, id) def get_network(self, context, id, fields=None): - net = super(OVSQuantumPluginV2, self).get_network(context, id, None) - self._extend_network_dict_provider(context, net) - self._extend_network_dict_l3(context, net) + session = context.session + with session.begin(subtransactions=True): + net = super(OVSQuantumPluginV2, self).get_network(context, + id, None) + self._extend_network_dict_provider(context, net) + self._extend_network_dict_l3(context, net) return self._fields(net, fields) def get_networks(self, context, filters=None, fields=None): - nets = super(OVSQuantumPluginV2, self).get_networks(context, filters, - None) - for net in nets: - self._extend_network_dict_provider(context, net) - self._extend_network_dict_l3(context, net) + session = context.session + with session.begin(subtransactions=True): + nets = super(OVSQuantumPluginV2, self).get_networks(context, + filters, + None) + for net in nets: + self._extend_network_dict_provider(context, net) + self._extend_network_dict_l3(context, net) - # TODO(rkukura): Filter on extended provider attributes. - nets = self._filter_nets_l3(context, nets, filters) + # TODO(rkukura): Filter on extended provider attributes. + nets = self._filter_nets_l3(context, nets, filters) return [self._fields(net, fields) for net in nets]