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

cli: make check subcommand more tolerant to failures #3086

Merged
merged 2 commits into from
Nov 27, 2020
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
10 changes: 9 additions & 1 deletion cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,25 @@ func getCPUFlags(cpuinfo string) string {
// haveKernelModule returns true if the specified module exists
// (either loaded or available to be loaded)
func haveKernelModule(module string) bool {
kmodLog := kataLog.WithField("module", module)

// First, check to see if the module is already loaded
path := filepath.Join(sysModuleDir, module)
if katautils.FileExists(path) {
return true
}

// Only root can load modules
if os.Getuid() != 0 {
kmodLog.Error("Module is not loaded and it can not be inserted. Please consider running with sudo or as root")
return false
}

// Now, check if the module is unloaded, but available.
// And modprobe it if so.
cmd := exec.Command(modProbeCmd, module)
if output, err := cmd.CombinedOutput(); err != nil {
kataLog.WithField("module", module).WithError(err).Warnf("modprobe insert module failed: %s", string(output))
kmodLog.WithError(err).WithField("output", string(output)).Warnf("modprobe insert module failed")
return false
}
return true
Expand Down
4 changes: 4 additions & 0 deletions cli/kata-check_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func TestCCCheckCLIFunction(t *testing.T) {
var cpuData []testCPUData
var moduleData []testModuleData

t.Skip(testDisabledAsNonRoot)

if cpuType == cpuTypeIntel {
cpuData = []testCPUData{
{archGenuineIntel, "lm vmx sse4_1", false},
Expand Down Expand Up @@ -245,6 +247,8 @@ func TestCheckCheckKernelModulesNoUnrestrictedGuest(t *testing.T) {
}

func TestCheckHostIsVMContainerCapable(t *testing.T) {
t.Skip(testDisabledAsNonRoot)

assert := assert.New(t)

dir, err := ioutil.TempDir("", "")
Expand Down
2 changes: 2 additions & 0 deletions cli/kata-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ func TestCheckCheckCPUAttribs(t *testing.T) {
}

func TestCheckHaveKernelModule(t *testing.T) {
t.Skip(testDisabledAsNonRoot)

assert := assert.New(t)

dir, err := ioutil.TempDir("", "")
Expand Down
10 changes: 8 additions & 2 deletions cli/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package main

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -276,12 +277,17 @@ func getReleases(releaseURL string, includeAll bool) ([]semver.Version, map[stri

releasesArray := []map[string]interface{}{}

bytes, err := ioutil.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil, fmt.Errorf("failed to read release details: %v", err)
} else if resp.StatusCode == http.StatusForbidden && bytes.Contains(body, []byte("limit exceeded")) {
// Do not fail if rate limit is exceeded
devimc marked this conversation as resolved.
Show resolved Hide resolved
kataLog.WithField("url", releaseURL).
Warn("API rate limit exceeded. Try again later. Read https://docs.github.com/apps/building-github-apps/understanding-rate-limits-for-github-apps for more information")
return []semver.Version{}, map[string]releaseDetails{}, nil
}

if err := json.Unmarshal(bytes, &releasesArray); err != nil {
if err := json.Unmarshal(body, &releasesArray); err != nil {
return nil, nil, fmt.Errorf("failed to unpack release details: %v", err)
}

Expand Down