2014-01-21 00:09:13 +08:00
|
|
|
# Copyright (C) 2013, 2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-08-07 02:58:43 +08:00
|
|
|
import atexit
|
|
|
|
import imp
|
2013-03-18 05:06:52 +08:00
|
|
|
import os
|
2013-03-18 06:18:22 +08:00
|
|
|
|
2016-04-19 04:42:12 +08:00
|
|
|
# Need to do this before any tests or virtinst import
|
2013-10-03 06:42:51 +08:00
|
|
|
os.environ["VIRTINST_TEST_SUITE"] = "1"
|
2019-05-16 01:06:29 +08:00
|
|
|
# Need to do this before we import argcomplete
|
|
|
|
os.environ.pop("_ARC_DEBUG", None)
|
2013-07-13 03:16:29 +08:00
|
|
|
|
2016-04-19 04:42:12 +08:00
|
|
|
# pylint: disable=wrong-import-position
|
2019-06-15 04:34:00 +08:00
|
|
|
from virtinst import buildconfig
|
2019-06-17 09:12:39 +08:00
|
|
|
from virtinst import log
|
2013-10-03 06:42:51 +08:00
|
|
|
# This sets all the cli bits back to their defaults
|
2019-06-15 04:34:00 +08:00
|
|
|
imp.reload(buildconfig)
|
2013-07-17 14:14:34 +08:00
|
|
|
|
2013-03-18 06:18:22 +08:00
|
|
|
from tests import utils
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
virtinstall = None
|
|
|
|
virtclone = None
|
|
|
|
virtconvert = None
|
|
|
|
virtxml = None
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2018-02-23 02:46:24 +08:00
|
|
|
def setup_logging():
|
2019-06-17 09:12:39 +08:00
|
|
|
import logging
|
2017-02-24 07:47:57 +08:00
|
|
|
rootLogger = logging.getLogger()
|
|
|
|
for handler in rootLogger.handlers:
|
|
|
|
rootLogger.removeHandler(handler)
|
2013-08-07 02:58:43 +08:00
|
|
|
|
2019-07-17 04:36:31 +08:00
|
|
|
fmt = "%(levelname)-8s %(message)s"
|
|
|
|
streamHandler = logging.StreamHandler()
|
|
|
|
streamHandler.setFormatter(logging.Formatter(fmt))
|
2018-02-23 02:46:24 +08:00
|
|
|
if utils.clistate.debug:
|
2019-07-17 04:36:31 +08:00
|
|
|
streamHandler.setLevel(logging.DEBUG)
|
2017-02-24 07:47:57 +08:00
|
|
|
else:
|
2019-07-17 04:36:31 +08:00
|
|
|
streamHandler.setLevel(logging.ERROR)
|
|
|
|
log.addHandler(streamHandler)
|
|
|
|
log.setLevel(logging.DEBUG)
|
2013-08-07 02:58:43 +08:00
|
|
|
|
|
|
|
|
2018-02-23 02:46:24 +08:00
|
|
|
def setup_cli_imports():
|
2017-02-24 07:47:57 +08:00
|
|
|
_cleanup_imports = []
|
2013-08-07 02:58:43 +08:00
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
def _cleanup_imports_cb():
|
|
|
|
for f in _cleanup_imports:
|
|
|
|
if os.path.exists(f):
|
|
|
|
os.unlink(f)
|
2013-08-07 02:58:43 +08:00
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
def _import(name, path):
|
|
|
|
_cleanup_imports.append(path + "c")
|
|
|
|
return imp.load_source(name, path)
|
2013-09-27 06:32:50 +08:00
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
global virtinstall
|
|
|
|
global virtclone
|
|
|
|
global virtconvert
|
|
|
|
global virtxml
|
|
|
|
atexit.register(_cleanup_imports_cb)
|
|
|
|
virtinstall = _import("virtinstall", "virt-install")
|
|
|
|
virtclone = _import("virtclone", "virt-clone")
|
|
|
|
virtconvert = _import("virtconvert", "virt-convert")
|
|
|
|
virtxml = _import("virtxml", "virt-xml")
|