From 8e11b03660cb1c5d4d6f48bf56b0b163ecbeb4fd Mon Sep 17 00:00:00 2001 From: Huy Mai Date: Fri, 24 Jan 2025 14:19:59 +0000 Subject: [PATCH] Change pool name and hard drive path Signed-off-by: Huy Mai --- hack/clean-e2e.sh | 8 ++--- test/vbmctl/main.go | 55 ++++++++++++++++++++++---------- test/vbmctl/templates/VM.xml.tpl | 5 ++- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/hack/clean-e2e.sh b/hack/clean-e2e.sh index 40ab5d10fb..b46e41fa93 100755 --- a/hack/clean-e2e.sh +++ b/hack/clean-e2e.sh @@ -19,9 +19,9 @@ virsh -c qemu:///system net-destroy baremetal-e2e virsh -c qemu:///system net-undefine baremetal-e2e # Clean volume pool directory -rm -rf /tmp/pool_oo/* +rm -rf /tmp/pool_oo # Clean volume pool -virsh pool-destroy default || true -virsh pool-delete default || true -virsh pool-undefine default || true +virsh pool-destroy oooq_pool || true +virsh pool-delete oooq_pool || true +virsh pool-undefine oooq_pool || true diff --git a/test/vbmctl/main.go b/test/vbmctl/main.go index 1572cc62cd..74a12d1676 100644 --- a/test/vbmctl/main.go +++ b/test/vbmctl/main.go @@ -21,9 +21,15 @@ var ( templateFiles embed.FS ) +const ( + poolName = "oooq_pool" + poolPath = "/tmp/pool_oo" +) + type Host struct { HostName string Networks bmoe2e.Networks + PoolName string PoolPath string } @@ -42,9 +48,36 @@ func RenderTemplate(inputFile string, data interface{}) (string, error) { return buf.String(), nil } +func startVolumePool(pool *libvirt.StoragePool) error { + if err := pool.SetAutostart(true); err != nil { + fmt.Println("Failed to Set the pool autostart") + fmt.Printf("Error occurred: %v\n", err) + return err + } + + active, err := pool.IsActive() + if err != nil { + return err + } + + if active { + return nil + } + + if err := pool.Create(0); err != nil { + fmt.Println("Failed to Start the pool") + fmt.Printf("Error occurred: %v\n", err) + return err + } + return nil +} + // CreateVolumePool creates a volume pool with specified name if a pool with // that name does not exist yet. func CreateVolumePool(poolName, poolPath string) (*libvirt.StoragePool, error) { + if err := os.MkdirAll(poolPath, 0777); err != nil && !os.IsExist(err) { + return nil, err + } // Connect to libvirt daemon conn, err := libvirt.NewConnect("qemu:///system") if err != nil { @@ -57,6 +90,9 @@ func CreateVolumePool(poolName, poolPath string) (*libvirt.StoragePool, error) { if err == nil { fmt.Println("Pool already exists") + if err := startVolumePool(pool); err != nil { + return nil, err + } return pool, nil } @@ -90,15 +126,7 @@ func CreateVolumePool(poolName, poolPath string) (*libvirt.StoragePool, error) { return nil, err } - if err = pool.SetAutostart(true); err != nil { - fmt.Println("Failed to Set the pool autostart") - fmt.Printf("Error occurred: %v\n", err) - return nil, err - } - - if err = pool.Create(0); err != nil { - fmt.Println("Failed to Start the pool") - fmt.Printf("Error occurred: %v\n", err) + if err := startVolumePool(pool); err != nil { return nil, err } @@ -160,8 +188,6 @@ func CreateVolume(volumeName, poolName, poolPath string, capacityInGB int) error // started. Errors during qcow2 file creation, volume creation, libvirt connection, // template rendering, or domain creation are returned. func CreateLibvirtVM(hostName string, networks *bmoe2e.Networks) error { - poolName := "default" - poolPath := "/tmp/pool_oo" opts := make(map[string]any) opts[qcow2.OPT_SIZE] = 3 * (1 << 30) // qcow2 file's size is 3g opts[qcow2.OPT_FMT] = "qcow2" // qcow2 format @@ -186,13 +212,10 @@ func CreateLibvirtVM(hostName string, networks *bmoe2e.Networks) error { } defer conn.Close() - data := struct { - HostName string - Networks bmoe2e.Networks - PoolPath string - }{ + data := Host{ HostName: hostName, Networks: *networks, + PoolName: poolName, PoolPath: poolPath, } diff --git a/test/vbmctl/templates/VM.xml.tpl b/test/vbmctl/templates/VM.xml.tpl index cace5e287e..d5d963d1e2 100644 --- a/test/vbmctl/templates/VM.xml.tpl +++ b/test/vbmctl/templates/VM.xml.tpl @@ -30,7 +30,8 @@ - + +
@@ -80,13 +81,11 @@ {{ end }} - -