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:
Tomáš Hozza 2024-01-19 21:05:46 +01:00 committed by Achilleas Koutsou
parent fb1b27c0ef
commit c4e5ab5aca
5 changed files with 5 additions and 110 deletions

View file

@ -14,6 +14,7 @@ import (
"time"
"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/internal/common"
)
@ -114,7 +115,7 @@ func WithBootedQemuImage(image string, ns NetNS, f func() error) error {
var qemuCmd *exec.Cmd
if common.CurrentArch() == "x86_64" {
hostDistroName, _, _, err := common.GetHostDistroName()
hostDistroName, err := distro.GetHostDistroName()
if err != nil {
return fmt.Errorf("cannot determing the current distro: %v", err)
}

View file

@ -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
}

View file

@ -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)
}
}
}

View file

@ -161,7 +161,7 @@ func New(repoPaths []string, stateDir string, solver *dnfjson.BaseSolver, df *di
logger = log.New(os.Stdout, "", 0)
}
hostDistroName, _, _, err := common.GetHostDistroName()
hostDistroName, err := distro.GetHostDistroName()
if err != nil {
return nil, fmt.Errorf("failed to read host distro information")
}