Skip to content

Commit 50f13d5

Browse files
committed
Feedback updates
1 parent b72bcbf commit 50f13d5

3 files changed

Lines changed: 65 additions & 4 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/distrohandler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func testCustomizeImageUnsupportedPackageSnapshotTimeHelper(t *testing.T, baseIm
161161
}
162162

163163
func TestCustomizeImageUnsupportedRpmSources(t *testing.T) {
164-
for _, baseImageInfo := range slices.Concat(baseImageUbuntuAll) {
164+
for _, baseImageInfo := range baseImageUbuntuAll {
165165
t.Run(baseImageInfo.Name, func(t *testing.T) {
166166
testCustomizeImageUnsupportedRpmSourcesHelper(t, baseImageInfo)
167167
})

toolkit/tools/pkg/imagecustomizerlib/distrohandler_ubuntu.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ const (
3131
grubEfiPackageDebianArm64 = "grub-efi-arm64"
3232
)
3333

34+
var (
35+
ErrUbuntuUnsupportedBootloaderHardReset = NewImageCustomizerError("Validation:UbuntuUnsupportedBootloaderHardReset", "bootloader hard-reset API is not supported yet for Ubuntu images")
36+
ErrUbuntuUnsupportedDisableBaseImageRepos = NewImageCustomizerError("Validation:UbuntuUnsupportedDisableBaseImageRepos", "disabling base image package repositories is not supported yet for Ubuntu images")
37+
)
38+
3439
func newUbuntuDistroHandler(targetOs targetos.TargetOs) *ubuntuDistroHandler {
3540
logger.Log.Debugf("Distro handler: Ubuntu (distro='%s', versionid='%s')", targetOs.Distro, targetOs.VersionId)
3641

@@ -72,7 +77,7 @@ func (d *ubuntuDistroHandler) checkForUnsupportedApis(rc *ResolvedConfig) error
7277
// Check if Ubuntu is being used with bootloader hard-reset.
7378
// Ubuntu bootloader config logic is not yet fully implemented.
7479
if rc.BootLoader.ResetType == imagecustomizerapi.ResetBootLoaderTypeHard {
75-
return fmt.Errorf("bootloader hard-reset API is not yet supported for Ubuntu images")
80+
return ErrUbuntuUnsupportedBootloaderHardReset
7681
}
7782

7883
if len(rc.Options.RpmsSources) > 0 {
@@ -83,7 +88,7 @@ func (d *ubuntuDistroHandler) checkForUnsupportedApis(rc *ResolvedConfig) error
8388
// passes --disable-base-image-rpm-repos. Ubuntu does not use RPM repos, so disabling
8489
// them is not meaningful and likely indicates a configuration mistake.
8590
if !rc.Options.UseBaseImageRpmRepos {
86-
return fmt.Errorf("disabling base image package repositories is not supported yet for Ubuntu images")
91+
return ErrUbuntuUnsupportedDisableBaseImageRepos
8792
}
8893

8994
if rc.HasPackageSnapshotTime() {
@@ -202,7 +207,7 @@ func (d *ubuntuDistroHandler) ConfigureDiskBootLoader(imageConnection *imageconn
202207
selinuxConfig imagecustomizerapi.SELinux, kernelCommandLine imagecustomizerapi.KernelCommandLine,
203208
currentSELinuxMode imagecustomizerapi.SELinuxMode, newImage bool,
204209
) error {
205-
return fmt.Errorf("bootloader hard-reset API is not yet supported for Ubuntu images")
210+
return ErrUbuntuUnsupportedBootloaderHardReset
206211
}
207212

208213
func (d *ubuntuDistroHandler) ReadGrubConfigLinuxArgs(bootDir string) (map[string][]grubConfigLinuxArg, error) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
package imagecustomizerlib
5+
6+
import (
7+
"os"
8+
"path/filepath"
9+
"testing"
10+
11+
"github.com/microsoft/azure-linux-image-tools/toolkit/tools/imagecustomizerapi"
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestCustomizeImageUbuntuUnsupportedAPIs(t *testing.T) {
16+
for _, baseImageInfo := range baseImageUbuntuAll {
17+
t.Run(baseImageInfo.Name, func(t *testing.T) {
18+
testCustomizeImageUbuntuUnsupportedAPIsHelper(t, baseImageInfo)
19+
})
20+
}
21+
}
22+
23+
func testCustomizeImageUbuntuUnsupportedAPIsHelper(t *testing.T, baseImageInfo testBaseImageInfo) {
24+
baseImage := checkSkipForCustomizeImage(t, baseImageInfo)
25+
26+
testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageUbuntuUnsupportedAPIs_"+baseImageInfo.Name)
27+
defer os.RemoveAll(testTmpDir)
28+
29+
buildDir := filepath.Join(testTmpDir, "build")
30+
31+
options := ImageCustomizerOptions{
32+
BuildDir: buildDir,
33+
InputImageFile: baseImage,
34+
OutputImageFile: "./out/image.vhdx",
35+
OutputImageFormat: "vhdx",
36+
UseBaseImageRpmRepos: true,
37+
PreviewFeatures: baseImageInfo.PreviewFeatures,
38+
}
39+
40+
config := &imagecustomizerapi.Config{
41+
OS: &imagecustomizerapi.OS{},
42+
}
43+
44+
config.OS.BootLoader.ResetType = imagecustomizerapi.ResetBootLoaderTypeHard
45+
46+
err := CustomizeImage(t.Context(), testTmpDir, config, options)
47+
assert.ErrorIs(t, err, ErrUbuntuUnsupportedBootloaderHardReset)
48+
assert.ErrorIs(t, err, ErrUnsupportedDistroApi)
49+
50+
config.OS.BootLoader.ResetType = imagecustomizerapi.ResetBootLoaderTypeDefault
51+
options.UseBaseImageRpmRepos = false
52+
53+
err = CustomizeImage(t.Context(), testTmpDir, config, options)
54+
assert.ErrorIs(t, err, ErrUbuntuUnsupportedDisableBaseImageRepos)
55+
assert.ErrorIs(t, err, ErrUnsupportedDistroApi)
56+
}

0 commit comments

Comments
 (0)