Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

kata-env: kata-env error out when there is no VERSION_ID. #1178

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func TestEnvGetHostInfoNoOSRelease(t *testing.T) {
assert.NoError(t, err)

_, err = getHostInfo()
assert.Error(t, err)
assert.NoError(t, err)
}

func TestEnvGetHostInfoNoProcVersion(t *testing.T) {
Expand Down Expand Up @@ -600,7 +600,7 @@ func TestEnvGetEnvInfoNoOSRelease(t *testing.T) {
assert.NoError(t, err)

_, err = getEnvInfo(configFile, config)
assert.Error(t, err)
assert.NoError(t, err)
}

func TestEnvGetEnvInfoNoProcCPUInfo(t *testing.T) {
Expand Down
16 changes: 13 additions & 3 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func getKernelVersion() (string, error) {
// returned.
func getDistroDetails() (name, version string, err error) {
files := []string{osRelease, osReleaseClr}
name = ""
version = ""

for _, file := range files {
contents, err := katautils.GetFileContents(file)
Expand All @@ -62,10 +64,10 @@ func getDistroDetails() (name, version string, err error) {
lines := strings.Split(contents, "\n")

for _, line := range lines {
if strings.HasPrefix(line, "NAME=") {
if strings.HasPrefix(line, "NAME=") && name == "" {
fields := strings.Split(line, "=")
name = strings.Trim(fields[1], `"`)
} else if strings.HasPrefix(line, "VERSION_ID=") {
} else if strings.HasPrefix(line, "VERSION_ID=") && version == "" {
fields := strings.Split(line, "=")
version = strings.Trim(fields[1], `"`)
}
Expand All @@ -76,7 +78,15 @@ func getDistroDetails() (name, version string, err error) {
}
}

return "", "", fmt.Errorf("failed to find expected fields in one of %v", files)
if name == "" {
name = unknown
}

if version == "" {
version = unknown
}

return name, version, nil
}

// genericGetCPUDetails returns the vendor and model of the CPU.
Expand Down
8 changes: 5 additions & 3 deletions cli/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func TestGetDistroDetails(t *testing.T) {
expectError bool
}

const unknown = "<<unknown>>"

tmpdir, err := ioutil.TempDir("", "")
if err != nil {
panic(err)
Expand Down Expand Up @@ -144,11 +146,11 @@ VERSION_ID="%s"

_, _, err = getDistroDetails()
// ENOENT
assert.Error(t, err)
assert.NoError(t, err)

data := []testData{
{"", "", "", "", true},
{"invalid", "", "", "", true},
{"", "", unknown, unknown, false},
{"invalid", "", unknown, unknown, false},
{clrContents, "", clrExpectedName, clrExpectedVersion, false},
{"", nonClrContents, nonClrExpectedName, nonClrExpectedVersion, false},
{clrContents, nonClrContents, nonClrExpectedName, nonClrExpectedVersion, false},
Expand Down