Skip to content

Commit

Permalink
virttests: Uses the new logging namespace format
Browse files Browse the repository at this point in the history
Because of recent logging changes in Avocado itself, let's follow suit
of commits adbfa56 and b26e803.

Signed-off-by: Beraldo Leal <[email protected]>
Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
beraldoleal authored and richtja committed Oct 12, 2021
1 parent bda27ba commit aa044c8
Show file tree
Hide file tree
Showing 115 changed files with 2,919 additions and 2,764 deletions.
61 changes: 31 additions & 30 deletions virttest/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from virttest import data_dir

LOG = logging.getLogger('avocado.' + __name__)


class ConfigLoader:

Expand Down Expand Up @@ -317,8 +319,8 @@ def download_test_provider(provider, update=False):
pass
except Exception:
if not dir_existed and os.path.isdir(download_dst):
logging.error('Cleaning up provider %s download dir %s', provider,
download_dst)
LOG.error('Cleaning up provider %s download dir %s', provider,
download_dst)
shutil.rmtree(download_dst)
raise

Expand All @@ -327,8 +329,8 @@ def download_test_provider(provider, update=False):
os.chdir(download_dst)
process.system('git log -1')
except process.CmdError:
logging.error('Something is unexpectedly wrong with the git repository at %s',
download_dst)
LOG.error('Something is unexpectedly wrong with the git repository at %s',
download_dst)
raise
finally:
os.chdir(original_dir)
Expand Down Expand Up @@ -371,15 +373,15 @@ def get_file_asset(title, src_path, destination):
for ext in (".xz", ".gz", ".7z", ".bz2"):
if os.path.exists(src_path + ext):
destination = destination + ext
logging.debug('Found source image %s', destination)
LOG.debug('Found source image %s', destination)
return {
'url': None, 'sha1_url': None, 'destination': src_path + ext,
'destination_uncompressed': destination,
'uncompress_cmd': None, 'shortname': title, 'title': title,
'downloaded': True}

