From: Gary Kotton Date: Tue, 25 Dec 2012 15:11:35 +0000 (+0000) Subject: Provide "atomic" database access for networks X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=19d65cdfd526d7ed5325f40f8dad31b1a04b4c47;p=openstack-build%2Fneutron-build.git 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 --- 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]