diff options
author | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2017-11-16 13:44:15 +0100 |
---|---|---|
committer | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2017-11-19 16:51:37 +0100 |
commit | 58bfa4b78a143699dff9962b1781a66b202e718e (patch) | |
tree | ec7f80152898b459d02ce755edf2c9938a80bc58 /libvirt/resource_libvirt_domain_test.go | |
parent | 3a52429e58643dad0e6122f3fb47b61be2ba2c72 (diff) | |
download | terraform-provider-libvirt-58bfa4b78a143699dff9962b1781a66b202e718e.tar terraform-provider-libvirt-58bfa4b78a143699dff9962b1781a66b202e718e.tar.gz |
Add support for remote http disks (qemu http curl backend)
Diffstat (limited to 'libvirt/resource_libvirt_domain_test.go')
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 954f1ba5..0fe6d078 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "log" + "net/url" "os" "testing" @@ -202,6 +203,38 @@ func TestAccLibvirtDomain_ScsiDisk(t *testing.T) { } +func TestAccLibvirtDomainUrlDisk(t *testing.T) { + var domain libvirt.Domain + u, err := url.Parse("http://download.opensuse.org/tumbleweed/iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso") + if err != nil { + t.Error(err) + } + + var configUrl = fmt.Sprintf(` + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test-domain" + disk { + url = "%s" + } + }`, u.String()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLibvirtDomainDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: configUrl, + Check: resource.ComposeTestCheckFunc( + testAccCheckLibvirtDomainExists("libvirt_domain.acceptance-test-domain", &domain), + testAccCheckLibvirtUrlDisk(u, &domain), + ), + }, + }, + }) + +} + func TestAccLibvirtDomain_NetworkInterface(t *testing.T) { var domain libvirt.Domain @@ -590,6 +623,41 @@ func testAccCheckLibvirtScsiDisk(n string, domain *libvirt.Domain) resource.Test } } +func testAccCheckLibvirtUrlDisk(u *url.URL, domain *libvirt.Domain) resource.TestCheckFunc { + return func(s *terraform.State) error { + xmlDesc, err := domain.GetXMLDesc(0) + if err != nil { + return fmt.Errorf("Error retrieving libvirt domain XML description: %s", err) + } + + domainDef := newDomainDef() + err = xml.Unmarshal([]byte(xmlDesc), &domainDef) + if err != nil { + return fmt.Errorf("Error reading libvirt domain XML description: %s", err) + } + + disks := domainDef.Devices.Disks + for _, disk := range disks { + if disk.Type != "network" { + return fmt.Errorf("Disk type is not network") + } + if disk.Source.Protocol != u.Scheme { + return fmt.Errorf("Disk protocol is not %s", u.Scheme) + } + if disk.Source.Name != u.Path { + return fmt.Errorf("Disk name is not %s", u.Path) + } + if len(disk.Source.Hosts) < 1 { + return fmt.Errorf("Disk has no hosts defined") + } + if disk.Source.Hosts[0].Name != u.Hostname() { + return fmt.Errorf("Disk hostname is not %s", u.Hostname()) + } + } + return nil + } +} + func createNvramFile() (string, error) { // size of an accepted, valid, nvram backing store NVRAMDummyBuffer := make([]byte, 131072) |