Merge pull request #1791 from wainersm/virtcontainers-1

virtcontainers: check that both initrd and image are not set
This commit is contained in:
James O. D. Hunt 2021-10-29 14:51:07 +01:00 committed by GitHub
commit 4e2dd41eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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,