refactor: use the new py39 dict | dict syntax to make a union

Change-Id: I335af032f8ae503e87b1fcdc781b3ebb5cf79cb8
This commit is contained in:
Ihar Hrachyshka 2024-09-25 16:26:18 -04:00
parent 545c1466e2
commit fdcd98464b
4 changed files with 18 additions and 18 deletions

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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,