-
Notifications
You must be signed in to change notification settings - Fork 7
Add --debug flag for step-level execution logging #312
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
Open
LakshmiSaiHarika
wants to merge
1
commit into
AMDEPYC:main
Choose a base branch
from
LakshmiSaiHarika:enhancement/create-logs-for-steps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,13 +32,15 @@ | |
| run_vm_stop_step, | ||
| test_artifact_dir, | ||
| ) | ||
| from .step_log import StepLogger | ||
| from .vm_profile import ( | ||
| DEFAULT_QEMU_BINARY, | ||
| find_ovmf_path, | ||
| VMLaunchResult, | ||
| VMProfileError, | ||
| stop_vm, | ||
| ) | ||
| from .guest_vsock import fetch_guest_journal, GuestVsockError | ||
|
|
||
| _LINE_WIDTH = 80 | ||
|
|
||
|
|
@@ -123,6 +125,13 @@ def parse_args(argv: list[str] | None = None) -> argparse.Namespace: | |
| default=False, | ||
| help="Allow making host-level changes, such as changing FW TCB settings.", | ||
| ) | ||
| parser.add_argument( | ||
| "--debug", | ||
| action="store_true", | ||
| default=False, | ||
| help="Enable debug logging: create steps.log and per-guest log directories " | ||
| "with qemu-boot.log, qemu-error.log, qemu-command.log, and guest-journal.log", | ||
| ) | ||
| return parser.parse_args(argv) | ||
|
|
||
|
|
||
|
|
@@ -361,6 +370,7 @@ def execute_test( | |
| ovmf_path: str | None = None, | ||
| environment: dict[str, str | None] | None = None, | ||
| allow_host_changes: bool = False, | ||
| debug: bool = False, | ||
| ) -> TestResult: | ||
| """Run a test, printing each step live as it executes.""" | ||
| started_at = datetime.now(timezone.utc).isoformat() | ||
|
|
@@ -389,13 +399,16 @@ def execute_test( | |
| artifact_dir.mkdir(parents=True, exist_ok=True) | ||
| _flush(f" Artifacts: {artifact_dir}") | ||
|
|
||
| step_logger = StepLogger(artifact_dir) if debug else None | ||
|
|
||
| profile = None | ||
| if test.requires_vm: | ||
| profile = effective_vm_profile( | ||
| declared_profile, | ||
| guest_path, | ||
| qemu_binary=qemu_binary, | ||
| ovmf_path=ovmf_path, | ||
| artifact_dir=artifact_dir, | ||
| ) | ||
|
|
||
| mod = import_test_module(test) | ||
|
|
@@ -449,6 +462,8 @@ def execute_test( | |
| if launch is not None and launch.ok and environment is not None: | ||
| update_environment_with_guest_os(environment, launch.profile) | ||
| elif step.kind == "vm_stop": | ||
| stopped_launch: VMLaunchResult | None = None | ||
| guest_journal_output: str | None = None | ||
| if launch is None: | ||
| sr = StepResult( | ||
| step=step, | ||
|
|
@@ -457,8 +472,16 @@ def execute_test( | |
| duration_ms=0, | ||
| ) | ||
| else: | ||
| # Fetch guest journald logs before stopping the VM | ||
| try: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could optimize the normal (not |
||
| journal_result = fetch_guest_journal(launch.profile) | ||
| guest_journal_output = journal_result.stdout | ||
| except GuestVsockError: | ||
| # Guest may have already halted or vsock unavailable | ||
| guest_journal_output = None | ||
| sr = run_vm_stop_step(step, launch) | ||
| if sr.result != "error": | ||
| stopped_launch = launch | ||
| launch = None | ||
| elif step.kind == "host": | ||
| sr = run_step(step, guest_path, artifact_dir) | ||
|
|
@@ -502,6 +525,20 @@ def execute_test( | |
| stderr=f"Unsupported step kind {step.kind!r}", | ||
| ) | ||
| step_results.append(sr) | ||
| # Log step details when debug is enabled | ||
| if step_logger is not None: | ||
| # For vm_stop, use the stopped_launch to get log paths and journal | ||
| active_launch = stopped_launch if step.kind == "vm_stop" and stopped_launch else launch | ||
| qemu_cmd = active_launch.command_line if active_launch is not None else None | ||
| guest_id = active_launch.guest_id if active_launch is not None else None | ||
| guest_error_log = active_launch.profile.guest_error_log if active_launch is not None else None | ||
| guest_boot_log = active_launch.profile.guest_boot_log if active_launch is not None else None | ||
| journal_for_log = guest_journal_output if step.kind == "vm_stop" else None | ||
| step_logger.log_step( | ||
| step, sr, command=qemu_cmd, guest_id=guest_id, | ||
| guest_error_log_path=guest_error_log, guest_boot_log_path=guest_boot_log, | ||
| guest_journal=journal_for_log, | ||
| ) | ||
|
|
||
| _flush(_step_result_line(sr, is_last)) | ||
|
|
||
|
|
@@ -572,6 +609,7 @@ def execute_certification( | |
| ovmf_path: str | None = None, | ||
| environment: dict[str, str | None] | None = None, | ||
| allow_host_changes: bool = False, | ||
| debug: bool = False, | ||
| ) -> CertificationResult: | ||
| """Run all tests in a certification with live output.""" | ||
| started_at = datetime.now(timezone.utc).isoformat() | ||
|
|
@@ -600,6 +638,7 @@ def execute_certification( | |
| ovmf_path=ovmf_path, | ||
| environment=environment, | ||
| allow_host_changes=allow_host_changes, | ||
| debug=debug, | ||
| ) | ||
| test_results.append(tr) | ||
| overall = _worse_result(overall, tr.result) | ||
|
|
@@ -736,6 +775,7 @@ def main(argv: list[str] | None = None) -> int: | |
| ovmf_path=ovmf_override, | ||
| environment=environment, | ||
| allow_host_changes=args.allow_host_changes, | ||
| debug=args.debug, | ||
| ) | ||
| prereq_results.append(tr) | ||
| _flush("") | ||
|
|
@@ -772,6 +812,7 @@ def main(argv: list[str] | None = None) -> int: | |
| ovmf_path=ovmf_override, | ||
| environment=environment, | ||
| allow_host_changes=args.allow_host_changes, | ||
| debug=args.debug, | ||
| ) | ||
| cert_results.append(cr) | ||
| total_tests += len(cr.test_results) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm defining this here might make logging errors in the future (if we forget to update both).
I also see that in other functions you also define the command and pass it to both the subprocess.run() and the StepHandlerResult.
I think it would be cleaner to wrap subprocess.run() in another function that returns the StepHandlerResult directly:
I realize this might be a lot of work for this PR so no worries if do not wish to handle it as a part of this PR, we can do a follow up.