virtcontainers: check that both initrd and image are not set

This changed valid() in hypervisor to check the case where both
initrd and image path are set; in this case it returns an error.

Fixes #1868
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
This commit is contained in:
Wainer dos Santos Moschetta 2021-05-03 15:42:58 -04:00
parent 3120b489e3
commit 309dae631a
3 changed files with 15 additions and 1 deletions

View File

@ -547,6 +547,10 @@ func (conf *HypervisorConfig) Valid() error {
return fmt.Errorf("Missing image and initrd path") 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 { if err := conf.CheckTemplateConfig(); err != nil {
return err return err
} }

View File

@ -134,6 +134,17 @@ func TestHypervisorConfigIsValid(t *testing.T) {
testHypervisorConfigValid(t, hypervisorConfig, true) 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) { func TestHypervisorConfigValidTemplateConfig(t *testing.T) {
hypervisorConfig := &HypervisorConfig{ hypervisorConfig := &HypervisorConfig{
KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel), KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel),

View File

@ -25,7 +25,6 @@ import (
func newQemuConfig() HypervisorConfig { func newQemuConfig() HypervisorConfig {
return HypervisorConfig{ return HypervisorConfig{
KernelPath: testQemuKernelPath, KernelPath: testQemuKernelPath,
ImagePath: testQemuImagePath,
InitrdPath: testQemuInitrdPath, InitrdPath: testQemuInitrdPath,
HypervisorPath: testQemuPath, HypervisorPath: testQemuPath,
NumVCPUs: defaultVCPUs, NumVCPUs: defaultVCPUs,