Merge pull request #865 from nitkon/kata-env

ppc64le: kata-env fails due to missing vendor field
This commit is contained in:
James O. D. Hunt 2018-11-28 09:22:47 +00:00 committed by GitHub
commit c2eea35b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 41 deletions

View File

@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
@ -483,8 +484,36 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}
type TestDataa struct {
contents string
expectedVendor string
expectedModel string
expectError bool
}
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) {

View File

@ -16,13 +16,15 @@ import (
const (
cpuFlagsTag = genericCPUFlagsTag
archCPUVendorField = genericCPUVendorField
archCPUModelField = genericCPUModelField
archCPUVendorField = ""
archCPUModelField = "model"
)
var (
ppc64CpuCmd = "ppc64_cpu"
smtStatusOption = "--smt"
_ = genericCPUVendorField
_ = genericCPUModelField
)
// 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) {
return genericGetCPUDetails()
vendor, model, err = genericGetCPUDetails()
if err == nil {
model = "POWER8"
}
return vendor, model, err
}
func isSMTOff() bool {

View File

@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
@ -207,8 +208,38 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}
type TestDataa struct {
contents string
expectedVendor string
expectedModel string
expectError bool
}
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) {

View File

@ -137,36 +137,7 @@ func makeCPUInfoFile(path, vendorID, flags string) error {
return ioutil.WriteFile(path, contents.Bytes(), testFileMode)
}
func genericTestGetCPUDetails(t *testing.T) {
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},
}
func genericTestGetCPUDetails(t *testing.T, validVendor string, validModel string, validContents string, data []TestDataa) {
tmpdir, err := ioutil.TempDir("", "")
if err != nil {
panic(err)

View File

@ -14,7 +14,9 @@ import (
)
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
return genericGetExpectedHostDetails(tmpdir)
expectedVendor := "moi"
expectedModel := "awesome XI"
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
}
func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {

View File

@ -8,7 +8,9 @@ package main
import "testing"
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
return genericGetExpectedHostDetails(tmpdir)
expectedVendor := ""
expectedModel := "POWER8"
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
}
func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {

View File

@ -244,7 +244,7 @@ func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
}, nil
}
func genericGetExpectedHostDetails(tmpdir string) (HostInfo, error) {
func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expectedModel string) (HostInfo, error) {
type filesToCreate struct {
file string
contents string
@ -259,8 +259,8 @@ func genericGetExpectedHostDetails(tmpdir string) (HostInfo, error) {
}
expectedCPU := CPUInfo{
Vendor: "moi",
Model: "awesome XI",
Vendor: expectedVendor,
Model: expectedModel,
}
expectedHostDetails := HostInfo{

View File

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