Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMimage get --debug option #6061

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions avocado/plugins/vmimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

from avocado.core import exit_codes, output
from avocado.core.output import LOG_UI
from avocado.core.output import LOG_UI, add_log_handler
from avocado.core.plugin_interfaces import CLICmd
from avocado.core.settings import settings
from avocado.utils import astring, vmimage
Expand Down Expand Up @@ -70,7 +70,7 @@
:rtype: dict
"""
cache_dir = settings.as_dict().get("datadir.paths.cache_dirs")[0]
image_info = vmimage.get(
image_info = vmimage.Image.from_parameters(

Check warning on line 73 in avocado/plugins/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/vmimage.py#L73

Added line #L73 was not covered by tests
name=distro, version=version, arch=arch, cache_dir=cache_dir
)
file_path = image_info.base_image
Expand Down Expand Up @@ -155,6 +155,17 @@
long_arg="--arch",
)

help_msg = "More information about failures"
settings.register_option(

Check warning on line 159 in avocado/plugins/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/vmimage.py#L158-L159

Added lines #L158 - L159 were not covered by tests
section="vmimage.get",
key="debug",
default=False,
help_msg=help_msg,
key_type=bool,
parser=get_parser,
long_arg="--debug",
)

def run(self, config):
subcommand = config.get("vmimage_subcommand")
if subcommand == "list":
Expand All @@ -164,6 +175,9 @@
name = config.get("vmimage.get.distro")
version = config.get("vmimage.get.version")
arch = config.get("vmimage.get.arch")
debug = config.get("vmimage.get.debug")
if debug:
add_log_handler(vmimage.LOG)

Check warning on line 180 in avocado/plugins/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/vmimage.py#L178-L180

Added lines #L178 - L180 were not covered by tests
try:
image = download_image(name, version, arch)
except AttributeError:
Expand Down
14 changes: 9 additions & 5 deletions avocado/utils/vmimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Provides VM images acquired from official repositories
"""

import logging
import os
import re
import tempfile
Expand All @@ -29,6 +30,8 @@
from avocado.utils import path as utils_path
from avocado.utils import process

LOG = logging.getLogger(__name__)

# pylint: disable=C0401
#: The "qemu-img" binary used when creating the snapshot images. If
#: set to None (the default), it will attempt to find a suitable binary
Expand Down Expand Up @@ -114,7 +117,7 @@
data = urlopen(url).read()
parser.feed(astring.to_text(data, self.HTML_ENCODING))
except HTTPError as exc:
raise ImageProviderError(f"Cannot open {self.url_versions}") from exc
raise ImageProviderError(f"Cannot open {url}") from exc

@staticmethod
def get_best_version(versions):
Expand Down Expand Up @@ -670,8 +673,8 @@
cache_dir=cache_dir,
snapshot_dir=snapshot_dir,
)
except ImageProviderError:
pass
except ImageProviderError as e:
LOG.debug(e)

Check warning on line 677 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L676-L677

Added lines #L676 - L677 were not covered by tests

raise AttributeError("Provider not available")

Expand Down Expand Up @@ -726,9 +729,10 @@
if name is None or name == provider.name.lower():
try:
return provider(**provider_args)
except ImageProviderError:
pass
except ImageProviderError as e:
LOG.debug(e)

Check warning on line 733 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L732-L733

Added lines #L732 - L733 were not covered by tests

LOG.debug("Provider for %s not available", name)

Check warning on line 735 in avocado/utils/vmimage.py

View check run for this annotation

Codecov / codecov/patch

avocado/utils/vmimage.py#L735

Added line #L735 was not covered by tests
raise AttributeError("Provider not available")


Expand Down
2 changes: 1 addition & 1 deletion selftests/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"nrunner-requirement": 28,
"unit": 678,
"jobs": 11,
"functional-parallel": 313,
"functional-parallel": 314,
"functional-serial": 7,
"optional-plugins": 0,
"optional-plugins-golang": 2,
Expand Down
11 changes: 11 additions & 0 deletions selftests/functional/plugin/vmimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def test_list_images(self):
result = process.run(cmd_line)
self.assertIn(expected_output, result.stdout_text)

def test_get_debug(self):
cmd_line = (
f"{AVOCADO} --config {self.config_file.name} vmimage "
f"get --debug --distro=SHOULD_NEVER_EXIST --arch zzz_64"
)
result = process.run(cmd_line, ignore_status=True)
self.assertEqual(result.exit_status, exit_codes.AVOCADO_FAIL)
self.assertIn(
"Provider for should_never_exist not available", result.stdout_text
)

def tearDown(self):
self.base_dir.cleanup()

Expand Down
Loading