Merge "[OVN] Prevent maintenance task fail resource stdattr does not exist"

This commit is contained in:
Zuul 2022-11-28 18:45:40 +00:00 committed by Gerrit Code Review
commit a3ab117944
4 changed files with 43 additions and 34 deletions

View File

@ -165,16 +165,10 @@ def get_revision_row(context, resource_uuid):
def bump_revision(context, resource, resource_type):
revision_number = ovn_utils.get_revision_number(resource, resource_type)
with db_api.CONTEXT_WRITER.using(context):
# NOTE(ralonsoh): "resource" could be a dict or an OVO.
try:
std_attr_id = resource.db_obj.standard_attr.id
except AttributeError:
std_attr_id = resource.get('standard_attr_id', None)
std_attr_id = _get_standard_attr_id(context, resource['id'],
resource_type)
_ensure_revision_row_exist(context, resource, resource_type,
std_attr_id)
std_attr_id = (std_attr_id or
_get_standard_attr_id(context, resource['id'],
resource_type))
row = context.session.merge(ovn_models.OVNRevisionNumbers(
standard_attr_id=std_attr_id, resource_uuid=resource['id'],
resource_type=resource_type))

View File

@ -228,34 +228,37 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase):
return
ovn_obj = res_map['ovn_get'](row.resource_uuid)
if not ovn_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 "
"this resource doesn't support updates",
row.resource_uuid)
elif row.resource_type == ovn_const.TYPE_SECURITY_GROUPS:
# In OVN, we don't care about updates to security groups,
# so just bump the revision number to whatever it's
# supposed to be.
revision_numbers_db.bump_revision(context, n_obj,
row.resource_type)
try:
if not ovn_obj:
res_map['ovn_create'](context, n_obj)
else:
ext_ids = getattr(ovn_obj, 'external_ids', {})
ovn_revision = int(ext_ids.get(
ovn_const.OVN_REV_NUM_EXT_ID_KEY, -1))
# 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'](context, n_obj)
else:
# If the resource exist and the revision number
# is equal on both databases just bump the revision on
# the cache table.
if row.resource_type == ovn_const.TYPE_SECURITY_GROUP_RULES:
LOG.error("SG rule %s found with a revision number while "
"this resource doesn't support updates",
row.resource_uuid)
elif row.resource_type == ovn_const.TYPE_SECURITY_GROUPS:
# In OVN, we don't care about updates to security groups,
# so just bump the revision number to whatever it's
# supposed to be.
revision_numbers_db.bump_revision(context, n_obj,
row.resource_type)
else:
ext_ids = getattr(ovn_obj, 'external_ids', {})
ovn_revision = int(ext_ids.get(
ovn_const.OVN_REV_NUM_EXT_ID_KEY, -1))
# 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'](context, n_obj)
else:
# If the resource exist and the revision number
# is equal on both databases just bump the revision on
# the cache table.
revision_numbers_db.bump_revision(context, n_obj,
row.resource_type)
except revision_numbers_db.StandardAttributeIDNotFound:
LOG.error('Standard attribute ID not found for object ID %s',
n_obj['id'])
def _fix_delete(self, context, row):
res_map = self._resources_func_map[row.resource_type]

View File

@ -491,7 +491,7 @@ class FakePort(object):
fake_uuid = uuidutils.generate_uuid()
port_attrs = {
'admin_state_up': True,
'allowed_address_pairs': [{}],
'allowed_address_pairs': [],
'binding:host_id': 'binding-host-id-' + fake_uuid,
'binding:profile': {},
'binding:vif_details': {},

View File

@ -24,6 +24,7 @@ from oslo_utils import uuidutils
from neutron.common.ovn import constants
from neutron.common.ovn import utils
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
from neutron.db.models import ovn as ovn_models
from neutron.db import ovn_revision_numbers_db
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import maintenance
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovn_db_sync
@ -295,6 +296,17 @@ class TestDBInconsistenciesPeriodics(testlib_api.SqlTestCaseLight,
def test_fix_security_group_create_version_mismatch(self):
self._test_fix_security_group_create(revision_number=2)
@mock.patch.object(maintenance, 'LOG')
def test__fix_create_update_no_sttd_attr(self, mock_log):
row_net = ovn_models.OVNRevisionNumbers(
standard_attr_id=1, resource_uuid=2,
resource_type=constants.TYPE_NETWORKS)
self.fake_ovn_client._plugin.get_network.return_value = {
'id': 'net_id', 'revision_number': 1}
self.periodic._fix_create_update(self.ctx, row_net)
mock_log.error.assert_called_once_with(
'Standard attribute ID not found for object ID %s', 'net_id')
def test__create_lrouter_port(self):
port = {'id': 'port-id',
'device_id': 'router-id'}