refactor: fix symlink issue on ubuntu

This commit is contained in:
Marin Salinas 2019-03-12 12:49:46 -06:00 committed by Megan Marsh
parent 27528aeb68
commit 810e30e8e1
4 changed files with 22 additions and 9 deletions

View File

@ -25,9 +25,7 @@ const testBuilderAccBasic = `
"region": "eu-west-2",
"source_omi": "ami-65efcc11",
"omi_name": "packer-test-{{timestamp}}",
"omi_virtualization_type": "hvm",
"device_path": "/dev/xvdf",
"mount_partition": "0"
"omi_virtualization_type": "hvm"
}]
}
`

View File

@ -42,7 +42,7 @@ func AvailableDevice() (string, error) {
// devicePrefix returns the prefix ("sd" or "xvd" or so on) of the devices
// on the system. The "vd" prefix appears on outscale images.
func devicePrefix() (string, error) {
available := []string{"sd", "xvd"}
available := []string{"sd", "xvd", "vd"}
f, err := os.Open("/sys/block")
if err != nil {
@ -56,6 +56,10 @@ func devicePrefix() (string, error) {
dirBase := filepath.Base(dir)
for _, prefix := range available {
if strings.HasPrefix(dirBase, prefix) {
//for outscale.
if prefix != "xvd" {
prefix = "xvd"
}
return prefix, nil
}
}

View File

@ -3,7 +3,6 @@ package chroot
import (
"context"
"fmt"
"strings"
osccommon "github.com/hashicorp/packer/builder/osc/common"
"github.com/hashicorp/packer/helper/multistep"
@ -30,7 +29,8 @@ func (s *StepLinkVolume) Run(ctx context.Context, state multistep.StateBag) mult
volumeId := state.Get("volume_id").(string)
// For the API call, it expects "sd" prefixed devices.
linkVolume := strings.Replace(device, "/xvd", "/sd", 1)
//linkVolume := strings.Replace(device, "/xvd", "/sd", 1)
linkVolume := device
ui.Say(fmt.Sprintf("Attaching the root volume to %s", linkVolume))
_, err := oapiconn.POST_LinkVolume(oapi.LinkVolumeRequest{

View File

@ -80,8 +80,19 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi
return multistep.ActionHalt
}
//TODO: Check the symlink created
deviceMount := device
//Check the symbolic link for the device to get the real device name
cmd := ShellCommand(fmt.Sprintf("lsblk -no pkname $(readlink -f %s)", device))
realDeviceName, err := cmd.Output()
if err != nil {
err := fmt.Errorf(
"Error retrieving the symlink of the device %s.\n", device)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
deviceMount := fmt.Sprintf("/dev/%s", strings.Replace(string(realDeviceName), "\n", "", -1))
log.Printf("[DEBUG] s.MountPartition = %s", s.MountPartition)
@ -108,7 +119,7 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi
return multistep.ActionHalt
}
log.Printf("[DEBUG] (step mount) mount command is %s", mountCommand)
cmd := ShellCommand(mountCommand)
cmd = ShellCommand(mountCommand)
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
err := fmt.Errorf(