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

Adds ability to produce html reports #2958

Merged
merged 1 commit into from
Nov 9, 2020
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ repos:
additional_dependencies:
- packaging
- rich
- subprocess-tee>=0.1.4
- subprocess-tee>=0.1.5
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.6.0
hooks:
- id: pylint
additional_dependencies:
- ansible-base
- rich
- subprocess-tee>=0.1.4
- subprocess-tee>=0.1.5
- testinfra
1 change: 1 addition & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ MOLECULE_INSTANCE_CONFIG ?
MOLECULE_DEPENDENCY_NAME Dependency type name, usually 'galaxy'
MOLECULE_DRIVER_NAME Name of the molecule scenario driver
MOLECULE_PROVISIONER_NAME Name of the provisioner tool (usually 'ansible')
MOLECULE_REPORT Name of HTML file where to dump execution report.
MOLECULE_SCENARIO_NAME Name of the scenario
MOLECULE_VERBOSITY Determine Ansible verbosity level.
MOLECULE_VERIFIER_NAME Name of the verifier tool (usually 'ansible')
Expand Down
8 changes: 8 additions & 0 deletions lib/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def click_group_ex():
"reset": "blue",
"test": "bright_yellow",
},
result_callback=result_callback,
)


Expand All @@ -246,3 +247,10 @@ def click_command_ex() -> Callable[[Callable[..., Any]], click.Command]:
return click.command( # type: ignore
cls=HelpColorsCommand, help_headers_color="yellow", help_options_color="green"
)


def result_callback(*args, **kwargs):
"""Click natural exit callback."""
# We want to be used we run out custom exit code, regardless if run was
# a success or failure.
util.sysexit(0)
6 changes: 4 additions & 2 deletions lib/molecule/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import sys
from typing import Any

from rich.console import Console
from rich.style import Style
from rich.theme import Theme
from subprocess_tee.rich import ConsoleEx

theme = Theme(
{
Expand Down Expand Up @@ -60,4 +60,6 @@ def should_do_markup() -> bool:
return sys.stdout.isatty() and os.environ.get("TERM") != "dumb"


console = Console(force_terminal=should_do_markup(), theme=theme)
console = ConsoleEx(
force_terminal=should_do_markup(), theme=theme, record=True, redirect=True
)
6 changes: 6 additions & 0 deletions lib/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def print_environment_vars(env: Optional[Dict[str, str]]) -> None:

def sysexit(code: int = 1) -> NoReturn:
"""Perform a system exit with given code, default 1."""
if "MOLECULE_REPORT" in os.environ:
report_file = os.environ["MOLECULE_REPORT"]
LOG.info("Writing %s report.", report_file)
with open(report_file, "w") as f:
f.write(console.export_html())

sys.exit(code)


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ install_requires =
pluggy >= 0.7.1, < 1.0
PyYAML >= 5.1, < 6
rich >= 6.0
subprocess-tee >= 0.1.4
subprocess-tee >= 0.1.5
setuptools >= 42 # for pkg_resources
yamllint >= 1.15.0, < 2
# selinux python module is needed as least by ansible-docker/podman modules
Expand Down