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