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 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
2019-06-14 23:34:00 +03:00
from virtinst import buildconfig
2019-12-12 01:34:03 +03:00
from virtinst import log , reset_logging
2013-10-03 02:42:51 +04:00
# This sets all the cli bits back to their defaults
2019-06-14 23:34:00 +03:00
imp . reload ( buildconfig )
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
virtxml = None
2013-03-18 01:06:52 +04:00
2018-02-22 21:46:24 +03:00
def setup_logging ( ) :
2019-06-17 04:12:39 +03:00
import logging
2019-12-12 01:34:03 +03:00
reset_logging ( )
2013-08-06 22:58:43 +04:00
2019-07-16 23:36:31 +03:00
fmt = " %(levelname)-8s %(message)s "
streamHandler = logging . StreamHandler ( )
streamHandler . setFormatter ( logging . Formatter ( fmt ) )
2018-02-22 21:46:24 +03:00
if utils . clistate . debug :
2019-07-16 23:36:31 +03:00
streamHandler . setLevel ( logging . DEBUG )
2017-02-24 02:47:57 +03:00
else :
2019-07-16 23:36:31 +03:00
streamHandler . setLevel ( logging . ERROR )
log . addHandler ( streamHandler )
log . setLevel ( logging . DEBUG )
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 virtxml
atexit . register ( _cleanup_imports_cb )
virtinstall = _import ( " virtinstall " , " virt-install " )
virtclone = _import ( " virtclone " , " virt-clone " )
virtxml = _import ( " virtxml " , " virt-xml " )