builder/googlecompute: tests for #867
This commit is contained in:
parent
05ecbd546b
commit
5f01415fb7
|
@ -10,6 +10,8 @@ FEATURES:
|
|||
IMPROVEMENTS:
|
||||
|
||||
* core: Most downloads made by Packer now use a custom user agent. [GH-803]
|
||||
* builder/googlecompute: SSH private key will be saved to disk if `-debug`
|
||||
is specified. [GH-867]
|
||||
* builder/virtualbox-ovf: Can specify import options such as "keepallmacs".
|
||||
[GH-883]
|
||||
|
||||
|
|
|
@ -12,8 +12,9 @@ import (
|
|||
|
||||
// StepCreateInstance represents a Packer build step that creates GCE instances.
|
||||
type StepCreateInstance struct {
|
||||
Debug bool
|
||||
|
||||
instanceName string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
// Run executes the Packer build step that creates a GCE instance.
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
|
||||
// StepCreateSSHKey represents a Packer build step that generates SSH key pairs.
|
||||
type StepCreateSSHKey struct {
|
||||
key int
|
||||
Debug bool
|
||||
DebugKeyPath string
|
||||
}
|
||||
|
@ -50,14 +49,19 @@ func (s *StepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
|
|||
|
||||
if s.Debug {
|
||||
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
|
||||
f, err := os.OpenFile(s.DebugKeyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
f, err := os.Create(s.DebugKeyPath)
|
||||
if err != nil {
|
||||
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
// Write out the key
|
||||
pem.Encode(f, &priv_blk)
|
||||
err = pem.Encode(f, &priv_blk)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package googlecompute
|
|||
|
||||
import (
|
||||
"github.com/mitchellh/multistep"
|
||||
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -27,3 +30,34 @@ func TestStepCreateSSHKey(t *testing.T) {
|
|||
t.Fatal("should have key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStepCreateSSHKey_debug(t *testing.T) {
|
||||
tf, err := ioutil.TempFile("", "packer")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
tf.Close()
|
||||
|
||||
state := testState(t)
|
||||
step := new(StepCreateSSHKey)
|
||||
step.Debug = true
|
||||
step.DebugKeyPath = tf.Name()
|
||||
|
||||
defer step.Cleanup(state)
|
||||
|
||||
// run the step
|
||||
if action := step.Run(state); action != multistep.ActionContinue {
|
||||
t.Fatalf("bad action: %#v", action)
|
||||
}
|
||||
|
||||
// Verify that we have a public/private key
|
||||
if _, ok := state.GetOk("ssh_private_key"); !ok {
|
||||
t.Fatal("should have key")
|
||||
}
|
||||
if _, ok := state.GetOk("ssh_public_key"); !ok {
|
||||
t.Fatal("should have key")
|
||||
}
|
||||
if _, err := os.Stat(tf.Name()); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,9 @@ import (
|
|||
|
||||
// stepInstanceInfo represents a Packer build step that gathers GCE instance info.
|
||||
type StepInstanceInfo struct {
|
||||
info int
|
||||
Debug bool
|
||||
|
||||
info int
|
||||
}
|
||||
|
||||
// Run executes the Packer build step that gathers GCE instance info.
|
||||
|
|
Loading…
Reference in New Issue