From ea27e1aa1ed7ad802d1167c1c80ae51fcd5cee99 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Mon, 6 Mar 2017 16:47:25 -0800 Subject: [PATCH] Update is_default field only when specified in the request Closes-bug: 1670524 Change-Id: Ie46fe7126693bcf6732332a479f4b2609c402c5d --- neutron/services/auto_allocate/db.py | 13 +++++++------ .../tempest/api/test_auto_allocated_topology.py | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/neutron/services/auto_allocate/db.py b/neutron/services/auto_allocate/db.py index 946ddade07f..e450ffab0b9 100644 --- a/neutron/services/auto_allocate/db.py +++ b/neutron/services/auto_allocate/db.py @@ -53,7 +53,7 @@ def _extend_external_network_default(core_plugin, net_res, net_db): def _ensure_external_network_default_value_callback( resource, event, trigger, context, request, network): """Ensure the is_default db field matches the create/update request.""" - is_default = request.get(IS_DEFAULT, False) + is_default = request.get(IS_DEFAULT) if event in (events.BEFORE_CREATE, events.BEFORE_UPDATE) and is_default: # ensure there is only one default external network at any given time pager = base_obj.Pager(limit=1) @@ -65,11 +65,12 @@ def _ensure_external_network_default_value_callback( net_id=objs[0].network_id) # Reflect the status of the is_default on the create/update request - obj = net_obj.ExternalNetwork.get_object(context, - network_id=network['id']) - if obj: - obj.is_default = is_default - obj.update() + if is_default is not None: + obj = net_obj.ExternalNetwork.get_object(context, + network_id=network['id']) + if obj: + obj.is_default = is_default + obj.update() class AutoAllocatedTopologyMixin(common_db_mixin.CommonDbMixin): diff --git a/neutron/tests/tempest/api/test_auto_allocated_topology.py b/neutron/tests/tempest/api/test_auto_allocated_topology.py index 7a6d5ac88da..0db7602a579 100644 --- a/neutron/tests/tempest/api/test_auto_allocated_topology.py +++ b/neutron/tests/tempest/api/test_auto_allocated_topology.py @@ -54,6 +54,9 @@ class TestAutoAllocatedTopology(base.BaseAdminNetworkTest): # Ensure the public external network is the default external network public_net_id = cfg.CONF.network.public_network_id cls.admin_client.update_network(public_net_id, is_default=True) + # Ensure that is_default does not accidentally flip back to False + # because of network_update requests that do not contain is_default. + cls.admin_client.update_network(public_net_id, description="gman") def _count_topology_resources(self): '''Count the resources whose names begin with 'auto_allocated_'.'''