Skip to content

Commit

Permalink
WIP: serializeStart()
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleas-k committed Apr 9, 2024
1 parent f38ffb4 commit 5e263ea
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 36 deletions.
4 changes: 3 additions & 1 deletion pkg/distro/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ func TestImageTypePipelineNames(t *testing.T) {
}

packageSets := make(map[string][]rpmmd.PackageSpec, len(allPipelines))
repoSets := make(map[string][]rpmmd.RepoConfig, len(allPipelines))
for _, plName := range allPipelines {
packageSets[plName] = minimalPackageSet
repoSets[plName] = repos
}

m, _, err := imageType.Manifest(&bp, options, repos, seed)
Expand All @@ -172,7 +174,7 @@ func TestImageTypePipelineNames(t *testing.T) {
}
commits[name] = commitSpecs
}
mf, err := m.Serialize(packageSets, containers, commits)
mf, err := m.Serialize(packageSets, containers, commits, repoSets)
assert.NoError(err)
pm := new(manifest)
err = json.Unmarshal(mf, pm)
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/bootc_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func makeBootcDiskImageOsbuildManifest(t *testing.T, opts *bootcDiskImageTestOpt
"image": []container.Spec{{Source: "other-src", Digest: makeFakeDigest(t), ImageID: makeFakeDigest(t)}},
}

osbuildManifest, err := m.Serialize(nil, fakeSourceSpecs, nil)
osbuildManifest, err := m.Serialize(nil, fakeSourceSpecs, nil, nil)
require.Nil(t, err)

return osbuildManifest
Expand Down
3 changes: 2 additions & 1 deletion pkg/manifest/anaconda_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ func (p *AnacondaInstaller) getPackageSpecs() []rpmmd.PackageSpec {
return p.packageSpecs
}

func (p *AnacondaInstaller) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec) {
func (p *AnacondaInstaller) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec, rpmRepos []rpmmd.RepoConfig) {
if len(p.packageSpecs) > 0 {
panic("double call to serializeStart()")
}
p.packageSpecs = packages
if p.kernelName != "" {
p.kernelVer = rpmmd.GetVerStrFromPackageSpecListPanic(p.packageSpecs, p.kernelName)
}
p.repos = append(p.repos, rpmRepos...)
}

func (p *AnacondaInstaller) serializeEnd() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/anaconda_installer_iso_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (p *AnacondaInstallerISOTree) getBuildPackages(_ Distro) []string {
return packages
}

