def run(self, args): log = logging.getLogger("avocado.app") log.info('Config files read (in order):') for cfg_path in settings.config_paths: log.debug(' %s' % cfg_path) if settings.config_paths_failed: log.error('\nConfig files that failed to read:') for cfg_path in settings.config_paths_failed: log.error(' %s' % cfg_path) log.debug("") if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" log.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) log.debug(format_str, config_key, value[1]) else: log.debug("Avocado replaces config dirs that can't be accessed") log.debug("with sensible defaults. Please edit your local config") log.debug("file to customize values") log.debug('') log.info('Avocado Data Directories:') log.debug(' base ' + data_dir.get_base_dir()) log.debug(' tests ' + data_dir.get_test_dir()) log.debug(' data ' + data_dir.get_data_dir()) log.debug(' logs ' + data_dir.get_logs_dir())
def handle_default(): LOG_UI.info("Config files read (in order, '*' means the file exists " "and had been read):") # Getting from settings because is already sorted config = settings.as_dict() for cfg_path in settings.all_config_paths: if cfg_path in settings.config_paths: LOG_UI.debug(' * %s', cfg_path) else: LOG_UI.debug(' %s', cfg_path) LOG_UI.debug("") if not config.get('config.datadir'): blength = 0 for namespace, value in config.items(): clength = len(namespace) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for namespace, value in config.items(): LOG_UI.debug(format_str, namespace, value) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base %s', data_dir.get_base_dir()) LOG_UI.debug(' tests %s', data_dir.get_test_dir()) LOG_UI.debug(' data %s', data_dir.get_data_dir()) LOG_UI.debug(' logs %s', data_dir.get_logs_dir()) LOG_UI.debug(' cache %s', ", ".join(data_dir.get_cache_dirs()))
def run(self, args): LOG_UI.info('Config files read (in order):') for cfg_path in settings.config_paths: LOG_UI.debug(' %s' % cfg_path) if settings.config_paths_failed: LOG_UI.error('\nConfig files that failed to read:') for cfg_path in settings.config_paths_failed: LOG_UI.error(' %s' % cfg_path) LOG_UI.debug("") if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) LOG_UI.debug(format_str, config_key, value[1]) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base ' + data_dir.get_base_dir()) LOG_UI.debug(' tests ' + data_dir.get_test_dir()) LOG_UI.debug(' data ' + data_dir.get_data_dir()) LOG_UI.debug(' logs ' + data_dir.get_logs_dir()) LOG_UI.debug(' cache ' + ", ".join(data_dir.get_cache_dirs()))
def get_crash_dir(): crash_dir_path = os.path.join(data_dir.get_data_dir(), "crashes") try: os.makedirs(crash_dir_path) except OSError: pass return crash_dir_path
def run(self, config): LOG_UI.info("Config files read (in order, '*' means the file exists " "and had been read):") for cfg_path in settings.all_config_paths: if cfg_path in settings.config_paths: LOG_UI.debug(' * %s', cfg_path) else: LOG_UI.debug(' %s', cfg_path) LOG_UI.debug("") if not config.get("datadir"): blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) LOG_UI.debug(format_str, config_key, value[1]) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base %s', data_dir.get_base_dir()) LOG_UI.debug(' tests %s', data_dir.get_test_dir()) LOG_UI.debug(' data %s', data_dir.get_data_dir()) LOG_UI.debug(' logs %s', data_dir.get_logs_dir()) LOG_UI.debug(' cache %s', ", ".join(data_dir.get_cache_dirs()))
def run(self, args): LOG_UI.info("Config files read (in order, '*' means the file exists " "and had been read):") for cfg_path in settings.all_config_paths: if cfg_path in settings.config_paths: LOG_UI.debug(' * %s', cfg_path) else: LOG_UI.debug(' %s', cfg_path) LOG_UI.debug("") if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" LOG_UI.debug(format_str, 'Section.Key', 'Value') for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) LOG_UI.debug(format_str, config_key, value[1]) else: LOG_UI.debug("Avocado replaces config dirs that can't be accessed") LOG_UI.debug("with sensible defaults. Please edit your local config") LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') LOG_UI.debug(' base %s', data_dir.get_base_dir()) LOG_UI.debug(' tests %s', data_dir.get_test_dir()) LOG_UI.debug(' data %s', data_dir.get_data_dir()) LOG_UI.debug(' logs %s', data_dir.get_logs_dir()) LOG_UI.debug(' cache %s', ", ".join(data_dir.get_cache_dirs()))
def run(self, args): view = output.View() view.notify(event="message", msg='Avocado Data Directories:') view.notify(event="message", msg=' base dir ' + data_dir.get_base_dir()) view.notify(event="message", msg=' tests dir ' + data_dir.get_test_dir()) view.notify(event="message", msg=' data dir ' + data_dir.get_data_dir()) view.notify(event="message", msg=' logs dir ' + data_dir.get_logs_dir()) view.notify(event="message", msg=' tmp dir ' + data_dir.get_tmp_dir())
def list_data_dirs(self, args): bcolors = output.colors pipe = output.get_paginator() pipe.write(bcolors.header_str('Avocado Data Directories:')) pipe.write('\n base dir: ' + data_dir.get_base_dir()) pipe.write('\n tests dir: ' + data_dir.get_test_dir()) pipe.write('\n data dir: ' + data_dir.get_data_dir()) pipe.write('\n logs dir: ' + data_dir.get_logs_dir()) pipe.write('\n tmp dir: ' + data_dir.get_tmp_dir())
def run(self, args): view = output.View(use_paginator=(args.paginator == 'on')) try: view.notify(event="message", msg='Config files read (in order):') for cfg_path in settings.config_paths: view.notify(event="message", msg=' %s' % cfg_path) if settings.config_paths_failed: view.notify(event="minor", msg='') view.notify(event="error", msg='Config files that failed to read:') for cfg_path in settings.config_paths_failed: view.notify(event="error", msg=' %s' % cfg_path) view.notify(event="minor", msg='') if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" view.notify(event="minor", msg=format_str % ('Section.Key', 'Value')) for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) view.notify(event="minor", msg=format_str % (config_key, value[1])) else: view.notify( event="minor", msg="Avocado replaces config dirs that can't be accessed") view.notify( event="minor", msg="with sensible defaults. Please edit your local config" ) view.notify(event="minor", msg="file to customize values") view.notify(event="message", msg='') view.notify(event="message", msg='Avocado Data Directories:') view.notify(event="minor", msg=' base ' + data_dir.get_base_dir()) view.notify(event="minor", msg=' tests ' + data_dir.get_test_dir()) view.notify(event="minor", msg=' data ' + data_dir.get_data_dir()) view.notify(event="minor", msg=' logs ' + data_dir.get_logs_dir()) finally: view.cleanup()
def run(self, args): view = output.View(use_paginator=(args.paginator == 'on')) try: view.notify(event="message", msg='Config files read (in order):') for cfg_path in settings.config_paths: view.notify(event="message", msg=' %s' % cfg_path) if settings.config_paths_failed: view.notify(event="minor", msg='') view.notify(event="error", msg='Config files that failed to read:') for cfg_path in settings.config_paths_failed: view.notify(event="error", msg=' %s' % cfg_path) view.notify(event="minor", msg='') if not args.datadir: blength = 0 for section in settings.config.sections(): for value in settings.config.items(section): clength = len('%s.%s' % (section, value[0])) if clength > blength: blength = clength format_str = " %-" + str(blength) + "s %s" view.notify(event="minor", msg=format_str % ('Section.Key', 'Value')) for section in settings.config.sections(): for value in settings.config.items(section): config_key = ".".join((section, value[0])) view.notify(event="minor", msg=format_str % (config_key, value[1])) else: view.notify(event="minor", msg="Avocado replaces config dirs that can't be accessed") view.notify(event="minor", msg="with sensible defaults. Please edit your local config") view.notify(event="minor", msg="file to customize values") view.notify(event="message", msg='') view.notify(event="message", msg='Avocado Data Directories:') view.notify(event="minor", msg=' base ' + data_dir.get_base_dir()) view.notify(event="minor", msg=' tests ' + data_dir.get_test_dir()) view.notify(event="minor", msg=' data ' + data_dir.get_data_dir()) view.notify(event="minor", msg=' logs ' + data_dir.get_logs_dir()) finally: view.cleanup()
if hasattr(sys, 'real_prefix'): # unlike default execution venv prefix does not contain /usr _DEFAULT_SHARED_PATH = os.path.join(sys.prefix, "shared") else: _DEFAULT_SHARED_PATH = os.path.join(sys.prefix, "share", "avocado-plugins-vt", "shared") if (os.path.isdir(_DEFAULT_SHARED_PATH) and len(os.listdir(_DEFAULT_SHARED_PATH)) > 0): _ROOT_PATH = os.path.dirname(_DEFAULT_SHARED_PATH) else: _ROOT_PATH = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) ROOT_DIR = os.path.abspath(_ROOT_PATH) BASE_BACKEND_DIR = os.path.join(ROOT_DIR, 'backends') DATA_DIR = os.path.join(data_dir.get_data_dir(), 'avocado-vt') SHARED_DIR = os.path.join(ROOT_DIR, 'shared') DEPS_DIR = os.path.join(ROOT_DIR, 'shared', 'deps') BASE_DOWNLOAD_DIR = os.path.join(SHARED_DIR, 'downloads') DOWNLOAD_DIR = os.path.join(DATA_DIR, 'downloads') TEST_PROVIDERS_DIR = os.path.join(ROOT_DIR, 'test-providers.d') BACKING_DATA_DIR = None class MissingDepsDirError(Exception): pass class UnknownBackendError(Exception): def __init__(self, backend): self.backend = backend
import os import sys import glob import shutil import stat from avocado.core import data_dir # we're running from source code directories #api_init = sys.modules['api'].__file__ #api_dir = os.path.realpath(os.path.dirname(api_init)) REALPATH = os.path.split(os.path.realpath(__file__))[0] _ROOT_PATH = os.path.dirname(REALPATH) ROOT_DIR = os.path.abspath(_ROOT_PATH) DATA_DIR = os.path.join(data_dir.get_data_dir(), 'data') SHARED_DIR = os.path.join(ROOT_DIR, 'shared') BASE_DOWNLOAD_DIR = os.path.join(SHARED_DIR, 'downloads') DOWNLOAD_DIR = os.path.join(DATA_DIR, 'downloads') TEST_PROVIDERS_DIR = os.path.join(ROOT_DIR, 'test-providers.d') BACKING_DATA_DIR = None class SubdirList(list): """ List of all non-hidden subdirectories beneath basedir """ def __in_filter__(self, item): if self.filterlist: for _filter in self.filterlist: if item.count(str(_filter)):
'shared'))) > 0 else: _INSTALLED_SYSTEM_WIDE = False if _INSTALLED_SYSTEM_WIDE: # avocado-vt is installed _ROOT_PATH = _SYSTEM_WIDE_ROOT_PATH else: # we're running from source code directories virttest_init = sys.modules['virttest'].__file__ virttest_dir = os.path.realpath(os.path.dirname(virttest_init)) _ROOT_PATH = os.path.dirname(virttest_dir) ROOT_DIR = os.path.abspath(_ROOT_PATH) BASE_BACKEND_DIR = os.path.join(ROOT_DIR, 'backends') DATA_DIR = os.path.join(data_dir.get_data_dir(), 'avocado-vt') SHARED_DIR = os.path.join(ROOT_DIR, 'shared') DEPS_DIR = os.path.join(ROOT_DIR, 'shared', 'deps') BASE_DOWNLOAD_DIR = os.path.join(SHARED_DIR, 'downloads') DOWNLOAD_DIR = os.path.join(DATA_DIR, 'downloads') TEST_PROVIDERS_DIR = os.path.join(ROOT_DIR, 'test-providers.d') TMP_DIR = tempfile.mkdtemp() BACKING_DATA_DIR = None class MissingDepsDirError(Exception): pass class UnknownBackendError(Exception):
class VirtBootstrap(plugin.Plugin): """ Implements the avocado 'virt-bootstrap' subcommand """ name = 'virt_bootstrap' enabled = True def configure(self, parser): self.parser = parser.subcommands.add_parser( 'virt-bootstrap', help='Download image files important to avocado virt tests') super(VirtBootstrap, self).configure(self.parser) def run(self, args): fail = False view = output.View(app_args=args) view.notify(event='message', msg='Probing your system for test requirements') try: utils_path.find_command('7za') view.notify(event='minor', msg='7zip present') except utils_path.CmdNotFoundError: view.notify(event='warning', msg=("7za not installed. You may " "install 'p7zip' (or the " "equivalent on your distro) to " "fix the problem")) fail = True jeos_sha1_url = 'https://lmr.fedorapeople.org/jeos/SHA1SUM_JEOS20' try: view.notify(event='minor', msg=('Verifying expected SHA1 ' 'sum from %s' % jeos_sha1_url)) sha1_file = urllib2.urlopen(jeos_sha1_url) sha1_contents = sha1_file.read() sha1 = sha1_contents.split(" ")[0] view.notify(event='minor', msg='Expected SHA1 sum: %s' % sha1) except Exception, e: view.notify(event='error', msg='Failed to get SHA1 from file: %s' % e) fail = True jeos_dst_dir = path.init_dir( os.path.join(data_dir.get_data_dir(), 'images')) jeos_dst_path = os.path.join(jeos_dst_dir, 'jeos-20-64.qcow2.7z') if os.path.isfile(jeos_dst_path): actual_sha1 = crypto.hash_file(filename=jeos_dst_path, algorithm="sha1") else: actual_sha1 = '0' if actual_sha1 != sha1: if actual_sha1 == '0': view.notify(event='minor', msg=('JeOS could not be found at %s. Downloading ' 'it (173 MB). Please wait...' % jeos_dst_path)) else: view.notify(event='minor', msg=('JeOS at %s is either corrupted or outdated. ' 'Downloading a new copy (173 MB). ' 'Please wait...' % jeos_dst_path)) jeos_url = 'https://lmr.fedorapeople.org/jeos/jeos-20-64.qcow2.7z' try: download.url_download(jeos_url, jeos_dst_path) except: view.notify(event='warning', msg=('Exiting upon user request (Download ' 'not finished)')) else: view.notify(event='minor', msg=('Compressed JeOS image found ' 'in %s, with proper SHA1' % jeos_dst_path)) view.notify(event='minor', msg=('Uncompressing the JeOS image to restore pristine ' 'state. Please wait...')) os.chdir(os.path.dirname(jeos_dst_path)) result = process.run('7za -y e %s' % os.path.basename(jeos_dst_path), ignore_status=True) if result.exit_status != 0: view.notify(event='error', msg=('Error uncompressing the image ' '(see details below):\n%s' % result)) fail = True else: view.notify(event='minor', msg='Successfully uncompressed the image') if fail: view.notify(event='warning', msg=('Problems found probing this system for tests ' 'requirements. Please check the error messages ' 'and fix the problems found')) else: view.notify(event='message', msg=('Your system appears to be all ' 'set to execute tests'))
class VirtBootstrap(CLICmd): """ Implements the avocado 'virt-bootstrap' subcommand """ name = 'virt-bootstrap' description = "Avocado-Virt 'virt-bootstrap' subcommand" def run(self, args): fail = False LOG.info('Probing your system for test requirements') try: utils_path.find_command('xz') logging.debug('xz present') except utils_path.CmdNotFoundError: LOG.warn("xz not installed. You may install xz (or the " "equivalent on your distro) to fix the problem") fail = True jeos_sha1_url = ("https://avocado-project.org/data/assets/jeos/25/" "SHA1SUM_JEOS25") try: LOG.debug('Verifying expected SHA1 sum from %s', jeos_sha1_url) sha1_file = urllib2.urlopen(jeos_sha1_url) sha1_contents = sha1_file.read() sha1 = sha1_contents.split(" ")[0] LOG.debug('Expected SHA1 sum: %s', sha1) except Exception, exc: LOG.error('Failed to get SHA1 from file: %s', exc) fail = True sha1 = "FAILED TO GET DOWNLOADED FROM AVOCADO-PROJECT" jeos_dst_dir = path.init_dir( os.path.join(data_dir.get_data_dir(), 'images')) jeos_dst_path = os.path.join(jeos_dst_dir, 'jeos-25-64.qcow2.xz') if os.path.isfile(jeos_dst_path): actual_sha1 = crypto.hash_file(filename=jeos_dst_path, algorithm="sha1") else: actual_sha1 = 'FILE DOES NOT EXIST LOCALLY' if actual_sha1 != sha1: if actual_sha1 == 'FILE DOES NOT EXIST LOCALLY': LOG.debug( 'JeOS could not be found at %s. Downloading ' 'it (205 MB). Please wait...', jeos_dst_path) else: LOG.debug( 'JeOS at %s is either corrupted or outdated. ' 'Downloading a new copy (205 MB). ' 'Please wait...', jeos_dst_path) jeos_url = ("https://avocado-project.org/data/assets/jeos/25/" "jeos-25-64.qcow2.xz") try: download.url_download(jeos_url, jeos_dst_path) except: LOG.warn('Exiting upon user request (Download not finished)') else: LOG.debug('Compressed JeOS image found in %s, with proper SHA1', jeos_dst_path) LOG.debug('Uncompressing the JeOS image to restore pristine ' 'state. Please wait...') os.chdir(os.path.dirname(jeos_dst_path)) cmd = 'xz --keep --force -d %s' % os.path.basename(jeos_dst_path) result = process.run(cmd, ignore_status=True) if result.exit_status != 0: LOG.error('Error uncompressing the image (see details below):\n%s', result) fail = True else: LOG.debug('Successfully uncompressed the image') if fail: LOG.warn('Problems found probing this system for tests ' 'requirements. Please check the error messages ' 'and fix the problems found') else: LOG.info('Your system appears to be all set to execute tests')
PERFORMANCE_TEST_DIR = os.path.join(CLOUDTEST_TEST_DIR, 'performance') RELIABILITY_TEST_DIR = os.path.join(CLOUDTEST_TEST_DIR, 'reliability') COMMON_TEST_DIR = os.path.join(CLOUDTEST_TEST_DIR, 'common') PERFORMANCE_CASE_DIR = os.path.join(ROOT_DIR, 'tests', 'performance', 'rally-jobs') CLOUDTEST_MODULE_TEST_DIR = os.path.join(CLOUDTEST_MODULE_DIR, 'tests') CLOUDTEST_INTEGRATE_TEST_DIR = os.path.join(CLOUDTEST_MODULE_TEST_DIR, 'integrate') STABILITY_TEST_DIR = os.path.join(CLOUDTEST_TEST_DIR, 'stability') CEPH_API_TEST_DIR = os.path.join(CLOUDTEST_TEST_DIR, 'ceph_api') NFVI_TEST_DIR = os.path.join(CLOUDTEST_TEST_DIR, 'nfv') CEPH_API_SCENARIOS_TEST_DIR = os.path.join(CEPH_API_TEST_DIR, 'tests', 'scenarios') BASE_BACKEND_DIR = os.path.join(ROOT_DIR, 'backends') DATA_DIR = os.path.join(data_dir.get_data_dir(), 'avocado-cloudtest') SHARED_DIR = os.path.join(ROOT_DIR, 'shared') BACKING_DATA_DIR = None class MissingDepsDirError(Exception): pass class UnknownBackendError(Exception): def __init__(self, backend): self.backend = backend def __str__(self): return ("Virt Backend %s is not currently supported by avocado-vt. " "Check for typos and the list of supported backends" %