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