From 6d055af6c868db97d846ae7008625245b3e00f2b Mon Sep 17 00:00:00 2001 From: dmaiocchi Date: Fri, 14 Dec 2018 23:22:09 +0100 Subject: [PATCH] Prevent to get size 0 and error out for backing store --- libvirt/cloudinit_def.go | 2 +- libvirt/resource_libvirt_volume.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libvirt/cloudinit_def.go b/libvirt/cloudinit_def.go index 849ef056a..e18862483 100644 --- a/libvirt/cloudinit_def.go +++ b/libvirt/cloudinit_def.go @@ -341,7 +341,7 @@ func downloadISO(virConn *libvirt.Connect, volume libvirt.StorageVol) (*os.File, if uint64(bytesCopied) != info.Capacity { stream.Abort() - return tmpFile, fmt.Errorf("Error while copying remote volume to local disk, bytesCopied %d != %d volume.size:", bytesCopied, info.Capacity) + return tmpFile, fmt.Errorf("Error while copying remote volume to local disk, bytesCopied %d != %d volume.size", bytesCopied, info.Capacity) } err = stream.Finish() diff --git a/libvirt/resource_libvirt_volume.go b/libvirt/resource_libvirt_volume.go index 4c52885c9..5e5e78673 100644 --- a/libvirt/resource_libvirt_volume.go +++ b/libvirt/resource_libvirt_volume.go @@ -193,16 +193,14 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Can't retrieve volume %s: %v", baseVolumeName.(string), err) } } - if baseVolume != nil { backingStoreDef, err := newDefBackingStoreFromLibvirt(baseVolume) if err != nil { return fmt.Errorf("Could not retrieve backing store definition: %s", err.Error()) } - - // does the backing store have some size information?, check at least that it is not smaller than the backing store - volumeDef.Capacity.Value = uint64(d.Get("size").(int)) if _, ok := d.GetOk("size"); ok { + // does the backing store have some size information?, check at least that it is not smaller than the backing store + volumeDef.Capacity.Value = uint64(d.Get("size").(int)) backingStoreVolumeDef, err := newDefVolumeFromLibvirt(baseVolume) if err != nil { return err @@ -215,8 +213,9 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error volumeDef.BackingStore = &backingStoreDef } } - - volumeDef.Capacity.Value = uint64(d.Get("size").(int)) + if _, ok := d.GetOk("size"); ok { + volumeDef.Capacity.Value = uint64(d.Get("size").(int)) + } data, err := xmlMarshallIndented(volumeDef) if err != nil { return fmt.Errorf("Error serializing libvirt volume: %s", err)