Skip to content
Permalink
Browse files

config: Error if image+initrd specified

If you build and install the runtime, the config file will contain an
entry for both an `initrd=` and an `image=` entry.

The Developer Guide explains that the user must disable one but it is
easy to forget.

Modified the runtime to fail if both an image and an initrd are
specified. Also added a new test for this scenario.

Fixes #318.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information...
jodh-intel committed May 18, 2018
1 parent be82c7f commit 8b56573cc7fa1aaa32d0550d30910301a8eaab03
Showing with 42 additions and 0 deletions.
  1. +5 −0 cli/config.go
  2. +37 −0 cli/config_test.go
@@ -309,6 +309,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
return vc.HypervisorConfig{}, err
}

if image != "" && initrd != "" {
return vc.HypervisorConfig{},
errors.New("cannot specify an image and an initrd in configuration file")
}

firmware, err := h.firmware()
if err != nil {
return vc.HypervisorConfig{}, err
@@ -625,6 +625,43 @@ func TestNewQemuHypervisorConfig(t *testing.T) {

}

func TestNewQemuHypervisorConfigImageAndInitrd(t *testing.T) {
assert := assert.New(t)

tmpdir, err := ioutil.TempDir(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)

imagePath := filepath.Join(tmpdir, "image")
initrdPath := filepath.Join(tmpdir, "initrd")
hypervisorPath := path.Join(tmpdir, "hypervisor")
kernelPath := path.Join(tmpdir, "kernel")

for _, file := range []string{imagePath, initrdPath, hypervisorPath, kernelPath} {
err = createEmptyFile(file)
assert.NoError(err)
}

machineType := "machineType"
disableBlock := true
enableIOThreads := true

hypervisor := hypervisor{
Path: hypervisorPath,
Kernel: kernelPath,
Image: imagePath,
Initrd: initrdPath,
MachineType: machineType,
DisableBlockDeviceUse: disableBlock,
EnableIOThreads: enableIOThreads,
}

_, err = newQemuHypervisorConfig(hypervisor)

// specifying both an image+initrd is invalid
assert.Error(err)
}

func TestNewShimConfig(t *testing.T) {
dir, err := ioutil.TempDir(testDir, "shim-config-")
if err != nil {

0 comments on commit 8b56573

Please sign in to comment.
You can’t perform that action at this time.