diff --git a/src/runtime/virtcontainers/hypervisor.go b/src/runtime/virtcontainers/hypervisor.go index a1949b056e..0186c397ed 100644 --- a/src/runtime/virtcontainers/hypervisor.go +++ b/src/runtime/virtcontainers/hypervisor.go @@ -547,6 +547,10 @@ func (conf *HypervisorConfig) Valid() error { return fmt.Errorf("Missing image and initrd path") } + if conf.ImagePath != "" && conf.InitrdPath != "" { + return fmt.Errorf("Image and initrd path cannot be both set") + } + if err := conf.CheckTemplateConfig(); err != nil { return err } diff --git a/src/runtime/virtcontainers/hypervisor_test.go b/src/runtime/virtcontainers/hypervisor_test.go index c2eaa107cc..d8c4f6448c 100644 --- a/src/runtime/virtcontainers/hypervisor_test.go +++ b/src/runtime/virtcontainers/hypervisor_test.go @@ -134,6 +134,17 @@ func TestHypervisorConfigIsValid(t *testing.T) { testHypervisorConfigValid(t, hypervisorConfig, true) } +func TestHypervisorConfigBothInitrdAndImage(t *testing.T) { + hypervisorConfig := &HypervisorConfig{ + KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel), + ImagePath: fmt.Sprintf("%s/%s", testDir, testImage), + InitrdPath: fmt.Sprintf("%s/%s", testDir, testInitrd), + HypervisorPath: "", + } + + testHypervisorConfigValid(t, hypervisorConfig, false) +} + func TestHypervisorConfigValidTemplateConfig(t *testing.T) { hypervisorConfig := &HypervisorConfig{ KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel), diff --git a/src/runtime/virtcontainers/qemu_test.go b/src/runtime/virtcontainers/qemu_test.go index eb10857dd2..deeb482dc6 100644 --- a/src/runtime/virtcontainers/qemu_test.go +++ b/src/runtime/virtcontainers/qemu_test.go @@ -25,7 +25,6 @@ import ( func newQemuConfig() HypervisorConfig { return HypervisorConfig{ KernelPath: testQemuKernelPath, - ImagePath: testQemuImagePath, InitrdPath: testQemuInitrdPath, HypervisorPath: testQemuPath, NumVCPUs: defaultVCPUs,