Drop internal/common/distro.go in favor of osbuild/images
Drop `common.GetHostDistroName()` implementation and use `distro.GetHostDistroName()` from the osbuild/images instead. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
fb1b27c0ef
commit
c4e5ab5aca
5 changed files with 5 additions and 110 deletions
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/osbuild/images/pkg/container"
|
"github.com/osbuild/images/pkg/container"
|
||||||
|
"github.com/osbuild/images/pkg/distro"
|
||||||
"github.com/osbuild/images/pkg/osbuild"
|
"github.com/osbuild/images/pkg/osbuild"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/upload/oci"
|
"github.com/osbuild/osbuild-composer/internal/upload/oci"
|
||||||
|
|
@ -351,7 +352,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
||||||
Arch: common.CurrentArch(),
|
Arch: common.CurrentArch(),
|
||||||
}
|
}
|
||||||
|
|
||||||
hostOS, _, _, err := common.GetHostDistroName()
|
hostOS, err := distro.GetHostDistroName()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithId.Warnf("Failed to get host distro name: %v", err)
|
logWithId.Warnf("Failed to get host distro name: %v", err)
|
||||||
hostOS = "linux"
|
hostOS = "linux"
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/osbuild/images/pkg/arch"
|
"github.com/osbuild/images/pkg/arch"
|
||||||
|
"github.com/osbuild/images/pkg/distro"
|
||||||
"github.com/osbuild/osbuild-composer/cmd/osbuild-image-tests/constants"
|
"github.com/osbuild/osbuild-composer/cmd/osbuild-image-tests/constants"
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
)
|
)
|
||||||
|
|
@ -114,7 +115,7 @@ func WithBootedQemuImage(image string, ns NetNS, f func() error) error {
|
||||||
|
|
||||||
var qemuCmd *exec.Cmd
|
var qemuCmd *exec.Cmd
|
||||||
if common.CurrentArch() == "x86_64" {
|
if common.CurrentArch() == "x86_64" {
|
||||||
hostDistroName, _, _, err := common.GetHostDistroName()
|
hostDistroName, err := distro.GetHostDistroName()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot determing the current distro: %v", err)
|
return fmt.Errorf("cannot determing the current distro: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetHostDistroName() (string, bool, bool, error) {
|
|
||||||
f, err := os.Open("/etc/os-release")
|
|
||||||
if err != nil {
|
|
||||||
return "", false, false, err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
osrelease, err := readOSRelease(f)
|
|
||||||
if err != nil {
|
|
||||||
return "", false, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
isStream := osrelease["NAME"] == "CentOS Stream"
|
|
||||||
|
|
||||||
version := strings.Split(osrelease["VERSION_ID"], ".")
|
|
||||||
name := osrelease["ID"] + "-" + strings.Join(version, "")
|
|
||||||
|
|
||||||
// TODO: We should probably index these things by the full CPE
|
|
||||||
beta := strings.Contains(osrelease["CPE_NAME"], "beta")
|
|
||||||
return name, beta, isStream, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readOSRelease(r io.Reader) (map[string]string, error) {
|
|
||||||
osrelease := make(map[string]string)
|
|
||||||
scanner := bufio.NewScanner(r)
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := strings.TrimSpace(scanner.Text())
|
|
||||||
if len(line) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
parts := strings.SplitN(line, "=", 2)
|
|
||||||
if len(parts) != 2 {
|
|
||||||
return nil, errors.New("readOSRelease: invalid input")
|
|
||||||
}
|
|
||||||
|
|
||||||
key := strings.TrimSpace(parts[0])
|
|
||||||
// drop all surrounding whitespace and double-quotes
|
|
||||||
value := strings.Trim(strings.TrimSpace(parts[1]), "\"")
|
|
||||||
osrelease[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
return osrelease, nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestOSRelease(t *testing.T) {
|
|
||||||
var cases = []struct {
|
|
||||||
Input string
|
|
||||||
OSRelease map[string]string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
``,
|
|
||||||
map[string]string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
`NAME=Fedora
|
|
||||||
VERSION="30 (Workstation Edition)"
|
|
||||||
ID=fedora
|
|
||||||
VERSION_ID=30
|
|
||||||
VERSION_CODENAME=""
|
|
||||||
PLATFORM_ID="platform:f30"
|
|
||||||
PRETTY_NAME="Fedora 30 (Workstation Edition)"
|
|
||||||
VARIANT="Workstation Edition"
|
|
||||||
VARIANT_ID=workstation`,
|
|
||||||
map[string]string{
|
|
||||||
"NAME": "Fedora",
|
|
||||||
"VERSION": "30 (Workstation Edition)",
|
|
||||||
"ID": "fedora",
|
|
||||||
"VERSION_ID": "30",
|
|
||||||
"VERSION_CODENAME": "",
|
|
||||||
"PLATFORM_ID": "platform:f30",
|
|
||||||
"PRETTY_NAME": "Fedora 30 (Workstation Edition)",
|
|
||||||
"VARIANT": "Workstation Edition",
|
|
||||||
"VARIANT_ID": "workstation",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, c := range cases {
|
|
||||||
r := strings.NewReader(c.Input)
|
|
||||||
|
|
||||||
osrelease, err := readOSRelease(r)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%d: readOSRelease: %v", i, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(osrelease, c.OSRelease) {
|
|
||||||
t.Fatalf("%d: readOSRelease returned unexpected result: %#v", i, osrelease)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -161,7 +161,7 @@ func New(repoPaths []string, stateDir string, solver *dnfjson.BaseSolver, df *di
|
||||||
logger = log.New(os.Stdout, "", 0)
|
logger = log.New(os.Stdout, "", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostDistroName, _, _, err := common.GetHostDistroName()
|
hostDistroName, err := distro.GetHostDistroName()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read host distro information")
|
return nil, fmt.Errorf("failed to read host distro information")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue