tests: abide logging options for clitests

We need to restore logging after calling the cli tools. Centralize
the logging reset behavior since we need that too

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2019-12-11 17:34:03 -05:00
parent 39366c37f6
commit 78ad233653
5 changed files with 21 additions and 14 deletions

View File

@ -14,7 +14,7 @@ os.environ.pop("_ARC_DEBUG", None)
# pylint: disable=wrong-import-position # pylint: disable=wrong-import-position
from virtinst import buildconfig from virtinst import buildconfig
from virtinst import log from virtinst import log, reset_logging
# This sets all the cli bits back to their defaults # This sets all the cli bits back to their defaults
imp.reload(buildconfig) imp.reload(buildconfig)
@ -28,9 +28,7 @@ virtxml = None
def setup_logging(): def setup_logging():
import logging import logging
rootLogger = logging.getLogger() reset_logging()
for handler in rootLogger.handlers:
rootLogger.removeHandler(handler)
fmt = "%(levelname)-8s %(message)s" fmt = "%(levelname)-8s %(message)s"
streamHandler = logging.StreamHandler() streamHandler = logging.StreamHandler()

View File

@ -21,6 +21,7 @@ from virtinst import log
from virtinst import OSDB from virtinst import OSDB
from virtinst.install import unattended from virtinst.install import unattended
from tests import setup_logging
from tests import virtinstall, virtclone, virtconvert, virtxml from tests import virtinstall, virtclone, virtconvert, virtxml
from tests import utils from tests import utils
@ -244,6 +245,8 @@ class Command(object):
sys.argv = oldargv sys.argv = oldargv
if oldenv: if oldenv:
os.environ = oldenv os.environ = oldenv
# Reset logging
setup_logging()
def _get_output(self, conn): def _get_output(self, conn):

View File

@ -65,4 +65,4 @@ from virtinst.snapshot import DomainSnapshot
from virtinst.connection import VirtinstConnection from virtinst.connection import VirtinstConnection
from virtinst.logger import log from virtinst.logger import log, reset_logging

View File

@ -23,7 +23,7 @@ from .buildconfig import BuildConfig
from .connection import VirtinstConnection from .connection import VirtinstConnection
from .devices import (Device, DeviceController, DeviceDisk, DeviceGraphics, from .devices import (Device, DeviceController, DeviceDisk, DeviceGraphics,
DeviceInterface, DevicePanic) DeviceInterface, DevicePanic)
from .logger import log from .logger import log, reset_logging
from .nodedev import NodeDevice from .nodedev import NodeDevice
from .osdict import OSDB from .osdict import OSDB
from .storage import StoragePool, StorageVolume from .storage import StoragePool, StorageVolume
@ -119,6 +119,7 @@ def setupParser(usage, description, introspection_epilog=False):
def earlyLogging(): def earlyLogging():
reset_logging()
import logging import logging
logging.basicConfig(level=logging.DEBUG, format='%(message)s') logging.basicConfig(level=logging.DEBUG, format='%(message)s')
@ -159,14 +160,7 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True):
import logging import logging
import logging.handlers import logging.handlers
rootLogger = logging.getLogger() reset_logging()
# Undo early logging
for handler in rootLogger.handlers:
rootLogger.removeHandler(handler)
# Undo any logging on our log handler. Needed for test suite
for handler in log.handlers:
log.removeHandler(handler)
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
if logfile: if logfile:

View File

@ -7,3 +7,15 @@ import logging
# This is exported by virtinst/__init__.py # This is exported by virtinst/__init__.py
log = logging.getLogger("virtinst") log = logging.getLogger("virtinst")
def reset_logging():
rootLogger = logging.getLogger()
# Undo early logging
for handler in rootLogger.handlers:
rootLogger.removeHandler(handler)
# Undo any logging on our log handler. Needed for test suite
for handler in log.handlers:
log.removeHandler(handler)