Merge "[OVN] Pass context while removing objects in OVN client"

This commit is contained in:
Zuul 2020-01-22 01:28:15 +00:00 committed by Gerrit Code Review
commit 1c792633ec
4 changed files with 18 additions and 17 deletions

View File

@ -267,7 +267,8 @@ class OVNMechanismDriver(api.MechanismDriver):
def _delete_security_group(self, resource, event, trigger,
security_group_id, **kwargs):
self._ovn_client.delete_security_group(security_group_id)
self._ovn_client.delete_security_group(kwargs['context'],
security_group_id)
def _update_security_group(self, resource, event, trigger,
security_group, **kwargs):
@ -289,10 +290,11 @@ class OVNMechanismDriver(api.MechanismDriver):
self._ovn_client.create_security_group_rule(
kwargs.get('security_group_rule'))
elif event == events.BEFORE_DELETE:
admin_context = n_context.get_admin_context()
sg_rule = self._plugin.get_security_group_rule(
admin_context, kwargs.get('security_group_rule_id'))
self._ovn_client.delete_security_group_rule(sg_rule)
kwargs['context'], kwargs.get('security_group_rule_id'))
self._ovn_client.delete_security_group_rule(
kwargs['context'],
sg_rule)
def _is_network_type_supported(self, network_type):
return (network_type in [const.TYPE_LOCAL,
@ -398,7 +400,9 @@ class OVNMechanismDriver(api.MechanismDriver):
expected, and will not prevent the resource from being
deleted.
"""
self._ovn_client.delete_network(context.current['id'])
self._ovn_client.delete_network(
context._plugin_context,
context.current['id'])
def create_subnet_precommit(self, context):
ovn_revision_numbers_db.create_initial_revision(

View File

@ -189,7 +189,7 @@ class DBInconsistenciesPeriodics(object):
revision_numbers_db.delete_revision(
context, row.resource_uuid, row.resource_type)
else:
res_map['ovn_delete'](row.resource_uuid)
res_map['ovn_delete'](context, row.resource_uuid)
def _fix_create_update_subnet(self, context, row):
# Get the lasted version of the port in Neutron DB

View File

@ -1609,8 +1609,7 @@ class OVNClient(object):
self.create_metadata_port(admin_context, network)
return network
def delete_network(self, network_id):
admin_context = n_context.get_admin_context()
def delete_network(self, context, network_id):
with self._nb_idl.transaction(check_error=True) as txn:
ls, ls_dns_record = self._nb_idl.get_ls_and_dns_record(
utils.ovn_name(network_id))
@ -1620,7 +1619,7 @@ class OVNClient(object):
if ls_dns_record:
txn.add(self._nb_idl.dns_del(ls_dns_record.uuid))
db_rev.delete_revision(
admin_context, network_id, ovn_const.TYPE_NETWORKS)
context, network_id, ovn_const.TYPE_NETWORKS)
def _is_qos_update_required(self, network):
# Is qos service enabled
@ -2045,8 +2044,7 @@ class OVNClient(object):
if self._nb_idl.get_port_group(pg_name):
txn.add(self._nb_idl.pg_del_ports(pg_name, port))
def delete_security_group(self, security_group_id):
admin_context = n_context.get_admin_context()
def delete_security_group(self, context, security_group_id):
with self._nb_idl.transaction(check_error=True) as txn:
if self._nb_idl.is_port_groups_supported():
name = utils.ovn_port_group_name(security_group_id)
@ -2056,7 +2054,7 @@ class OVNClient(object):
name = utils.ovn_addrset_name(security_group_id,
ip_version)
txn.add(self._nb_idl.delete_address_set(name=name))
db_rev.delete_revision(admin_context, security_group_id,
db_rev.delete_revision(context, security_group_id,
ovn_const.TYPE_SECURITY_GROUPS)
def _process_security_group_rule(self, rule, is_add_acl=True):
@ -2071,11 +2069,10 @@ class OVNClient(object):
db_rev.bump_revision(
admin_context, rule, ovn_const.TYPE_SECURITY_GROUP_RULES)
def delete_security_group_rule(self, rule):
admin_context = n_context.get_admin_context()
def delete_security_group_rule(self, context, rule):
self._process_security_group_rule(rule, is_add_acl=False)
db_rev.delete_revision(
admin_context, rule['id'], ovn_const.TYPE_SECURITY_GROUP_RULES)
context, rule['id'], ovn_const.TYPE_SECURITY_GROUP_RULES)
def _find_metadata_port(self, context, network_id):
if not ovn_conf.is_ovn_metadata_enabled():

View File

@ -127,7 +127,7 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase):
def test__delete_security_group(self):
self.mech_driver._delete_security_group(
resources.SECURITY_GROUP, events.AFTER_CREATE, {},
security_group_id=self.fake_sg['id'])
security_group_id=self.fake_sg['id'], context=self.context)
ip4_name = ovn_utils.ovn_addrset_name(self.fake_sg['id'], 'ip4')
ip6_name = ovn_utils.ovn_addrset_name(self.fake_sg['id'], 'ip6')
delete_address_set_calls = [mock.call(name=name)
@ -160,7 +160,7 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase):
return_value=rule):
self.mech_driver._process_sg_rule_notification(
resources.SECURITY_GROUP_RULE, events.BEFORE_DELETE, {},
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=False)