Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
5f01415f
Commit
5f01415f
authored
Feb 21, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/googlecompute: tests for #867
parent
05ecbd54
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
5 deletions
+47
-5
CHANGELOG.md
CHANGELOG.md
+2
-0
builder/googlecompute/step_create_instance.go
builder/googlecompute/step_create_instance.go
+2
-1
builder/googlecompute/step_create_ssh_key.go
builder/googlecompute/step_create_ssh_key.go
+7
-3
builder/googlecompute/step_create_ssh_key_test.go
builder/googlecompute/step_create_ssh_key_test.go
+34
-0
builder/googlecompute/step_instance_info.go
builder/googlecompute/step_instance_info.go
+2
-1
No files found.
CHANGELOG.md
View file @
5f01415f
...
...
@@ -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]
...
...
builder/googlecompute/step_create_instance.go
View file @
5f01415f
...
...
@@ -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.
...
...
builder/googlecompute/step_create_ssh_key.go
View file @
5f01415f
...
...
@@ -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
}
...
...
builder/googlecompute/step_create_ssh_key_test.go
View file @
5f01415f
...
...
@@ -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
)
}
}
builder/googlecompute/step_instance_info.go
View file @
5f01415f
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment