From 19d65cdfd526d7ed5325f40f8dad31b1a04b4c47 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 | 28 +++++++++++-------- .../plugins/openvswitch/ovs_quantum_plugin.py | 28 +++++++++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/quantum/plugins/linuxbridge/lb_quantum_plugin.py b/quantum/plugins/linuxbridge/lb_quantum_plugin.py index 86a05a201..7c946d000 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) - 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: + 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) - # TODO(rkukura): Filter on extended provider attributes. - nets = self._filter_nets_l3(context, nets, filters) + def get_networks(self, context, filters=None, fields=None): + 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) 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 195bac2f8..9ce325d6a 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) - 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: + 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) - # TODO(rkukura): Filter on extended provider attributes. - nets = self._filter_nets_l3(context, nets, filters) + def get_networks(self, context, filters=None, fields=None): + 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) return [self._fields(net, fields) for net in nets] -- 2.45.2