Skip to content

Commit

Permalink
skip the tests if the host does not support logical pools
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacvicar committed Sep 29, 2024
1 parent e740d6f commit f724f41
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion libvirt/resource_libvirt_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package libvirt

import (
"context"
"encoding/xml"
"fmt"
"regexp"
"testing"
Expand Down Expand Up @@ -126,6 +128,7 @@ func TestAccLibvirtPool_DirBasic(t *testing.T) {
randomPoolResource := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
randomPoolName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
poolPath := "/tmp/cluster-api-provider-libvirt-pool-" + randomPoolName

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down Expand Up @@ -181,11 +184,49 @@ func TestAccLibvirtPool_DirBasicDeprecated(t *testing.T) {
})
}

func testAccPreCheckSupportsLogicalPool(t *testing.T) {
type storagePoolCaps struct {
Pools []struct {
Type string `xml:"type,attr"`
Supported string `xml:"supported,attr"`
} `xml:"pool"`
XMLName xml.Name `xml:"storagepoolCapabilities"`
}

client := testAccProvider.Meta().(*Client)

respStr, err := client.libvirt.ConnectGetStoragePoolCapabilities(0)
if err != nil {
t.Fatalf("Error getting storage pool capabilities: %s", err)
}

var caps storagePoolCaps
err = xml.Unmarshal([]byte(respStr), &caps)
if err != nil {
t.Fatalf("Error unmarshalling storage pool capabilities: %s", err)
}

for _, pool := range caps.Pools {
if pool.Type == "logical" && pool.Supported != "yes" {
t.Skip("Storage pool capabilities does not support logical pools")
}
}
}

func TestAccLibvirtPool_LVMBasic(t *testing.T) {

var pool libvirt.StoragePool
randomPoolResource := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
randomPoolName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)

// we need the plugin configured before we can test for support for lvm pools.
diag := testAccProvider.Configure(context.Background(), terraform.NewResourceConfigRaw(nil))
if diag.HasError() {
t.Fatal("error configuring provider")
}

testAccPreCheckSupportsLogicalPool(t)

blockDev, err := testhelper.CreateTempLoopDevice(t, randomPoolName)
if err != nil {
t.Fatal(err)
Expand All @@ -212,7 +253,6 @@ func TestAccLibvirtPool_LVMBasic(t *testing.T) {
path = "%s"
}
}
}`, randomPoolResource, randomPoolName, blockDev.LoopDevice),
Check: resource.ComposeTestCheckFunc(
testAccCheckLibvirtPoolExists("libvirt_pool."+randomPoolResource, &pool),
Expand Down

0 comments on commit f724f41

Please sign in to comment.