Skip to content

Commit

Permalink
Backwards compatibility and Travis patch
Browse files Browse the repository at this point in the history
Now checks both `ec2` and `ebs` config fields in storage driver.
Added skip tests check to instance id tests.
Moved DefaultMaxRetries under ebs instead of storage driver.
  • Loading branch information
proudh committed Sep 15, 2016
1 parent 4220692 commit 9699c2f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
3 changes: 3 additions & 0 deletions drivers/storage/ebs/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const (

// TagDelimiter separates tags from volume or snapshot names
TagDelimiter = "/"

// DefaultMaxRetries is the max number of times to retry failed operations
DefaultMaxRetries = 10
)

func init() {
Expand Down
41 changes: 31 additions & 10 deletions drivers/storage/ebs/storage/ec2_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ const (
waitVolumeAttach = "attach"
// waitVolumeDetach signifies to wait for volume detachment to complete
waitVolumeDetach = "detach"

// DefaultMaxRetries is the max number of times to retry failed operations
DefaultMaxRetries = 10
)

type driver struct {
Expand Down Expand Up @@ -1243,40 +1240,64 @@ func (d *driver) getFullName(name string) string {

// Retrieve config arguments
func (d *driver) accessKey() string {
if d.config.GetString("ebs.accessKey") != "" {
return d.config.GetString("ebs.accessKey")
}
return d.config.GetString("ec2.accessKey")
}

func (d *driver) secretKey() string {
if d.config.GetString("ebs.secretKey") != "" {
return d.config.GetString("ebs.secretKey")
}
return d.config.GetString("ec2.secretKey")
}

func (d *driver) region() string {
if d.config.GetString("ebs.region") != "" {
return d.config.GetString("ebs.region")
}
return d.config.GetString("ec2.region")
}

func (d *driver) endpoint() string {
if d.config.GetString("ebs.endpoint") != "" {
return d.config.GetString("ebs.endpoint")
}
return d.config.GetString("ec2.endpoint")
}

func (d *driver) maxRetries() int {
// if maxRetries in config is non-numeric or a negative number,
// set it to the default number of max retries.
if maxRetriesString := d.config.GetString("ec2.maxRetries"); maxRetriesString != "0" {
maxRetries := d.config.GetInt("ec2.maxRetries")
if maxRetries <= 0 {
return DefaultMaxRetries
if maxRetriesString := d.config.GetString("ebs.maxRetries"); maxRetriesString != "" {
if maxRetriesString == "0" {
return 0
} else if maxRetries := d.config.GetInt("ebs.maxRetries"); maxRetries > 0 {
return maxRetries
}
} else if maxRetriesString := d.config.GetString(
"ec2.maxRetries"); maxRetriesString != "" {
if maxRetriesString == "0" {
return 0
} else if maxRetries := d.config.GetInt("ec2.maxRetries"); maxRetries > 0 {
return maxRetries
}
return maxRetries
}

return 0
return ebs.DefaultMaxRetries
}

func (d *driver) tag() string {
if d.config.GetString("ebs.tag") != "" {
return d.config.GetString("ebs.tag")
}
return d.config.GetString("ec2.tag")
}

// TODO rexrayTag
/*func (d *driver) rexrayTag() string {
if d.config.GetString("ebs.rexrayTag") != "" {
return d.config.GetString("ebs.rexrayTag")
}
return d.config.GetString("ec2.rexrayTag")
}*/
8 changes: 8 additions & 0 deletions drivers/storage/ebs/tests/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func TestConfig(t *testing.T) {
// Check if InstanceID metadata is properly returned by executor
// and InstanceID.ID is filled out by InstanceInspect
func TestInstanceID(t *testing.T) {
if skipTests() {
t.SkipNow()
}

// create storage driver
sd, err := registry.NewStorageDriver(ebs.Name)
if err != nil {
Expand Down Expand Up @@ -126,6 +130,10 @@ func TestInstanceID(t *testing.T) {
// Check if InstanceID metadata is properly returned by executor
// and InstanceID.ID is filled out by InstanceInspect
func TestInstanceIDEC2(t *testing.T) {
if skipTests() {
t.SkipNow()
}

// create storage driver
sd, err := registry.NewStorageDriver("ec2")
if err != nil {
Expand Down

0 comments on commit 9699c2f

Please sign in to comment.