Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/windowscontainers"
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/winrm"
"github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/wsfc"
"github.com/GoogleCloudPlatform/cloud-image-tests/utils"
"github.com/GoogleCloudPlatform/compute-daisy/compute"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
Expand Down Expand Up @@ -479,10 +480,10 @@ func main() {
// Find the project of the image.
project := ""
for _, k := range imageKeys {
if strings.Contains(k, "sap") {
if utils.IsSAP(k) {
// sap follows a slightly different naming convention.
imageName := strings.Split(k, "-")[0]
if strings.HasPrefix(image, imageName) && strings.Contains(image, "sap") {
if strings.HasPrefix(image, imageName) && utils.IsSAP(image) {
project = projectMap[k]
break
}
Expand Down
3 changes: 1 addition & 2 deletions test_suites/acceleratorconfig/nic_naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package acceleratorconfig
import (
"fmt"
"regexp"
"strings"
"testing"

"github.com/GoogleCloudPlatform/cloud-image-tests/utils"
Expand Down Expand Up @@ -71,7 +70,7 @@ func TestNICNaming(t *testing.T) {
if !rdmaNICNameRegex.MatchString(iface.Name) {
// Allow images that don't have intent-based names yet to match the predictable name scheme instead.
// TODO remove exceptions when predictable name scheme is incorporated in each image.
if strings.Contains(image, "ubuntu") || strings.Contains(image, "rocky") {
if utils.IsUbuntu(image) || utils.IsRocky(image) {
if !predictableNICNameRegex.MatchString(iface.Name) {
t.Errorf("NIC name %q does not match predictable name scheme %q", iface.Name, predictableNICNameRegex.String())
}
Expand Down
2 changes: 1 addition & 1 deletion test_suites/cvm/cvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestTDXAttestation(t *testing.T) {
}
ctx := utils.Context(t)
// For Ubuntu image, the tdx_guest module was moved to linux-modules-extra package in the 1016 and newer kernels.
if strings.Contains(image, "ubuntu") {
if utils.IsUbuntu(image) {
kernelVersionCmd := exec.CommandContext(ctx, "uname", "-r")
kernelVersionOut, err := kernelVersionCmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test_suites/disk/disk_resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestDiskResize(t *testing.T) {

func getDiskSize(image string) (int64, error) {
diskPath := "/"
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
diskPath = "/mnt/stateful_partition"
}

Expand Down
18 changes: 9 additions & 9 deletions test_suites/hostnamevalidation/hostname_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ func TestCustomHostname(t *testing.T) {
}

// guest-configs does not support wicked
if strings.Contains(image, "sles") {
if utils.IsSLES(image) {
t.Skip("SLES doesn't support custom hostnames.")
}
if strings.Contains(image, "suse") {
if utils.IsSUSE(image) {
t.Skip("SUSE doesn't support custom hostnames.")
}
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
// Does not have updated guest-configs with systemd-network support.
t.Skip("Not supported on cos")
}
if strings.Contains(image, "ubuntu") {
if utils.IsUbuntu(image) {
// Does not have updated guest-configs with systemd-network support.
t.Skip("Not supported on ubuntu")
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestFQDN(t *testing.T) {
printSuseDebugInfo(t)
if hostname != metadataHostname {
// TODO(b/460799853): Remove this exception once the bug is fixed.
if strings.Contains(image, "sles") && strings.Contains(image, "arm") {
if utils.IsSLES(image) && strings.Contains(image, "arm") {
t.Skipf("Skipping TestFQDN for SLES ARM image: %q due to b/460799853, got hostname: %q, want hostname: %q", image, hostname, metadataHostname)
}
t.Errorf("hostname -f does not match metadata. Expected: %q got: %q", metadataHostname, hostname)
Expand Down Expand Up @@ -328,19 +328,19 @@ func TestHostsFile(t *testing.T) {
if err != nil {
t.Fatalf("couldn't get image from metadata")
}
if strings.Contains(image, "sles") {
if utils.IsSLES(image) {
// guest-configs does not support wicked
t.Skip("Not supported on SLES")
}
if strings.Contains(image, "suse") {
if utils.IsSUSE(image) {
// guest-configs does not support wicked
t.Skip("Not supported on SUSE")
}
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
// Does not have updated guest-configs with systemd-network support.
t.Skip("Not supported on cos")
}
if strings.Contains(image, "ubuntu") {
if utils.IsUbuntu(image) {
// Does not have updated guest-configs with systemd-network support.
t.Skip("Not supported on ubuntu")
}
Expand Down
4 changes: 2 additions & 2 deletions test_suites/imageboot/image_boot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ func findInstanceStartTime(ctx context.Context, t *testing.T) time.Time {
func findEssentialServiceStartTime(ctx context.Context, t *testing.T, image string) time.Time {
t.Helper()
essentialServices := []string{"google-guest-agent.service", "google-guest-agent-manager.service", "sshd.service"}
if strings.Contains(image, "windows") {
if utils.IsWindowsImage(image) {
essentialServices = []string{"GCEAgent", "GCEAgentManager"}
} else if strings.Contains(image, "ubuntu") {
} else if utils.IsUbuntu(image) {
essentialServices = []string{"google-guest-agent.service", "google-guest-agent-manager.service", "ssh.service"}
}
latestStartTime := time.Time{}
Expand Down
42 changes: 21 additions & 21 deletions test_suites/licensevalidation/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ func requiredLicenseList(t *imagetest.TestWorkflow) ([]string, error) {
var requiredLicenses []string
var project string
switch {
case strings.Contains(image.Name, "almalinux"):
case utils.IsAlmaLinux(image.Name):
project = "almalinux-cloud"
case strings.Contains(image.Name, "centos"):
case utils.IsCentOS(image.Name):
project = "centos-cloud"
transform = func() {
if image.Family == "centos-stream-8" {
// centos-stream-8 doesn't include -8
requiredLicenses[len(requiredLicenses)-1] = requiredLicenses[len(requiredLicenses)-1][:len(requiredLicenses[len(requiredLicenses)-1])-2]
}
}
case strings.Contains(image.Name, "debian"):
case utils.IsDebian(image.Name):
project = "debian-cloud"
transform = func() {
// Rightmost dash separated segment with only [a-z] chars should be the codename
Expand All @@ -133,55 +133,55 @@ func requiredLicenseList(t *imagetest.TestWorkflow) ([]string, error) {
requiredLicenses[i] += "-" + codename
}
}
case strings.Contains(image.Name, "opensuse"):
case utils.IsOpenSUSE(image.Name):
project = "opensuse-cloud"
// Quirk of opensuse licensing. This suffix will not need to be updated with version changes.
transform = func() { requiredLicenses[len(requiredLicenses)-1] += "-42" }
case strings.Contains(image.Name, "rhel") && strings.Contains(image.Name, "eus"):
case utils.IsRHELEUS(image.Name):
project = "rhel-cloud"
transform = func() {
rhelMajorVersion := strings.TrimPrefix(regexp.MustCompile("rhel-[0-9]{1,2}").FindString(image.Name), "rhel-")
suffix := "server"
if strings.Contains(image.Name, "byos") {
if utils.IsBYOS(image.Name) {
suffix = "byos"
}
requiredLicenses = []string{
fmt.Sprintf(licenseURLTmpl, project, fmt.Sprintf("rhel-%s-%s", rhelMajorVersion, suffix)),
fmt.Sprintf(licenseURLTmpl, project, fmt.Sprintf("rhel-%s-server-eus", rhelMajorVersion)),
}
}
case strings.Contains(image.Name, "rhel") && strings.Contains(image.Name, "lvm"):
case utils.IsRHELLVM(image.Name):
project = "rhel-cloud"
transform = func() {
rhelMajorVersion := strings.TrimPrefix(regexp.MustCompile("rhel-[0-9]{1,2}").FindString(image.Name), "rhel-")
suffix := "server"
if strings.Contains(image.Name, "byos") {
if utils.IsBYOS(image.Name) {
suffix = "byos"
}
requiredLicenses = []string{
fmt.Sprintf(licenseURLTmpl, project, fmt.Sprintf("rhel-%s-%s", rhelMajorVersion, suffix)),
fmt.Sprintf(licenseURLTmpl, project, fmt.Sprintf("rhel-lvm")),
}
}
case strings.Contains(image.Name, "rhel") && strings.Contains(image.Name, "sap"):
case utils.IsRHEL(image.Name) && utils.IsSAP(image.Name):
project = "rhel-sap-cloud"
transform = func() {
newSuffix := "-sap"
if strings.Contains(image.Name, "byos") {
if utils.IsBYOS(image.Name) {
newSuffix += "-byos"
}
rhelSapVersionRe := regexp.MustCompile("-[0-9]+-sap-(ha|byos)$")
requiredLicenses[len(requiredLicenses)-1] = rhelSapVersionRe.ReplaceAllString(requiredLicenses[len(requiredLicenses)-1], newSuffix)
}
case strings.Contains(image.Name, "rhel"):
case utils.IsRHEL(image.Name):
project = "rhel-cloud"
transform = func() {
if !strings.Contains(image.Name, "byos") {
if !utils.IsBYOS(image.Name) {
requiredLicenses[len(requiredLicenses)-1] += "-server"
}
requiredLicenses[len(requiredLicenses)-1] = strings.ReplaceAll(requiredLicenses[len(requiredLicenses)-1], "-c3m", "")
}
case strings.Contains(image.Name, "rocky") && strings.Contains(image.Name, "nvidia"):
case utils.IsRocky(image.Name) && utils.IsAccelerator(image.Name):
project = "rocky-linux-cloud"
rockyVersion := strings.TrimPrefix(regexp.MustCompile("rocky-linux-[0-9]{1,2}").FindString(image.Name), "rocky-linux-")
gpuDriverVersion := strings.TrimPrefix(regexp.MustCompile("nvidia-([0-9]{3}|latest)").FindString(image.Name), "nvidia-")
Expand All @@ -192,13 +192,13 @@ func requiredLicenseList(t *imagetest.TestWorkflow) ([]string, error) {
fmt.Sprintf(licenseURLTmpl, "rocky-linux-cloud", fmt.Sprintf("rocky-linux-%s-optimized-gcp", rockyVersion)),
}
}
case strings.Contains(image.Name, "oracle-linux"):
case utils.IsOracle(image.Name):
project = "oracle-linux-cloud"
case strings.Contains(image.Name, "rocky-linux"):
case utils.IsRocky(image.Name):
project = "rocky-linux-cloud"
case strings.Contains(image.Name, "sles") && strings.Contains(image.Name, "sap"):
case utils.IsSLES(image.Name) && utils.IsSAP(image.Name):
project = "suse-sap-cloud"
case strings.Contains(image.Name, "sles"):
case utils.IsSLES(image.Name):
project = "suse-cloud"
transform = func() {
// SLES licenses are major version only, e.g., "sles-15", "sles-16".
Expand All @@ -207,7 +207,7 @@ func requiredLicenseList(t *imagetest.TestWorkflow) ([]string, error) {
majorVersion := matches[1] // Captured group, e.g., "sles-16"
requiredLicenses[0] = fmt.Sprintf(licenseURLTmpl, project, majorVersion)
}
case strings.Contains(image.Name, "ubuntu") && strings.Contains(image.Name, "nvidia"):
case utils.IsUbuntu(image.Name) && utils.IsAccelerator(image.Name):
project = "ubuntu-os-cloud"
ubuntuVersion := strings.TrimPrefix(regexp.MustCompile("ubuntu-accelerator-[0-9]{4}").FindString(image.Name), "ubuntu-accelerator-")
if strings.HasSuffix(ubuntuVersion, "04") {
Expand All @@ -223,17 +223,17 @@ func requiredLicenseList(t *imagetest.TestWorkflow) ([]string, error) {
}
case strings.Contains(image.Name, "ubuntu-pro") || strings.Contains(image.Name, "ubuntu-minimal-pro"):
project = "ubuntu-os-pro-cloud"
case strings.Contains(image.Name, "ubuntu"):
case utils.IsUbuntu(image.Name):
project = "ubuntu-os-cloud"
case strings.Contains(image.Name, "windows") && strings.Contains(image.Name, "sql"):
case utils.IsWindowsImage(image.Name) && utils.IsWindowsSQLImage(image.Name):
project = "windows-cloud"
transform = func() {
requiredLicenses = []string{
fmt.Sprintf(licenseURLTmpl, "windows-sql-cloud", strings.Replace(sqlVersionRe.FindString(image.Name), "sql-", "sql-server-", -1)),
fmt.Sprintf(licenseURLTmpl, project, strings.Replace(sqlWindowsVersionRe.FindString(image.Name), "windows-", "windows-server-", -1)),
}
}
case strings.Contains(image.Name, "windows"):
case utils.IsWindowsImage(image.Name):
project = "windows-cloud"
transform = func() {
requiredLicenses = []string{fmt.Sprintf(licenseURLTmpl, project, "windows-server-"+regexp.MustCompile("[0-9]{4}(-r[0-9])?").FindString(image.Family)+"-dc")}
Expand Down
4 changes: 2 additions & 2 deletions test_suites/lvmvalidation/lvmvalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getSAPStatus(ctx context.Context) (bool, error) {
if err != nil {
return false, fmt.Errorf("failed to get image name: %v", err)
}
return strings.Contains(imageName, "sap"), nil
return utils.IsSAP(imageName), nil
}

// getLVMStatus returns true if the image is LVM, false otherwise.
Expand All @@ -53,7 +53,7 @@ func getLVMStatus(ctx context.Context) (bool, error) {
if err != nil {
return false, fmt.Errorf("failed to get image name: %v", err)
}
return strings.Contains(imageName, "lvm"), nil
return utils.IsRHELLVM(imageName), nil
}

// TestLVMPackage checks the lvm2 package install status.
Expand Down
2 changes: 1 addition & 1 deletion test_suites/mdsroutes/mds_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func shouldSkipSecondaryNICMDSCheck(ctx context.Context, t *testing.T) bool {
if err != nil {
t.Fatalf("Failed to get image from metadata: %v", err)
}
return utils.IsWindows() || strings.Contains(image, "sles") || strings.Contains(image, "debian-13")
return utils.IsWindows() || utils.IsSLES(image) || strings.Contains(image, "debian-13")
}

func TestMetadataPath(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions test_suites/metadata/metadata_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"io"
"os"
"os/exec"
"strings"
"testing"
"time"

Expand All @@ -39,7 +38,7 @@ func isUbuntu(ctx context.Context, t *testing.T) bool {
t.Logf("Could not read os-release: %v, defaulting skip agent reinstall to false", err)
return false
}
return strings.Contains(string(content), "ubuntu")
return utils.IsUbuntu(string(content))
}

func isVersionMismatch(ctx context.Context, t *testing.T, pkg string) bool {
Expand All @@ -57,7 +56,7 @@ func isVersionMismatch(ctx context.Context, t *testing.T, pkg string) bool {
}

// Ubuntu built/installed packages includes "ubuntu" in the version string.
return !strings.Contains(string(out), "ubuntu")
return !utils.IsUbuntu(string(out))
}

func reinstallGuestAgent(ctx context.Context, t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions test_suites/metadata/scripts_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package metadata
import (
"fmt"
"path"
"strings"
"testing"

"github.com/GoogleCloudPlatform/cloud-image-tests/utils"
Expand Down Expand Up @@ -50,7 +49,7 @@ func testScripts(t *testing.T, stage string, success bool) {
if err != nil {
t.Fatalf("could not determine image: %v", err)
}
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
return
}

Expand Down
3 changes: 1 addition & 2 deletions test_suites/metadata/shutdown_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package metadata

import (
"fmt"
"strings"
"testing"

"github.com/GoogleCloudPlatform/cloud-image-tests/utils"
Expand Down Expand Up @@ -60,7 +59,7 @@ func TestShutdownScripts(t *testing.T) {
}

// Only perform agent reinstall for non-COS images.
if !strings.Contains(image, "cos") {
if !utils.IsCOS(image) {
reinstallGuestAgent(ctx, t)
testScripts(t, "shutdown", false)
}
Expand Down
2 changes: 1 addition & 1 deletion test_suites/metadata/startup_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestStartupScripts(t *testing.T) {
}

// Only perform agent reinstall for non-COS images.
if !strings.Contains(image, "cos") {
if !utils.IsCOS(image) {
reinstallGuestAgent(ctx, t)
testScripts(t, "startup", false)
}
Expand Down
8 changes: 4 additions & 4 deletions test_suites/network/alias_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestAliases(t *testing.T) {
if err != nil {
t.Fatalf("could not determine image: %v", err)
}
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
t.Skipf("COS does not support IP aliases")
}
if err := verifyIPAliases(t); err != nil {
Expand All @@ -52,7 +52,7 @@ func TestAliasAfterReboot(t *testing.T) {
if err != nil {
t.Fatalf("could not determine image: %v", err)
}
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
t.Skipf("COS does not support IP aliases")
}
_, err = os.Stat(markerFile)
Expand Down Expand Up @@ -118,7 +118,7 @@ func skipIfUbuntu(t *testing.T) {
if err != nil {
t.Fatalf("could not determine image: %v", err)
}
if strings.Contains(image, "ubuntu") {
if utils.IsUbuntu(image) {
t.Skipf("Skipping test for Ubuntu images due to b/434210587")
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ func readNic(ctx context.Context, t *testing.T, id int) net.Interface {
if err != nil {
t.Fatalf("could not determine image: %v", err)
}
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
t.Skipf("COS does not support IP aliases")
}
iface, err := utils.GetInterface(ctx, id)
Expand Down
2 changes: 1 addition & 1 deletion test_suites/network/multinic_minimal_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestWaitForPing(t *testing.T) {
if err != nil {
t.Fatalf("could not determine image: %v", err)
}
if strings.Contains(image, "cos") {
if utils.IsCOS(image) {
allowTCPCmd := exec.CommandContext(ctx, "iptables", "-A", "INPUT", "-p", "tcp", "-j", "ACCEPT")
if out, err := allowTCPCmd.CombinedOutput(); err != nil {
t.Fatalf("iptables -A INPUT -p tcp -j ACCEPT failed: %s %v", out, err)
Expand Down
Loading