diff --git a/neutron/pecan_wsgi/hooks/policy_enforcement.py b/neutron/pecan_wsgi/hooks/policy_enforcement.py index 20aa758ebab..fd9ffd71a00 100644 --- a/neutron/pecan_wsgi/hooks/policy_enforcement.py +++ b/neutron/pecan_wsgi/hooks/policy_enforcement.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import copy - from neutron_lib import constants as const from oslo_log import log as logging from oslo_policy import policy as oslo_policy @@ -118,8 +116,7 @@ class PolicyHook(hooks.PecanHook): parent_id=parent_id) if resource_obj: original_resources.append(resource_obj) - obj = copy.copy(resource_obj) - obj.update(item) + obj = resource_obj | item obj[const.ATTRIBUTES_TO_UPDATE] = list(item) # Put back the item in the list so that policies could be # enforced diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 0d51040a86e..e874e7d195f 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -2272,9 +2272,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): fip1 = {'id': _uuid(), 'floating_ip_address': '8.8.8.8', 'fixed_ip_address': '7.7.7.7', 'status': 'ACTIVE', 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']} - fip2 = copy.copy(fip1) - fip2.update({'id': _uuid(), 'status': 'DOWN', - 'floating_ip_address': '9.9.9.9'}) + fip2 = fip1 | {'id': _uuid(), 'status': 'DOWN', + 'floating_ip_address': '9.9.9.9'} router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2] ri = legacy_router.LegacyRouter(agent, router['id'], router, @@ -2350,8 +2349,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): fip1 = {'id': _uuid(), 'floating_ip_address': '8.8.8.8', 'fixed_ip_address': '7.7.7.7', 'status': 'ACTIVE', 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']} - fip2 = copy.copy(fip1) - fip2.update({'id': _uuid(), 'status': 'DOWN', }) + fip2 = fip1 | {'id': _uuid(), 'status': 'DOWN', } router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2] ri = legacy_router.LegacyRouter(agent, router['id'], router, diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py index 7e5ddda033f..567bf85aa7b 100644 --- a/neutron/tests/unit/objects/test_base.py +++ b/neutron/tests/unit/objects/test_base.py @@ -887,9 +887,7 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase): 'found in test class %r' % self._test_class) - filters = copy.copy(self.valid_field_filter) - filters[synthetic_fields.pop()] = 'xxx' - + filters = self.valid_field_filter | {synthetic_fields.pop(): 'xxx'} with mock.patch.object(obj_db_api, 'get_objects', return_value=self.db_objs): self.assertRaises(n_exc.InvalidInput, diff --git a/neutron/tests/unit/services/ovn_l3/test_plugin.py b/neutron/tests/unit/services/ovn_l3/test_plugin.py index 19e52b89356..66e522d8401 100644 --- a/neutron/tests/unit/services/ovn_l3/test_plugin.py +++ b/neutron/tests/unit/services/ovn_l3/test_plugin.py @@ -866,12 +866,19 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): 'cidr': '192.168.2.0/24', 'gateway_ip': '192.168.2.254'} # Old gateway info with same network and different subnet - self.get_router.return_value = copy.copy(self.fake_router_with_ext_gw) - self.get_router.return_value['external_gateway_info'] = { - 'network_id': 'ext-network-id', - 'external_fixed_ips': [{'ip_address': '192.168.2.1', - 'subnet_id': 'old-ext-subnet-id'}]} - self.get_router.return_value['gw_port_id'] = 'old-gw-port-id' + self.get_router.return_value = ( + self.fake_router_with_ext_gw | + { + 'external_gateway_info': { + 'network_id': 'ext-network-id', + 'external_fixed_ips': [ + {'ip_address': '192.168.2.1', + 'subnet_id': 'old-ext-subnet-id'} + ] + }, + 'gw_port_id': 'old-gw-port-id' + } + ) ur.return_value = self.fake_router_with_ext_gw self.get_subnet.side_effect = lambda ctx, sid: { 'ext-subnet-id': self.fake_ext_subnet,