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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestOutputAndInjectArtifacts(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

ukifyExists, err := file.CommandExists("ukify")
assert.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@ import (
)

func TestCustomizeImageMultiKernel(t *testing.T) {
for _, version := range supportedAzureLinuxVersions {
t.Run(string(version), func(t *testing.T) {
testCustomizeImageMultiKernel(t, "TestCustomizeImageMultiKernel"+string(version),
baseImageTypeCoreEfi, version)
for _, baseImageInfo := range baseImageAll {
t.Run(baseImageInfo.Name, func(t *testing.T) {
testCustomizeImageMultiKernel(t, "TestCustomizeImageMultiKernel"+baseImageInfo.Name, baseImageInfo)
})
}
}

func testCustomizeImageMultiKernel(t *testing.T, testName string, imageType baseImageType,
imageVersion baseImageVersion,
) {
baseImage := checkSkipForCustomizeImage(t, imageType, imageVersion)
func testCustomizeImageMultiKernel(t *testing.T, testName string, baseImageInfo testBaseImageInfo) {
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)

testTmpDir := filepath.Join(tmpDir, testName)
buildDir := filepath.Join(testTmpDir, "build")
outImageFilePath := filepath.Join(testTmpDir, "image.raw")

configFile := ""
switch imageVersion {
switch baseImageInfo.Version {
case baseImageVersionAzl2:
configFile = filepath.Join(testDir, "multikernel-azl2.yaml")

Expand Down Expand Up @@ -60,7 +57,7 @@ func testCustomizeImageMultiKernel(t *testing.T, testName string, imageType base
linuxCommandRegex := regexp.MustCompile(`linux.* console=tty0 console=ttyS0 `)
matches := linuxCommandRegex.FindAllString(grubCfgContents, -1)

switch imageVersion {
switch baseImageInfo.Version {
case baseImageVersionAzl2:
// AZL2's default grub.cfg file doesn't support multiple kernels.
assert.GreaterOrEqual(t, len(matches), 1, "grub.cfg:\n%s", grubCfgContents)
Expand Down
8 changes: 4 additions & 4 deletions toolkit/tools/pkg/imagecustomizerlib/customizefiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestCopyAdditionalFiles(t *testing.T) {
}

func TestCustomizeImageAdditionalFiles(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalFiles")
buildDir := filepath.Join(testTmpDir, "build")
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestCustomizeImageAdditionalFiles(t *testing.T) {
}

func TestCustomizeImageAdditionalFilesInfiniteFile(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalFilesInfiniteFile")
buildDir := filepath.Join(testTmpDir, "build")
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestCopyAdditionalDirs(t *testing.T) {
}

func TestCustomizeImageAdditionalDirs(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalDirs")
buildDir := filepath.Join(testTmpDir, "build")
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestCustomizeImageAdditionalDirs(t *testing.T) {
}

func TestCustomizeImageAdditionalDirsInfiniteFile(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageAdditionalDirsInfiniteFile")
buildDir := filepath.Join(testTmpDir, "build")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestUpdateHostname(t *testing.T) {
}

func TestCustomizeImageHostname(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageHostname")
buildDir := filepath.Join(testTmpDir, "build")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func TestCustomizeImageOverlays(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTempDir := filepath.Join(tmpDir, "TestCustomizeImageOverlays")
buildDir := filepath.Join(testTempDir, "build")
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestCustomizeImageOverlays(t *testing.T) {
}

func TestCustomizeImageOverlaysSELinux(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTempDir := filepath.Join(tmpDir, "TestCustomizeImageOverlaysSELinux")
buildDir := filepath.Join(testTempDir, "build")
Expand Down
31 changes: 19 additions & 12 deletions toolkit/tools/pkg/imagecustomizerlib/customizepackages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func TestCustomizeImagePackagesAddOfflineDir(t *testing.T) {
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesAddOfflineDir")

baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)
downloadedRpmsDir := getDownloadedRpmsDir(t, "2.0")

buildDir := filepath.Join(testTmpDir, "build")
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestCustomizeImagePackagesAddOfflineLocalRepoNoGpgKey(t *testing.T) {
func testCustomizeImagePackagesAddOfflineLocalRepoHelper(t *testing.T, testName string, withGpgKey bool) {
testTmpDir := filepath.Join(tmpDir, testName)

baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

downloadedRpmsRepoFile := getDownloadedRpmsRepoFile(t, "2.0", withGpgKey)
rpmSources := []string{downloadedRpmsRepoFile}
Expand Down Expand Up @@ -176,7 +176,7 @@ func testCustomizeImagePackagesAddOfflineLocalRepoHelper(t *testing.T, testName
}

func TestCustomizeImagePackagesUpdate(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, baseImageInfo := checkSkipForCustomizeDefaultImage(t)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesUpdate")
buildDir := filepath.Join(testTmpDir, "build")
Expand All @@ -198,7 +198,7 @@ func TestCustomizeImagePackagesUpdate(t *testing.T) {
defer imageConnection.Close()

// Ensure tdnf cache was cleaned.
ensureTdnfCacheCleanup(t, imageConnection, "/var/cache/tdnf")
ensureTdnfCacheCleanup(t, imageConnection, "/var/cache/tdnf", baseImageInfo)

// Ensure packages were installed.
ensureFilesExist(t, imageConnection,
Expand All @@ -212,7 +212,7 @@ func TestCustomizeImagePackagesUpdate(t *testing.T) {
}

func TestCustomizeImagePackagesDiskSpace(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionDefault)
baseImage, _ := checkSkipForCustomizeDefaultImage(t)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesDiskSpace")
buildDir := filepath.Join(testTmpDir, "build")
Expand All @@ -228,7 +228,8 @@ func TestCustomizeImagePackagesDiskSpace(t *testing.T) {
}

func TestCustomizeImagePackagesUrlSource(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
baseImageInfo := testBaseImageAzl3CoreEfi
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesUrlSource")
buildDir := filepath.Join(testTmpDir, "build")
Expand Down Expand Up @@ -258,7 +259,8 @@ func TestCustomizeImagePackagesUrlSource(t *testing.T) {
}

func TestCustomizeImagePackagesBadRepo(t *testing.T) {
baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
baseImageInfo := testBaseImageAzl3CoreEfi
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)

testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesBadRepo")
buildDir := filepath.Join(testTmpDir, "build")
Expand All @@ -274,7 +276,9 @@ func TestCustomizeImagePackagesBadRepo(t *testing.T) {
assert.ErrorContains(t, err, "failed to refresh tdnf repo metadata")
}

func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirPath string) {
func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirPath string,
baseImageInfo testBaseImageInfo,
) {
// Array to capture all the files of the provided root directory
var existingFiles []string

Expand All @@ -285,7 +289,7 @@ func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirP
return fmt.Errorf("Failed to access path (%s): %w", path, err)
}
// Ignore files in the local-repo folder if the base image version is 2.0
if !(strings.Contains(path, "local-repo") && baseImageVersionDefault == "2.0") {
if !(strings.Contains(path, "local-repo") && baseImageInfo.Version == baseImageVersionAzl2) {
fileInfo, err := os.Stat(path)
if err != nil {
return fmt.Errorf("failed to get file info for %s: %w", path, err)
Expand All @@ -307,7 +311,8 @@ func ensureTdnfCacheCleanup(t *testing.T, imageConnection *ImageConnection, dirP
func TestCustomizeImagePackagesSnapshotTime(t *testing.T) {
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesSnapshotTime")

baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
baseImageInfo := testBaseImageAzl3CoreEfi
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
buildDir := filepath.Join(testTmpDir, "build")
outImageFilePath := filepath.Join(testTmpDir, "image.raw")

Expand Down Expand Up @@ -355,7 +360,8 @@ func TestCustomizeImagePackagesSnapshotTime(t *testing.T) {
func TestCustomizeImagePackagesCliSnapshotTimeOverridesConfigFile(t *testing.T) {
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesSnapshotTime")

baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
baseImageInfo := testBaseImageAzl3CoreEfi
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
buildDir := filepath.Join(testTmpDir, "build")
outImageFilePath := filepath.Join(testTmpDir, "image.raw")
snapshotTimeConfig := "2025-03-19"
Expand Down Expand Up @@ -403,7 +409,8 @@ func TestCustomizeImagePackagesCliSnapshotTimeOverridesConfigFile(t *testing.T)
func TestCustomizeImagePackagesSnapshotTimeWithoutPreviewFlagFails(t *testing.T) {
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImagePackagesSnapshotTimeWithoutPreviewFlagFails")

baseImage := checkSkipForCustomizeImage(t, baseImageTypeCoreEfi, baseImageVersionAzl3)
baseImageInfo := testBaseImageAzl3CoreEfi
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)

buildDir := filepath.Join(testTmpDir, "build")
outImageFilePath := filepath.Join(testTmpDir, "image.raw")
Expand Down
Loading
Loading