From 7f20dd89a3ea5fa24f64ea7086d707c1e86cb485 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Sun, 13 May 2018 18:22:41 +0800 Subject: [PATCH] hypervisor: cleanup valid method The boolean return value is not necessary. Signed-off-by: Peng Tao --- virtcontainers/hypervisor.go | 8 ++++---- virtcontainers/hypervisor_test.go | 9 ++++++--- virtcontainers/mock_hypervisor.go | 4 ++-- virtcontainers/qemu.go | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index 3950f890c6..8f0c5997cf 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -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 diff --git a/virtcontainers/hypervisor_test.go b/virtcontainers/hypervisor_test.go index e9f0caabaa..e84899fb8b 100644 --- a/virtcontainers/hypervisor_test.go +++ b/virtcontainers/hypervisor_test.go @@ -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() } } diff --git a/virtcontainers/mock_hypervisor.go b/virtcontainers/mock_hypervisor.go index f86d372534..d41714ea77 100644 --- a/virtcontainers/mock_hypervisor.go +++ b/virtcontainers/mock_hypervisor.go @@ -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 } diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index f59aa3301d..94b935eb95 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -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 }