mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 08:17:37 +00:00
Merge pull request #8389 from justxuewei/vm-capable-test
runtime: Fix TestCheckHostIsVMContainerCapable unstablity issue
This commit is contained in:
commit
268d4d622f
@ -9,6 +9,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
@ -18,6 +19,8 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const denylistModuleConf = "/etc/modprobe.d/denylist-kata-kernel-modules.conf"
|
||||||
|
|
||||||
func setupCheckHostIsVMContainerCapable(assert *assert.Assertions, cpuInfoFile string, cpuData []testCPUData, moduleData []testModuleData) {
|
func setupCheckHostIsVMContainerCapable(assert *assert.Assertions, cpuInfoFile string, cpuData []testCPUData, moduleData []testModuleData) {
|
||||||
createModules(assert, cpuInfoFile, moduleData)
|
createModules(assert, cpuInfoFile, moduleData)
|
||||||
|
|
||||||
@ -322,6 +325,36 @@ func TestCheckHostIsVMContainerCapable(t *testing.T) {
|
|||||||
|
|
||||||
err = hostIsVMContainerCapable(details)
|
err = hostIsVMContainerCapable(details)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
|
// Remove required kernel modules and add them to denylist
|
||||||
|
denylistFile, err := os.Create(denylistModuleConf)
|
||||||
|
assert.Nil(err)
|
||||||
|
succeedToRemoveOneModule := false
|
||||||
|
for mod := range archRequiredKernelModules {
|
||||||
|
cmd := exec.Command(modProbeCmd, "-r", mod)
|
||||||
|
if output, err := cmd.CombinedOutput(); err == nil {
|
||||||
|
succeedToRemoveOneModule = true
|
||||||
|
} else {
|
||||||
|
kataLog.WithField("output", string(output)).Warn("failed to remove module")
|
||||||
|
}
|
||||||
|
// Write the following into the denylist file
|
||||||
|
// blacklist <mod>
|
||||||
|
// install <mod> /bin/false
|
||||||
|
_, err = denylistFile.WriteString(fmt.Sprintf("blacklist %s\ninstall %s /bin/false\n", mod, mod))
|
||||||
|
assert.Nil(err)
|
||||||
|
}
|
||||||
|
denylistFile.Close()
|
||||||
|
assert.True(succeedToRemoveOneModule)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
os.Remove(denylistModuleConf)
|
||||||
|
}()
|
||||||
|
|
||||||
|
// remove the modules to force a failure
|
||||||
|
err = os.RemoveAll(sysModuleDir)
|
||||||
|
assert.NoError(err)
|
||||||
|
err = hostIsVMContainerCapable(details)
|
||||||
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArchKernelParamHandler(t *testing.T) {
|
func TestArchKernelParamHandler(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user