mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 18:47:03 +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 (
|
var (
|
||||||
procCPUInfo = "/proc/cpuinfo"
|
procCPUInfo = "/proc/cpuinfo"
|
||||||
sysModuleDir = "/sys/module"
|
sysModuleDir = "/sys/module"
|
||||||
modInfoCmd = "modinfo"
|
modProbeCmd = "modprobe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// variables rather than consts to allow tests to modify them
|
// variables rather than consts to allow tests to modify them
|
||||||
@ -120,8 +120,9 @@ func haveKernelModule(module string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, check if the module is unloaded, but available
|
// Now, check if the module is unloaded, but available.
|
||||||
cmd := exec.Command(modInfoCmd, module)
|
// And modprobe it if so.
|
||||||
|
cmd := exec.Command(modProbeCmd, module)
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
@ -448,15 +448,15 @@ func TestCheckHaveKernelModule(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
savedModInfoCmd := modInfoCmd
|
savedModProbeCmd := modProbeCmd
|
||||||
savedSysModuleDir := sysModuleDir
|
savedSysModuleDir := sysModuleDir
|
||||||
|
|
||||||
// XXX: override (fake the modprobe command failing)
|
// XXX: override (fake the modprobe command failing)
|
||||||
modInfoCmd = "false"
|
modProbeCmd = "false"
|
||||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modInfoCmd = savedModInfoCmd
|
modProbeCmd = savedModProbeCmd
|
||||||
sysModuleDir = savedSysModuleDir
|
sysModuleDir = savedSysModuleDir
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -471,13 +471,13 @@ func TestCheckHaveKernelModule(t *testing.T) {
|
|||||||
assert.False(result)
|
assert.False(result)
|
||||||
|
|
||||||
// XXX: override - make our fake "modprobe" succeed
|
// XXX: override - make our fake "modprobe" succeed
|
||||||
modInfoCmd = "true"
|
modProbeCmd = "true"
|
||||||
|
|
||||||
result = haveKernelModule(module)
|
result = haveKernelModule(module)
|
||||||
assert.True(result)
|
assert.True(result)
|
||||||
|
|
||||||
// disable "modprobe" again
|
// disable "modprobe" again
|
||||||
modInfoCmd = "false"
|
modProbeCmd = "false"
|
||||||
|
|
||||||
fooDir := filepath.Join(sysModuleDir, module)
|
fooDir := filepath.Join(sysModuleDir, module)
|
||||||
err = os.MkdirAll(fooDir, testDirMode)
|
err = os.MkdirAll(fooDir, testDirMode)
|
||||||
@ -498,15 +498,15 @@ func TestCheckCheckKernelModules(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
savedModInfoCmd := modInfoCmd
|
savedModProbeCmd := modProbeCmd
|
||||||
savedSysModuleDir := sysModuleDir
|
savedSysModuleDir := sysModuleDir
|
||||||
|
|
||||||
// XXX: override (fake the modprobe command failing)
|
// XXX: override (fake the modprobe command failing)
|
||||||
modInfoCmd = "false"
|
modProbeCmd = "false"
|
||||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modInfoCmd = savedModInfoCmd
|
modProbeCmd = savedModProbeCmd
|
||||||
sysModuleDir = savedSysModuleDir
|
sysModuleDir = savedSysModuleDir
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -590,15 +590,15 @@ func TestCheckCheckKernelModulesUnreadableFile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
savedModInfoCmd := modInfoCmd
|
savedModProbeCmd := modProbeCmd
|
||||||
savedSysModuleDir := sysModuleDir
|
savedSysModuleDir := sysModuleDir
|
||||||
|
|
||||||
// XXX: override (fake the modprobe command failing)
|
// XXX: override (fake the modprobe command failing)
|
||||||
modInfoCmd = "false"
|
modProbeCmd = "false"
|
||||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modInfoCmd = savedModInfoCmd
|
modProbeCmd = savedModProbeCmd
|
||||||
sysModuleDir = savedSysModuleDir
|
sysModuleDir = savedSysModuleDir
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -637,15 +637,15 @@ func TestCheckCheckKernelModulesInvalidFileContents(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
savedModInfoCmd := modInfoCmd
|
savedModProbeCmd := modProbeCmd
|
||||||
savedSysModuleDir := sysModuleDir
|
savedSysModuleDir := sysModuleDir
|
||||||
|
|
||||||
// XXX: override (fake the modprobe command failing)
|
// XXX: override (fake the modprobe command failing)
|
||||||
modInfoCmd = "false"
|
modProbeCmd = "false"
|
||||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modInfoCmd = savedModInfoCmd
|
modProbeCmd = savedModProbeCmd
|
||||||
sysModuleDir = savedSysModuleDir
|
sysModuleDir = savedSysModuleDir
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -700,15 +700,15 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
savedModInfoCmd := modInfoCmd
|
savedModProbeCmd := modProbeCmd
|
||||||
savedSysModuleDir := sysModuleDir
|
savedSysModuleDir := sysModuleDir
|
||||||
|
|
||||||
// XXX: override (fake the modprobe command failing)
|
// XXX: override (fake the modprobe command failing)
|
||||||
modInfoCmd = "false"
|
modProbeCmd = "false"
|
||||||
sysModuleDir = filepath.Join(dir, "sys/module")
|
sysModuleDir = filepath.Join(dir, "sys/module")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
modInfoCmd = savedModInfoCmd
|
modProbeCmd = savedModProbeCmd
|
||||||
sysModuleDir = savedSysModuleDir
|
sysModuleDir = savedSysModuleDir
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user