Make the Distroregistry FromHost() return distro with correct name

Composer does not have 1:1 mapping of what can be the Host Distro name
and the names of supported distributions held in the Distroregistry.

The fact that the host distro `Name()` method as passed to the Weldr API
does not return the same name as what is used as distro name for
repository definitions. This makes it hard to use `distro.Distro` and
`distro.Arch` directly and rely on the values returned by them as their
name.

Add `New*HostDistro()` to all distro definitions, accepting the name
that should be returned by the distro's `Name()` method. This is useful
mainly if the host distro is Beta or Stream variant of the distro.

Change the distroregistry.Registry to contain host distro as a separate
value set when creating it using `New()` function. This value is
returned by `Registry.FromHost()` method. Determining the host distro is
handled by the `NewDefault()` function. Move the distro name mangling to
distroregistry package. Add relevant unit tests.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-05-06 14:53:42 +02:00 committed by Ondřej Budai
parent dda9cce03e
commit fba9fe1072
10 changed files with 231 additions and 65 deletions

View file

@ -19,10 +19,11 @@ import (
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
const name = "rhel-90"
const defaultName = "rhel-90"
const modulePlatformID = "platform:el9"
type distribution struct {
name string
arches map[string]architecture
buildPackages []string
}
@ -252,7 +253,7 @@ func (t *imageType) Manifest(c *blueprint.Customizations,
}
func (d *distribution) Name() string {
return name
return d.name
}
func (d *distribution) ModulePlatformID() string {
@ -742,6 +743,14 @@ func newRandomUUIDFromReader(r io.Reader) (uuid.UUID, error) {
}
func New() distro.Distro {
return newDistro(defaultName)
}
func NewHostDistro(name string) distro.Distro {
return newDistro(name)
}
func newDistro(name string) distro.Distro {
const GigaByte = 1024 * 1024 * 1024
qcow2ImageType := imageType{
@ -839,6 +848,7 @@ func New() distro.Distro {
"xfsprogs",
"xz",
},
name: name,
}
x8664 := architecture{
distro: &r,