mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 19:16:23 +00:00
Merge pull request #865 from nitkon/kata-env
ppc64le: kata-env fails due to missing vendor field
This commit is contained in:
commit
c2eea35b18
@ -7,6 +7,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -483,8 +484,36 @@ func TestKvmIsUsable(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TestDataa struct {
|
||||||
|
contents string
|
||||||
|
expectedVendor string
|
||||||
|
expectedModel string
|
||||||
|
expectError bool
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetCPUDetails(t *testing.T) {
|
func TestGetCPUDetails(t *testing.T) {
|
||||||
genericTestGetCPUDetails(t)
|
const validVendorName = "a vendor"
|
||||||
|
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
||||||
|
|
||||||
|
const validModelName = "some CPU model"
|
||||||
|
validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)
|
||||||
|
|
||||||
|
validContents := fmt.Sprintf(`
|
||||||
|
a : b
|
||||||
|
%s
|
||||||
|
foo : bar
|
||||||
|
%s
|
||||||
|
`, validVendor, validModel)
|
||||||
|
|
||||||
|
data := []TestDataa{
|
||||||
|
{"", "", "", true},
|
||||||
|
{"invalid", "", "", true},
|
||||||
|
{archCPUVendorField, "", "", true},
|
||||||
|
{validVendor, "", "", true},
|
||||||
|
{validModel, "", "", true},
|
||||||
|
{validContents, validVendorName, validModelName, false},
|
||||||
|
}
|
||||||
|
genericTestGetCPUDetails(t, validVendor, validModel, validContents, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetCPUtype(t *testing.T) {
|
func TestSetCPUtype(t *testing.T) {
|
||||||
|
@ -16,13 +16,15 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
cpuFlagsTag = genericCPUFlagsTag
|
cpuFlagsTag = genericCPUFlagsTag
|
||||||
archCPUVendorField = genericCPUVendorField
|
archCPUVendorField = ""
|
||||||
archCPUModelField = genericCPUModelField
|
archCPUModelField = "model"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ppc64CpuCmd = "ppc64_cpu"
|
ppc64CpuCmd = "ppc64_cpu"
|
||||||
smtStatusOption = "--smt"
|
smtStatusOption = "--smt"
|
||||||
|
_ = genericCPUVendorField
|
||||||
|
_ = genericCPUModelField
|
||||||
)
|
)
|
||||||
|
|
||||||
// archRequiredCPUFlags maps a CPU flag value to search for and a
|
// archRequiredCPUFlags maps a CPU flag value to search for and a
|
||||||
@ -96,7 +98,11 @@ func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getCPUDetails() (vendor, model string, err error) {
|
func getCPUDetails() (vendor, model string, err error) {
|
||||||
return genericGetCPUDetails()
|
vendor, model, err = genericGetCPUDetails()
|
||||||
|
if err == nil {
|
||||||
|
model = "POWER8"
|
||||||
|
}
|
||||||
|
return vendor, model, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func isSMTOff() bool {
|
func isSMTOff() bool {
|
||||||
|
@ -7,6 +7,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -207,8 +208,38 @@ func TestKvmIsUsable(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TestDataa struct {
|
||||||
|
contents string
|
||||||
|
expectedVendor string
|
||||||
|
expectedModel string
|
||||||
|
expectError bool
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetCPUDetails(t *testing.T) {
|
func TestGetCPUDetails(t *testing.T) {
|
||||||
genericTestGetCPUDetails(t)
|
|
||||||
|
const validVendorName = ""
|
||||||
|
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
||||||
|
|
||||||
|
const validModelName = "POWER8"
|
||||||
|
validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)
|
||||||
|
|
||||||
|
validContents := fmt.Sprintf(`
|
||||||
|
a : b
|
||||||
|
%s
|
||||||
|
foo : bar
|
||||||
|
%s
|
||||||
|
`, validVendor, validModel)
|
||||||
|
|
||||||
|
data := []TestDataa{
|
||||||
|
{"", "", "", true},
|
||||||
|
{"invalid", "", "", true},
|
||||||
|
{archCPUVendorField, "", "", true},
|
||||||
|
{validVendor, "", "", true},
|
||||||
|
{validModel, "", validModelName, false},
|
||||||
|
{validContents, validVendorName, validModelName, false},
|
||||||
|
}
|
||||||
|
|
||||||
|
genericTestGetCPUDetails(t, validVendor, validModel, validContents, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetCPUtype(t *testing.T) {
|
func TestSetCPUtype(t *testing.T) {
|
||||||
|
@ -137,36 +137,7 @@ func makeCPUInfoFile(path, vendorID, flags string) error {
|
|||||||
return ioutil.WriteFile(path, contents.Bytes(), testFileMode)
|
return ioutil.WriteFile(path, contents.Bytes(), testFileMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func genericTestGetCPUDetails(t *testing.T) {
|
func genericTestGetCPUDetails(t *testing.T, validVendor string, validModel string, validContents string, data []TestDataa) {
|
||||||
type testData struct {
|
|
||||||
contents string
|
|
||||||
expectedVendor string
|
|
||||||
expectedModel string
|
|
||||||
expectError bool
|
|
||||||
}
|
|
||||||
|
|
||||||
const validVendorName = "a vendor"
|
|
||||||
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
|
||||||
|
|
||||||
const validModelName = "some CPU model"
|
|
||||||
validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)
|
|
||||||
|
|
||||||
validContents := fmt.Sprintf(`
|
|
||||||
a : b
|
|
||||||
%s
|
|
||||||
foo : bar
|
|
||||||
%s
|
|
||||||
`, validVendor, validModel)
|
|
||||||
|
|
||||||
data := []testData{
|
|
||||||
{"", "", "", true},
|
|
||||||
{"invalid", "", "", true},
|
|
||||||
{archCPUVendorField, "", "", true},
|
|
||||||
{validVendor, "", "", true},
|
|
||||||
{validModel, "", "", true},
|
|
||||||
{validContents, validVendorName, validModelName, false},
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -14,7 +14,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
|
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
|
||||||
return genericGetExpectedHostDetails(tmpdir)
|
expectedVendor := "moi"
|
||||||
|
expectedModel := "awesome XI"
|
||||||
|
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
|
func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
|
||||||
|
@ -8,7 +8,9 @@ package main
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
|
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
|
||||||
return genericGetExpectedHostDetails(tmpdir)
|
expectedVendor := ""
|
||||||
|
expectedModel := "POWER8"
|
||||||
|
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
|
func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
|
||||||
|
@ -244,7 +244,7 @@ func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genericGetExpectedHostDetails(tmpdir string) (HostInfo, error) {
|
func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expectedModel string) (HostInfo, error) {
|
||||||
type filesToCreate struct {
|
type filesToCreate struct {
|
||||||
file string
|
file string
|
||||||
contents string
|
contents string
|
||||||
@ -259,8 +259,8 @@ func genericGetExpectedHostDetails(tmpdir string) (HostInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectedCPU := CPUInfo{
|
expectedCPU := CPUInfo{
|
||||||
Vendor: "moi",
|
Vendor: expectedVendor,
|
||||||
Model: "awesome XI",
|
Model: expectedModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedHostDetails := HostInfo{
|
expectedHostDetails := HostInfo{
|
||||||
|
@ -140,7 +140,7 @@ func genericGetCPUDetails() (vendor, model string, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if vendor == "" {
|
if archCPUVendorField != "" && vendor == "" {
|
||||||
return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
|
return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user