mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 02:56:18 +00:00
kata-check: modprobe missing kernel modules
So that we can possibly verify its parameter later on. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
c3cfe8204a
commit
ea9ecd7386
@ -60,7 +60,7 @@ const (
|
||||
var (
|
||||
procCPUInfo = "/proc/cpuinfo"
|
||||
sysModuleDir = "/sys/module"
|
||||
modInfoCmd = "modinfo"
|
||||
modProbeCmd = "modprobe"
|
||||
)
|
||||
|
||||
// variables rather than consts to allow tests to modify them
|
||||
@ -120,8 +120,9 @@ func haveKernelModule(module string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Now, check if the module is unloaded, but available
|
||||
cmd := exec.Command(modInfoCmd, module)
|
||||
// Now, check if the module is unloaded, but available.
|
||||
// And modprobe it if so.
|
||||
cmd := exec.Command(modProbeCmd, module)
|
||||
err := cmd.Run()
|
||||
return err == nil
|
||||
}
|
||||
|
@ -448,15 +448,15 @@ func TestCheckHaveKernelModule(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
savedModInfoCmd := modInfoCmd
|
||||
savedModProbeCmd := modProbeCmd
|
||||
savedSysModuleDir := sysModuleDir
|
||||
|
||||
// XXX: override (fake the modprobe command failing)
|
||||
modInfoCmd = "false"
|
||||
modProbeCmd = "false"
|
||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||
|
||||
defer func() {
|
||||
modInfoCmd = savedModInfoCmd
|
||||
modProbeCmd = savedModProbeCmd
|
||||
sysModuleDir = savedSysModuleDir
|
||||
}()
|
||||
|
||||
@ -471,13 +471,13 @@ func TestCheckHaveKernelModule(t *testing.T) {
|
||||
assert.False(result)
|
||||
|
||||
// XXX: override - make our fake "modprobe" succeed
|
||||
modInfoCmd = "true"
|
||||
modProbeCmd = "true"
|
||||
|
||||
result = haveKernelModule(module)
|
||||
assert.True(result)
|
||||
|
||||
// disable "modprobe" again
|
||||
modInfoCmd = "false"
|
||||
modProbeCmd = "false"
|
||||
|
||||
fooDir := filepath.Join(sysModuleDir, module)
|
||||
err = os.MkdirAll(fooDir, testDirMode)
|
||||
@ -498,15 +498,15 @@ func TestCheckCheckKernelModules(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
savedModInfoCmd := modInfoCmd
|
||||
savedModProbeCmd := modProbeCmd
|
||||
savedSysModuleDir := sysModuleDir
|
||||
|
||||
// XXX: override (fake the modprobe command failing)
|
||||
modInfoCmd = "false"
|
||||
modProbeCmd = "false"
|
||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||
|
||||
defer func() {
|
||||
modInfoCmd = savedModInfoCmd
|
||||
modProbeCmd = savedModProbeCmd
|
||||
sysModuleDir = savedSysModuleDir
|
||||
}()
|
||||
|
||||
@ -590,15 +590,15 @@ func TestCheckCheckKernelModulesUnreadableFile(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
savedModInfoCmd := modInfoCmd
|
||||
savedModProbeCmd := modProbeCmd
|
||||
savedSysModuleDir := sysModuleDir
|
||||
|
||||
// XXX: override (fake the modprobe command failing)
|
||||
modInfoCmd = "false"
|
||||
modProbeCmd = "false"
|
||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||
|
||||
defer func() {
|
||||
modInfoCmd = savedModInfoCmd
|
||||
modProbeCmd = savedModProbeCmd
|
||||
sysModuleDir = savedSysModuleDir
|
||||
}()
|
||||
|
||||
@ -637,15 +637,15 @@ func TestCheckCheckKernelModulesInvalidFileContents(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
savedModInfoCmd := modInfoCmd
|
||||
savedModProbeCmd := modProbeCmd
|
||||
savedSysModuleDir := sysModuleDir
|
||||
|
||||
// XXX: override (fake the modprobe command failing)
|
||||
modInfoCmd = "false"
|
||||
modProbeCmd = "false"
|
||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||
|
||||
defer func() {
|
||||
modInfoCmd = savedModInfoCmd
|
||||
modProbeCmd = savedModProbeCmd
|
||||
sysModuleDir = savedSysModuleDir
|
||||
}()
|
||||
|
||||
@ -700,15 +700,15 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
savedModInfoCmd := modInfoCmd
|
||||
savedModProbeCmd := modProbeCmd
|
||||
savedSysModuleDir := sysModuleDir
|
||||
|
||||
// XXX: override (fake the modprobe command failing)
|
||||
modInfoCmd = "false"
|
||||
modProbeCmd = "false"
|
||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||
|
||||
defer func() {
|
||||
modInfoCmd = savedModInfoCmd
|
||||
modProbeCmd = savedModProbeCmd
|
||||
sysModuleDir = savedSysModuleDir
|
||||
}()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user