summaryrefslogtreecommitdiff
path: root/libvirt
diff options
context:
space:
mode:
authorThomas Hipp <thomashipp@gmail.com>2017-11-10 15:25:56 +0100
committerGitHub <noreply@github.com>2017-11-10 15:25:56 +0100
commit6284d746e12ed81215adbc5f97ba8d0fed835ba4 (patch)
tree9ef1faa8a3cff9d4f1b7eaba5f59c4e158e1605c /libvirt
parent6896ed4e03b29fe47b60e0e818f48c4ae5c29157 (diff)
parent59e2398e8480c0dc81e4ced182fea3234404d4ae (diff)
downloadterraform-provider-libvirt-6284d746e12ed81215adbc5f97ba8d0fed835ba4.tar
terraform-provider-libvirt-6284d746e12ed81215adbc5f97ba8d0fed835ba4.tar.gz
Merge pull request #226 from dmacvicar/fix_firmware_test_suse
Fix libvirt ovmf firmware integration test on non-Ubuntu
Diffstat (limited to 'libvirt')
-rw-r--r--libvirt/resource_libvirt_domain_test.go58
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),
),
},
},