Skip to content

Commit

Permalink
Prevent to get size 0 and error out
Browse files Browse the repository at this point in the history
for backing store
  • Loading branch information
MalloZup committed Dec 14, 2018
1 parent a8132fa commit 6d055af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libvirt/cloudinit_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 5 additions & 6 deletions libvirt/resource_libvirt_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6d055af

Please sign in to comment.