mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 09:13:29 +00:00
hypervisor: cleanup valid method
The boolean return value is not necessary. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
18e6a6effc
commit
7f20dd89a3
@ -218,13 +218,13 @@ type HypervisorConfig struct {
|
|||||||
Msize9p uint32
|
Msize9p uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conf *HypervisorConfig) valid() (bool, error) {
|
func (conf *HypervisorConfig) valid() error {
|
||||||
if conf.KernelPath == "" {
|
if conf.KernelPath == "" {
|
||||||
return false, fmt.Errorf("Missing kernel path")
|
return fmt.Errorf("Missing kernel path")
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.ImagePath == "" && conf.InitrdPath == "" {
|
if conf.ImagePath == "" && conf.InitrdPath == "" {
|
||||||
return false, fmt.Errorf("Missing image and initrd path")
|
return fmt.Errorf("Missing image and initrd path")
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.DefaultVCPUs == 0 {
|
if conf.DefaultVCPUs == 0 {
|
||||||
@ -251,7 +251,7 @@ func (conf *HypervisorConfig) valid() (bool, error) {
|
|||||||
conf.Msize9p = defaultMsize9p
|
conf.Msize9p = defaultMsize9p
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddKernelParam allows the addition of new kernel parameters to an existing
|
// AddKernelParam allows the addition of new kernel parameters to an existing
|
||||||
|
@ -107,9 +107,12 @@ func TestNewHypervisorFromUnknownHypervisorType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testHypervisorConfigValid(t *testing.T, hypervisorConfig *HypervisorConfig, expected bool) {
|
func testHypervisorConfigValid(t *testing.T, hypervisorConfig *HypervisorConfig, success bool) {
|
||||||
ret, _ := hypervisorConfig.valid()
|
err := hypervisorConfig.valid()
|
||||||
if ret != expected {
|
if success && err != nil {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
if !success && err == nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ type mockHypervisor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockHypervisor) init(id string, hypervisorConfig *HypervisorConfig, vmConfig Resources, storage resourceStorage) error {
|
func (m *mockHypervisor) init(id string, hypervisorConfig *HypervisorConfig, vmConfig Resources, storage resourceStorage) error {
|
||||||
valid, err := hypervisorConfig.valid()
|
err := hypervisorConfig.valid()
|
||||||
if valid == false || err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +173,8 @@ func (q *qemu) qemuPath() (string, error) {
|
|||||||
|
|
||||||
// init intializes the Qemu structure.
|
// init intializes the Qemu structure.
|
||||||
func (q *qemu) init(id string, hypervisorConfig *HypervisorConfig, vmConfig Resources, storage resourceStorage) error {
|
func (q *qemu) init(id string, hypervisorConfig *HypervisorConfig, vmConfig Resources, storage resourceStorage) error {
|
||||||
valid, err := hypervisorConfig.valid()
|
err := hypervisorConfig.valid()
|
||||||
if valid == false || err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user