summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@midokura.com>2017-07-25 05:11:06 +0000
committerYAMAMOTO Takashi <yamamoto@midokura.com>2017-07-25 05:11:06 +0000
commitabf1b4b010b0e929931968e786f7db82cb6511ee (patch)
tree24006550d5891d0ecb1b64d76e02f32a92ef21da
parentcb773098d276cfbabc600361e91cb709ec846ba8 (diff)
downloadneutron-abf1b4b010b0e929931968e786f7db82cb6511ee.tar.gz
Revert "deepcopy binding and binding levels avoid expiration"
This reverts commit cb773098d276cfbabc600361e91cb709ec846ba8. Change-Id: I027aff53310493f8ece433b14637cf61cfb86465 Closes-Bug: #1700448
-rw-r--r--neutron/plugins/ml2/driver_context.py8
-rw-r--r--neutron/plugins/ml2/plugin.py13
-rw-r--r--neutron/tests/unit/plugins/ml2/test_plugin.py9
-rw-r--r--neutron/tests/unit/plugins/ml2/test_port_binding.py3
4 files changed, 8 insertions, 25 deletions
diff --git a/neutron/plugins/ml2/driver_context.py b/neutron/plugins/ml2/driver_context.py
index bf7b503d6c..d18bb25d6c 100644
--- a/neutron/plugins/ml2/driver_context.py
+++ b/neutron/plugins/ml2/driver_context.py
@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import copy
-
from neutron_lib import constants
from oslo_log import log
from oslo_serialization import jsonutils
@@ -98,10 +96,8 @@ class PortContext(MechanismDriverContext, api.PortContext):
else:
self._network_context = NetworkContext(
plugin, plugin_context, network) if network else None
- # NOTE(kevinbenton): these copys can go away once we are working with
- # OVO objects here instead of native SQLA objects.
- self._binding = copy.deepcopy(binding)
- self._binding_levels = copy.deepcopy(binding_levels)
+ self._binding = binding
+ self._binding_levels = binding_levels
self._segments_to_bind = None
self._new_bound_segment = None
self._next_segments_to_bind = None
diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py
index 3ccb2476df..dd3554a22c 100644
--- a/neutron/plugins/ml2/plugin.py
+++ b/neutron/plugins/ml2/plugin.py
@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import copy
-
from eventlet import greenthread
from neutron_lib.api import validators
from neutron_lib import constants as const
@@ -350,10 +348,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
binding.host = ''
self._update_port_dict_binding(port, binding)
- # merging here brings binding changes into the session so they can be
- # committed since the binding attached to the context is detached from
- # the session
- mech_context._plugin_context.session.merge(binding)
return changes
def _bind_port_if_needed(self, context, allow_notify=False,
@@ -516,8 +510,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
cur_binding.vif_details = new_binding.vif_details
db.clear_binding_levels(session, port_id, cur_binding.host)
db.set_binding_levels(session, bind_context._binding_levels)
- # refresh context with a snapshot of updated state
- cur_context._binding = copy.deepcopy(cur_binding)
cur_context._binding_levels = bind_context._binding_levels
# Update PortContext's port dictionary to reflect the
@@ -1422,8 +1414,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
self._update_port_dict_binding(port, binding)
binding.host = attrs and attrs.get(portbindings.HOST_ID)
binding.router_id = attrs and attrs.get('device_id')
- # merge into session to reflect changes
- mech_context._plugin_context.session.merge(binding)
@utils.transaction_guard
@db_api.retry_if_session_inactive()
@@ -1645,7 +1635,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
session, port['id'], host)
if not binding:
return
- binding.status = status
+ binding['status'] = status
+ binding.update(binding)
updated = True
if (updated and
diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py
index 69d4834187..488a661724 100644
--- a/neutron/tests/unit/plugins/ml2/test_plugin.py
+++ b/neutron/tests/unit/plugins/ml2/test_plugin.py
@@ -1596,8 +1596,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
plugin = manager.NeutronManager.get_plugin()
binding = ml2_db.get_locked_port_and_binding(self.context.session,
port['port']['id'])[1]
- with self.context.session.begin(subtransactions=True):
- binding.host = 'test'
+ binding['host'] = 'test'
mech_context = driver_context.PortContext(
plugin, self.context, port['port'],
plugin.get_network(self.context, port['port']['network_id']),
@@ -1605,9 +1604,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
with mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.'
'_update_port_dict_binding') as update_mock:
attrs = {portbindings.HOST_ID: None}
- self.assertEqual('test', binding.host)
- with self.context.session.begin(subtransactions=True):
- plugin._process_port_binding(mech_context, attrs)
+ plugin._process_port_binding(mech_context, attrs)
self.assertTrue(update_mock.mock_calls)
self.assertEqual('', binding.host)
@@ -2510,7 +2507,7 @@ class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase):
binding.host = 'vm_host'
binding.vnic_type = portbindings.VNIC_NORMAL
binding.profile = ''
- binding.vif_type = 'unbound'
+ binding.vif_type = ''
binding.vif_details = ''
with mock.patch.object(ml2_plugin.Ml2Plugin, '__init__') as init,\
diff --git a/neutron/tests/unit/plugins/ml2/test_port_binding.py b/neutron/tests/unit/plugins/ml2/test_port_binding.py
index bab7ffd906..f4fd1419dc 100644
--- a/neutron/tests/unit/plugins/ml2/test_port_binding.py
+++ b/neutron/tests/unit/plugins/ml2/test_port_binding.py
@@ -15,7 +15,6 @@
import mock
from neutron_lib import constants as const
-from oslo_serialization import jsonutils
from neutron import context
from neutron.extensions import portbindings
@@ -195,7 +194,7 @@ class PortBindingTestCase(test_plugin.NeutronDbPluginV2TestCase):
port_id=original_port['id'],
host=original_port['binding:host_id'],
vnic_type=original_port['binding:vnic_type'],
- profile=jsonutils.dumps(original_port['binding:profile']),
+ profile=original_port['binding:profile'],
vif_type=original_port['binding:vif_type'],
vif_details=original_port['binding:vif_details'])
levels = 1