func (p *AnacondaInstallerISOTree) serializeStart(_ []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec) {
func (p *AnacondaInstallerISOTree) serializeStart(_ []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec, _ []rpmmd.RepoConfig) {
if p.ostreeCommitSpec != nil || p.containerSpec != nil {
panic("double call to serializeStart()")
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/manifest/anaconda_installer_iso_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func TestAnacondaISOTreePayloadsBad(t *testing.T) {

assert.PanicsWithValue(
"pipeline supports at most one ostree commit",
func() { pipeline.serializeStart(nil, nil, make([]ostree.CommitSpec, 2)) },
func() { pipeline.serializeStart(nil, nil, make([]ostree.CommitSpec, 2), nil) },
)
assert.PanicsWithValue(
"pipeline supports at most one container",
func() { pipeline.serializeStart(nil, make([]container.Spec, 2), nil) },
func() { pipeline.serializeStart(nil, make([]container.Spec, 2), nil, nil) },
)
}

Expand All @@ -216,7 +216,7 @@ func TestAnacondaISOTreeSerializeWithOS(t *testing.T) {
t.Run("plain", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.OSPipeline = osPayload
pipeline.serializeStart(nil, nil, nil)
pipeline.serializeStart(nil, nil, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, payloadStages,
Expand All @@ -229,7 +229,7 @@ func TestAnacondaISOTreeSerializeWithOS(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.OSPipeline = osPayload
pipeline.KSPath = testKsPath
pipeline.serializeStart(nil, nil, nil)
pipeline.serializeStart(nil, nil, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.kickstart"),
Expand All @@ -242,7 +242,7 @@ func TestAnacondaISOTreeSerializeWithOS(t *testing.T) {
pipeline.OSPipeline = osPayload
pipeline.KSPath = testKsPath
pipeline.ISOLinux = true
pipeline.serializeStart(nil, nil, nil)
pipeline.serializeStart(nil, nil, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.isolinux", "org.osbuild.kickstart"),
Expand All @@ -255,7 +255,7 @@ func TestAnacondaISOTreeSerializeWithOS(t *testing.T) {
pipeline.KSPath = testKsPath
pipeline.ISOLinux = true
pipeline.UnattendedKickstart = true
pipeline.serializeStart(nil, nil, nil)
pipeline.serializeStart(nil, nil, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.isolinux", "org.osbuild.kickstart"),
Expand All @@ -270,7 +270,7 @@ func TestAnacondaISOTreeSerializeWithOS(t *testing.T) {
pipeline.ISOLinux = true
pipeline.UnattendedKickstart = true
pipeline.NoPasswd = []string{`%wheel`, `%sudo`}
pipeline.serializeStart(nil, nil, nil)
pipeline.serializeStart(nil, nil, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.isolinux", "org.osbuild.kickstart"),
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestAnacondaISOTreeSerializeWithOSTree(t *testing.T) {
t.Run("plain", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.KSPath = testKsPath
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit})
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit}, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, payloadStages,
Expand All @@ -314,7 +314,7 @@ func TestAnacondaISOTreeSerializeWithOSTree(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.KSPath = testKsPath
pipeline.ISOLinux = true
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit})
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit}, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.isolinux"), variantStages))
Expand All @@ -325,7 +325,7 @@ func TestAnacondaISOTreeSerializeWithOSTree(t *testing.T) {
pipeline.KSPath = testKsPath
pipeline.ISOLinux = true
pipeline.UnattendedKickstart = true
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit})
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit}, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.isolinux"), variantStages))
Expand All @@ -338,7 +338,7 @@ func TestAnacondaISOTreeSerializeWithOSTree(t *testing.T) {
pipeline.ISOLinux = true
pipeline.UnattendedKickstart = true
pipeline.NoPasswd = []string{`%wheel`, `%sudo`}
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit})
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit}, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.isolinux"), variantStages))
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestAnacondaISOTreeSerializeWithContainer(t *testing.T) {
t.Run("kspath", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.KSPath = testKsPath
pipeline.serializeStart(nil, []container.Spec{containerPayload}, nil)
pipeline.serializeStart(nil, []container.Spec{containerPayload}, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, payloadStages,
Expand All @@ -381,7 +381,7 @@ func TestAnacondaISOTreeSerializeWithContainer(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.KSPath = testKsPath
pipeline.ISOLinux = true
pipeline.serializeStart(nil, []container.Spec{containerPayload}, nil)
pipeline.serializeStart(nil, []container.Spec{containerPayload}, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, append(payloadStages, "org.osbuild.isolinux"), variantStages))
Expand Down
5 changes: 3 additions & 2 deletions pkg/manifest/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ func (p *BuildrootFromPackages) getPackageSpecs() []rpmmd.PackageSpec {
return p.packageSpecs
}

func (p *BuildrootFromPackages) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec) {
func (p *BuildrootFromPackages) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec, rpmRepos []rpmmd.RepoConfig) {
if len(p.packageSpecs) > 0 {
panic("double call to serializeStart()")
}
p.packageSpecs = packages
p.repos = append(p.repos, rpmRepos...)
}

func (p *BuildrootFromPackages) serializeEnd() {
Expand Down Expand Up @@ -198,7 +199,7 @@ func (p *BuildrootFromContainer) getContainerSpecs() []container.Spec {
return p.containerSpecs
}

func (p *BuildrootFromContainer) serializeStart(_ []rpmmd.PackageSpec, containerSpecs []container.Spec, _ []ostree.CommitSpec) {
func (p *BuildrootFromContainer) serializeStart(_ []rpmmd.PackageSpec, containerSpecs []container.Spec, _ []ostree.CommitSpec, _ []rpmmd.RepoConfig) {
if len(p.containerSpecs) > 0 {
panic("double call to serializeStart()")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestNewBuildFromContainerSpecs(t *testing.T) {
}
// containerSpecs is "nil" until serializeStart populates it
require.Nil(t, build.getContainerSpecs())
build.serializeStart(nil, fakeContainerSpecs, nil)
build.serializeStart(nil, fakeContainerSpecs, nil, nil)
assert.Equal(t, build.getContainerSpecs(), fakeContainerSpecs)

osbuildPipeline := build.serialize()
Expand Down
3 changes: 2 additions & 1 deletion pkg/manifest/commit_server_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ func (p *OSTreeCommitServer) getPackageSpecs() []rpmmd.PackageSpec {
return p.packageSpecs
}

func (p *OSTreeCommitServer) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec) {
func (p *OSTreeCommitServer) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec, rpmRepos []rpmmd.RepoConfig) {
if len(p.packageSpecs) > 0 {
panic("double call to serializeStart()")
}
p.packageSpecs = packages
p.repos = append(p.repos, rpmRepos...)
}

func (p *OSTreeCommitServer) serializeEnd() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/manifest/coreos_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ func (p *CoreOSInstaller) getPackageSpecs() []rpmmd.PackageSpec {
return p.packageSpecs
}

func (p *CoreOSInstaller) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec) {
func (p *CoreOSInstaller) serializeStart(packages []rpmmd.PackageSpec, _ []container.Spec, _ []ostree.CommitSpec, rpmRepos []rpmmd.RepoConfig) {
if len(p.packageSpecs) > 0 {
panic("double call to serializeStart()")
}
p.packageSpecs = packages
if p.kernelName != "" {
p.kernelVer = rpmmd.GetVerStrFromPackageSpecListPanic(p.packageSpecs, p.kernelName)
}
p.repos = append(p.repos, rpmRepos...)
}

func (p *CoreOSInstaller) getInline() []string {
Expand Down
5 changes: 4 additions & 1 deletion pkg/manifest/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type ContentTest struct {
containerSpecs []container.Spec
commitSpecs []ostree.CommitSpec

repos []rpmmd.RepoConfig

// serialization flag
serializing bool
}
Expand Down Expand Up @@ -63,13 +65,14 @@ func (p *ContentTest) getOSTreeCommits() []ostree.CommitSpec {
return p.commitSpecs
}

func (p *ContentTest) serializeStart(pkgs []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec) {
func (p *ContentTest) serializeStart(pkgs []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec, rpmRepos []rpmmd.RepoConfig) {
if p.serializing {
panic("double call to serializeStart()")
}
p.packageSpecs = pkgs
p.containerSpecs = containers
p.commitSpecs = commits
p.repos = rpmRepos

p.serializing = true
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ func (m Manifest) GetOSTreeSourceSpecs() map[string][]ostree.SourceSpec {
return ostreeSpecs
}

func (m Manifest) Serialize(packageSets map[string][]rpmmd.PackageSpec, containerSpecs map[string][]container.Spec, ostreeCommits map[string][]ostree.CommitSpec) (OSBuildManifest, error) {
func (m Manifest) Serialize(packageSets map[string][]rpmmd.PackageSpec, containerSpecs map[string][]container.Spec, ostreeCommits map[string][]ostree.CommitSpec, rpmRepos map[string][]rpmmd.RepoConfig) (OSBuildManifest, error) {
pipelines := make([]osbuild.Pipeline, 0)
packages := make([]rpmmd.PackageSpec, 0)
commits := make([]ostree.CommitSpec, 0)
inline := make([]string, 0)
containers := make([]container.Spec, 0)
for _, pipeline := range m.pipelines {
pipeline.serializeStart(packageSets[pipeline.Name()], containerSpecs[pipeline.Name()], ostreeCommits[pipeline.Name()])
pipeline.serializeStart(packageSets[pipeline.Name()], containerSpecs[pipeline.Name()], ostreeCommits[pipeline.Name()], rpmRepos[pipeline.Name()])
}
for _, pipeline := range m.pipelines {
commits = append(commits, pipeline.getOSTreeCommits()...)
Expand Down
4 changes: 3 additions & 1 deletion pkg/manifest/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (p *OS) getContainerSpecs() []container.Spec {
return p.containerSpecs
}

func (p *OS) serializeStart(packages []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec) {
func (p *OS) serializeStart(packages []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec, rpmRepos []rpmmd.RepoConfig) {
if len(p.packageSpecs) > 0 {
panic("double call to serializeStart()")
}
Expand All @@ -355,6 +355,8 @@ func (p *OS) serializeStart(packages []rpmmd.PackageSpec, containers []container
if p.KernelName != "" {
p.kernelVer = rpmmd.GetVerStrFromPackageSpecListPanic(p.packageSpecs, p.KernelName)
}

p.repos = append(p.repos, rpmRepos...)
}

func (p *OS) serializeEnd() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewTestOS() *OS {
packages := []rpmmd.PackageSpec{
{Name: "pkg1", Checksum: "sha1:c02524e2bd19490f2a7167958f792262754c5f46"},
}
os.serializeStart(packages, nil, nil)
os.serializeStart(packages, nil, nil, repos)

return os
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/ostree_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (p *OSTreeDeployment) getContainerSources() []container.SourceSpec {
}
}

func (p *OSTreeDeployment) serializeStart(packages []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec) {
func (p *OSTreeDeployment) serializeStart(_ []rpmmd.PackageSpec, containers []container.Spec, commits []ostree.CommitSpec, _ []rpmmd.RepoConfig) {
if p.ostreeSpec != nil || p.containerSpec != nil {
panic("double call to serializeStart()")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifest/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Pipeline interface {
// its full Spec. See the ostree package for more details.
getOSTreeCommitSources() []ostree.SourceSpec

serializeStart([]rpmmd.PackageSpec, []container.Spec, []ostree.CommitSpec)
serializeStart([]rpmmd.PackageSpec, []container.Spec, []ostree.CommitSpec, []rpmmd.RepoConfig)
serializeEnd()
serialize() osbuild.Pipeline

Expand Down Expand Up @@ -166,7 +166,7 @@ func NewBase(name string, build Build) Base {

// serializeStart must be called exactly once before each call
// to serialize().
func (p Base) serializeStart([]rpmmd.PackageSpec, []container.Spec, []ostree.CommitSpec) {
func (p Base) serializeStart([]rpmmd.PackageSpec, []container.Spec, []ostree.CommitSpec, []rpmmd.RepoConfig) {
}

// serializeEnd must be called exactly once after each call to
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/raw_bootc.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (p *RawBootcImage) getContainerSpecs() []container.Spec {
return p.containerSpecs
}

func (p *RawBootcImage) serializeStart(_ []rpmmd.PackageSpec, containerSpecs []container.Spec, _ []ostree.CommitSpec) {
func (p *RawBootcImage) serializeStart(_ []rpmmd.PackageSpec, containerSpecs []container.Spec, _ []ostree.CommitSpec, _ []rpmmd.RepoConfig) {
if len(p.containerSpecs) > 0 {
panic("double call to serializeStart()")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifest/raw_bootc_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ func (rbc *RawBootcImage) Serialize() osbuild.Pipeline {
return rbc.serialize()
}

func (rbc *RawBootcImage) SerializeStart(a []rpmmd.PackageSpec, b []container.Spec, c []ostree.CommitSpec) {
rbc.serializeStart(a, b, c)
func (rbc *RawBootcImage) SerializeStart(a []rpmmd.PackageSpec, b []container.Spec, c []ostree.CommitSpec, r []rpmmd.RepoConfig) {
rbc.serializeStart(a, b, c, r)
}
6 changes: 3 additions & 3 deletions pkg/manifest/raw_bootc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestRawBootcImageSerialize(t *testing.T) {
rawBootcPipeline.Users = []users.User{{Name: "root", Key: common.ToPtr("some-ssh-key")}}
rawBootcPipeline.KernelOptionsAppend = []string{"karg1", "karg2"}

rawBootcPipeline.SerializeStart(nil, []container.Spec{{Source: "foo"}}, nil)
rawBootcPipeline.SerializeStart(nil, []container.Spec{{Source: "foo"}}, nil, nil)
imagePipeline := rawBootcPipeline.Serialize()
assert.Equal(t, "image", imagePipeline.Name)

Expand All @@ -70,7 +70,7 @@ func TestRawBootcImageSerializeMountsValidated(t *testing.T) {
rawBootcPipeline := manifest.NewRawBootcImage(build, nil, nil)
// note that we create a partition table without /boot here
rawBootcPipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/missing-boot")
rawBootcPipeline.SerializeStart(nil, []container.Spec{{Source: "foo"}}, nil)
rawBootcPipeline.SerializeStart(nil, []container.Spec{{Source: "foo"}}, nil, nil)
assert.PanicsWithError(t, `required mounts for bootupd stage [/boot /boot/efi] missing`, func() {
rawBootcPipeline.Serialize()
})
Expand All @@ -83,7 +83,7 @@ func TestRawBootcImageSerializeValidatesUsers(t *testing.T) {

rawBootcPipeline := manifest.NewRawBootcImage(build, nil, nil)
rawBootcPipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/boot", "/boot/efi")
rawBootcPipeline.SerializeStart(nil, []container.Spec{{Source: "foo"}}, nil)
rawBootcPipeline.SerializeStart(nil, []container.Spec{{Source: "foo"}}, nil, nil)

for _, tc := range []struct {
users []users.User
Expand Down

0 comments on commit 5e263ea

Please sign in to comment.