hypervisor: cleanup valid method

The boolean return value is not necessary.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao 2018-05-13 18:22:41 +08:00
parent 18e6a6effc
commit 7f20dd89a3
4 changed files with 14 additions and 11 deletions

View File

@ -218,13 +218,13 @@ type HypervisorConfig struct {
Msize9p uint32
}
func (conf *HypervisorConfig) valid() (bool, error) {
func (conf *HypervisorConfig) valid() error {
if conf.KernelPath == "" {
return false, fmt.Errorf("Missing kernel path")
return fmt.Errorf("Missing kernel path")
}
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 {
@ -251,7 +251,7 @@ func (conf *HypervisorConfig) valid() (bool, error) {
conf.Msize9p = defaultMsize9p
}
return true, nil
return nil
}
// AddKernelParam allows the addition of new kernel parameters to an existing

View File

@ -107,9 +107,12 @@ func TestNewHypervisorFromUnknownHypervisorType(t *testing.T) {
}
}
func testHypervisorConfigValid(t *testing.T, hypervisorConfig *HypervisorConfig, expected bool) {
ret, _ := hypervisorConfig.valid()
if ret != expected {
func testHypervisorConfigValid(t *testing.T, hypervisorConfig *HypervisorConfig, success bool) {
err := hypervisorConfig.valid()
if success && err != nil {
t.Fatal()
}
if !success && err == nil {
t.Fatal()
}
}

View File

@ -10,8 +10,8 @@ type mockHypervisor struct {
}
func (m *mockHypervisor) init(id string, hypervisorConfig *HypervisorConfig, vmConfig Resources, storage resourceStorage) error {
valid, err := hypervisorConfig.valid()
if valid == false || err != nil {
err := hypervisorConfig.valid()
if err != nil {
return err
}

View File

@ -173,8 +173,8 @@ func (q *qemu) qemuPath() (string, error) {
// init intializes the Qemu structure.
func (q *qemu) init(id string, hypervisorConfig *HypervisorConfig, vmConfig Resources, storage resourceStorage) error {
valid, err := hypervisorConfig.valid()
if valid == false || err != nil {
err := hypervisorConfig.valid()
if err != nil {
return err
}