From c828015bc31e039f9bc09cc0aaf28969bff1558b Mon Sep 17 00:00:00 2001 From: DanHam Date: Fri, 27 Apr 2018 20:09:19 +0100 Subject: [PATCH] Follow variable varName <-> statebag var_name convention --- builder/vmware/common/step_compact_disk.go | 10 +++++----- builder/vmware/common/step_compact_disk_test.go | 12 ++++++------ builder/vmware/iso/step_create_disk.go | 14 +++++++------- builder/vmware/vmx/step_clone_vmx.go | 8 ++++---- builder/vmware/vmx/step_clone_vmx_test.go | 8 ++++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/builder/vmware/common/step_compact_disk.go b/builder/vmware/common/step_compact_disk.go index d4ed5100f..8d315a67e 100644 --- a/builder/vmware/common/step_compact_disk.go +++ b/builder/vmware/common/step_compact_disk.go @@ -28,7 +28,7 @@ type StepCompactDisk struct { func (s StepCompactDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) - diskPaths := state.Get("disk_full_paths").([]string) + diskFullPaths := state.Get("disk_full_paths").([]string) if s.Skip { log.Println("Skipping disk compaction step...") @@ -36,22 +36,22 @@ func (s StepCompactDisk) Run(_ context.Context, state multistep.StateBag) multis } ui.Say("Compacting all attached virtual disks...") - for i, diskPath := range diskPaths { + for i, diskFullPath := range diskFullPaths { ui.Message(fmt.Sprintf("Compacting virtual disk %d", i+1)) // Get the file size of the virtual disk prior to compaction - fi, err := os.Stat(diskPath) + fi, err := os.Stat(diskFullPath) if err != nil { state.Put("error", fmt.Errorf("Error getting virtual disk file info pre compaction: %s", err)) return multistep.ActionHalt } diskFileSizeStart := fi.Size() // Defragment and compact the disk - if err := driver.CompactDisk(diskPath); err != nil { + if err := driver.CompactDisk(diskFullPath); err != nil { state.Put("error", fmt.Errorf("Error compacting disk: %s", err)) return multistep.ActionHalt } // Get the file size of the virtual disk post compaction - fi, err = os.Stat(diskPath) + fi, err = os.Stat(diskFullPath) if err != nil { state.Put("error", fmt.Errorf("Error getting virtual disk file info post compaction: %s", err)) return multistep.ActionHalt diff --git a/builder/vmware/common/step_compact_disk_test.go b/builder/vmware/common/step_compact_disk_test.go index fec048f9a..a07755229 100644 --- a/builder/vmware/common/step_compact_disk_test.go +++ b/builder/vmware/common/step_compact_disk_test.go @@ -23,8 +23,8 @@ func TestStepCompactDisk(t *testing.T) { t.Fatalf("Error creating fake vmdk file: %s", err) } - diskPath := diskFile.Name() - defer os.Remove(diskPath) + diskFullPath := diskFile.Name() + defer os.Remove(diskFullPath) content := []byte("I am the fake vmdk's contents") if _, err := diskFile.Write(content); err != nil { @@ -35,7 +35,7 @@ func TestStepCompactDisk(t *testing.T) { } // Set up required state - state.Put("disk_full_paths", []string{diskPath}) + state.Put("disk_full_paths", []string{diskFullPath}) driver := state.Get("driver").(*DriverMock) @@ -51,7 +51,7 @@ func TestStepCompactDisk(t *testing.T) { if !driver.CompactDiskCalled { t.Fatal("should've called") } - if driver.CompactDiskPath != diskPath { + if driver.CompactDiskPath != diskFullPath { t.Fatal("should call with right path") } } @@ -61,8 +61,8 @@ func TestStepCompactDisk_skip(t *testing.T) { step := new(StepCompactDisk) step.Skip = true - diskPaths := []string{"foo"} - state.Put("disk_full_paths", diskPaths) + diskFullPaths := []string{"foo"} + state.Put("disk_full_paths", diskFullPaths) driver := state.Get("driver").(*DriverMock) diff --git a/builder/vmware/iso/step_create_disk.go b/builder/vmware/iso/step_create_disk.go index 8426c7366..b4ced8cd1 100644 --- a/builder/vmware/iso/step_create_disk.go +++ b/builder/vmware/iso/step_create_disk.go @@ -31,26 +31,26 @@ func (stepCreateDisk) Run(_ context.Context, state multistep.StateBag) multistep // Users can configure disks at several locations in the template so // first collate all the disk requirements - var diskPaths, diskSizes []string + var diskFullPaths, diskSizes []string // The 'main' or 'default' disk - diskPaths = append(diskPaths, filepath.Join(config.OutputDir, config.DiskName+".vmdk")) + diskFullPaths = append(diskFullPaths, filepath.Join(config.OutputDir, config.DiskName+".vmdk")) diskSizes = append(diskSizes, fmt.Sprintf("%dM", uint64(config.DiskSize))) // Additional disks if len(config.AdditionalDiskSize) > 0 { for i, diskSize := range config.AdditionalDiskSize { path := filepath.Join(config.OutputDir, fmt.Sprintf("%s-%d.vmdk", config.DiskName, i+1)) - diskPaths = append(diskPaths, path) + diskFullPaths = append(diskFullPaths, path) size := fmt.Sprintf("%dM", uint64(diskSize)) diskSizes = append(diskSizes, size) } } // Create all required disks - for i, diskPath := range diskPaths { - log.Printf("[INFO] Creating disk with Path: %s and Size: %s", diskPath, diskSizes[i]) + for i, diskFullPath := range diskFullPaths { + log.Printf("[INFO] Creating disk with Path: %s and Size: %s", diskFullPath, diskSizes[i]) // Additional disks currently use the same adapter type and disk // type as specified for the main disk - if err := driver.CreateDisk(diskPath, diskSizes[i], config.DiskAdapterType, config.DiskTypeId); err != nil { + if err := driver.CreateDisk(diskFullPath, diskSizes[i], config.DiskAdapterType, config.DiskTypeId); err != nil { err := fmt.Errorf("Error creating disk: %s", err) state.Put("error", err) ui.Error(err.Error()) @@ -59,7 +59,7 @@ func (stepCreateDisk) Run(_ context.Context, state multistep.StateBag) multistep } // Stash the disk paths so we can retrieve later e.g. when compacting - state.Put("disk_full_paths", diskPaths) + state.Put("disk_full_paths", diskFullPaths) return multistep.ActionContinue } diff --git a/builder/vmware/vmx/step_clone_vmx.go b/builder/vmware/vmx/step_clone_vmx.go index 9e03bc5c1..6fc34c43e 100644 --- a/builder/vmware/vmx/step_clone_vmx.go +++ b/builder/vmware/vmx/step_clone_vmx.go @@ -115,13 +115,13 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste } // Write out the relative, host filesystem paths to the disks - var diskPaths []string + var diskFullPaths []string for _, diskFilename := range diskFilenames { log.Printf("Found attached disk with filename: %s", diskFilename) - diskPaths = append(diskPaths, filepath.Join(s.OutputDir, diskFilename)) + diskFullPaths = append(diskFullPaths, filepath.Join(s.OutputDir, diskFilename)) } - if len(diskPaths) == 0 { + if len(diskFullPaths) == 0 { state.Put("error", fmt.Errorf("Could not enumerate disk info from the vmx file")) return multistep.ActionHalt } @@ -139,7 +139,7 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste // Stash all required information in our state bag state.Put("vmx_path", vmxPath) - state.Put("disk_full_paths", diskPaths) + state.Put("disk_full_paths", diskFullPaths) state.Put("vmnetwork", networkType) return multistep.ActionContinue diff --git a/builder/vmware/vmx/step_clone_vmx_test.go b/builder/vmware/vmx/step_clone_vmx_test.go index e180e57a0..d781df687 100644 --- a/builder/vmware/vmx/step_clone_vmx_test.go +++ b/builder/vmware/vmx/step_clone_vmx_test.go @@ -43,9 +43,9 @@ func TestStepCloneVMX(t *testing.T) { // Set up expected mock disk file paths diskFilenames := []string{scsiFilename, sataFilename, ideFilename, nvmeFilename} - var diskPaths []string + var diskFullPaths []string for _, diskFilename := range diskFilenames { - diskPaths = append(diskPaths, filepath.Join(td, diskFilename)) + diskFullPaths = append(diskFullPaths, filepath.Join(td, diskFilename)) } // Create the source @@ -91,8 +91,8 @@ func TestStepCloneVMX(t *testing.T) { if stateDiskPaths, ok := state.GetOk("disk_full_paths"); !ok { t.Fatal("should set disk_full_paths") } else { - assert.ElementsMatchf(t, stateDiskPaths.([]string), diskPaths, - "%s\nshould contain the same elements as:\n%s", stateDiskPaths.([]string), diskPaths) + assert.ElementsMatchf(t, stateDiskPaths.([]string), diskFullPaths, + "%s\nshould contain the same elements as:\n%s", stateDiskPaths.([]string), diskFullPaths) } // Test we got the network type