if os.path.exists(src_path):
logging.debug('Found source image %s', destination)
LOG.debug('Found source image %s', destination)
return {'url': src_path, 'sha1_url': None, 'destination': destination,
'destination_uncompressed': None, 'uncompress_cmd': None,
'shortname': title, 'title': title,
Expand Down Expand Up @@ -455,13 +457,13 @@ def uncompress_asset(asset_info, force=False):

if os.path.isfile(destination) and force:
os.chdir(os.path.dirname(destination_uncompressed))
logging.debug('Uncompressing %s -> %s', destination,
destination_uncompressed)
LOG.debug('Uncompressing %s -> %s', destination,
destination_uncompressed)
process.run(uncompress_cmd, shell=True)
backup_file = destination_uncompressed + '.backup'
if os.path.isfile(backup_file):
logging.debug('Copying %s -> %s', destination_uncompressed,
backup_file)
LOG.debug('Copying %s -> %s', destination_uncompressed,
backup_file)
shutil.copy(destination_uncompressed, backup_file)


Expand All @@ -486,13 +488,13 @@ def download_file(asset_info, interactive=False, force=False):

if sha1_url is not None:
try:
logging.info("Verifying expected SHA1 sum from %s", sha1_url)
LOG.info("Verifying expected SHA1 sum from %s", sha1_url)
sha1_file = urllib.request.urlopen(sha1_url)
sha1_contents = astring.to_text(sha1_file.read())
sha1 = sha1_contents.split(" ")[0]
logging.info("Expected SHA1 sum: %s", sha1)
LOG.info("Expected SHA1 sum: %s", sha1)
except Exception as e:
logging.error("Failed to get SHA1 from file: %s", e)
LOG.error("Failed to get SHA1 from file: %s", e)
else:
sha1 = None

Expand All @@ -501,7 +503,7 @@ def download_file(asset_info, interactive=False, force=False):
os.makedirs(destination_dir)

if not os.path.isfile(destination):
logging.warning("File %s not found", destination)
LOG.warning("File %s not found", destination)
if interactive:
answer = genio.ask("Would you like to download it from %s?" % url)
else:
Expand All @@ -512,12 +514,12 @@ def download_file(asset_info, interactive=False, force=False):
"Downloading %s" % title)
had_to_download = True
except Exception as download_failure:
logging.error("Check your internet connection: %s",
download_failure)
LOG.error("Check your internet connection: %s",
download_failure)
else:
logging.warning("Missing file %s", destination)
LOG.warning("Missing file %s", destination)
else:
logging.info("Found %s", destination)
LOG.info("Found %s", destination)
if sha1 is None:
answer = 'n'
else:
Expand All @@ -526,27 +528,27 @@ def download_file(asset_info, interactive=False, force=False):
if answer == 'y':
actual_sha1 = crypto.hash_file(destination, algorithm='sha1')
if actual_sha1 != sha1:
logging.info("Actual SHA1 sum: %s", actual_sha1)
LOG.info("Actual SHA1 sum: %s", actual_sha1)
if interactive:
answer = genio.ask("The file seems corrupted or outdated. "
"Would you like to download it?")
else:
logging.info("The file seems corrupted or outdated")
LOG.info("The file seems corrupted or outdated")
answer = 'y'
if answer == 'y':
logging.info("Updating image to the latest available...")
LOG.info("Updating image to the latest available...")
while not file_ok:
try:
download.url_download_interactive(url, destination,
title)
except Exception as download_failure:
logging.error("Check your internet connection: %s",
download_failure)
LOG.error("Check your internet connection: %s",
download_failure)
sha1_post_download = crypto.hash_file(destination,
algorithm='sha1')
had_to_download = True
if sha1_post_download != sha1:
logging.error("Actual SHA1 sum: %s", actual_sha1)
LOG.error("Actual SHA1 sum: %s", actual_sha1)
if interactive:
answer = genio.ask("The file downloaded %s is "
"corrupted. Would you like "
Expand All @@ -556,24 +558,23 @@ def download_file(asset_info, interactive=False, force=False):
answer = 'n'
if answer == 'n':
problems_ignored = True
logging.error("File %s is corrupted" %
destination)
LOG.error("File %s is corrupted" % destination)
file_ok = True
else:
file_ok = False
else:
file_ok = True
else:
file_ok = True
logging.info("SHA1 sum check OK")
LOG.info("SHA1 sum check OK")
else:
problems_ignored = True
logging.info("File %s present, but did not verify integrity",
destination)
LOG.info("File %s present, but did not verify integrity",
destination)

if file_ok:
if not problems_ignored:
logging.info("%s present, with proper checksum", destination)
LOG.info("%s present, with proper checksum", destination)

uncompress_asset(asset_info=asset_info, force=force or had_to_download)

Expand Down
35 changes: 18 additions & 17 deletions virttest/base_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from . import arch
from .staging import utils_koji

LOG = logging.getLogger('avocado.' + __name__)


class NoModuleError(Exception):

Expand Down Expand Up @@ -180,14 +182,14 @@ def _set_param_cleanup(self):
self.cleanup = True
cleanup = self.params.get('installer_cleanup', 'yes')
if cleanup == 'no':
logging.debug("Setting installer cleanup attribute to False")
LOG.debug("Setting installer cleanup attribute to False")
self.cleanup = False

def set_install_params(self, test=None, params=None):
"""
Called by test to setup parameters from the configuration file
"""
logging.info("calling set install params")
LOG.info("calling set install params")
if test is not None:
self._set_test_dirs(test, params)

Expand Down Expand Up @@ -350,7 +352,7 @@ def write_version_keyval(self, test):
except AttributeError:
version = "Unknown"
sw_version = {('software_version_%s' % self.name): version}
logging.debug("Writing test keyval %s", sw_version)
LOG.debug("Writing test keyval %s", sw_version)
test.write_test_keyval(sw_version)

def load_modules(self, module_list=None):
Expand All @@ -370,8 +372,7 @@ def load_modules(self, module_list=None):
if not module_list:
raise NoModuleError("Module list empty")

logging.info("Loading modules from default locations through "
"modprobe")
LOG.info("Loading modules from default locations through modprobe")
for module in module_list:
process.system("modprobe %s" % module)

Expand All @@ -384,7 +385,7 @@ def unload_modules(self, module_list=None):
"""
if module_list is None:
module_list = self.module_list
logging.info("Unloading kernel modules: %s" % " ".join(module_list))
LOG.info("Unloading kernel modules: %s" % " ".join(module_list))
for module in module_list:
linux_modules.unload_module(module)

Expand Down Expand Up @@ -470,8 +471,8 @@ def __init__(self, mode, name, test=None, params=None):
super(NoopInstaller, self).__init__(mode, name, test, params)

def install(self):
logging.info("Assuming virtualization software to be already "
"installed. Doing nothing")
LOG.info("Assuming virtualization software to be already "
"installed. Doing nothing")


class YumInstaller(BaseInstaller):
Expand Down Expand Up @@ -560,7 +561,7 @@ def _expand_koji_pkgs_with_debuginfo(self):
:return: None
"""
logging.debug("Koji package list to be updated with debuginfo pkgs")
LOG.debug("Koji package list to be updated with debuginfo pkgs")

koji_pkgs_with_debug = []
for pkg_text in self.koji_pkgs:
Expand All @@ -575,8 +576,8 @@ def _expand_koji_pkgs_with_debuginfo(self):
pkg.subpackages.append(debuginfo_pkg_name)

pkg_with_debug_text = pkg.to_text()
logging.debug("KojiPkgSpec with debuginfo package added: %s",
pkg_with_debug_text)
LOG.debug("KojiPkgSpec with debuginfo package added: %s",
pkg_with_debug_text)
koji_pkgs_with_debug.append(pkg_with_debug_text)

# swap current koji_pkgs with on that includes debuginfo pkgs
Expand Down Expand Up @@ -623,8 +624,8 @@ def _install_phase_download(self):
if pkg.is_valid():
koji_client.get_pkgs(pkg, dst_dir=self.test_workdir)
else:
logging.error('Package specification (%s) is invalid: %s' %
(pkg, pkg.describe_invalid()))
LOG.error('Package specification (%s) is invalid: %s' %
(pkg, pkg.describe_invalid()))
for pkg_text in self.koji_scratch_pkgs:
pkg = utils_koji.KojiScratchPkgSpec(pkg_text)
koji_client.get_scratch_pkgs(pkg, dst_dir=self.test_workdir)
Expand All @@ -633,17 +634,17 @@ def _install_phase_install(self):
if self.koji_yumrepo_baseurl is not None:
repo = yumrepo.YumRepo(self.param_key_prefix,
self.koji_yumrepo_baseurl)
logging.debug('Enabling YUM Repo "%s" at "%s"',
self.param_key_prefix, self.koji_yumrepo_baseurl)
LOG.debug('Enabling YUM Repo "%s" at "%s"',
self.param_key_prefix, self.koji_yumrepo_baseurl)
repo.save()

os.chdir(self.test_workdir)
rpm_file_names = " ".join(self._get_rpm_file_names())
process.system("yum --nogpgcheck -y install %s" % rpm_file_names)

if self.koji_yumrepo_baseurl is not None:
logging.debug('Disabling YUM Repo "%s" at "%s"',
self.param_key_prefix, self.koji_yumrepo_baseurl)
LOG.debug('Disabling YUM Repo "%s" at "%s"',
self.param_key_prefix, self.koji_yumrepo_baseurl)
repo.remove()


Expand Down
Loading

0 comments on commit aa044c8

Please sign in to comment.