Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Packer
Commits
1b7ef252
Unverified
Commit
1b7ef252
authored
5 years ago
by
Adrien Delorme
Committed by
GitHub
5 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #8303 from alrs/amazon-builder-cleanup
Cleanup builder/amazon/common
parents
10ae0baa
d0720798
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
builder/amazon/common/ami_config_test.go
+0
-1
builder/amazon/common/ami_config_test.go
builder/amazon/common/errors.go
+1
-1
builder/amazon/common/errors.go
builder/amazon/common/step_modify_ebs_instance_test.go
+0
-105
builder/amazon/common/step_modify_ebs_instance_test.go
builder/amazon/common/step_run_spot_instance_test.go
+0
-53
builder/amazon/common/step_run_spot_instance_test.go
with
1 addition
and
160 deletions
+1
-160
builder/amazon/common/ami_config_test.go
+
0
-
1
View file @
1b7ef252
...
...
@@ -69,7 +69,6 @@ func TestAMIConfigPrepare_regions(t *testing.T) {
if
errs
=
c
.
prepareRegions
(
accessConf
);
len
(
errs
)
>
0
{
t
.
Fatalf
(
"shouldn't have err: %#v"
,
errs
)
}
errs
=
errs
[
:
0
]
c
.
AMIRegions
=
[]
string
{
"us-east-1"
,
"us-west-1"
,
"us-east-1"
}
if
errs
=
c
.
prepareRegions
(
accessConf
);
len
(
errs
)
>
0
{
...
...
This diff is collapsed.
Click to expand it.
builder/amazon/common/errors.go
+
1
-
1
View file @
1b7ef252
...
...
@@ -24,7 +24,7 @@ type stsDecoder interface {
func
decodeAWSError
(
decoder
stsDecoder
,
err
error
)
error
{
groups
:=
encodedFailureMessagePattern
.
FindStringSubmatch
(
err
.
Error
())
if
groups
!=
nil
&&
len
(
groups
)
>
1
{
if
len
(
groups
)
>
1
{
result
,
decodeErr
:=
decoder
.
DecodeAuthorizationMessage
(
&
sts
.
DecodeAuthorizationMessageInput
{
EncodedMessage
:
aws
.
String
(
groups
[
2
]),
})
...
...
This diff is collapsed.
Click to expand it.
builder/amazon/common/step_modify_ebs_instance_test.go
deleted
100644 → 0
+
0
-
105
View file @
10ae0baa
package
common
import
(
"bytes"
"context"
"fmt"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
helperconfig
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
// Define a mock struct to be used in unit tests for common aws steps.
type
mockEC2Conn_ModifyEBS
struct
{
ec2iface
.
EC2API
Config
*
aws
.
Config
// Counters to figure out what code path was taken
shouldError
bool
modifyImageAttrCount
int
}
func
(
m
*
mockEC2Conn_ModifyEBS
)
ModifyInstanceAttribute
(
modifyInput
*
ec2
.
ModifyInstanceAttributeInput
)
(
*
ec2
.
ModifyInstanceAttributeOutput
,
error
)
{
m
.
modifyImageAttrCount
++
// don't need to define output since we always discard it anyway.
output
:=
&
ec2
.
ModifyInstanceAttributeOutput
{}
if
m
.
shouldError
{
return
output
,
fmt
.
Errorf
(
"fake ModifyInstanceAttribute error"
)
}
return
output
,
nil
}
// Create statebag for running test
func
fakeModifyEBSBackedInstanceState
()
multistep
.
StateBag
{
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"ui"
,
&
packer
.
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
})
state
.
Put
(
"instance"
,
"i-12345"
)
return
state
}
func
StepModifyEBSBackedInstance_EnableAMIENASupport
(
t
*
testing
.
T
)
{
// Value is unset, so we shouldn't modify
stepModifyEBSBackedInstance
:=
StepModifyEBSBackedInstance
{
EnableAMIENASupport
:
helperconfig
.
TriUnset
,
EnableAMISriovNetSupport
:
false
,
}
// mock out the region connection code
mockConn
:=
&
mockEC2Conn_ModifyEBS
{
Config
:
aws
.
NewConfig
(),
}
state
:=
fakeModifyEBSBackedInstanceState
()
state
.
Put
(
"ec2"
,
mockConn
)
stepModifyEBSBackedInstance
.
Run
(
context
.
Background
(),
state
)
if
mockConn
.
modifyImageAttrCount
>
0
{
t
.
Fatalf
(
"Should not have modified image since EnableAMIENASupport is unset"
)
}
// Value is true, so we should modify
stepModifyEBSBackedInstance
=
StepModifyEBSBackedInstance
{
EnableAMIENASupport
:
helperconfig
.
TriTrue
,
EnableAMISriovNetSupport
:
false
,
}
// mock out the region connection code
mockConn
=
&
mockEC2Conn_ModifyEBS
{
Config
:
aws
.
NewConfig
(),
}
state
=
fakeModifyEBSBackedInstanceState
()
state
.
Put
(
"ec2"
,
mockConn
)
stepModifyEBSBackedInstance
.
Run
(
context
.
Background
(),
state
)
if
mockConn
.
modifyImageAttrCount
!=
1
{
t
.
Fatalf
(
"Should have modified image, since EnableAMIENASupport is true"
)
}
// Value is false, so we should modify
stepModifyEBSBackedInstance
=
StepModifyEBSBackedInstance
{
EnableAMIENASupport
:
helperconfig
.
TriFalse
,
EnableAMISriovNetSupport
:
false
,
}
// mock out the region connection code
mockConn
=
&
mockEC2Conn_ModifyEBS
{
Config
:
aws
.
NewConfig
(),
}
state
=
fakeModifyEBSBackedInstanceState
()
state
.
Put
(
"ec2"
,
mockConn
)
stepModifyEBSBackedInstance
.
Run
(
context
.
Background
(),
state
)
if
mockConn
.
modifyImageAttrCount
!=
1
{
t
.
Fatalf
(
"Should have modified image, since EnableAMIENASupport is true"
)
}
}
This diff is collapsed.
Click to expand it.
builder/amazon/common/step_run_spot_instance_test.go
+
0
-
53
View file @
1b7ef252
...
...
@@ -4,67 +4,14 @@ import (
"bytes"
"fmt"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
// Define a mock struct to be used in unit tests for common aws steps.
type
mockEC2ConnSpot
struct
{
ec2iface
.
EC2API
Config
*
aws
.
Config
// Counters to figure out what code path was taken
describeSpotPriceHistoryCount
int
}
// Generates fake SpotPriceHistory data and returns it in the expected output
// format. Also increments a
func
(
m
*
mockEC2ConnSpot
)
DescribeSpotPriceHistory
(
copyInput
*
ec2
.
DescribeSpotPriceHistoryInput
)
(
*
ec2
.
DescribeSpotPriceHistoryOutput
,
error
)
{
m
.
describeSpotPriceHistoryCount
++
testTime
:=
time
.
Now
()
.
Add
(
-
1
*
time
.
Hour
)
sp
:=
[]
*
ec2
.
SpotPrice
{
{
AvailabilityZone
:
aws
.
String
(
"us-east-1c"
),
InstanceType
:
aws
.
String
(
"t2.micro"
),
ProductDescription
:
aws
.
String
(
"Linux/UNIX"
),
SpotPrice
:
aws
.
String
(
"0.003500"
),
Timestamp
:
&
testTime
,
},
{
AvailabilityZone
:
aws
.
String
(
"us-east-1f"
),
InstanceType
:
aws
.
String
(
"t2.micro"
),
ProductDescription
:
aws
.
String
(
"Linux/UNIX"
),
SpotPrice
:
aws
.
String
(
"0.003500"
),
Timestamp
:
&
testTime
,
},
{
AvailabilityZone
:
aws
.
String
(
"us-east-1b"
),
InstanceType
:
aws
.
String
(
"t2.micro"
),
ProductDescription
:
aws
.
String
(
"Linux/UNIX"
),
SpotPrice
:
aws
.
String
(
"0.003500"
),
Timestamp
:
&
testTime
,
},
}
output
:=
&
ec2
.
DescribeSpotPriceHistoryOutput
{
SpotPriceHistory
:
sp
}
return
output
,
nil
}
func
getMockConnSpot
()
ec2iface
.
EC2API
{
mockConn
:=
&
mockEC2ConnSpot
{
Config
:
aws
.
NewConfig
(),
}
return
mockConn
}
// Create statebag for running test
func
tStateSpot
()
multistep
.
StateBag
{
state
:=
new
(
multistep
.
BasicStateBag
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help