2014-01-21 00:09:13 +08:00
|
|
|
# Copyright (C) 2013, 2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2013-10-28 04:59:47 +08:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
|
2013-08-07 02:58:43 +08:00
|
|
|
import atexit
|
|
|
|
import imp
|
2013-03-18 05:06:52 +08:00
|
|
|
import logging
|
|
|
|
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"
|
2014-03-07 01:35:01 +08:00
|
|
|
os.environ["VIRTINST_TEST_URL_DIR"] = os.path.abspath(
|
|
|
|
"tests/cli-test-xml/fakefedoratree/")
|
2013-07-13 03:16:29 +08:00
|
|
|
|
2016-04-19 04:42:12 +08:00
|
|
|
# pylint: disable=wrong-import-position
|
2013-07-17 14:14:34 +08:00
|
|
|
from virtcli import cliconfig
|
2013-10-03 06:42:51 +08:00
|
|
|
# This sets all the cli bits back to their defaults
|
2017-10-11 19:35:56 +08:00
|
|
|
imp.reload(cliconfig)
|
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
|
|
|
|
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
def _setup_logging():
|
|
|
|
rootLogger = logging.getLogger()
|
|
|
|
for handler in rootLogger.handlers:
|
|
|
|
rootLogger.removeHandler(handler)
|
2013-08-07 02:58:43 +08:00
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
|
|
format="%(levelname)-8s %(message)s")
|
2013-08-07 02:58:43 +08:00
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
if utils.get_debug():
|
|
|
|
rootLogger.setLevel(logging.DEBUG)
|
|
|
|
else:
|
|
|
|
rootLogger.setLevel(logging.ERROR)
|
2013-08-07 02:58:43 +08:00
|
|
|
|
|
|
|
|
2017-02-24 07:47:57 +08:00
|
|
|
def _setup_cli_imports():
|
|
|
|
_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")
|
|
|
|
|
|
|
|
|
|
|
|
_setup_logging()
|
|
|
|
_setup_cli_imports()
|