mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-21 20:08:54 +00:00
katautils: Move SetKernelParams from CreateSandbox to updateRuntimeConfig
Function SetKernelParams is just to update the runtimeConfig according to itself. It just around the configuration. So this patch moves it to updateRuntimeConfig. Fixes: #1106 Signed-off-by: Hui Zhu <teawater@hyper.sh>
This commit is contained in:
@@ -720,62 +720,3 @@ func TestCreate(t *testing.T) {
|
||||
os.RemoveAll(path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateInvalidKernelParams(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
path, err := ioutil.TempDir("", "containers-mapping")
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
katautils.SetCtrsMapTreePath(ctrsMapTreePath)
|
||||
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
runtimeConfig, err := newTestRuntimeConfig(tmpdir, testConsole, true)
|
||||
assert.NoError(err)
|
||||
|
||||
bundlePath := filepath.Join(tmpdir, "bundle")
|
||||
|
||||
err = makeOCIBundle(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
pidFilePath := filepath.Join(tmpdir, "pidfile.txt")
|
||||
|
||||
ociConfigFile := filepath.Join(bundlePath, "config.json")
|
||||
assert.True(katautils.FileExists(ociConfigFile))
|
||||
|
||||
spec, err := readOCIConfigFile(ociConfigFile)
|
||||
assert.NoError(err)
|
||||
|
||||
// Force createSandbox() to be called.
|
||||
spec.Annotations = make(map[string]string)
|
||||
spec.Annotations[testContainerTypeAnnotation] = testContainerTypeSandbox
|
||||
|
||||
// rewrite the file
|
||||
err = writeOCIConfigFile(spec, ociConfigFile)
|
||||
assert.NoError(err)
|
||||
|
||||
savedFunc := katautils.GetKernelParamsFunc
|
||||
defer func() {
|
||||
katautils.GetKernelParamsFunc = savedFunc
|
||||
}()
|
||||
|
||||
katautils.GetKernelParamsFunc = func(needSystemd bool) []vc.Param {
|
||||
return []vc.Param{
|
||||
{
|
||||
Key: "",
|
||||
Value: "",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
for detach := range []bool{true, false} {
|
||||
err := create(context.Background(), testContainerID, bundlePath, testConsole, pidFilePath, true, true, runtimeConfig)
|
||||
assert.Errorf(err, "%+v", detach)
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
os.RemoveAll(path)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user