diff --git a/integration_test/gce/gce_testing.go b/integration_test/gce/gce_testing.go index 21e4c6310c..4aaca5a156 100644 --- a/integration_test/gce/gce_testing.go +++ b/integration_test/gce/gce_testing.go @@ -1262,7 +1262,7 @@ 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 { @@ -1270,13 +1270,13 @@ func attemptCreateInstance(ctx context.Context, logger *log.Logger, options VMOp } } - 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 { @@ -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-") } @@ -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) } @@ -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) } @@ -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)) @@ -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) diff --git a/integration_test/gce/gce_testing_test.go b/integration_test/gce/gce_testing_test.go index 75aa0f4592..ccf9bd9395 100644 --- a/integration_test/gce/gce_testing_test.go +++ b/integration_test/gce/gce_testing_test.go @@ -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.") @@ -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 @@ -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 { diff --git a/integration_test/ops_agent_test/main_test.go b/integration_test/ops_agent_test/main_test.go index 0ba1aa7c00..8df8cadee5 100644 --- a/integration_test/ops_agent_test/main_test.go +++ b/integration_test/ops_agent_test/main_test.go @@ -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 &" @@ -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.