Merge pull request #5757 from arizvisa/virtualbox-guest_additions_url-interpolation

Fixed an issue where the VirtualBox builder was checking for whether guest_additions_url was empty or not before it actually interpolated any variables.
This commit is contained in:
SwampDragons 2018-01-04 15:39:29 -08:00 committed by GitHub
commit ff3cbbf28c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 13 deletions

View File

@ -66,21 +66,25 @@ func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
checksumType := "sha256" checksumType := "sha256"
// Use the provided source (URL or file path) or generate it // Grab the guest_additions_url as specified by the user.
url := s.GuestAdditionsURL url := s.GuestAdditionsURL
if url != "" {
s.Ctx.Data = &guestAdditionsUrlTemplate{
Version: version,
}
url, err = interpolate.Render(url, &s.Ctx) // Initialize the template context so we can interpolate some variables..
if err != nil { s.Ctx.Data = &guestAdditionsUrlTemplate{
err := fmt.Errorf("Error preparing guest additions url: %s", err) Version: version,
state.Put("error", err) }
ui.Error(err.Error())
return multistep.ActionHalt // Interpolate any user-variables specified within the guest_additions_url
} url, err = interpolate.Render(s.GuestAdditionsURL, &s.Ctx)
} else { if err != nil {
err := fmt.Errorf("Error preparing guest additions url: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
// If this resulted in an empty url, then ask the driver about it.
if url == "" {
url, err = driver.Iso() url, err = driver.Iso()
if err == nil { if err == nil {
@ -93,6 +97,8 @@ func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
additionsName) additionsName)
} }
} }
// The driver couldn't even figure it out, so fail hard.
if url == "" { if url == "" {
err := fmt.Errorf("Couldn't detect guest additions URL.\n" + err := fmt.Errorf("Couldn't detect guest additions URL.\n" +
"Please specify `guest_additions_url` manually.") "Please specify `guest_additions_url` manually.")
@ -101,6 +107,7 @@ func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
return multistep.ActionHalt return multistep.ActionHalt
} }
// Figure out a default checksum here
if checksumType != "none" { if checksumType != "none" {
if s.GuestAdditionsSHA256 != "" { if s.GuestAdditionsSHA256 != "" {
checksum = s.GuestAdditionsSHA256 checksum = s.GuestAdditionsSHA256
@ -112,6 +119,7 @@ func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
} }
} }
// Convert the file/url to an actual URL for step_download to process.
url, err = common.DownloadableURL(url) url, err = common.DownloadableURL(url)
if err != nil { if err != nil {
err := fmt.Errorf("Error preparing guest additions url: %s", err) err := fmt.Errorf("Error preparing guest additions url: %s", err)
@ -122,6 +130,7 @@ func (s *StepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
log.Printf("Guest additions URL: %s", url) log.Printf("Guest additions URL: %s", url)
// We're good, so let's go ahead and download this thing..
downStep := &common.StepDownload{ downStep := &common.StepDownload{
Checksum: checksum, Checksum: checksum,
ChecksumType: checksumType, ChecksumType: checksumType,