summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-15 04:38:53 +0000
committerGerrit Code Review <review@openstack.org>2017-06-15 04:38:53 +0000
commit4853229fead92b586e3d0dcf6bffb2a4e974e643 (patch)
treeca17f630664d3094735dc39c47d79ec16253a9ec
parenta222a25be129fdcf670c36e2a4b17a18719a09e4 (diff)
parentcb773098d276cfbabc600361e91cb709ec846ba8 (diff)
Merge "deepcopy binding and binding levels avoid expiration" into stable/newton
-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, 25 insertions, 8 deletions
diff --git a/neutron/plugins/ml2/driver_context.py b/neutron/plugins/ml2/driver_context.py
index d18bb25..bf7b503 100644
--- a/neutron/plugins/ml2/driver_context.py
+++ b/neutron/plugins/ml2/driver_context.py
@@ -13,6 +13,8 @@
13# License for the specific language governing permissions and limitations 13# License for the specific language governing permissions and limitations
14# under the License. 14# under the License.
15 15
16import copy
17
16from neutron_lib import constants 18from neutron_lib import constants
17from oslo_log import log 19from oslo_log import log
18from oslo_serialization import jsonutils 20from oslo_serialization import jsonutils
@@ -96,8 +98,10 @@ class PortContext(MechanismDriverContext, api.PortContext):
96 else: 98 else:
97 self._network_context = NetworkContext( 99 self._network_context = NetworkContext(
98 plugin, plugin_context, network) if network else None 100 plugin, plugin_context, network) if network else None
99 self._binding = binding 101 # NOTE(kevinbenton): these copys can go away once we are working with
100 self._binding_levels = binding_levels 102 # OVO objects here instead of native SQLA objects.
103 self._binding = copy.deepcopy(binding)
104 self._binding_levels = copy.deepcopy(binding_levels)
101 self._segments_to_bind = None 105 self._segments_to_bind = None
102 self._new_bound_segment = None 106 self._new_bound_segment = None
103 self._next_segments_to_bind = None 107 self._next_segments_to_bind = None
diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py
index dd3554a..3ccb247 100644
--- a/neutron/plugins/ml2/plugin.py
+++ b/neutron/plugins/ml2/plugin.py
@@ -13,6 +13,8 @@
13# License for the specific language governing permissions and limitations 13# License for the specific language governing permissions and limitations
14# under the License. 14# under the License.
15 15
16import copy
17
16from eventlet import greenthread 18from eventlet import greenthread
17from neutron_lib.api import validators 19from neutron_lib.api import validators
18from neutron_lib import constants as const 20from neutron_lib import constants as const
@@ -348,6 +350,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
348 binding.host = '' 350 binding.host = ''
349 351
350 self._update_port_dict_binding(port, binding) 352 self._update_port_dict_binding(port, binding)
353 # merging here brings binding changes into the session so they can be
354 # committed since the binding attached to the context is detached from
355 # the session
356 mech_context._plugin_context.session.merge(binding)
351 return changes 357 return changes
352 358
353 def _bind_port_if_needed(self, context, allow_notify=False, 359 def _bind_port_if_needed(self, context, allow_notify=False,
@@ -510,6 +516,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
510 cur_binding.vif_details = new_binding.vif_details 516 cur_binding.vif_details = new_binding.vif_details
511 db.clear_binding_levels(session, port_id, cur_binding.host) 517 db.clear_binding_levels(session, port_id, cur_binding.host)
512 db.set_binding_levels(session, bind_context._binding_levels) 518 db.set_binding_levels(session, bind_context._binding_levels)
519 # refresh context with a snapshot of updated state
520 cur_context._binding = copy.deepcopy(cur_binding)
513 cur_context._binding_levels = bind_context._binding_levels 521 cur_context._binding_levels = bind_context._binding_levels
514 522
515 # Update PortContext's port dictionary to reflect the 523 # Update PortContext's port dictionary to reflect the
@@ -1414,6 +1422,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
1414 self._update_port_dict_binding(port, binding) 1422 self._update_port_dict_binding(port, binding)
1415 binding.host = attrs and attrs.get(portbindings.HOST_ID) 1423 binding.host = attrs and attrs.get(portbindings.HOST_ID)
1416 binding.router_id = attrs and attrs.get('device_id') 1424 binding.router_id = attrs and attrs.get('device_id')
1425 # merge into session to reflect changes
1426 mech_context._plugin_context.session.merge(binding)
1417 1427
1418 @utils.transaction_guard 1428 @utils.transaction_guard
1419 @db_api.retry_if_session_inactive() 1429 @db_api.retry_if_session_inactive()
@@ -1635,8 +1645,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
1635 session, port['id'], host) 1645 session, port['id'], host)
1636 if not binding: 1646 if not binding:
1637 return 1647 return
1638 binding['status'] = status 1648 binding.status = status
1639 binding.update(binding)
1640 updated = True 1649 updated = True
1641 1650
1642 if (updated and 1651 if (updated and
diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py
index 488a661..69d4834 100644
--- a/neutron/tests/unit/plugins/ml2/test_plugin.py
+++ b/neutron/tests/unit/plugins/ml2/test_plugin.py
@@ -1596,7 +1596,8 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
1596 plugin = manager.NeutronManager.get_plugin() 1596 plugin = manager.NeutronManager.get_plugin()
1597 binding = ml2_db.get_locked_port_and_binding(self.context.session, 1597 binding = ml2_db.get_locked_port_and_binding(self.context.session,
1598 port['port']['id'])[1] 1598 port['port']['id'])[1]
1599 binding['host'] = 'test' 1599 with self.context.session.begin(subtransactions=True):
1600 binding.host = 'test'
1600 mech_context = driver_context.PortContext( 1601 mech_context = driver_context.PortContext(
1601 plugin, self.context, port['port'], 1602 plugin, self.context, port['port'],
1602 plugin.get_network(self.context, port['port']['network_id']), 1603 plugin.get_network(self.context, port['port']['network_id']),
@@ -1604,7 +1605,9 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
1604 with mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.' 1605 with mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.'
1605 '_update_port_dict_binding') as update_mock: 1606 '_update_port_dict_binding') as update_mock:
1606 attrs = {portbindings.HOST_ID: None} 1607 attrs = {portbindings.HOST_ID: None}
1607 plugin._process_port_binding(mech_context, attrs) 1608 self.assertEqual('test', binding.host)
1609 with self.context.session.begin(subtransactions=True):
1610 plugin._process_port_binding(mech_context, attrs)
1608 self.assertTrue(update_mock.mock_calls) 1611 self.assertTrue(update_mock.mock_calls)
1609 self.assertEqual('', binding.host) 1612 self.assertEqual('', binding.host)
1610 1613
@@ -2507,7 +2510,7 @@ class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase):
2507 binding.host = 'vm_host' 2510 binding.host = 'vm_host'
2508 binding.vnic_type = portbindings.VNIC_NORMAL 2511 binding.vnic_type = portbindings.VNIC_NORMAL
2509 binding.profile = '' 2512 binding.profile = ''
2510 binding.vif_type = '' 2513 binding.vif_type = 'unbound'
2511 binding.vif_details = '' 2514 binding.vif_details = ''
2512 2515
2513 with mock.patch.object(ml2_plugin.Ml2Plugin, '__init__') as init,\ 2516 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 f4fd141..bab7ffd 100644
--- a/neutron/tests/unit/plugins/ml2/test_port_binding.py
+++ b/neutron/tests/unit/plugins/ml2/test_port_binding.py
@@ -15,6 +15,7 @@
15 15
16import mock 16import mock
17from neutron_lib import constants as const 17from neutron_lib import constants as const
18from oslo_serialization import jsonutils
18 19
19from neutron import context 20from neutron import context
20from neutron.extensions import portbindings 21from neutron.extensions import portbindings
@@ -194,7 +195,7 @@ class PortBindingTestCase(test_plugin.NeutronDbPluginV2TestCase):
194 port_id=original_port['id'], 195 port_id=original_port['id'],
195 host=original_port['binding:host_id'], 196 host=original_port['binding:host_id'],
196 vnic_type=original_port['binding:vnic_type'], 197 vnic_type=original_port['binding:vnic_type'],
197 profile=original_port['binding:profile'], 198 profile=jsonutils.dumps(original_port['binding:profile']),
198 vif_type=original_port['binding:vif_type'], 199 vif_type=original_port['binding:vif_type'],
199 vif_details=original_port['binding:vif_details']) 200 vif_details=original_port['binding:vif_details'])
200 levels = 1 201 levels = 1