From 9016c1f810ee734d4a19032a470d4acb9462639d Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Tue, 18 Aug 2015 23:35:46 -0700 Subject: [PATCH] l2pop: check port mac in pre-commit to stop change Check that a port mac address hasn't changed during the precommit phase of the port update rather than the post commit so the resulting exception actually stops it from happening. Change-Id: I62f120b3c954fa4251a7d676cf2c623e6da5a98b Closes-Bug: #1486379 --- neutron/plugins/ml2/drivers/l2pop/mech_driver.py | 9 +++++++-- .../unit/plugins/ml2/drivers/l2pop/test_mech_driver.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py index a584b213a..2d9c94ac3 100644 --- a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py +++ b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py @@ -99,7 +99,7 @@ class L2populationMechanismDriver(api.MechanismDriver, return True - def update_port_postcommit(self, context): + def update_port_precommit(self, context): port = context.current orig = context.original @@ -107,7 +107,12 @@ class L2populationMechanismDriver(api.MechanismDriver, context.status == const.PORT_STATUS_ACTIVE): LOG.warning(_LW("unable to modify mac_address of ACTIVE port " "%s"), port['id']) - raise ml2_exc.MechanismDriverError(method='update_port_postcommit') + raise ml2_exc.MechanismDriverError(method='update_port_precommit') + + def update_port_postcommit(self, context): + port = context.current + orig = context.original + diff_ips = self._get_diff_ips(orig, port) if diff_ips: self._fixed_ips_changed(context, orig, port, diff_ips) diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py index dd40deae7..c9f170f05 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py @@ -892,7 +892,7 @@ class TestL2PopulationMechDriver(base.BaseTestCase): [constants.FLOODING_ENTRY]}} self.assertEqual(expected_result, result) - def test_update_port_postcommit_mac_address_changed_raises(self): + def test_update_port_precommit_mac_address_changed_raises(self): port = {'status': u'ACTIVE', 'device_owner': u'compute:None', 'mac_address': u'12:34:56:78:4b:0e', @@ -912,4 +912,4 @@ class TestL2PopulationMechDriver(base.BaseTestCase): mech_driver = l2pop_mech_driver.L2populationMechanismDriver() with testtools.ExpectedException(ml2_exc.MechanismDriverError): - mech_driver.update_port_postcommit(ctx) + mech_driver.update_port_precommit(ctx) -- 2.45.2