Skip to content

Commit

Permalink
Correction after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Le ConTesteur committed Sep 15, 2023
1 parent 96420e3 commit 54e2ab3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions post-processor/vagrant/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"path/filepath"
"strconv"
"strings"

packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)
Expand Down Expand Up @@ -68,16 +69,16 @@ func (p *LibVirtProvider) KeepInputArtifact() bool {
func (p *LibVirtProvider) Process(ui packersdk.Ui, artifact packersdk.Artifact, dir string) (vagrantfile string, metadata map[string]interface{}, err error) {
disks := []map[string]string{}
format := artifact.State("diskType").(string)

diskName := artifact.State("diskName").(string)
// Copy the disk image into the temporary directory (as box.img)
for i, path := range artifact.Files() {
// DiskName is [vmName, vmName1, vmName2]
// DiskName is [vmName, vmName-1, vmName-2]
if strings.HasPrefix(filepath.Base(path), diskName) {
ui.Message(fmt.Sprintf("Copying from artifact: %s", path))
diskName := fmt.Sprintf("box_%d.img", i)
dstPath := filepath.Join(dir, diskName)
dstDiskName := fmt.Sprintf("box_%d.img", i)
dstPath := filepath.Join(dir, dstDiskName)
disks = append(disks, map[string]string{
"path": diskName,
"path": dstDiskName,
"format": format,
})
if err = CopyContents(dstPath, path); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions post-processor/vagrant/libvirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func Test_ManyFilesInArtifact(t *testing.T) {
[]string{},
},
{
[]string{"test-0"},
[]string{"test"},
"vmdk",
[]string{"box_0.img"},
},
{
[]string{"test-0", "/test-1", "test-2"},
[]string{"test", "/test-1", "test-2"},
"qcow2",
[]string{"box_0.img", "box_1.img", "box_2.img"},
},
Expand All @@ -119,6 +119,7 @@ func Test_ManyFilesInArtifact(t *testing.T) {
StateValues: map[string]interface{}{
"diskType": tc.Format,
"diskSize": "1234M",
"diskName": "test",
"domainType": "kvm",
},
}
Expand Down

0 comments on commit 54e2ab3

Please sign in to comment.