diff --git a/neutron/cmd/ovn/neutron_ovn_db_sync_util.py b/neutron/cmd/ovn/neutron_ovn_db_sync_util.py index d0620497e2a..4256a31bd9a 100644 --- a/neutron/cmd/ovn/neutron_ovn_db_sync_util.py +++ b/neutron/cmd/ovn/neutron_ovn_db_sync_util.py @@ -66,7 +66,7 @@ class OVNMechanismDriver(mech_driver.OVNMechanismDriver): def create_port_postcommit(self, context): port = context.current - self.ovn_client.create_port(port) + self.ovn_client.create_port(context, port) def update_port_precommit(self, context): pass @@ -74,7 +74,7 @@ class OVNMechanismDriver(mech_driver.OVNMechanismDriver): def update_port_postcommit(self, context): port = context.current original_port = context.original - self.ovn_client.update_port(port, original_port) + self.ovn_client.update_port(context, port, original_port) def delete_port_precommit(self, context): pass diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py index 21786e82435..b6e7cd76496 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py @@ -265,7 +265,8 @@ class OVNMechanismDriver(api.MechanismDriver): def _create_security_group(self, resource, event, trigger, security_group, **kwargs): - self._ovn_client.create_security_group(security_group) + self._ovn_client.create_security_group(kwargs['context'], + security_group) def _delete_security_group(self, resource, event, trigger, security_group_id, **kwargs): @@ -290,7 +291,7 @@ class OVNMechanismDriver(api.MechanismDriver): self, resource, event, trigger, **kwargs): if event == events.AFTER_CREATE: self._ovn_client.create_security_group_rule( - kwargs.get('security_group_rule')) + kwargs['context'], kwargs.get('security_group_rule')) elif event == events.BEFORE_DELETE: sg_rule = self._plugin.get_security_group_rule( kwargs['context'], kwargs.get('security_group_rule_id')) @@ -348,7 +349,7 @@ class OVNMechanismDriver(api.MechanismDriver): cause the deletion of the resource. """ network = context.current - self._ovn_client.create_network(network) + self._ovn_client.create_network(context._plugin_context, network) def update_network_precommit(self, context): """Update resources of a network. @@ -388,7 +389,8 @@ class OVNMechanismDriver(api.MechanismDriver): # https://bugs.launchpad.net/neutron/+bug/1739798 is fixed. if context._plugin_context.session.is_active: return - self._ovn_client.update_network(context.current) + self._ovn_client.update_network(context._plugin_context, + context.current) def delete_network_postcommit(self, context): """Delete a network. @@ -412,15 +414,17 @@ class OVNMechanismDriver(api.MechanismDriver): ovn_const.TYPE_SUBNETS) def create_subnet_postcommit(self, context): - self._ovn_client.create_subnet(context.current, + self._ovn_client.create_subnet(context._plugin_context, + context.current, context.network.current) def update_subnet_postcommit(self, context): self._ovn_client.update_subnet( - context.current, context.network.current) + context._plugin_context, context.current, context.network.current) def delete_subnet_postcommit(self, context): - self._ovn_client.delete_subnet(context.current['id']) + self._ovn_client.delete_subnet(context._plugin_context, + context.current['id']) def create_port_precommit(self, context): """Allocate resources for a new port. @@ -492,10 +496,11 @@ class OVNMechanismDriver(api.MechanismDriver): def _notify_dhcp_updated(self, port_id): """Notifies Neutron that the DHCP has been update for port.""" + admin_context = n_context.get_admin_context() if provisioning_blocks.is_object_blocked( - n_context.get_admin_context(), port_id, resources.PORT): + admin_context, port_id, resources.PORT): provisioning_blocks.provisioning_complete( - n_context.get_admin_context(), port_id, resources.PORT, + admin_context, port_id, resources.PORT, provisioning_blocks.DHCP_ENTITY) def _validate_ignored_port(self, port, original_port): @@ -527,7 +532,7 @@ class OVNMechanismDriver(api.MechanismDriver): """ port = copy.deepcopy(context.current) port['network'] = context.network.current - self._ovn_client.create_port(port) + self._ovn_client.create_port(context._plugin_context, port) self._notify_dhcp_updated(port['id']) def update_port_precommit(self, context): @@ -590,11 +595,11 @@ class OVNMechanismDriver(api.MechanismDriver): if ((port['status'] == const.PORT_STATUS_DOWN and ovn_const.MIGRATING_ATTR in port[portbindings.PROFILE].keys() and port[portbindings.VIF_TYPE] == portbindings.VIF_TYPE_OVS)): - admin_context = n_context.get_admin_context() LOG.info("Setting port %s status from DOWN to UP in order " "to emit vif-interface-plugged event.", port['id']) - self._plugin.update_port_status(admin_context, port['id'], + self._plugin.update_port_status(context._plugin_context, + port['id'], const.PORT_STATUS_ACTIVE) # The revision has been changed. In the meantime # port-update event already updated the OVN configuration, @@ -602,7 +607,8 @@ class OVNMechanismDriver(api.MechanismDriver): # will fail that OVN has port with bigger revision. return - self._ovn_client.update_port(port, port_object=original_port) + self._ovn_client.update_port(context._plugin_context, port, + port_object=original_port) self._notify_dhcp_updated(port['id']) def delete_port_postcommit(self, context): @@ -811,13 +817,13 @@ class OVNMechanismDriver(api.MechanismDriver): self._update_dnat_entry_if_needed(port_id) self._wait_for_metadata_provisioned_if_needed(port_id) + admin_context = n_context.get_admin_context() provisioning_blocks.provisioning_complete( - n_context.get_admin_context(), + admin_context, port_id, resources.PORT, provisioning_blocks.L2_AGENT_ENTITY) - admin_context = n_context.get_admin_context() try: # NOTE(lucasagomes): Router ports in OVN is never bound # to a host given their decentralized nature. By calling diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py index 7d11e84d00e..bbca827e09a 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py @@ -156,7 +156,7 @@ class DBInconsistenciesPeriodics(object): ovn_obj = res_map['ovn_get'](row.resource_uuid) if not ovn_obj: - res_map['ovn_create'](n_obj) + res_map['ovn_create'](context, n_obj) else: if row.resource_type == ovn_const.TYPE_SECURITY_GROUP_RULES: LOG.error("SG rule %s found with a revision number while " @@ -175,7 +175,7 @@ class DBInconsistenciesPeriodics(object): # If the resource exist in the OVN DB but the revision # number is different from Neutron DB, updated it. if ovn_revision != n_obj['revision_number']: - res_map['ovn_update'](n_obj) + res_map['ovn_update'](context, n_obj) else: # If the resource exist and the revision number # is equal on both databases just bump the revision on @@ -200,9 +200,9 @@ class DBInconsistenciesPeriodics(object): context, sn_db_obj['network_id']) if row.revision_number == ovn_const.INITIAL_REV_NUM: - self._ovn_client.create_subnet(sn_db_obj, n_db_obj) + self._ovn_client.create_subnet(context, sn_db_obj, n_db_obj) else: - self._ovn_client.update_subnet(sn_db_obj, n_db_obj) + self._ovn_client.update_subnet(context, sn_db_obj, n_db_obj) # The migration will run just once per neutron-server instance. If the lock # is held by some other neutron-server instance in the cloud, we'll attempt @@ -309,7 +309,8 @@ class DBInconsistenciesPeriodics(object): 'type_': INCONSISTENCY_TYPE_DELETE}) try: if row.resource_type == ovn_const.TYPE_SUBNETS: - self._ovn_client.delete_subnet(row.resource_uuid) + self._ovn_client.delete_subnet(admin_context, + row.resource_uuid) else: self._fix_delete(admin_context, row) except Exception: @@ -322,11 +323,10 @@ class DBInconsistenciesPeriodics(object): LOG.info('Maintenance task: Synchronization finished ' '(took %.2f seconds)', self._sync_timer.elapsed()) - def _create_lrouter_port(self, port): - admin_context = n_context.get_admin_context() + def _create_lrouter_port(self, context, port): router_id = port['device_id'] self._ovn_client._l3_plugin.add_router_interface( - admin_context, router_id, {'port_id': port['id']}, may_exist=True) + context, router_id, {'port_id': port['id']}, may_exist=True) def _check_subnet_global_dhcp_opts(self): inconsistent_subnets = [] @@ -380,7 +380,8 @@ class DBInconsistenciesPeriodics(object): neutron_net = self._ovn_client._plugin.get_network( admin_context, subnet['network_id']) try: - self._ovn_client.update_subnet(subnet, neutron_net) + self._ovn_client.update_subnet(admin_context, subnet, + neutron_net) except Exception: LOG.exception('Failed to update subnet %s', subnet['id']) diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py index 7c71605766b..309783a8a32 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py @@ -302,7 +302,7 @@ class OVNClient(object): ovn_const.HA_CHASSIS_GROUP_DEFAULT_NAME).execute( check_error=True).uuid - def create_port(self, port): + def create_port(self, context, port): if utils.is_lsp_ignored(port): return @@ -321,7 +321,6 @@ class OVNClient(object): utils.get_revision_number( port, ovn_const.TYPE_PORTS))} lswitch_name = utils.ovn_name(port['network_id']) - admin_context = n_context.get_admin_context() sg_cache = {} subnet_cache = {} @@ -391,8 +390,7 @@ class OVNClient(object): allowed_address_pairs and port_info.type != ovn_const.LSP_TYPE_VIRTUAL): addrs = [addr['ip_address'] for addr in allowed_address_pairs] - self._set_unset_virtual_port_type( - admin_context, txn, port, addrs) + self._set_unset_virtual_port_type(context, txn, port, addrs) port_cmd = txn.add(self._nb_idl.create_lswitch_port( **kwargs)) @@ -416,7 +414,7 @@ class OVNClient(object): utils.ovn_port_group_name(sg), port_cmd)) else: # SGs modelled as Address Sets: - acls_new = ovn_acl.add_acls(self._plugin, admin_context, + acls_new = ovn_acl.add_acls(self._plugin, context, port, sg_cache, subnet_cache, self._nb_idl) for acl in acls_new: @@ -448,7 +446,7 @@ class OVNClient(object): port, lswitch_name) txn.add(self._nb_idl.qos_add(**qos_rule_column)) - db_rev.bump_revision(admin_context, port, ovn_const.TYPE_PORTS) + db_rev.bump_revision(context, port, ovn_const.TYPE_PORTS) def _set_unset_virtual_port_type(self, context, txn, parent_port, addresses, unset=False): @@ -475,7 +473,7 @@ class OVNClient(object): # TODO(lucasagomes): The ``port_object`` parameter was added to # keep things backward compatible. Remove it in the Rocky release. - def update_port(self, port, qos_options=None, port_object=None): + def update_port(self, context, port, qos_options=None, port_object=None): if utils.is_lsp_ignored(port): return # Does not need to add qos rule to port_info @@ -494,7 +492,6 @@ class OVNClient(object): utils.get_revision_number( port, ovn_const.TYPE_PORTS))} lswitch_name = utils.ovn_name(port['network_id']) - admin_context = n_context.get_admin_context() sg_cache = {} subnet_cache = {} @@ -549,9 +546,9 @@ class OVNClient(object): if (self._is_virtual_port_supported() and port_info.type != ovn_const.LSP_TYPE_VIRTUAL): self._set_unset_virtual_port_type( - admin_context, txn, port, addr_pairs_diff.added) + context, txn, port, addr_pairs_diff.added) self._set_unset_virtual_port_type( - admin_context, txn, port, addr_pairs_diff.removed, + context, txn, port, addr_pairs_diff.removed, unset=True) # NOTE(lizk): Fail port updating if port doesn't exist. This @@ -613,7 +610,7 @@ class OVNClient(object): # ensure only the necessary ACLs are added and deleted # on the transaction. acls_new = ovn_acl.add_acls(self._plugin, - admin_context, + context, port, sg_cache, subnet_cache, @@ -722,7 +719,7 @@ class OVNClient(object): self.add_txns_to_remove_port_dns_records(txn, port_object) if check_rev_cmd.result == ovn_const.TXN_COMMITTED: - db_rev.bump_revision(admin_context, port, ovn_const.TYPE_PORTS) + db_rev.bump_revision(context, port, ovn_const.TYPE_PORTS) def _create_qos_rules(self, qos_options, port, lswitch_name, if_delete=False): @@ -1141,7 +1138,7 @@ class OVNClient(object): if fip_status: self._l3_plugin.update_floatingip_status( - n_context.get_admin_context(), floatingip['id'], fip_status) + context, floatingip['id'], fip_status) # TODO(lucasagomes): The ``fip_object`` parameter was added to # keep things backward compatible since old FIPs might not have @@ -1192,7 +1189,8 @@ class OVNClient(object): else const.IPv6_ANY)) return gateways_info - def _delete_router_ext_gw(self, context, router, networks, txn): + def _delete_router_ext_gw(self, router, networks, txn): + context = n_context.get_admin_context() if not networks: networks = [] router_id = router['id'] @@ -1213,8 +1211,7 @@ class OVNClient(object): gw_lrouter_name)) def _get_nets_and_ipv6_ra_confs_for_router_port( - self, port_fixed_ips): - context = n_context.get_admin_context() + self, context, port_fixed_ips): networks = set() ipv6_ra_configs = {} ipv6_ra_configs_supported = self._nb_idl.is_col_present( @@ -1238,13 +1235,14 @@ class OVNClient(object): return list(networks), ipv6_ra_configs - def _add_router_ext_gw(self, context, router, networks, txn): + def _add_router_ext_gw(self, router, networks, txn): + context = n_context.get_admin_context() router_id = router['id'] # 1. Add the external gateway router port. gateways = self._get_gw_info(context, router) gw_port_id = router['gw_port_id'] port = self._plugin.get_port(context, gw_port_id) - self._create_lrouter_port(router_id, port, txn=txn) + self._create_lrouter_port(context, router_id, port, txn=txn) def _build_extids(gw_info): # TODO(lucasagomes): Remove this check after OVS 2.8.2 is tagged @@ -1271,8 +1269,9 @@ class OVNClient(object): self.update_nat_rules(router, networks, enable_snat=True, txn=txn) return port - def _check_external_ips_changed(self, context, ovn_snats, + def _check_external_ips_changed(self, ovn_snats, ovn_static_routes, router): + context = n_context.get_admin_context() gateways = self._get_gw_info(context, router) ovn_gw_subnets = None if self._nb_idl.is_col_present('Logical_Router_Static_Route', @@ -1354,9 +1353,8 @@ class OVNClient(object): ovn_const.OVN_REV_NUM_EXT_ID_KEY: str(utils.get_revision_number( router, ovn_const.TYPE_ROUTERS))} - def create_router(self, router, add_external_gateway=True): + def create_router(self, context, router, add_external_gateway=True): """Create a logical router.""" - admin_context = n_context.get_admin_context() external_ids = self._gen_router_ext_ids(router) enabled = router.get('admin_state_up') lrouter_name = utils.ovn_name(router['id']) @@ -1371,22 +1369,21 @@ class OVNClient(object): # synchronization work if add_external_gateway: networks = self._get_v4_network_of_all_router_ports( - admin_context, router['id']) + context, router['id']) if router.get(l3.EXTERNAL_GW_INFO) and networks is not None: added_gw_port = self._add_router_ext_gw( - admin_context, router, networks, txn) + router, networks, txn) if added_gw_port: - db_rev.bump_revision(admin_context, added_gw_port, + db_rev.bump_revision(context, added_gw_port, ovn_const.TYPE_ROUTER_PORTS) - db_rev.bump_revision(admin_context, router, ovn_const.TYPE_ROUTERS) + db_rev.bump_revision(context, router, ovn_const.TYPE_ROUTERS) # TODO(lucasagomes): The ``router_object`` parameter was added to # keep things backward compatible with old routers created prior to # the database sync work. Remove it in the Rocky release. - def update_router(self, new_router, router_object=None): + def update_router(self, context, new_router, router_object=None): """Update a logical router.""" - admin_context = n_context.get_admin_context() router_id = new_router['id'] router_name = utils.ovn_name(router_id) ovn_router = self._nb_idl.get_lrouter(router_name) @@ -1398,8 +1395,7 @@ class OVNClient(object): if router_object: gateway_old = gateway_old or router_object.get(l3.EXTERNAL_GW_INFO) ovn_snats = utils.get_lrouter_snats(ovn_router) - networks = self._get_v4_network_of_all_router_ports( - admin_context, router_id) + networks = self._get_v4_network_of_all_router_ports(context, router_id) try: check_rev_cmd = self._nb_idl.check_revision_number( router_name, new_router, ovn_const.TYPE_ROUTERS) @@ -1408,27 +1404,27 @@ class OVNClient(object): if gateway_new and not gateway_old: # Route gateway is set added_gw_port = self._add_router_ext_gw( - admin_context, new_router, networks, txn) + new_router, networks, txn) elif gateway_old and not gateway_new: # router gateway is removed txn.add(self._nb_idl.delete_lrouter_ext_gw(router_name)) if router_object: self._delete_router_ext_gw( - admin_context, router_object, networks, txn) + router_object, networks, txn) deleted_gw_port_id = router_object['gw_port_id'] elif gateway_new and gateway_old: # Check if external gateway has changed, if yes, delete # the old gateway and add the new gateway if self._check_external_ips_changed( - admin_context, ovn_snats, gateway_old, new_router): + ovn_snats, gateway_old, new_router): txn.add(self._nb_idl.delete_lrouter_ext_gw( router_name)) if router_object: self._delete_router_ext_gw( - admin_context, router_object, networks, txn) + router_object, networks, txn) deleted_gw_port_id = router_object['gw_port_id'] added_gw_port = self._add_router_ext_gw( - admin_context, new_router, networks, txn) + new_router, networks, txn) else: # Check if snat has been enabled/disabled and update new_snat_state = gateway_new.get('enable_snat', True) @@ -1448,18 +1444,18 @@ class OVNClient(object): added, removed = helpers.diff_list_of_dict( old_routes, routes) self.update_router_routes( - admin_context, router_id, added, removed, txn=txn) + context, router_id, added, removed, txn=txn) if check_rev_cmd.result == ovn_const.TXN_COMMITTED: - db_rev.bump_revision(admin_context, new_router, + db_rev.bump_revision(context, new_router, ovn_const.TYPE_ROUTERS) if added_gw_port: - db_rev.bump_revision(admin_context, added_gw_port, + db_rev.bump_revision(context, added_gw_port, ovn_const.TYPE_ROUTER_PORTS) if deleted_gw_port_id: - db_rev.delete_revision(admin_context, deleted_gw_port_id, + db_rev.delete_revision(context, deleted_gw_port_id, ovn_const.TYPE_ROUTER_PORTS) except Exception as e: @@ -1548,12 +1544,12 @@ class OVNClient(object): return options - def _create_lrouter_port(self, router_id, port, txn=None): + def _create_lrouter_port(self, context, router_id, port, txn=None): """Create a logical router port.""" lrouter = utils.ovn_name(router_id) networks, ipv6_ra_configs = ( self._get_nets_and_ipv6_ra_confs_for_router_port( - port['fixed_ips'])) + context, port['fixed_ips'])) lrouter_port_name = utils.ovn_lrouter_port_name(port['id']) is_gw_port = const.DEVICE_OWNER_ROUTER_GW == port.get( 'device_owner') @@ -1589,10 +1585,8 @@ class OVNClient(object): lsp_address=lsp_address)] self._transaction(commands, txn=txn) - def create_router_port(self, router_id, router_interface): - admin_context = n_context.get_admin_context() - port = self._plugin.get_port( - admin_context, router_interface['port_id']) + def create_router_port(self, context, router_id, router_interface): + port = self._plugin.get_port(context, router_interface['port_id']) with self._nb_idl.transaction(check_error=True) as txn: multi_prefix = False if (len(router_interface.get('subnet_ids', [])) == 1 and @@ -1601,16 +1595,16 @@ class OVNClient(object): # NOTE(lizk) It's adding a subnet onto an already # existing router interface port, try to update lrouter port # 'networks' column. - self._update_lrouter_port(port, txn=txn) + self._update_lrouter_port(context, port, txn=txn) multi_prefix = True else: - self._create_lrouter_port(router_id, port, txn=txn) + self._create_lrouter_port(context, router_id, port, txn=txn) - router = self._l3_plugin.get_router(admin_context, router_id) + router = self._l3_plugin.get_router(context, router_id) if router.get(l3.EXTERNAL_GW_INFO): cidr = None for fixed_ip in port['fixed_ips']: - subnet = self._plugin.get_subnet(admin_context, + subnet = self._plugin.get_subnet(context, fixed_ip['subnet_id']) if multi_prefix: if 'subnet_id' in router_interface: @@ -1623,13 +1617,13 @@ class OVNClient(object): self.update_nat_rules(router, networks=[cidr], enable_snat=True, txn=txn) - db_rev.bump_revision(admin_context, port, ovn_const.TYPE_ROUTER_PORTS) + db_rev.bump_revision(context, port, ovn_const.TYPE_ROUTER_PORTS) - def _update_lrouter_port(self, port, if_exists=False, txn=None): + def _update_lrouter_port(self, context, port, if_exists=False, txn=None): """Update a logical router port.""" networks, ipv6_ra_configs = ( self._get_nets_and_ipv6_ra_confs_for_router_port( - port['fixed_ips'])) + context, port['fixed_ips'])) lsp_address = ovn_const.DEFAULT_ADDR_FOR_LSP_WITH_PEER lrp_name = utils.ovn_lrouter_port_name(port['id']) @@ -1649,18 +1643,18 @@ class OVNClient(object): self._transaction(commands, txn=txn) - def update_router_port(self, port, if_exists=False): - admin_context = n_context.get_admin_context() + def update_router_port(self, context, port, if_exists=False): lrp_name = utils.ovn_lrouter_port_name(port['id']) check_rev_cmd = self._nb_idl.check_revision_number( lrp_name, port, ovn_const.TYPE_ROUTER_PORTS) with self._nb_idl.transaction(check_error=True) as txn: txn.add(check_rev_cmd) - self._update_lrouter_port(port, if_exists=if_exists, txn=txn) + self._update_lrouter_port(context, port, if_exists=if_exists, + txn=txn) if check_rev_cmd.result == ovn_const.TXN_COMMITTED: db_rev.bump_revision( - admin_context, port, ovn_const.TYPE_ROUTER_PORTS) + context, port, ovn_const.TYPE_ROUTER_PORTS) def _delete_lrouter_port(self, context, port_id, router_id=None, txn=None): """Delete a logical router port.""" @@ -1687,7 +1681,7 @@ class OVNClient(object): port = self._plugin.get_port(context, port_id) # The router interface port still exists, call ovn to # update it - self._update_lrouter_port(port, txn=txn) + self._update_lrouter_port(context, port, txn=txn) except n_exc.PortNotFound: # The router interface port doesn't exist any more, # we will call ovn to delete it once we remove the snat @@ -1782,11 +1776,10 @@ class OVNClient(object): ovn_const.MCAST_FLOOD_UNREGISTERED: value} return params - def create_network(self, network): + def create_network(self, context, network): # Create a logical switch with a name equal to the Neutron network # UUID. This provides an easy way to refer to the logical switch # without having to track what UUID OVN assigned to it. - admin_context = n_context.get_admin_context() lswitch_params = self._gen_network_parameters(network) lswitch_name = utils.ovn_name(network['id']) with self._nb_idl.transaction(check_error=True) as txn: @@ -1796,8 +1789,8 @@ class OVNClient(object): if physnet: self._create_provnet_port(txn, network, physnet, network.get(pnet.SEGMENTATION_ID)) - db_rev.bump_revision(admin_context, network, ovn_const.TYPE_NETWORKS) - self.create_metadata_port(admin_context, network) + db_rev.bump_revision(context, network, ovn_const.TYPE_NETWORKS) + self.create_metadata_port(context, network) return network def delete_network(self, context, network_id): @@ -1842,7 +1835,7 @@ class OVNClient(object): name=lrp_name, if_exists=True, options=options)) self._transaction(commands, txn=txn) - def update_network(self, network): + def update_network(self, context, network): lswitch_name = utils.ovn_name(network['id']) # Check if QoS needs to be update, before updating OVNDB qos_update_required = self._is_qos_update_required(network) @@ -1876,7 +1869,6 @@ class OVNClient(object): # =========================== # in the DNS row for this network. - admin_context = n_context.get_admin_context() with self._nb_idl.transaction(check_error=True) as txn: txn.add(check_rev_cmd) lswitch_params = self._gen_network_parameters(network) @@ -1890,18 +1882,19 @@ class OVNClient(object): ovn_const.OVN_NETWORK_MTU_EXT_ID_KEY) != str(network['mtu'])): subnets = self._plugin.get_subnets_by_network( - admin_context, network['id']) + context, network['id']) for subnet in subnets: - self.update_subnet(subnet, network, txn) + self.update_subnet(context, subnet, network, txn) if utils.is_provider_network(network): - self.set_gateway_mtu(admin_context, network, txn) + # make sure to use admin context as this is a providernet + self.set_gateway_mtu(n_context.get_admin_context(), + network, txn) if check_rev_cmd.result == ovn_const.TXN_COMMITTED: if qos_update_required: self._qos_driver.update_network(network) - db_rev.bump_revision( - admin_context, network, ovn_const.TYPE_NETWORKS) + db_rev.bump_revision(context, network, ovn_const.TYPE_NETWORKS) def _add_subnet_dhcp_options(self, subnet, network, ovn_dhcp_options=None): @@ -2142,13 +2135,12 @@ class OVNClient(object): txn.add(self._nb_idl.add_dhcp_options( subnet['id'], port_id=port_id, options=options)) - def create_subnet(self, subnet, network): - admin_context = n_context.get_admin_context() + def create_subnet(self, context, subnet, network): if subnet['enable_dhcp']: if subnet['ip_version'] == 4: - self.update_metadata_port(admin_context, network['id']) + self.update_metadata_port(context, network['id']) self._add_subnet_dhcp_options(subnet, network) - db_rev.bump_revision(admin_context, subnet, ovn_const.TYPE_SUBNETS) + db_rev.bump_revision(context, subnet, ovn_const.TYPE_SUBNETS) def _modify_subnet_dhcp_options(self, subnet, ovn_subnet, network, txn): if subnet['enable_dhcp'] and not ovn_subnet: @@ -2158,13 +2150,12 @@ class OVNClient(object): elif not subnet['enable_dhcp'] and ovn_subnet: self._remove_subnet_dhcp_options(subnet['id'], txn) - def update_subnet(self, subnet, network, txn=None): - admin_context = n_context.get_admin_context() + def update_subnet(self, context, subnet, network, txn=None): ovn_subnet = self._nb_idl.get_subnet_dhcp_options( subnet['id'])['subnet'] if subnet['enable_dhcp'] or ovn_subnet: - self.update_metadata_port(admin_context, network['id']) + self.update_metadata_port(context, network['id']) check_rev_cmd = self._nb_idl.check_revision_number( subnet['id'], subnet, ovn_const.TYPE_SUBNETS) @@ -2176,21 +2167,19 @@ class OVNClient(object): else: self._modify_subnet_dhcp_options(subnet, ovn_subnet, network, txn) if check_rev_cmd.result == ovn_const.TXN_COMMITTED: - db_rev.bump_revision(admin_context, subnet, ovn_const.TYPE_SUBNETS) + db_rev.bump_revision(context, subnet, ovn_const.TYPE_SUBNETS) - def delete_subnet(self, subnet_id): - admin_context = n_context.get_admin_context() + def delete_subnet(self, context, subnet_id): with self._nb_idl.transaction(check_error=True) as txn: self._remove_subnet_dhcp_options(subnet_id, txn) db_rev.delete_revision( - admin_context, subnet_id, ovn_const.TYPE_SUBNETS) + context, subnet_id, ovn_const.TYPE_SUBNETS) - def create_security_group(self, security_group): + def create_security_group(self, context, security_group): # If the OVN schema supports Port Groups, we'll model security groups # as such. Otherwise, for backwards compatibility, we'll keep creating # two Address Sets for each Neutron SG (one for IPv4 and one for # IPv6). - admin_context = n_context.get_admin_context() with self._nb_idl.transaction(check_error=True) as txn: ext_ids = {ovn_const.OVN_SG_EXT_ID_KEY: security_group['id']} if self._nb_idl.is_port_groups_supported(): @@ -2208,7 +2197,7 @@ class OVNClient(object): txn.add(self._nb_idl.create_address_set( name=name, external_ids=ext_ids)) db_rev.bump_revision( - admin_context, security_group, ovn_const.TYPE_SECURITY_GROUPS) + context, security_group, ovn_const.TYPE_SECURITY_GROUPS) def create_default_drop_port_group(self, ports=None): pg_name = ovn_const.OVN_DROP_PORT_GROUP_NAME @@ -2255,11 +2244,10 @@ class OVNClient(object): self._plugin, admin_context, self._nb_idl, rule['security_group_id'], rule, is_add_acl=is_add_acl) - def create_security_group_rule(self, rule): - admin_context = n_context.get_admin_context() + def create_security_group_rule(self, context, rule): self._process_security_group_rule(rule) db_rev.bump_revision( - admin_context, rule, ovn_const.TYPE_SECURITY_GROUP_RULES) + context, rule, ovn_const.TYPE_SECURITY_GROUP_RULES) def delete_security_group_rule(self, context, rule): self._process_security_group_rule(rule, is_add_acl=False) diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py index 1fc4c90ccae..17c372f3f0b 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py @@ -103,7 +103,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer): # Create the port in OVN. This will include ACL and Address Set # updates as needed. - self._ovn_client.create_port(port) + self._ovn_client.create_port(ctx, port) def remove_common_acls(self, neutron_acls, nb_acls): """Take out common acls of the two acl dictionaries. @@ -610,7 +610,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer): LOG.warning("Creating the router %s in OVN NB DB", router['id']) self._ovn_client.create_router( - router, add_external_gateway=False) + ctx, router, add_external_gateway=False) if 'routes' in router: update_sroutes_list.append( {'id': router['id'], 'add': router['routes'], @@ -642,7 +642,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer): LOG.warning("Creating the router port %s in OVN NB DB", rrport['id']) self._ovn_client._create_lrouter_port( - rrport['device_id'], rrport) + ctx, rrport['device_id'], rrport) except RuntimeError: LOG.warning("Create router port in OVN " "NB failed for router port %s", rrport['id']) @@ -656,7 +656,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer): LOG.warning( "Updating networks on router port %s in OVN NB DB", rport['id']) - self._ovn_client.update_router_port(rport) + self._ovn_client.update_router_port(ctx, rport) except RuntimeError: LOG.warning("Update router port networks in OVN " "NB failed for router port %s", rport['id']) @@ -1000,7 +1000,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer): try: LOG.debug('Creating the network %s in OVN NB DB', network['id']) - self._ovn_client.create_network(network) + self._ovn_client.create_network(ctx, network) except RuntimeError: LOG.warning("Create network in OVN NB failed for " "network %s", network['id']) diff --git a/neutron/services/ovn_l3/plugin.py b/neutron/services/ovn_l3/plugin.py index e91d1230452..b291844b11f 100644 --- a/neutron/services/ovn_l3/plugin.py +++ b/neutron/services/ovn_l3/plugin.py @@ -128,7 +128,7 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase, def create_router(self, context, router): router = super(OVNL3RouterPlugin, self).create_router(context, router) try: - self._ovn_client.create_router(router) + self._ovn_client.create_router(context, router) except Exception: with excutils.save_and_reraise_exception(): # Delete the logical router @@ -142,7 +142,8 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase, result = super(OVNL3RouterPlugin, self).update_router(context, id, router) try: - self._ovn_client.update_router(result, original_router) + self._ovn_client.update_router(context, result, + original_router) except Exception: with excutils.save_and_reraise_exception(): LOG.exception('Unable to update lrouter for %s', id) @@ -192,7 +193,7 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase, context, router_id, interface_info, may_exist=may_exist) try: self._ovn_client.create_router_port( - router_id, router_interface_info) + context, router_id, router_interface_info) except Exception: with excutils.save_and_reraise_exception(): super(OVNL3RouterPlugin, self).remove_router_interface( @@ -402,4 +403,5 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase, # internally creates the port, and then calls update, which will # trigger this callback even before we had the chance to create # the OVN NB DB side - l3plugin._ovn_client.update_router_port(current, if_exists=True) + l3plugin._ovn_client.update_router_port(kwargs['context'], + current, if_exists=True) diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py index 914ba44766c..d7cd29b6a1f 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py @@ -79,6 +79,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): self.match_old_mac_dhcp_subnets = [] self.expected_dns_records = [] self.expected_ports_with_unknown_addr = [] + self.ctx = context.get_admin_context() ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', True, group='ovn') ovn_config.cfg.CONF.set_override( @@ -1208,14 +1209,14 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): _ovn_client = self.l3_plugin._ovn_client networks, _ = ( _ovn_client._get_nets_and_ipv6_ra_confs_for_router_port( - port_fixed_ips)) + self.ctx, port_fixed_ips)) return networks def _get_ipv6_ra_configs_for_router_port(port_fixed_ips): _ovn_client = self.l3_plugin._ovn_client networks, ipv6_ra_configs = ( _ovn_client._get_nets_and_ipv6_ra_confs_for_router_port( - port_fixed_ips)) + self.ctx, port_fixed_ips)) return ipv6_ra_configs for router_id in db_router_ids: diff --git a/neutron/tests/unit/fake_resources.py b/neutron/tests/unit/fake_resources.py index 1363fb3eb48..442d457e08b 100644 --- a/neutron/tests/unit/fake_resources.py +++ b/neutron/tests/unit/fake_resources.py @@ -310,6 +310,7 @@ class FakeSubnetContext(object): self.fake_subnet = subnet self.fake_original_subnet = original_subnet self.fake_network = FakeNetworkContext(network, None) + self._plugin_context = mock.MagicMock() @property def current(self): diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py index 0bd17a4f4a4..08af3436593 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py @@ -132,13 +132,13 @@ class TestDBInconsistenciesPeriodics(testlib_api.SqlTestCaseLight, # database if ovn_rev < 0: self.fake_ovn_client.create_network.assert_called_once_with( - self.net) + self.ctx, self.net) # If the revision number is > 0 it means that the object already # exist and we just need to update to match the latest in the # neutron database so, update_network() should be called. else: self.fake_ovn_client.update_network.assert_called_once_with( - self.net) + self.ctx, self.net) def test_fix_network_create(self): self._test_fix_create_update_network(ovn_rev=-1, neutron_rev=2) @@ -174,13 +174,13 @@ class TestDBInconsistenciesPeriodics(testlib_api.SqlTestCaseLight, # database if ovn_rev < 0: self.fake_ovn_client.create_port.assert_called_once_with( - self.port) + self.ctx, self.port) # If the revision number is > 0 it means that the object already # exist and we just need to update to match the latest in the # neutron database so, update_port() should be called. else: self.fake_ovn_client.update_port.assert_called_once_with( - self.port) + self.ctx, self.port) def test_fix_port_create(self): self._test_fix_create_update_port(ovn_rev=-1, neutron_rev=2) @@ -211,7 +211,7 @@ class TestDBInconsistenciesPeriodics(testlib_api.SqlTestCaseLight, if revision_number < 0: self.fake_ovn_client.create_security_group.assert_called_once_with( - sg) + self.ctx, sg) else: # If the object already exist let's make sure we just bump # the revision number in the ovn_revision_numbers table @@ -228,10 +228,10 @@ class TestDBInconsistenciesPeriodics(testlib_api.SqlTestCaseLight, def test__create_lrouter_port(self): port = {'id': 'port-id', 'device_id': 'router-id'} - self.periodic._create_lrouter_port(port) + self.periodic._create_lrouter_port(self.ctx, port) l3_mock = self.periodic._ovn_client._l3_plugin l3_mock.add_router_interface.assert_called_once_with( - mock.ANY, port['device_id'], {'port_id': port['id']}, + self.ctx, port['device_id'], {'port_id': port['id']}, may_exist=True) @mock.patch.object(maintenance.LOG, 'debug') diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py index 16116a34d09..a02f53b217b 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py @@ -595,7 +595,7 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase): self.assertEqual( len(create_network_list), ovn_nb_synchronizer._ovn_client.create_network.call_count) - create_network_calls = [mock.call(net['net']) + create_network_calls = [mock.call(mock.ANY, net['net']) for net in create_network_list] ovn_nb_synchronizer._ovn_client.create_network.assert_has_calls( create_network_calls, any_order=True) @@ -603,7 +603,8 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase): self.assertEqual( len(create_port_list), ovn_nb_synchronizer._ovn_client.create_port.call_count) - create_port_calls = [mock.call(port) for port in create_port_list] + create_port_calls = [mock.call(mock.ANY, port) + for port in create_port_list] ovn_nb_synchronizer._ovn_client.create_port.assert_has_calls( create_port_calls, any_order=True) @@ -677,7 +678,8 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase): len(del_floating_ip_list), ovn_nb_synchronizer._ovn_client._delete_floatingip.call_count) - create_router_calls = [mock.call(r, add_external_gateway=False) + create_router_calls = [mock.call(mock.ANY, r, + add_external_gateway=False) for r in create_router_list] self.assertEqual( len(create_router_list), @@ -685,7 +687,7 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase): ovn_nb_synchronizer._ovn_client.create_router.assert_has_calls( create_router_calls, any_order=True) - create_router_port_calls = [mock.call(p['device_id'], + create_router_port_calls = [mock.call(mock.ANY, p['device_id'], mock.ANY) for p in create_router_port_list] self.assertEqual( @@ -697,7 +699,7 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase): self.assertEqual(len(del_router_list), ovn_api.delete_lrouter.call_count) - update_router_port_calls = [mock.call(p) + update_router_port_calls = [mock.call(mock.ANY, p) for p in update_router_port_list] self.assertEqual( len(update_router_port_list), diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py index 4b86972d3a5..2759a3c8162 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py @@ -111,7 +111,7 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase): def test__create_security_group(self, mock_bump): self.mech_driver._create_security_group( resources.SECURITY_GROUP, events.AFTER_CREATE, {}, - security_group=self.fake_sg) + security_group=self.fake_sg, context=self.context) external_ids = {ovn_const.OVN_SG_EXT_ID_KEY: self.fake_sg['id']} ip4_name = ovn_utils.ovn_addrset_name(self.fake_sg['id'], 'ip4') ip6_name = ovn_utils.ovn_addrset_name(self.fake_sg['id'], 'ip6') @@ -143,7 +143,7 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase): rule = {'security_group_id': 'sg_id'} self.mech_driver._process_sg_rule_notification( resources.SECURITY_GROUP_RULE, events.AFTER_CREATE, {}, - security_group_rule=rule) + security_group_rule=rule, context=self.context) ovn_acl_up.assert_called_once_with( mock.ANY, mock.ANY, mock.ANY, 'sg_id', rule, is_add_acl=True) @@ -1492,7 +1492,7 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase): self.mech_driver.create_port_postcommit(fake_ctx) passed_fake_port = copy.deepcopy(fake_port) passed_fake_port['network'] = fake_ctx.network.current - mock_create_port.assert_called_once_with(passed_fake_port) + mock_create_port.assert_called_once_with(mock.ANY, passed_fake_port) mock_notify_dhcp.assert_called_once_with(fake_port['id']) @mock.patch.object(mech_driver.OVNMechanismDriver, @@ -1512,32 +1512,31 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase): passed_fake_port_orig['network'] = fake_ctx.network.current mock_update_port.assert_called_once_with( - passed_fake_port, port_object=passed_fake_port_orig) + mock.ANY, passed_fake_port, port_object=passed_fake_port_orig) mock_notify_dhcp.assert_called_once_with(fake_port['id']) @mock.patch.object(mech_driver.OVNMechanismDriver, '_is_port_provisioning_required', lambda *_: True) @mock.patch.object(mech_driver.OVNMechanismDriver, '_notify_dhcp_updated') @mock.patch.object(ovn_client.OVNClient, 'update_port') - @mock.patch.object(context, 'get_admin_context') def test_update_port_postcommit_live_migration( - self, mock_admin_context, mock_update_port, mock_notify_dhcp): + self, mock_update_port, mock_notify_dhcp): self.plugin.update_port_status = mock.Mock() - foo_admin_context = mock.Mock() - mock_admin_context.return_value = foo_admin_context + fake_context = 'fake_context' fake_port = fakes.FakePort.create_one_port( attrs={ 'status': const.PORT_STATUS_DOWN, portbindings.PROFILE: {ovn_const.MIGRATING_ATTR: 'foo'}, portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info() - fake_ctx = mock.Mock(current=fake_port, original=fake_port) + fake_ctx = mock.Mock(current=fake_port, original=fake_port, + _plugin_context=fake_context) self.mech_driver.update_port_postcommit(fake_ctx) mock_update_port.assert_not_called() mock_notify_dhcp.assert_not_called() self.plugin.update_port_status.assert_called_once_with( - foo_admin_context, fake_port['id'], const.PORT_STATUS_ACTIVE) + fake_context, fake_port['id'], const.PORT_STATUS_ACTIVE) def _add_chassis_agent(self, nb_cfg, agent_type, updated_at=None): chassis = mock.Mock() @@ -1630,7 +1629,7 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase): device_owner=const.DEVICE_OWNER_ROUTER_GW) as port: # Let's update the MTU to something different network['network']['mtu'] = new_mtu - fake_ctx = mock.Mock(current=network['network']) + fake_ctx = mock.MagicMock(current=network['network']) fake_ctx._plugin_context.session.is_active = False self.mech_driver.update_network_postcommit(fake_ctx) diff --git a/neutron/tests/unit/services/ovn_l3/test_plugin.py b/neutron/tests/unit/services/ovn_l3/test_plugin.py index ed5030f823a..f2e0fdf63a6 100644 --- a/neutron/tests/unit/services/ovn_l3/test_plugin.py +++ b/neutron/tests/unit/services/ovn_l3/test_plugin.py @@ -300,7 +300,7 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): 'router-port-id', 'lrp-router-port-id', is_gw_port=False, lsp_address=ovn_const.DEFAULT_ADDR_FOR_LSP_WITH_PEER) self.bump_rev_p.assert_called_once_with( - self.admin_context, self.fake_router_port, + mock.ANY, self.fake_router_port, ovn_const.TYPE_ROUTER_PORTS) @mock.patch('neutron.db.l3_db.L3_NAT_dbonly_mixin.add_router_interface') @@ -526,9 +526,9 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): lsp_address=ovn_const.DEFAULT_ADDR_FOR_LSP_WITH_PEER) self.l3_inst._ovn.add_static_route.assert_has_calls(expected_calls) - bump_rev_calls = [mock.call(self.admin_context, self.fake_ext_gw_port, + bump_rev_calls = [mock.call(mock.ANY, self.fake_ext_gw_port, ovn_const.TYPE_ROUTER_PORTS), - mock.call(self.admin_context, + mock.call(mock.ANY, self.fake_router_with_ext_gw, ovn_const.TYPE_ROUTERS), ] @@ -577,7 +577,7 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): 'neutron-router-id', logical_ip='10.0.0.0/24', external_ip='192.168.1.1', type='snat') self.bump_rev_p.assert_called_with( - self.admin_context, self.fake_router_port, + mock.ANY, self.fake_router_port, ovn_const.TYPE_ROUTER_PORTS) @mock.patch('neutron.db.db_base_plugin_v2.NeutronDbPluginV2.get_port') @@ -648,7 +648,7 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): external_ip='192.168.1.1', type='snat') self.bump_rev_p.assert_called_with( - self.admin_context, self.fake_router_port, + mock.ANY, self.fake_router_port, ovn_const.TYPE_ROUTER_PORTS) @mock.patch('neutron.db.db_base_plugin_v2.NeutronDbPluginV2.get_port') @@ -705,7 +705,7 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): 'neutron-router-id', type='snat', logical_ip='10.0.0.0/24', external_ip='192.168.1.1') self.bump_rev_p.assert_called_with( - self.admin_context, self.fake_ext_gw_port, + mock.ANY, self.fake_ext_gw_port, ovn_const.TYPE_ROUTER_PORTS) @mock.patch.object(utils, 'get_lrouter_ext_gw_static_route') @@ -763,10 +763,10 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): external_ip='192.168.1.1') self.bump_rev_p.assert_called_with( - self.admin_context, self.fake_ext_gw_port, + mock.ANY, self.fake_ext_gw_port, ovn_const.TYPE_ROUTER_PORTS) self.del_rev_p.assert_called_once_with( - self.admin_context, 'old-gw-port-id', ovn_const.TYPE_ROUTER_PORTS) + mock.ANY, 'old-gw-port-id', ovn_const.TYPE_ROUTER_PORTS) @mock.patch.object(utils, 'get_lrouter_ext_gw_static_route') @mock.patch('neutron.db.db_base_plugin_v2.NeutronDbPluginV2.get_port') @@ -1387,16 +1387,20 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): @mock.patch('neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb.' 'ovn_client.OVNClient.update_router_port') def test_port_update_postcommit(self, update_rp_mock): - kwargs = {'port': {'device_owner': 'foo'}} + kwargs = {'port': {'device_owner': 'foo'}, + 'context': 'fake_context'} self.l3_inst._port_update(resources.PORT, events.AFTER_UPDATE, None, **kwargs) update_rp_mock.assert_not_called() - kwargs = {'port': {'device_owner': constants.DEVICE_OWNER_ROUTER_INTF}} + kwargs = {'port': {'device_owner': constants.DEVICE_OWNER_ROUTER_INTF}, + 'context': 'fake_context'} self.l3_inst._port_update(resources.PORT, events.AFTER_UPDATE, None, **kwargs) - update_rp_mock.assert_called_once_with(kwargs['port'], if_exists=True) + update_rp_mock.assert_called_once_with(kwargs['context'], + kwargs['port'], + if_exists=True) @mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.update_port_status') @mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.update_port') @@ -1535,7 +1539,7 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): external_ip='192.168.1.1', type='snat') self.bump_rev_p.assert_called_with( - self.admin_context, self.fake_router_port, + mock.ANY, self.fake_router_port, ovn_const.TYPE_ROUTER_PORTS)