Skip to content

Commit

Permalink
Testing: Update IsSUSE and call to prepareSLES. (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscovalentecastro committed May 22, 2024
1 parent 7a58c41 commit 955360c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
24 changes: 16 additions & 8 deletions integration_test/gce/gce_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,21 +1262,21 @@ func attemptCreateInstance(ctx context.Context, logger *log.Logger, options VMOp
vm.OS = *os
}

if vm.OS.ID == "opensuse" || vm.OS.ID == "opensuse-leap" || vm.OS.ID == "sles" || vm.OS.ID == "sles_sap" {
if IsSUSEVM(vm) {
// Set download.max_silent_tries to 5 (by default, it is commented out in
// the config file). This should help with issues like b/211003972.
if _, err := RunRemotely(ctx, logger, vm, "sudo sed -i -E 's/.*download.max_silent_tries.*/download.max_silent_tries = 5/g' /etc/zypp/zypp.conf"); err != nil {
return nil, fmt.Errorf("attemptCreateInstance() failed to configure retries in zypp.conf: %v", err)
}
}

if strings.HasPrefix(vm.ImageSpec, "sles-") {
if IsSLESVM(vm) {
if err := prepareSLES(ctx, logger, vm); err != nil {
return nil, fmt.Errorf("%s: %v", prepareSLESMessage, err)
}
}

if IsSUSE(vm.ImageSpec) {
if IsSUSEVM(vm) {
// Set ZYPP_LOCK_TIMEOUT so tests that use zypper don't randomly fail
// because some background process happened to be using zypper at the same time.
if _, err := RunRemotely(ctx, logger, vm, `echo 'ZYPP_LOCK_TIMEOUT=300' | sudo tee -a /etc/environment`); err != nil {
Expand All @@ -1302,7 +1302,15 @@ func attemptCreateInstance(ctx context.Context, logger *log.Logger, options VMOp
return vm, nil
}

func IsSUSE(imageSpec string) bool {
func IsSLESVM(vm *VM) bool {
return vm.OS.ID == "sles" || vm.OS.ID == "sles_sap"
}

func IsSUSEVM(vm *VM) bool {
return vm.OS.ID == "opensuse" || vm.OS.ID == "opensuse-leap" || IsSLESVM(vm)
}

func IsSUSEImageSpec(imageSpec string) bool {
return strings.HasPrefix(imageSpec, "suse-") || strings.HasPrefix(imageSpec, "opensuse-") || strings.Contains(imageSpec, "sles-")
}

Expand Down Expand Up @@ -1351,7 +1359,7 @@ func CreateInstance(origCtx context.Context, logger *log.Logger, options VMOptio
// windows-*-core instances sometimes fail to be ssh-able: b/305721001
(IsWindowsCore(options.ImageSpec) && strings.Contains(err.Error(), windowsStartupFailedMessage)) ||
// SLES instances sometimes fail to be ssh-able: b/186426190
(IsSUSE(options.ImageSpec) && strings.Contains(err.Error(), startupFailedMessage)) ||
(IsSUSEImageSpec(options.ImageSpec) && strings.Contains(err.Error(), startupFailedMessage)) ||
strings.Contains(err.Error(), prepareSLESMessage)
}

Expand Down Expand Up @@ -1550,7 +1558,7 @@ func InstallGsutilIfNeeded(ctx context.Context, logger *log.Logger, vm *VM) erro

// SUSE seems to be the only distro without gsutil, so what follows is all
// very SUSE-specific.
if vm.OS.ID != "opensuse" && vm.OS.ID != "opensuse-leap" && vm.OS.ID != "sles" && vm.OS.ID != "sles_sap" {
if !IsSUSEVM(vm) {
return installErr("gsutil", vm.OS.ID)
}

Expand Down Expand Up @@ -1765,7 +1773,7 @@ func waitForStartWindows(ctx context.Context, logger *log.Logger, vm *VM) error
func waitForStartLinux(ctx context.Context, logger *log.Logger, vm *VM) error {
var backoffPolicy backoff.BackOff
backoffPolicy = backoff.NewConstantBackOff(vmInitBackoffDuration)
if IsSUSE(vm.ImageSpec) {
if IsSUSEImageSpec(vm.ImageSpec) {
// Give up early on SUSE due to b/186426190. If this step times out, the
// error will be retried with a fresh VM.
backoffPolicy = backoff.WithMaxRetries(backoffPolicy, uint64((5*time.Minute)/vmInitBackoffDuration))
Expand Down Expand Up @@ -1807,7 +1815,7 @@ func waitForStartLinux(ctx context.Context, logger *log.Logger, vm *VM) error {
return fmt.Errorf("%v. Last err=%v", startupFailedMessage, err)
}

if IsSUSE(vm.ImageSpec) {
if IsSUSEImageSpec(vm.ImageSpec) {
// TODO(b/259122953): SUSE needs additional startup time. Remove once we have more
// sensible/deterministic workarounds for each of the individual problems.
time.Sleep(slesStartupDelay)
Expand Down
8 changes: 4 additions & 4 deletions integration_test/gce/gce_testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func SetupLoggerAndVM(t *testing.T, platform string) (context.Context, *logging.

logger := gce.SetupLogger(t)
options := gce.VMOptions{
ImageSpec: platform,
TimeToLive: "1h",
ImageSpec: platform,
TimeToLive: "1h",
MachineType: agents.RecommendedMachineType(platform),
}
logger.ToMainLog().Println("Calling SetupVM(). For details, see VM_initialization.txt.")
Expand Down Expand Up @@ -407,7 +407,7 @@ func eachByte() []byte {
// calculateRemoteMD5 computes the MD5 of the given file in a
// platform-specific way and returns the result as a lowercase hex string.
func calculateRemoteMD5(ctx context.Context, logger *log.Logger, vm *gce.VM, path string) (string, error) {
if gce.IsWindows(vm.Platform) {
if gce.IsWindows(vm.ImageSpec) {
output, err := gce.RunRemotely(ctx, logger, vm, fmt.Sprintf("(Get-FileHash -Algorithm MD5 -Path '%s').Hash", path))
if err != nil {
return "", err
Expand Down Expand Up @@ -454,7 +454,7 @@ func TestUploadContent(t *testing.T) {
t.Errorf("got MD5 %q for file %v (size %v), want %q", actualMD5, path, len(data), expectedMD5)
if len(data) < 1000 {
var dumpCmd string
if gce.IsWindows(vm.Platform) {
if gce.IsWindows(vm.ImageSpec) {
// Use pwsh instead of powershell to get access to "-AsByteStream".
dumpCmd = fmt.Sprintf(`pwsh -Command "'bytes in base 10:'; Get-Content -AsByteStream '%s'"`, path)
} else {
Expand Down
8 changes: 4 additions & 4 deletions integration_test/ops_agent_test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4418,15 +4418,15 @@ func getRecentServiceOutputForImage(imageSpec string) string {
return "sudo systemctl status google-cloud-ops-agent"
}

func listenToPortForImage(imageSpec string) string {
if gce.IsWindows(imageSpec) {
func listenToPortForImage(vm *gce.VM) string {
if gce.IsWindows(vm.ImageSpec) {
cmd := strings.Join([]string{
`Invoke-WmiMethod -Path 'Win32_Process' -Name Create -ArgumentList 'powershell.exe -Command "$Listener = [System.Net.Sockets.TcpListener]20201; $Listener.Start(); Start-Sleep -Seconds 600"'`,
}, ";")

return cmd
}
if gce.IsCentOS(imageSpec) || gce.IsSUSE(imageSpec) {
if gce.IsCentOS(vm.ImageSpec) || gce.IsSUSEVM(vm) {
return "nohup nc -l 20201 1>/dev/null 2>/dev/null &"
}
return "nohup nc -l -p 20201 1>/dev/null 2>/dev/null &"
Expand Down Expand Up @@ -4461,7 +4461,7 @@ func TestPortsAndAPIHealthChecks(t *testing.T) {
}
}

if _, err := gce.RunRemotely(ctx, logger, vm, listenToPortForImage(vm.ImageSpec)); err != nil {
if _, err := gce.RunRemotely(ctx, logger, vm, listenToPortForImage(vm)); err != nil {
t.Fatal(err)
}
// Wait for port to be in listen mode.
Expand Down

0 comments on commit 955360c

Please sign in to comment.