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:
parent
dda9cce03e
commit
fba9fe1072
10 changed files with 231 additions and 65 deletions
|
|
@ -11,7 +11,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/cloudapi"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
|
|
@ -76,9 +75,9 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string, logger *
|
|||
func (c *Composer) InitWeldr(repoPaths []string, weldrListener net.Listener) error {
|
||||
archName := common.CurrentArch()
|
||||
|
||||
hostDistro, beta, isStream, err := c.distros.FromHost()
|
||||
if err != nil {
|
||||
return err
|
||||
hostDistro := c.distros.FromHost()
|
||||
if hostDistro == nil {
|
||||
return fmt.Errorf("host distro is not supported")
|
||||
}
|
||||
|
||||
arch, err := hostDistro.GetArch(archName)
|
||||
|
|
@ -86,21 +85,7 @@ func (c *Composer) InitWeldr(repoPaths []string, weldrListener net.Listener) err
|
|||
return fmt.Errorf("Host distro does not support host architecture: %v", err)
|
||||
}
|
||||
|
||||
// TODO: refactor to be more generic
|
||||
name := hostDistro.Name()
|
||||
if strings.HasPrefix(name, "rhel-8") {
|
||||
name = "rhel-8"
|
||||
}
|
||||
if beta {
|
||||
name += "-beta"
|
||||
}
|
||||
|
||||
// override repository for centos stream, remove when CentOS 8 is EOL
|
||||
if isStream && name == "centos-8" {
|
||||
name = "centos-stream-8"
|
||||
}
|
||||
|
||||
repos, err := rpmmd.LoadRepositories(repoPaths, name)
|
||||
repos, err := rpmmd.LoadRepositories(repoPaths, hostDistro.Name())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error loading repositories for %s: %v", hostDistro.Name(), err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue