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

Testing: improve Windows test logs #499

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

martijnvans
Copy link
Contributor

@martijnvans martijnvans commented Mar 29, 2022

The idea is to parse the XML returned by powershell over stderr, and extract the human readable part and print that.

To do this, I had to separate out the part of runCommand() that logs the command and the raw stdout/stderr into a function runAndLog(), and for runRemotelyWindows(), get it to call runCommand() directly, skipping runAndLog() in order to do its own logging.

This whole thing is just a workaround for the fact that powershell ignores -OutputFormat Text when run noninteractively.

Before: https://storage.cloud.google.com/ops-agents-public-buckets-test-logs/prod/stackdriver_agents/testing/consumer/ops_agent/presubmit_github/windows/449/20220322-104940/logs/TestLoggingAgentCrashRestart_windows-2019/main_log.txt

After: https://storage.googleapis.com/ops-agents-public-buckets-test-logs/prod/stackdriver_agents/testing/consumer/ops_agent/test/windows/1043/20220808-084805/logs/TestLoggingAgentCrashRestart_windows-2019/main_log.txt

I also checked that when there is something useful on stderr, like a "missing cmdlet" error, it does show up right, and I checked that if the XML fails to parse, that the raw XML is dumped to the log, as desired.

[]string{winRM(),
"--host=" + vm.IPAddress,
"--username=" + vm.WindowsCredentials.Username,
"--password=" + vm.WindowsCredentials.Password,
fmt.Sprintf("--command=powershell -NonInteractive -encodedcommand %q", base64.StdEncoding.EncodeToString([]byte(encoded))),
fmt.Sprintf("--command=powershell -NonInteractive -OutputFormat Text -EncodedCommand %q", base64.StdEncoding.EncodeToString([]byte(encoded))),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding -OutputFormat Text does nothing, but I included it here because:

  1. it's always bothered me how this seemingly-useful option is not called out in our code anywhere
  2. if microsoft ever fixes powershell's behavior, we'll start using the fix automatically.

@martijnvans martijnvans changed the title Testing: parse XML returned by powershell over stderr Testing: improve Windows test logs Mar 30, 2022
@martijnvans martijnvans requested review from a team and igorpeshansky and removed request for a team April 27, 2022 15:26
integration_test/gce/gce_testing.go Outdated Show resolved Hide resolved
integration_test/gce/gce_testing.go Outdated Show resolved Hide resolved
integration_test/gce/gce_testing.go Outdated Show resolved Hide resolved
integration_test/gce/gce_testing.go Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 7, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants