distro: remove HostDistro contructors
The host distro object was identical to the regular distro objects for a while now. The constructors in the registry have been aliases to the base constructors for a long time. - Deleted all HostDistro constructors from the distributions. - Changed the supported distro list to only contain base constructor functions. - The host distro in the distro registry is a copy of the base distro that matches the host and does not call a separate constructor.
This commit is contained in:
parent
fcc8437b22
commit
47f935f8b7
7 changed files with 24 additions and 109 deletions
|
|
@ -784,20 +784,6 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
parts := strings.Split(name, "-")
|
||||
if len(parts) != 2 || parts[0] != "fedora" {
|
||||
panic("invalid distro name: " + name)
|
||||
}
|
||||
|
||||
version, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
panic("invalid distro version: " + name + ": " + err.Error())
|
||||
}
|
||||
|
||||
return newDistro(version)
|
||||
}
|
||||
|
||||
// New creates a new distro object, defining the supported architectures and image types
|
||||
func NewF36() distro.Distro {
|
||||
return newDistro(36)
|
||||
|
|
|
|||
|
|
@ -451,10 +451,6 @@ func New() distro.Distro {
|
|||
return newDistro("rhel-7")
|
||||
}
|
||||
|
||||
func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return newDistro("rhel-7")
|
||||
}
|
||||
|
||||
func newDistro(distroName string) distro.Distro {
|
||||
|
||||
rd := distroMap[distroName]
|
||||
|
|
|
|||
|
|
@ -598,58 +598,30 @@ func New() distro.Distro {
|
|||
|
||||
}
|
||||
|
||||
func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return New()
|
||||
}
|
||||
|
||||
func NewRHEL84() distro.Distro {
|
||||
return newDistro("rhel", 4)
|
||||
}
|
||||
|
||||
func NewRHEL84HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return NewRHEL84()
|
||||
}
|
||||
|
||||
func NewRHEL85() distro.Distro {
|
||||
return newDistro("rhel", 5)
|
||||
}
|
||||
|
||||
func NewRHEL85HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return NewRHEL85()
|
||||
}
|
||||
|
||||
func NewRHEL86() distro.Distro {
|
||||
return newDistro("rhel", 6)
|
||||
}
|
||||
|
||||
func NewRHEL86HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return NewRHEL86()
|
||||
}
|
||||
|
||||
func NewRHEL87() distro.Distro {
|
||||
return newDistro("rhel", 7)
|
||||
}
|
||||
|
||||
func NewRHEL87HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return NewRHEL87()
|
||||
}
|
||||
|
||||
func NewRHEL88() distro.Distro {
|
||||
return newDistro("rhel", 8)
|
||||
}
|
||||
|
||||
func NewRHEL88HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return NewRHEL88()
|
||||
}
|
||||
|
||||
func NewCentos() distro.Distro {
|
||||
return newDistro("centos", 0)
|
||||
}
|
||||
|
||||
func NewCentosHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
return NewCentos()
|
||||
}
|
||||
|
||||
func newDistro(name string, minor int) *distribution {
|
||||
var rd distribution
|
||||
switch name {
|
||||
|
|
|
|||
|
|
@ -131,47 +131,22 @@ func New() distro.Distro {
|
|||
return d
|
||||
}
|
||||
|
||||
func NewHostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
// NOTE: args are ignored - host distro constructors are deprecated
|
||||
return New()
|
||||
}
|
||||
|
||||
func NewCentOS9() distro.Distro {
|
||||
return newDistro("centos", 0)
|
||||
}
|
||||
|
||||
func NewCentOS9HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
// NOTE: args are ignored - host distro constructors are deprecated
|
||||
return NewCentOS9()
|
||||
}
|
||||
|
||||
func NewRHEL90() distro.Distro {
|
||||
return newDistro("rhel", 0)
|
||||
}
|
||||
|
||||
func NewRHEL90HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
// NOTE: args are ignored - host distro constructors are deprecated
|
||||
return NewRHEL90()
|
||||
}
|
||||
|
||||
func NewRHEL91() distro.Distro {
|
||||
return newDistro("rhel", 1)
|
||||
}
|
||||
|
||||
func NewRHEL91HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
// NOTE: args are ignored - host distro constructors are deprecated
|
||||
return NewRHEL91()
|
||||
}
|
||||
|
||||
func NewRHEL92() distro.Distro {
|
||||
return newDistro("rhel", 2)
|
||||
}
|
||||
|
||||
func NewRHEL92HostDistro(name, modulePlatformID, ostreeRef string) distro.Distro {
|
||||
// NOTE: args are ignored - host distro constructors are deprecated
|
||||
return NewRHEL92()
|
||||
}
|
||||
|
||||
func newDistro(name string, minor int) *distribution {
|
||||
var rd distribution
|
||||
switch name {
|
||||
|
|
|
|||
|
|
@ -591,7 +591,7 @@ func TestRhel9_GetArch(t *testing.T) {
|
|||
|
||||
func TestRhel9_Name(t *testing.T) {
|
||||
distro := rhel9.New()
|
||||
assert.Equal(t, "rhel-90", distro.Name())
|
||||
assert.Equal(t, "rhel-9", distro.Name())
|
||||
}
|
||||
|
||||
func TestRhel9_ModulePlatformID(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -15,31 +15,26 @@ import (
|
|||
|
||||
// When adding support for a new distribution, add it here.
|
||||
// Note that this is a constant, do not write to this array.
|
||||
var supportedDistros = []supportedDistro{
|
||||
{fedora.NewF36, fedora.NewHostDistro},
|
||||
{fedora.NewF37, fedora.NewHostDistro},
|
||||
{fedora.NewF38, fedora.NewHostDistro},
|
||||
var supportedDistros = []func() distro.Distro{
|
||||
fedora.NewF36,
|
||||
fedora.NewF37,
|
||||
fedora.NewF38,
|
||||
|
||||
{rhel7.New, rhel7.NewHostDistro},
|
||||
rhel7.New,
|
||||
|
||||
{rhel8.New, rhel8.NewHostDistro},
|
||||
{rhel8.NewRHEL84, rhel8.NewRHEL84HostDistro},
|
||||
{rhel8.NewRHEL85, rhel8.NewRHEL85HostDistro},
|
||||
{rhel8.NewRHEL86, rhel8.NewRHEL86HostDistro},
|
||||
{rhel8.NewRHEL87, rhel8.NewRHEL87HostDistro},
|
||||
{rhel8.NewRHEL88, rhel8.NewRHEL88HostDistro},
|
||||
{rhel8.NewCentos, rhel8.NewCentosHostDistro},
|
||||
rhel8.New,
|
||||
rhel8.NewRHEL84,
|
||||
rhel8.NewRHEL85,
|
||||
rhel8.NewRHEL86,
|
||||
rhel8.NewRHEL87,
|
||||
rhel8.NewRHEL88,
|
||||
rhel8.NewCentos,
|
||||
|
||||
{rhel9.New, rhel9.NewHostDistro},
|
||||
{rhel9.NewRHEL90, rhel9.NewRHEL90HostDistro},
|
||||
{rhel9.NewRHEL91, rhel9.NewRHEL91HostDistro},
|
||||
{rhel9.NewRHEL92, rhel9.NewRHEL92HostDistro},
|
||||
{rhel9.NewCentOS9, rhel9.NewCentOS9HostDistro},
|
||||
}
|
||||
|
||||
type supportedDistro struct {
|
||||
defaultDistro func() distro.Distro
|
||||
hostDistro func(name, modulePlatformID, ostreeRef string) distro.Distro
|
||||
rhel9.New,
|
||||
rhel9.NewRHEL90,
|
||||
rhel9.NewRHEL91,
|
||||
rhel9.NewRHEL92,
|
||||
rhel9.NewCentOS9,
|
||||
}
|
||||
|
||||
type Registry struct {
|
||||
|
|
@ -75,19 +70,12 @@ func NewDefault() *Registry {
|
|||
// If there was an error, then the hostDistroName will be an empty string
|
||||
// and as a result, the hostDistro will have a nil value when calling New().
|
||||
// Getting the host distro later using FromHost() will return nil as well.
|
||||
hostDistroName, hostDistroIsBeta, hostDistroIsStream, _ := common.GetHostDistroName()
|
||||
|
||||
hostDistroName, _, _, _ := common.GetHostDistroName()
|
||||
for _, supportedDistro := range supportedDistros {
|
||||
distro := supportedDistro.defaultDistro()
|
||||
|
||||
distro := supportedDistro()
|
||||
if distro.Name() == hostDistroName {
|
||||
hostDistro = supportedDistro.hostDistro(
|
||||
mangleHostDistroName(distro.Name(), hostDistroIsBeta, hostDistroIsStream),
|
||||
distro.ModulePlatformID(),
|
||||
distro.OSTreeRef(),
|
||||
)
|
||||
hostDistro = supportedDistro()
|
||||
}
|
||||
|
||||
distros = append(distros, distro)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ func TestRegistry_List(t *testing.T) {
|
|||
// build expected distros
|
||||
var expected []string
|
||||
for _, supportedDistro := range supportedDistros {
|
||||
d := supportedDistro.defaultDistro()
|
||||
d := supportedDistro()
|
||||
expected = append(expected, d.Name())
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ func TestRegistry_FromHost(t *testing.T) {
|
|||
// expected distros
|
||||
var distros []distro.Distro
|
||||
for _, supportedDistro := range supportedDistros {
|
||||
distros = append(distros, supportedDistro.defaultDistro())
|
||||
distros = append(distros, supportedDistro())
|
||||
}
|
||||
|
||||
t.Run("host distro is nil", func(t *testing.T) {
|
||||
|
|
@ -109,9 +109,7 @@ func TestRegistry_FromHost(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("host distro not nil", func(t *testing.T) {
|
||||
// NOTE(akoutsou): The arguments to NewHostDistro are ignored since RHEL 8.6
|
||||
// The function signature will change in the near future.
|
||||
hostDistro := rhel8.NewHostDistro("", "", "")
|
||||
hostDistro := rhel8.New()
|
||||
fmt.Println(hostDistro.Name())
|
||||
registry, err := New(hostDistro, distros...)
|
||||
require.Nil(t, err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue