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
37903337
Commit
37903337
authored
Dec 13, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/googlecompute: update gsutil
parent
a2cf4cae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
12 deletions
+104
-12
builder/googlecompute/builder.go
builder/googlecompute/builder.go
+1
-1
builder/googlecompute/step_update_gsutil.go
builder/googlecompute/step_update_gsutil.go
+18
-11
builder/googlecompute/step_update_gsutil_test.go
builder/googlecompute/step_update_gsutil_test.go
+85
-0
No files found.
builder/googlecompute/builder.go
View file @
37903337
...
...
@@ -58,9 +58,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SSHWaitTimeout
:
5
*
time
.
Minute
,
},
new
(
common
.
StepProvision
),
new
(
StepUpdateGsutil
),
}
/*
new(stepUpdateGsutil),
new(stepCreateImage),
new(stepUploadImage),
new(stepRegisterImage),
...
...
builder/googlecompute/step_update_gsutil.go
View file @
37903337
...
...
@@ -7,9 +7,9 @@ import (
"github.com/mitchellh/packer/packer"
)
//
s
tepUpdateGsutil represents a Packer build step that updates the gsutil
//
S
tepUpdateGsutil represents a Packer build step that updates the gsutil
// utility to the latest version available.
type
s
tepUpdateGsutil
int
type
S
tepUpdateGsutil
int
// Run executes the Packer build step that updates the gsutil utility to the
// latest version available.
...
...
@@ -17,29 +17,36 @@ type stepUpdateGsutil int
// This step is required to prevent the image creation process from hanging;
// the image creation process utilizes the gcimagebundle cli tool which will
// prompt to update gsutil if a newer version is available.
func
(
s
*
stepUpdateGsutil
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
var
(
config
=
state
.
Get
(
"config"
)
.
(
*
Config
)
comm
=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
sudoPrefix
=
""
ui
=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
)
ui
.
Say
(
"Updating gsutil..."
)
func
(
s
*
StepUpdateGsutil
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
sudoPrefix
:=
""
if
config
.
SSHUsername
!=
"root"
{
sudoPrefix
=
"sudo "
}
gsutilUpdateCmd
:=
"/usr/local/bin/gsutil update -n -f"
cmd
:=
new
(
packer
.
RemoteCmd
)
cmd
.
Command
=
fmt
.
Sprintf
(
"%s%s"
,
sudoPrefix
,
gsutilUpdateCmd
)
ui
.
Say
(
"Updating gsutil..."
)
err
:=
cmd
.
StartWithUi
(
comm
,
ui
)
if
err
==
nil
&&
cmd
.
ExitStatus
!=
0
{
err
=
fmt
.
Errorf
(
"gsutil update exited with non-zero exit status: %d"
,
cmd
.
ExitStatus
)
}
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error updating gsutil: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
// Cleanup.
func
(
s
*
s
tepUpdateGsutil
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
S
tepUpdateGsutil
)
Cleanup
(
state
multistep
.
StateBag
)
{}
builder/googlecompute/step_update_gsutil_test.go
0 → 100644
View file @
37903337
package
googlecompute
import
(
"strings"
"testing"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
func
TestStepUpdateGsutil_impl
(
t
*
testing
.
T
)
{
var
_
multistep
.
Step
=
new
(
StepUpdateGsutil
)
}
func
TestStepUpdateGsutil
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepUpdateGsutil
)
defer
step
.
Cleanup
(
state
)
comm
:=
new
(
packer
.
MockCommunicator
)
state
.
Put
(
"communicator"
,
comm
)
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
// Verify
if
!
comm
.
StartCalled
{
t
.
Fatal
(
"start should be called"
)
}
if
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatal
(
"should not sudo"
)
}
if
!
strings
.
Contains
(
comm
.
StartCmd
.
Command
,
"gsutil update"
)
{
t
.
Fatalf
(
"bad command: %#v"
,
comm
.
StartCmd
.
Command
)
}
}
func
TestStepUpdateGsutil_badExitStatus
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepUpdateGsutil
)
defer
step
.
Cleanup
(
state
)
comm
:=
new
(
packer
.
MockCommunicator
)
comm
.
StartExitStatus
=
12
state
.
Put
(
"communicator"
,
comm
)
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionHalt
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
!
ok
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestStepUpdateGsutil_nonRoot
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepUpdateGsutil
)
defer
step
.
Cleanup
(
state
)
comm
:=
new
(
packer
.
MockCommunicator
)
state
.
Put
(
"communicator"
,
comm
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
config
.
SSHUsername
=
"bob"
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
// Verify
if
!
comm
.
StartCalled
{
t
.
Fatal
(
"start should be called"
)
}
if
!
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatal
(
"should sudo"
)
}
if
!
strings
.
Contains
(
comm
.
StartCmd
.
Command
,
"gsutil update"
)
{
t
.
Fatalf
(
"bad command: %#v"
,
comm
.
StartCmd
.
Command
)
}
}
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