Skip to content

Commit

Permalink
network: debug syncutil
Browse files Browse the repository at this point in the history
It would be helpful to have debug messages from syncutil directly in
pytest.log

Change-Id: I8e215b261b6284dbe5dcf2a24291d0641e8d7679
Signed-off-by: Eitan Raviv <eraviv@redhat.com>
  • Loading branch information
erav committed Jan 5, 2022
1 parent de724f8 commit 5e628e8
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion network-suite-master/ovirtlib/syncutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
#
import collections
import logging
import os
import time

Expand Down Expand Up @@ -71,17 +72,22 @@ def sync(
end_time = _monothonic_time() + timeout

args, kwargs = _parse_args(exec_func_args)

logger = SyncLogger(exec_func, args, kwargs)
logger.log_start()
try:
time.sleep(delay_start)
_audit(exec_func, sdk_entity, 0)
result = exec_func(*args, **kwargs)
logger.log_iteration(0, result)
except Exception as e:
logger.log_iteration(0, e)
if error_criteria(e):
logger.log_end()
raise
result = e
else:
if success_criteria(result):
logger.log_end()
return result

i = 0
Expand All @@ -91,16 +97,22 @@ def sync(
try:
_audit(exec_func, sdk_entity, i)
result = exec_func(*args, **kwargs)
logger.log_iteration(i, result)
except Exception as e:
logger.log_iteration(i, e)
if success_criteria(e):
logger.log_end()
return e
if error_criteria(e):
logger.log_end()
raise
result = e
else:
if success_criteria(result):
logger.log_end()
return result

logger.log_end()
raise Timeout(result)


Expand Down Expand Up @@ -140,3 +152,25 @@ def _parse_args(exec_func_args):

def _monothonic_time():
return os.times()[4]


class SyncLogger:
def __init__(self, exec_func, args, kwargs):
self._func = exec_func
self._args = args
self._kwargs = kwargs
self._logger = logging.getLogger(__name__)

def log_start(self):
self._debug('start')

def log_end(self):
self._debug('end')

def log_iteration(self, iteration, output):
self._debug(f'iteration {iteration} output: {output}')

def _debug(self, phase):
self._logger.debug(
f'sync {phase} for: {self._func}, {self._args}, {self._kwargs}'
)

0 comments on commit 5e628e8

Please sign in to comment.