Skip to content

Commit

Permalink
Feedback on version checking.
Browse files Browse the repository at this point in the history
Also add a bit of sanity checking and argument consistency to the
msi install/uninstall APIs
  • Loading branch information
derekwbrown committed Oct 9, 2024
1 parent 33dfcf8 commit c7e4512
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/new-e2e/tests/windows/common/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func UninstallAgent(host *components.RemoteHost, logPath string) error {
if err != nil {
return err
}
return windowsCommon.UninstallMSI(host, product, logPath)
return windowsCommon.UninstallMSI(host, product, "", logPath)
}

// HasValidDatadogCodeSignature an error if the file at the given path is not validy signed by the Datadog Code Signing certificate
Expand Down
11 changes: 8 additions & 3 deletions test/new-e2e/tests/windows/common/msi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package common

import (
"fmt"

"strings"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
)

Expand All @@ -19,6 +19,11 @@ import (
// - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.4#example-7-specifying-arguments-to-the-process
// - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.4
func MsiExec(host *components.RemoteHost, operation string, product string, args string, logPath string) error {

if !strings.HasPrefix(operation, "/") {
return fmt.Errorf("unexpected operation: %s", operation)
}

remoteLogPath, err := GetTemporaryFile(host)
if err != nil {
return err
Expand Down Expand Up @@ -48,8 +53,8 @@ func InstallMSI(host *components.RemoteHost, msiPath string, args string, logPat
}

// UninstallMSI uninstalls an MSI on the VM and collects the uninstall log
func UninstallMSI(host *components.RemoteHost, msiPath string, logPath string) error {
err := MsiExec(host, "/x", msiPath, "", logPath)
func UninstallMSI(host *components.RemoteHost, msiPath string, args string, logPath string) error {
err := MsiExec(host, "/x", msiPath, args, logPath)
if err != nil {
return fmt.Errorf("failed to uninstall MSI: %w", err)
}
Expand Down
24 changes: 18 additions & 6 deletions test/new-e2e/tests/windows/common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ import (

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
)

// GetFileVersion gets the file version information from the versioninfo resource
// of the specified file. It returns as a single string
func GetFileVersion(host *components.RemoteHost, remoteFileName string) (string, error) {
pscommand := fmt.Sprintf(`(Get-Item "%s").VersionInfo.FileVersion`, remoteFileName)
remoteversion, err := host.Execute(pscommand)
if err != nil {
return "", fmt.Errorf("failed to get version: %w", err)
}
return strings.TrimSpace(remoteversion), nil
}

// VerifyVersion takes a filename and an expected version and determines
// if the file matches the expected version.
//
Expand All @@ -33,19 +45,19 @@ func VerifyVersion(host *components.RemoteHost, remoteFileName, expectedVersion
expectedVersion = string(output)
expectedVersion = expectedVersion[:strings.Index(expectedVersion, "-")]
}
versions := strings.Split(expectedVersion, ".")
fmt.Printf("Looking for version %v\n", versions)
if len(versions) != 3 {
expectedparts := strings.Split(expectedVersion, ".")
fmt.Printf("Looking for version %v\n", expectedparts)
if len(expectedparts) != 3 {
return fmt.Errorf("expected version must be in the form M.m.p.b")
}
pscommand := fmt.Sprintf(`(Get-Item "%s").VersionInfo.FileVersion`, remoteFileName)
remoteversion, err := host.Execute(pscommand)

remoteversion, err := GetFileVersion(host, remoteFileName)
if err != nil {
return fmt.Errorf("failed to get version: %w", err)
}
remoteversionparts := strings.Split(strings.TrimSpace(remoteversion), ".")
fmt.Printf("Found version %v\n", remoteversionparts)
for idx, v := range versions {
for idx, v := range expectedparts {
if v != remoteversionparts[idx] {
return fmt.Errorf("expected version %v, got %v", expectedVersion, remoteversion)
}
Expand Down

0 comments on commit c7e4512

Please sign in to comment.