ppc64le: kata-env fails due to missing vendor field

There is no vendor field in /proc/cpuinfo contents
on ppc64le. Make sure to return "" for vendor field
for ppc64le and fix all the corresponding testcases
as well.

Fixes: #864

Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com
This commit is contained in:
Nitesh Konkar 2018-11-27 15:26:33 +05:30
parent 6d17e27de0
commit ca58bb4ca1
8 changed files with 82 additions and 41 deletions

View File

@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
@ -488,8 +489,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

@ -15,13 +15,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
@ -94,7 +96,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

@ -179,7 +179,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
@ -194,8 +194,8 @@ func genericGetExpectedHostDetails(tmpdir string) (HostInfo, error) {
}
expectedCPU := CPUInfo{
Vendor: "moi",
Model: "awesome XI",
Vendor: expectedVendor,
Model: expectedModel,
}
expectedHostDetails := HostInfo{

View File

@ -150,7 +150,7 @@ func genericGetCPUDetails() (vendor, model string, err error) {
}
}
if vendor == "" {
if archCPUVendorField != "" && vendor == "" {
return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
}