Skip to content

Fix Ubuntu makepfxcert.ps1 problems#3980

Open
paulmedynski wants to merge 1 commit intomainfrom
dev/paul/ubuntu-openssl
Open

Fix Ubuntu makepfxcert.ps1 problems#3980
paulmedynski wants to merge 1 commit intomainfrom
dev/paul/ubuntu-openssl

Conversation

@paulmedynski
Copy link
Contributor

@paulmedynski paulmedynski commented Feb 25, 2026

Description

Code changes:

  • Updated makepfxcert.ps1 to use improved FQCN lookup, and only install OpenSSL module it if isn't installed already.
  • Improved diatnostigs when running powershell scripts as part of certificate tests.
    These changes will help us diagnose what is hanging the script.

In the meantime, I have also updated our 1ES Ubuntu images to install the powershell OpenSSL module, so the script won't have to.

Testing

  • PR pipelines will confirm any regressions.
  • Manual run of CI pipelines will show the new diagnostics, and confirm the 1ES image updates.

- Updated makepfxcert.ps1 to use improved FQCN lookup, and only install OpenSSL module it if isn't installed already.
- Improved diatnostigs when running powershell scripts as part of certificate tests.
@paulmedynski paulmedynski added this to the 7.0.0-preview4 milestone Feb 25, 2026
@paulmedynski paulmedynski requested a review from a team as a code owner February 25, 2026 12:41
Copilot AI review requested due to automatic review settings February 25, 2026 12:41
@paulmedynski paulmedynski added the Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems. label Feb 25, 2026
@github-project-automation github-project-automation bot moved this to To triage in SqlClient Board Feb 25, 2026
Copy link
Contributor Author

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

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

Commentary for reviewers.

try {
# Get FQDN of the machine
Write-Output "Get FQDN of the machine..."
$fqdn = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
Copy link
Contributor Author

Choose a reason for hiding this comment

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

GetHostByName is deprecated, and $env:computerName isn't always populated on Linux.

RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
Arguments = $"{script} -OutDir {currentDirectory} > result.txt",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer redirecting stdout to a file that we never inspect or emit.

if (! File.Exists(script))
{
powerShellCommand = "pwsh";
throw new Exception($"Script {script} does not exist");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Early return to avoid large nested blocks.

output.AppendLine(e.Data);
}
});
output.AppendLine($"[OUT] {e.Data}");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prefixing the stdout and stderr so it's obvious which stream they came from.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the manual certificate-generation flow used by CertificateTestWithTdsServer on Ubuntu/Linux, aiming to reduce hangs and improve diagnostics when running the PowerShell-based certificate scripts in CI.

Changes:

  • Update makepfxcert.ps1 FQDN lookup logic and avoid reinstalling the OpenSSL PowerShell module when already present.
  • Improve PowerShell script execution diagnostics by capturing and labeling stdout/stderr output in the manual test harness.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Microsoft.Data.SqlClient/tests/ManualTests/makepfxcert.ps1 Adjusts host/FQDN resolution and makes OpenSSL module installation conditional; adds PowerShell tracing.
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert/CertificateTestWithTdsServer.cs Refactors PowerShell invocation to use pwsh on non-Windows and improves captured output formatting.

Comment on lines +197 to +203
FileName = powerShellCommand,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
Arguments = $"{script} -OutDir {currentDirectory}",
CreateNoWindow = false,
Verb = "runas"
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

ProcessStartInfo.Arguments = $"{script} -OutDir {currentDirectory}" does not quote/escape either path. If the repo/work directory contains spaces (common in CI), PowerShell will parse this incorrectly and the script won’t run. Build the arguments using -File and quote/escape the script path and -OutDir value (or use ArgumentList when available).

Copilot uses AI. Check for mistakes.
proc.Kill();
proc.WaitForExit(2000);
throw new Exception($"Could not generate certificate; script output: {output}");
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

After the process exits, the code only fails on timeout and never checks proc.ExitCode. If the script fails quickly (e.g., certificate generation errors), the test will continue with missing/invalid artifacts and later failures will be harder to diagnose. Throw when ExitCode != 0 and include the captured output to surface the root cause immediately.

Suggested change
}
}
if (proc.ExitCode != 0)
{
throw new Exception($"Could not generate certificate; exit code {proc.ExitCode}; script output: {output}");
}

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +26

Set-PSDebug -Trace 1

Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

Set-PSDebug -Trace 1 is enabled unconditionally, which will massively increase log volume and can slow down or even time out CI runs. Consider making tracing opt-in (e.g., gated by an env var/parameter) and ensure it’s turned back off (e.g., in a finally) so normal runs aren’t impacted.

Copilot uses AI. Check for mistakes.
@paulmedynski paulmedynski moved this from To triage to In review in SqlClient Board Feb 25, 2026
@paulmedynski paulmedynski modified the milestones: 7.0.0-preview4, 7.0.0 Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Engineering Use this for issues that are targeted for changes in the 'eng' folder or build systems.

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants