Skip to content

Commit

Permalink
test: update registry and image type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleas-k committed Nov 10, 2023
1 parent d48418c commit 60d0b8e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
22 changes: 21 additions & 1 deletion pkg/distro/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func TestImageType_PackageSetsChains(t *testing.T) {
URL: "https://example.com", // required by some image types
},
}
if imageType.Name() == "coreos-qcow2" {
options.OSTree.Container = "https://registry.example.com/image"
}

manifest, _, err := imageType.Manifest(&bp, options, nil, 0)
require.NoError(t, err)
imagePkgSets := manifest.GetPackageSetChains()
Expand Down Expand Up @@ -134,6 +138,9 @@ func TestImageTypePipelineNames(t *testing.T) {
options.OSTree = &ostree.ImageOptions{
URL: "https://example.com",
}
if imageType.Name() == "coreos-qcow2" {
options.OSTree.Container = "https://registry.example.com/image"
}

// Pipelines that require package sets will fail if none
// are defined. OS pipelines require a kernel.
Expand Down Expand Up @@ -168,6 +175,18 @@ func TestImageTypePipelineNames(t *testing.T) {
}
commits[name] = commitSpecs
}
if options.OSTree.Container != "" {
for name, containerSources := range m.GetContainerSourceSpecs() {
containers[name] = []container.Spec{
{
Source: options.OSTree.Container,
Digest: fmt.Sprintf("sha256:%x", sha256.Sum256([]byte(containerSources[0].Source))),
TLSVerify: containerSources[0].TLSVerify,
ImageID: fmt.Sprintf("sha256:%x", sha256.Sum256([]byte(containerSources[0].Source))),
},
}
}
}
mf, err := m.Serialize(packageSets, containers, commits)
assert.NoError(err)
pm := new(manifest)
Expand Down Expand Up @@ -445,7 +464,8 @@ func TestPipelineRepositories(t *testing.T) {

// Add ostree options for image types that require them
options.OSTree = &ostree.ImageOptions{
URL: "https://example.com",
URL: "https://example.com",
Container: "https://registry.example.com/image",
}

repos := tCase.repos
Expand Down
27 changes: 26 additions & 1 deletion pkg/distro/distro_test_common/distro_test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestDistro_KernelOption(t *testing.T, d distro.Distro) {
// Ostree installers and raw images download a payload to embed or
// deploy. The kernel is part of the payload so it doesn't appear in
// the image type's package lists.
"coreos-qcow2": true,
"edge-ami": true,
"edge-installer": true,
"edge-raw-image": true,
Expand Down Expand Up @@ -168,18 +169,22 @@ func TestDistro_OSTreeOptions(t *testing.T, d distro.Distro) {
}

typesWithPayload := map[string]bool{
"edge-vsphere": true,
"edge-ami": true,
"edge-installer": true,
"edge-raw-image": true,
"edge-simplified-installer": true,
"edge-vsphere": true,
"iot-ami": true,
"iot-installer": true,
"iot-qcow2-image": true,
"iot-raw-image": true,
"iot-simplified-installer": true,
}

typesWithContainerPayload := map[string]bool{
"coreos-qcow2": true,
}

assert := assert.New(t)

{ // empty options: payload ref should equal default
Expand All @@ -206,6 +211,10 @@ func TestDistro_OSTreeOptions(t *testing.T, d distro.Distro) {
}
options := distro.ImageOptions{OSTree: &ostreeOptions}

if typesWithContainerPayload[typeName] {
ostreeOptions.Container = "https://registry.example.com/image"
}

m, _, err := imgType.Manifest(bp, options, nil, 0)
assert.NoError(err)

Expand Down Expand Up @@ -254,6 +263,10 @@ func TestDistro_OSTreeOptions(t *testing.T, d distro.Distro) {
// payload types require URL
ostreeOptions.URL = "https://example.com/repo"
}
if typesWithContainerPayload[typeName] {
ostreeOptions.Container = "https://registry.example.com/image"
}

options := distro.ImageOptions{OSTree: &ostreeOptions}
m, _, err := imgType.Manifest(bp, options, nil, 0)
assert.NoError(err)
Expand Down Expand Up @@ -300,6 +313,10 @@ func TestDistro_OSTreeOptions(t *testing.T, d distro.Distro) {
ImageRef: "test/x86_64/01",
URL: "https://example.com/repo",
}
if typesWithContainerPayload[typeName] {
ostreeOptions.Container = "https://registry.example.com/image"
}

options := distro.ImageOptions{OSTree: &ostreeOptions}
m, _, err := imgType.Manifest(bp, options, nil, 0)
assert.NoError(err)
Expand Down Expand Up @@ -344,6 +361,10 @@ func TestDistro_OSTreeOptions(t *testing.T, d distro.Distro) {
ParentRef: "test/x86_64/01",
URL: "https://example.com/repo",
}
if typesWithContainerPayload[typeName] {
ostreeOptions.Container = "https://registry.example.com/image"
}

options := distro.ImageOptions{OSTree: &ostreeOptions}
m, _, err := imgType.Manifest(bp, options, nil, 0)
assert.NoError(err)
Expand Down Expand Up @@ -398,6 +419,10 @@ func TestDistro_OSTreeOptions(t *testing.T, d distro.Distro) {
ParentRef: "test/x86_64/02",
URL: "https://example.com/repo",
}
if typesWithContainerPayload[typeName] {
ostreeOptions.Container = "https://registry.example.com/image"
}

options := distro.ImageOptions{OSTree: &ostreeOptions}
m, _, err := imgType.Manifest(bp, options, nil, 0)
assert.NoError(err)
Expand Down
15 changes: 8 additions & 7 deletions pkg/distro/fedora/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func TestDistro_ManifestError(t *testing.T) {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for boot ISO image type \"%s\": (allowed: User, Group)", imgTypeName))
} else if imgTypeName == "live-installer" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for boot ISO image type \"%s\": (allowed: None)", imgTypeName))
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" {
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" || imgTypeName == "coreos-qcow2" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for image type %q: (allowed: User, Group, Directories, Files, Services)", imgTypeName))
} else {
assert.NoError(t, err)
Expand All @@ -516,6 +516,7 @@ func TestArchitecture_ListImageTypes(t *testing.T) {
imgNames: []string{
"ami",
"container",
"coreos-qcow2",
"image-installer",
"iot-commit",
"iot-container",
Expand Down Expand Up @@ -671,7 +672,7 @@ func TestDistro_CustomFileSystemManifestError(t *testing.T) {
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "iot-commit" || imgTypeName == "iot-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" {
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" || imgTypeName == "coreos-qcow2" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for image type %q: (allowed: User, Group, Directories, Files, Services)", imgTypeName))
} else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" || imgTypeName == "image-installer" {
continue
Expand Down Expand Up @@ -703,7 +704,7 @@ func TestDistro_TestRootMountPoint(t *testing.T) {
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "iot-commit" || imgTypeName == "iot-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" {
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" || imgTypeName == "coreos-qcow2" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for image type %q: (allowed: User, Group, Directories, Files, Services)", imgTypeName))
} else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" || imgTypeName == "image-installer" {
continue
Expand Down Expand Up @@ -737,7 +738,7 @@ func TestDistro_CustomFileSystemSubDirectories(t *testing.T) {
for _, imgTypeName := range arch.ListImageTypes() {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if strings.HasPrefix(imgTypeName, "iot-") || strings.HasPrefix(imgTypeName, "image-") {
if strings.HasPrefix(imgTypeName, "iot-") || strings.HasPrefix(imgTypeName, "image-") || imgTypeName == "coreos-qcow2" {
continue
} else if imgTypeName == "live-installer" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for boot ISO image type \"%s\": (allowed: None)", imgTypeName))
Expand Down Expand Up @@ -777,7 +778,7 @@ func TestDistro_MountpointsWithArbitraryDepthAllowed(t *testing.T) {
for _, imgTypeName := range arch.ListImageTypes() {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if strings.HasPrefix(imgTypeName, "iot-") || strings.HasPrefix(imgTypeName, "image-") {
if strings.HasPrefix(imgTypeName, "iot-") || strings.HasPrefix(imgTypeName, "image-") || imgTypeName == "coreos-qcow2" {
continue
} else if imgTypeName == "live-installer" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for boot ISO image type \"%s\": (allowed: None)", imgTypeName))
Expand Down Expand Up @@ -813,7 +814,7 @@ func TestDistro_DirtyMountpointsNotAllowed(t *testing.T) {
for _, imgTypeName := range arch.ListImageTypes() {
imgType, _ := arch.GetImageType(imgTypeName)
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if strings.HasPrefix(imgTypeName, "iot-") || strings.HasPrefix(imgTypeName, "image-") {
if strings.HasPrefix(imgTypeName, "iot-") || strings.HasPrefix(imgTypeName, "image-") || imgTypeName == "coreos-qcow2" {
continue
} else if imgTypeName == "live-installer" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for boot ISO image type \"%s\": (allowed: None)", imgTypeName))
Expand Down Expand Up @@ -843,7 +844,7 @@ func TestDistro_CustomUsrPartitionNotLargeEnough(t *testing.T) {
_, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0)
if imgTypeName == "iot-commit" || imgTypeName == "iot-container" {
assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types")
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" {
} else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" || imgTypeName == "coreos-qcow2" {
assert.EqualError(t, err, fmt.Sprintf("unsupported blueprint customizations found for image type %q: (allowed: User, Group, Directories, Files, Services)", imgTypeName))
} else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" || imgTypeName == "image-installer" {
continue
Expand Down
3 changes: 2 additions & 1 deletion pkg/distro/fedora/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp
}
}

if t.name == "iot-raw-image" || t.name == "iot-qcow2-image" {
if t.name == "iot-raw-image" || t.name == "iot-qcow2-image" || t.name == "coreos-qcow2" {
// TODO: support kernel args for these types
allowed := []string{"User", "Group", "Directories", "Files", "Services"}
if err := customizations.CheckAllowed(allowed...); err != nil {
return nil, fmt.Errorf("unsupported blueprint customizations found for image type %q: (allowed: %s)", t.name, strings.Join(allowed, ", "))
Expand Down

0 comments on commit 60d0b8e

Please sign in to comment.