mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-15 06:34:03 +00:00
Merge pull request #8213 from jodh-intel/validate-hypervisor-cfg-name
runtime: Validate hypervisor section name in config file
This commit is contained in:
commit
048cc70654
@ -55,6 +55,8 @@ const (
|
|||||||
|
|
||||||
// the maximum amount of PCI bridges that can be cold plugged in a VM
|
// the maximum amount of PCI bridges that can be cold plugged in a VM
|
||||||
maxPCIBridges uint32 = 5
|
maxPCIBridges uint32 = 5
|
||||||
|
|
||||||
|
errInvalidHypervisorPrefix = "configuration file contains invalid hypervisor section"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tomlConfig struct {
|
type tomlConfig struct {
|
||||||
@ -1175,6 +1177,8 @@ func updateRuntimeConfigHypervisor(configPath string, tomlConf tomlConfig, confi
|
|||||||
case dragonballHypervisorTableType:
|
case dragonballHypervisorTableType:
|
||||||
config.HypervisorType = vc.DragonballHypervisor
|
config.HypervisorType = vc.DragonballHypervisor
|
||||||
hConfig, err = newDragonballHypervisorConfig(hypervisor)
|
hConfig, err = newDragonballHypervisorConfig(hypervisor)
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("%s: %+q", errInvalidHypervisorPrefix, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1735,3 +1735,59 @@ vfio_mode="vfio"
|
|||||||
assert.Equal(t, config.Runtime.InterNetworkModel, "macvtap")
|
assert.Equal(t, config.Runtime.InterNetworkModel, "macvtap")
|
||||||
assert.Equal(t, config.Runtime.VfioMode, "vfio")
|
assert.Equal(t, config.Runtime.VfioMode, "vfio")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateRuntimeConfigHypervisor(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
type tableTypeEntry struct {
|
||||||
|
name string
|
||||||
|
valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
configFile := "/some/where/configuration.toml"
|
||||||
|
|
||||||
|
// Note: We cannot test acrnHypervisorTableType since
|
||||||
|
// newAcrnHypervisorConfig() expects ACRN binaries to be
|
||||||
|
// installed.
|
||||||
|
var entries = []tableTypeEntry{
|
||||||
|
{clhHypervisorTableType, true},
|
||||||
|
{dragonballHypervisorTableType, true},
|
||||||
|
{firecrackerHypervisorTableType, true},
|
||||||
|
{qemuHypervisorTableType, true},
|
||||||
|
{"foo", false},
|
||||||
|
{"bar", false},
|
||||||
|
{clhHypervisorTableType + "baz", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, h := range entries {
|
||||||
|
config := oci.RuntimeConfig{}
|
||||||
|
|
||||||
|
tomlConf := tomlConfig{
|
||||||
|
Hypervisor: map[string]hypervisor{
|
||||||
|
h.name: {
|
||||||
|
NumVCPUs: int32(2),
|
||||||
|
MemorySize: uint32(2048),
|
||||||
|
Path: "/",
|
||||||
|
Kernel: "/",
|
||||||
|
Image: "/",
|
||||||
|
Firmware: "/",
|
||||||
|
FirmwareVolume: "/",
|
||||||
|
SharedFS: "virtio-fs",
|
||||||
|
VirtioFSDaemon: "/usr/libexec/kata-qemu/virtiofsd",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := updateRuntimeConfigHypervisor(configFile, tomlConf, &config)
|
||||||
|
|
||||||
|
if h.valid {
|
||||||
|
assert.NoError(err, "test %d (%+v)", i, h)
|
||||||
|
} else {
|
||||||
|
assert.Error(err, "test %d (%+v)", i, h)
|
||||||
|
|
||||||
|
expectedErr := fmt.Errorf("%v: %v: %+q", configFile, errInvalidHypervisorPrefix, h.name)
|
||||||
|
|
||||||
|
assert.Equal(err, expectedErr, "test %d (%+v)", i, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user