-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using env variable to set vmware timeout value #1078
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import ( | |
"context" | ||
"fmt" | ||
"net/url" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
@@ -38,8 +40,14 @@ const ( | |
VSpherePasswordKey = "VSpherePasswordKey" | ||
|
||
noDescription = "" | ||
defaultWaitTime = 10 * time.Minute | ||
defaultWaitTime = 60 * time.Minute | ||
defaultRetryLimit = 30 * time.Minute | ||
|
||
vmWareTimeoutMinEnv = "VMWARE_GOM_TIMEOUT_MIN" | ||
) | ||
|
||
var ( | ||
vmWareTimeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute | ||
) | ||
|
||
// FcdProvider provides blockstorage.Provider | ||
|
@@ -118,7 +126,7 @@ func (p *FcdProvider) VolumeCreateFromSnapshot(ctx context.Context, snapshot blo | |
return nil, errors.Wrap(err, "Failed to create disk from snapshot") | ||
} | ||
log.Debug().Print("Started CreateDiskFromSnapshot task", field.M{"VolumeID": volID, "SnapshotID": snapshotID}) | ||
res, err := task.Wait(ctx, defaultWaitTime) | ||
res, err := task.Wait(ctx, vmWareTimeout) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to wait on task") | ||
} | ||
|
@@ -151,7 +159,7 @@ func (p *FcdProvider) VolumeDelete(ctx context.Context, volume *blockstorage.Vol | |
if err != nil { | ||
return errors.Wrap(err, "Failed to delete the disk") | ||
} | ||
_, err = task.Wait(ctx, defaultWaitTime) | ||
_, err = task.Wait(ctx, vmWareTimeout) | ||
return err | ||
} | ||
|
||
|
@@ -193,7 +201,7 @@ func (p *FcdProvider) SnapshotCreate(ctx context.Context, volume blockstorage.Vo | |
return false, errors.Wrap(lerr, "Failed to create snapshot") | ||
} | ||
log.Debug().Print("Started CreateSnapshot task", field.M{"VolumeID": volume.ID}) | ||
res, lerr = task.Wait(ctx, defaultWaitTime) | ||
res, lerr = task.Wait(ctx, vmWareTimeout) | ||
if lerr != nil { | ||
if soap.IsVimFault(lerr) { | ||
switch soap.ToVimFault(lerr).(type) { | ||
|
@@ -252,7 +260,7 @@ func (p *FcdProvider) SnapshotDelete(ctx context.Context, snapshot *blockstorage | |
return false, errors.Wrap(lerr, "Failed to delete snapshot") | ||
} | ||
log.Debug().Print("Started SnapshotDelete task", field.M{"VolumeID": volID, "SnapshotID": snapshotID}) | ||
_, lerr = task.Wait(ctx, defaultWaitTime) | ||
_, lerr = task.Wait(ctx, vmWareTimeout) | ||
if lerr != nil { | ||
// The following error handling was pulled from https://github.com/vmware-tanzu/astrolabe/blob/91eeed4dcf77edd1387a25e984174f159d66fedb/pkg/ivd/ivd_protected_entity.go#L433 | ||
if soap.IsVimFault(lerr) { | ||
|
@@ -334,7 +342,7 @@ func (p *FcdProvider) setTagsVolume(ctx context.Context, volume *blockstorage.Vo | |
if err != nil { | ||
return errors.Wrap(err, "Failed to update metadata") | ||
} | ||
_, err = task.Wait(ctx, defaultWaitTime) | ||
_, err = task.Wait(ctx, vmWareTimeout) | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to wait on task") | ||
} | ||
|
@@ -350,3 +358,14 @@ func (p *FcdProvider) VolumesList(ctx context.Context, tags map[string]string, z | |
func (p *FcdProvider) SnapshotsList(ctx context.Context, tags map[string]string) ([]*blockstorage.Snapshot, error) { | ||
return nil, errors.New("Not implemented") | ||
} | ||
|
||
func getEnvAsIntOrDefault(envKey string, def int) int { | ||
if v, ok := os.LookupEnv(envKey); ok { | ||
iv, err := strconv.Atoi(v) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log error. Defaulting on hidden failures are difficult to diagnose. It will help if you log a warning, or similar, to If checking error, then return non-default value whenever While the code will work for the application, it seems as though the current implementation could cause frustration in operation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aaron-kasten logging the case where an invalid option was provided |
||
if err == nil && iv > 0 { | ||
return iv | ||
} | ||
} | ||
|
||
return def | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package vmware | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
@@ -55,3 +57,28 @@ func (s *VMWareSuite) TestURLParse(c *C) { | |
} | ||
} | ||
} | ||
|
||
func (s *VMWareSuite) TestTimeoutEnvSetting(c *C) { | ||
tempEnv := os.Getenv(vmWareTimeoutMinEnv) | ||
os.Unsetenv(vmWareTimeoutMinEnv) | ||
timeout := time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute | ||
c.Assert(timeout, Equals, defaultWaitTime) | ||
|
||
os.Setenv(vmWareTimeoutMinEnv, "7") | ||
timeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute | ||
c.Assert(timeout, Equals, 7*time.Minute) | ||
|
||
Comment on lines
+67
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also test for "0" or "-1". What values would you expect? |
||
os.Setenv(vmWareTimeoutMinEnv, "badValue") | ||
timeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute | ||
c.Assert(timeout, Equals, defaultWaitTime) | ||
|
||
os.Setenv(vmWareTimeoutMinEnv, "-1") | ||
timeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute | ||
c.Assert(timeout, Equals, defaultWaitTime) | ||
|
||
os.Setenv(vmWareTimeoutMinEnv, "0") | ||
timeout = time.Duration(getEnvAsIntOrDefault(vmWareTimeoutMinEnv, int(defaultWaitTime/time.Minute))) * time.Minute | ||
c.Assert(timeout, Equals, defaultWaitTime) | ||
|
||
os.Setenv(vmWareTimeoutMinEnv, tempEnv) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Personal bias toward less nesting.
if ...; !ok { return def }
, thenreturn def
again below if you have a reason to.