diff options
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 472eddae..9b81951a 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "log" + "os" "testing" "github.com/hashicorp/terraform/helper/resource" @@ -591,13 +592,13 @@ func testAccCheckLibvirtScsiDisk(n string, domain *libvirt.Domain) resource.Test func createNvramFile() (string, error) { // size of an accepted, valid, nvram backing store - nvram_dummy_buffer := make([]byte, 131072) + NVRAMDummyBuffer := make([]byte, 131072) file, err := ioutil.TempFile("/tmp", "nvram") if err != nil { return "", err } file.Chmod(0777) - _, err = file.Write(nvram_dummy_buffer) + _, err = file.Write(NVRAMDummyBuffer) if err != nil { return "", err } @@ -607,21 +608,46 @@ func createNvramFile() (string, error) { return file.Name(), nil } -func TestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T) { - nvram_path, err := createNvramFile() +func TestAccLibvirtDomainFirmware(t *testing.T) { + NVRAMPath, err := createNvramFile() if err != nil { t.Fatal(err) } + firmware := fmt.Sprintf("/usr/share/qemu/ovmf-x86_64-code.bin") + if _, err := os.Stat(firmware); os.IsNotExist(err) { + firmware = "/usr/share/ovmf/OVMF.fd" + if _, err := os.Stat(firmware); os.IsNotExist(err) { + t.Skip("Can't test domain custom firmware: OVMF firmware not found: %s") + } + } + + template := fmt.Sprintf("/usr/share/qemu/ovmf-x86_64-vars.bin") + if _, err := os.Stat(template); os.IsNotExist(err) { + template = "/usr/share/qemu/OVMF.fd" + if _, err := os.Stat(template); os.IsNotExist(err) { + t.Skip("Can't test domain custom firmware template: OVMF template not found: %s") + } + } + + t.Run("No Template", func(t *testing.T) { + subtestAccLibvirtDomainFirmwareNoTemplate(t, NVRAMPath, firmware) + }) + t.Run("With Template", func(t *testing.T) { + subtestAccLibvirtDomainFirmwareTemplate(t, NVRAMPath, firmware, template) + }) +} + +func subtestAccLibvirtDomainFirmwareNoTemplate(t *testing.T, NVRAMPath string, firmware string) { var domain libvirt.Domain var config = fmt.Sprintf(` resource "libvirt_domain" "acceptance-test-domain" { name = "terraform-test-firmware-no-template" - firmware = "/usr/share/ovmf/OVMF.fd" + firmware = "%s" nvram { file = "%s" } - }`, nvram_path) + }`, firmware, NVRAMPath) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -635,17 +661,17 @@ func TestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T) { resource.TestCheckResourceAttr( "libvirt_domain.acceptance-test-domain", "name", "terraform-test-firmware-no-template"), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "nvram.file", nvram_path), + "libvirt_domain.acceptance-test-domain", "nvram.file", NVRAMPath), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "firmware", "/usr/share/ovmf/OVMF.fd"), + "libvirt_domain.acceptance-test-domain", "firmware", firmware), ), }, }, }) } -func TestAccLibvirtDomain_FirmwareTemplate(t *testing.T) { - nvram_path, err := createNvramFile() +func subtestAccLibvirtDomainFirmwareTemplate(t *testing.T, NVRAMPath string, firmware string, template string) { + NVRAMPath, err := createNvramFile() if err != nil { t.Fatal(err) } @@ -654,12 +680,12 @@ func TestAccLibvirtDomain_FirmwareTemplate(t *testing.T) { var config = fmt.Sprintf(` resource "libvirt_domain" "acceptance-test-domain" { name = "terraform-test-firmware-with-template" - firmware = "/usr/share/ovmf/OVMF.fd" + firmware = "%s" nvram { file = "%s" - template = "/usr/share/qemu/OVMF.fd" + template = "%s" } - }`, nvram_path) + }`, firmware, NVRAMPath, template) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -673,11 +699,11 @@ func TestAccLibvirtDomain_FirmwareTemplate(t *testing.T) { resource.TestCheckResourceAttr( "libvirt_domain.acceptance-test-domain", "name", "terraform-test-firmware-with-template"), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "nvram.file", nvram_path), + "libvirt_domain.acceptance-test-domain", "nvram.file", NVRAMPath), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "nvram.template", "/usr/share/qemu/OVMF.fd"), + "libvirt_domain.acceptance-test-domain", "nvram.template", template), resource.TestCheckResourceAttr( - "libvirt_domain.acceptance-test-domain", "firmware", "/usr/share/ovmf/OVMF.fd"), + "libvirt_domain.acceptance-test-domain", "firmware", firmware), ), }, }, |