mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-23 17:24:18 +01:00
config: Detect if VM memory smaller than image
Add a heuristic to ensure the amount of memory allocated to the hypervisor is bigger than the size of the image. This catches simple configuration issues where `default_memory=` is set to a smaller value than the size of either the `image=` or `initrd=` files. If the configured image type is `initrd`, fail but only warn in the logs for `image` as although it seems a highly unlikely scenario, it is permitted. Update tests to ensure that created resources have `>0` bytes. Fixes #636. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
@@ -362,3 +362,37 @@ func TestWriteFileErrNoPath(t *testing.T) {
|
||||
err = writeFile(dir, "", 0000)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestFileSize(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
dir, err := ioutil.TempDir(testDir, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
file := filepath.Join(dir, "foo")
|
||||
|
||||
// ENOENT
|
||||
_, err = fileSize(file)
|
||||
assert.Error(err)
|
||||
|
||||
err = createEmptyFile(file)
|
||||
assert.NoError(err)
|
||||
|
||||
// zero size
|
||||
size, err := fileSize(file)
|
||||
assert.NoError(err)
|
||||
assert.Equal(size, int64(0))
|
||||
|
||||
msg := "hello"
|
||||
msgLen := len(msg)
|
||||
|
||||
err = writeFile(file, msg, testFileMode)
|
||||
assert.NoError(err)
|
||||
|
||||
size, err = fileSize(file)
|
||||
assert.NoError(err)
|
||||
assert.Equal(size, int64(msgLen))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user