diff options
author | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2017-11-17 15:00:37 +0100 |
---|---|---|
committer | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2017-11-24 17:56:44 +0100 |
commit | 06f312e1ca81074d3806816535d3039251691fb4 (patch) | |
tree | 4eecdcaac2a7e4ace11067fa77c2416ef0ba69dc /libvirt | |
parent | 8e1bce8a4c28e69f4c84ae33bec7afd70aa7f7aa (diff) | |
download | terraform-provider-libvirt-06f312e1ca81074d3806816535d3039251691fb4.tar terraform-provider-libvirt-06f312e1ca81074d3806816535d3039251691fb4.tar.gz |
Fix tests by adding fixture for kernel and initrd
Diffstat (limited to 'libvirt')
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 3 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 45 | ||||
-rw-r--r-- | libvirt/testdata/README.md | 13 | ||||
-rw-r--r-- | libvirt/testdata/initrd.img | bin | 0 -> 98 bytes | |||
-rwxr-xr-x | libvirt/testdata/tetris.elf | bin | 0 -> 19384 bytes |
5 files changed, 52 insertions, 9 deletions
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 81cc2d70..272d1eec 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -9,6 +9,7 @@ import ( "net" "net/url" "os" + "sort" "strconv" "strings" "time" @@ -304,6 +305,8 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error cmdlineArgs = append(cmdlineArgs, fmt.Sprintf("%s=%v", k, v)) } } + + sort.Strings(cmdlineArgs) domainDef.OS.KernelArgs = strings.Join(cmdlineArgs, " ") if cpu, ok := d.GetOk("cpu"); ok { diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 29e01095..055c67c4 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -237,12 +237,28 @@ func TestAccLibvirtDomainURLDisk(t *testing.T) { func TestAccLibvirtDomainKernelInitrdCmdline(t *testing.T) { var domain libvirt.Domain + var kernel libvirt.StorageVol + var initrd libvirt.StorageVol var config = fmt.Sprintf(` + resource "libvirt_volume" "kernel" { + source = "testdata/tetris.elf" + name = "kernel" + pool = "default" + format = "raw" + } + + resource "libvirt_volume" "initrd" { + source = "testdata/initrd.img" + name = "initrd" + pool = "default" + format = "raw" + } + resource "libvirt_domain" "acceptance-test-domain" { name = "terraform-test-domain" - kernel = "/boot/vmlinuz" - initrd = "/boot/initrd" + kernel = "${libvirt_volume.kernel.id}" + initrd = "${libvirt_volume.initrd.id}" cmdline { foo = 1 bar = "bye" @@ -260,8 +276,10 @@ func TestAccLibvirtDomainKernelInitrdCmdline(t *testing.T) { resource.TestStep{ Config: config, Check: resource.ComposeTestCheckFunc( + testAccCheckLibvirtVolumeExists("libvirt_volume.kernel", &kernel), + testAccCheckLibvirtVolumeExists("libvirt_volume.initrd", &initrd), testAccCheckLibvirtDomainExists("libvirt_domain.acceptance-test-domain", &domain), - testAccCheckLibvirtDomainKernelInitrdCmdline(&domain), + testAccCheckLibvirtDomainKernelInitrdCmdline(&domain, &kernel, &initrd), ), }, }, @@ -692,7 +710,7 @@ func testAccCheckLibvirtURLDisk(u *url.URL, domain *libvirt.Domain) resource.Tes } } -func testAccCheckLibvirtDomainKernelInitrdCmdline(domain *libvirt.Domain) resource.TestCheckFunc { +func testAccCheckLibvirtDomainKernelInitrdCmdline(domain *libvirt.Domain, kernel *libvirt.StorageVol, initrd *libvirt.StorageVol) resource.TestCheckFunc { return func(s *terraform.State) error { xmlDesc, err := domain.GetXMLDesc(0) if err != nil { @@ -705,14 +723,23 @@ func testAccCheckLibvirtDomainKernelInitrdCmdline(domain *libvirt.Domain) resour return fmt.Errorf("Error reading libvirt domain XML description: %s", err) } - if domainDef.OS.Kernel != "/boot/vmlinuz" { - return fmt.Errorf("Kernel is not set correctly") + key, err := kernel.GetKey() + if err != nil { + return fmt.Errorf("Can't get kernel volume id") + } + if domainDef.OS.Kernel != key { + return fmt.Errorf("Kernel is not set correctly: '%s' vs '%s'", domainDef.OS.Kernel, key) + } + + key, err = initrd.GetKey() + if err != nil { + return fmt.Errorf("Can't get initrd volume id") } - if domainDef.OS.Initrd != "/boot/initrd" { - return fmt.Errorf("Initrd is not set correctly") + if domainDef.OS.Initrd != key { + return fmt.Errorf("Initrd is not set correctly: '%s' vs '%s'", domainDef.OS, key) } if domainDef.OS.KernelArgs != "bar=bye foo=1 foo=2" { - return fmt.Errorf("Kernel args not set correctly") + return fmt.Errorf("Kernel args not set correctly: '%s'", domainDef.OS.KernelArgs) } return nil } diff --git a/libvirt/testdata/README.md b/libvirt/testdata/README.md new file mode 100644 index 00000000..d571154f --- /dev/null +++ b/libvirt/testdata/README.md @@ -0,0 +1,13 @@ +# Test data + +* tetris.elf: https://github.com/programble/bare-metal-tetris + +``` +License + +Copyright © 2013–2014, Curtis McEnroe programble@gmail.com + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +``` diff --git a/libvirt/testdata/initrd.img b/libvirt/testdata/initrd.img Binary files differnew file mode 100644 index 00000000..d2f6e345 --- /dev/null +++ b/libvirt/testdata/initrd.img diff --git a/libvirt/testdata/tetris.elf b/libvirt/testdata/tetris.elf Binary files differnew file mode 100755 index 00000000..6bbc9c7c --- /dev/null +++ b/libvirt/testdata/tetris.elf |