Fix retry logic logging

logging has a method debug, and a static variable DEBUG, which are entirely
different. Tenacity requires the integer value which is passed in for logging
actions.

This is rooted in the examples published on tenacity logging, since the lower
level caller doesn't log in many cases, and our testing didn't catch this precise
case because we were only validating that logging was called, not that logging
worked. We also didn't see any of the errors related to CI resource
contention being lessened when the patch was running, and many of the chances
of lock conflicts being reduced in other fixes.

Duplicates the retry test *without* the logging mock, as not mocking the logging
would have yielded the break.

Change-Id: I4a65a044e90aff3cffae24f191e425bc75b5fb74
This commit is contained in:
Julia Kreger 2023-07-20 11:01:00 -07:00
parent ef73871524
commit 2d8986bda4
2 changed files with 21 additions and 1 deletions

View File

@ -85,7 +85,7 @@ def wrap_sqlite_retry(f):
multiplier=0.25,
max=CONF.database.sqlite_max_wait_for_retry),
before_sleep=(
tenacity.before_sleep_log(LOG, logging.debug)
tenacity.before_sleep_log(LOG, logging.DEBUG)
),
reraise=True):
with attempt:

View File

@ -879,6 +879,26 @@ class DbNodeTestCase(base.DbTestCase):
self.assertEqual(3, mock_update.call_count)
self.assertEqual(2, log_mock.log.call_count)
def test_update_node_retries_without_log_mock(self):
"""Test retry logic to ensure it works."""
node = utils.create_test_node()
CONF.set_override('sqlite_retries', True, group='database')
# NOTE(TheJulia): Update is an ideal place to test retries
# as the underlying work is done by _do_update_node.
with mock.patch.object(db_conn, '_do_update_node',
autospec=True) as mock_update:
sa_err = sa_exc.OperationalError(
statement=None,
params=None,
orig=Exception('database is locked'))
mock_update.side_effect = [
sa_err,
sa_err,
node
]
self.dbapi.update_node(node.id, {'extra': {'foo': 'bar'}})
self.assertEqual(3, mock_update.call_count)
def test_update_node_uuid(self):
node = utils.create_test_node()
self.assertRaises(exception.InvalidParameterValue,