From cadeededae5d4bab34dcf9010a07810a298caf97 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 10 Nov 2017 13:30:08 +0100 Subject: Fix libvirt ovmf firmware integration test on non-Ubuntu On SUSE systems, these paths are different. In order to reuse the code that looks for the right files, we make the template and no-template case sub-tests of the main test containing the lookup code. Also, if the files are not there, skip the test. --- libvirt/resource_libvirt_domain_test.go | 46 ++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 472eddae..da4c3023 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" @@ -607,21 +608,46 @@ func createNvramFile() (string, error) { return file.Name(), nil } -func TestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T) { +func TestAccLibvirtDomain_Firmware(t *testing.T) { nvram_path, err := createNvramFile() if err != nil { t.Fatal(err) } + firmware := fmt.Sprintf("/usr/share/qemu/ovmf-x86_64.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) { + subtestAccLibvirtDomain_FirmwareNoTemplate(t, nvram_path, firmware) + }) + t.Run("With Template", func(t *testing.T) { + subtestAccLibvirtDomain_FirmwareTemplate(t, nvram_path, firmware, template) + }) +} + +func subtestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T, nvram_path 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, nvram_path) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -637,14 +663,14 @@ func TestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T) { resource.TestCheckResourceAttr( "libvirt_domain.acceptance-test-domain", "nvram.file", nvram_path), 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) { +func subtestAccLibvirtDomain_FirmwareTemplate(t *testing.T, nvram_path string, firmware string, template string) { nvram_path, 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, nvram_path, template) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -675,9 +701,9 @@ func TestAccLibvirtDomain_FirmwareTemplate(t *testing.T) { resource.TestCheckResourceAttr( "libvirt_domain.acceptance-test-domain", "nvram.file", nvram_path), 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), ), }, }, -- cgit v1.2.3 From bac5f817ede55b8c86d615c63d6f226d9dd4b7b5 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 10 Nov 2017 14:10:28 +0100 Subject: make the firmware file consistent with the docs --- libvirt/resource_libvirt_domain_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index da4c3023..1eaa482c 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -614,7 +614,7 @@ func TestAccLibvirtDomain_Firmware(t *testing.T) { t.Fatal(err) } - firmware := fmt.Sprintf("/usr/share/qemu/ovmf-x86_64.bin") + 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) { -- cgit v1.2.3 From 59e2398e8480c0dc81e4ced182fea3234404d4ae Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 10 Nov 2017 14:36:21 +0100 Subject: make golint happy --- libvirt/resource_libvirt_domain_test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 1eaa482c..9b81951a 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -592,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 } @@ -608,8 +608,8 @@ func createNvramFile() (string, error) { return file.Name(), nil } -func TestAccLibvirtDomain_Firmware(t *testing.T) { - nvram_path, err := createNvramFile() +func TestAccLibvirtDomainFirmware(t *testing.T) { + NVRAMPath, err := createNvramFile() if err != nil { t.Fatal(err) } @@ -631,14 +631,14 @@ func TestAccLibvirtDomain_Firmware(t *testing.T) { } t.Run("No Template", func(t *testing.T) { - subtestAccLibvirtDomain_FirmwareNoTemplate(t, nvram_path, firmware) + subtestAccLibvirtDomainFirmwareNoTemplate(t, NVRAMPath, firmware) }) t.Run("With Template", func(t *testing.T) { - subtestAccLibvirtDomain_FirmwareTemplate(t, nvram_path, firmware, template) + subtestAccLibvirtDomainFirmwareTemplate(t, NVRAMPath, firmware, template) }) } -func subtestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T, nvram_path string, firmware string) { +func subtestAccLibvirtDomainFirmwareNoTemplate(t *testing.T, NVRAMPath string, firmware string) { var domain libvirt.Domain var config = fmt.Sprintf(` resource "libvirt_domain" "acceptance-test-domain" { @@ -647,7 +647,7 @@ func subtestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T, nvram_path string, nvram { file = "%s" } - }`, firmware, nvram_path) + }`, firmware, NVRAMPath) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -661,7 +661,7 @@ func subtestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T, nvram_path string, 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", firmware), ), @@ -670,8 +670,8 @@ func subtestAccLibvirtDomain_FirmwareNoTemplate(t *testing.T, nvram_path string, }) } -func subtestAccLibvirtDomain_FirmwareTemplate(t *testing.T, nvram_path string, firmware string, template string) { - nvram_path, err := createNvramFile() +func subtestAccLibvirtDomainFirmwareTemplate(t *testing.T, NVRAMPath string, firmware string, template string) { + NVRAMPath, err := createNvramFile() if err != nil { t.Fatal(err) } @@ -685,7 +685,7 @@ func subtestAccLibvirtDomain_FirmwareTemplate(t *testing.T, nvram_path string, f file = "%s" template = "%s" } - }`, firmware, nvram_path, template) + }`, firmware, NVRAMPath, template) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -699,7 +699,7 @@ func subtestAccLibvirtDomain_FirmwareTemplate(t *testing.T, nvram_path string, f 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", template), resource.TestCheckResourceAttr( -- cgit v1.2.3