diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index ae4e67225e..64efe64b22 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -1486,6 +1486,10 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, LOG.exception("Unable to update NSX backend, rolling " "back changes on neutron") with excutils.save_and_reraise_exception(): + # remove the AZ from the network before rollback because + # it is read only, and breaks the rollback + if 'availability_zone_hints' in original_net: + del original_net['availability_zone_hints'] super(NsxV3Plugin, self).update_network( context, id, {'network': original_net}) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index 18fcec93c8..fdd3e36df1 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -695,6 +695,21 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin): self.assertEqual(ctx_manager.exception.code, 503) + def test_update_network_rollback(self): + with self.network() as net: + # Fail the backend update + with mock.patch("vmware_nsxlib.v3.core_resources." + "NsxLibLogicalSwitch.update", + side_effect=nsxlib_exc.ManagerError): + args = {'network': {'description': 'test rollback'}} + req = self.new_update_request('networks', args, + net['network']['id'], fmt='json') + res = self.deserialize('json', req.get_response(self.api)) + # should fail with the nsxlib error (meaning that the rollback + # did not fail) + self.assertEqual('ManagerError', + res['NeutronError']['type']) + class TestSubnetsV2(test_plugin.TestSubnetsV2, NsxV3PluginTestCaseMixin):