Skip to content
Permalink
Browse files

sanity: specify timeouts as durations

This is cleaner. This also changes the values of the command line
timeout parameters from plain int (10) to durations (10s), but this is
okay as we are preparing a major new release.
  • Loading branch information
pohly committed Nov 5, 2019
1 parent fa0fb7c commit 81bc9394e942291546ccc4d887e0387b3f1b05ba
Showing with 15 additions and 10 deletions.
  1. +7 −2 cmd/csi-sanity/sanity_test.go
  2. +8 −8 pkg/sanity/sanity.go
@@ -20,6 +20,7 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/kubernetes-csi/csi-test/pkg/sanity"
)
@@ -49,6 +50,10 @@ func int64Var(p *int64, name string, usage string) {
flag.Int64Var(p, prefix+name, *p, usage)
}

func durationVar(p *time.Duration, name string, usage string) {
flag.DurationVar(p, prefix+name, *p, usage)
}

func TestMain(m *testing.M) {
version := flag.Bool("version", false, "print version of this program")

@@ -59,10 +64,10 @@ func TestMain(m *testing.M) {
stringVar(&config.StagingPath, "stagingdir", "Mount point for NodeStage if staging is supported")
stringVar(&config.CreateTargetPathCmd, "createmountpathcmd", "Command to run for target path creation")
stringVar(&config.CreateStagingPathCmd, "createstagingpathcmd", "Command to run for staging path creation")
intVar(&config.CreatePathCmdTimeout, "createpathcmdtimeout", "Timeout for the commands to create target and staging paths, in seconds")
durationVar(&config.CreatePathCmdTimeout, "createpathcmdtimeout", "Timeout for the commands to create target and staging paths, in seconds")
stringVar(&config.RemoveTargetPathCmd, "removemountpathcmd", "Command to run for target path removal")
stringVar(&config.RemoveStagingPathCmd, "removestagingpathcmd", "Command to run for staging path removal")
intVar(&config.RemovePathCmdTimeout, "removepathcmdtimeout", "Timeout for the commands to remove target and staging paths, in seconds")
durationVar(&config.RemovePathCmdTimeout, "removepathcmdtimeout", "Timeout for the commands to remove target and staging paths, in seconds")
stringVar(&config.SecretsFile, "secrets", "CSI secrets file")
int64Var(&config.TestVolumeSize, "testvolumesize", "Base volume size used for provisioned volumes")
int64Var(&config.TestVolumeExpandSize, "testvolumeexpandsize", "Target size for expanded volumes")
@@ -130,14 +130,14 @@ type TestConfig struct {
CreateTargetPathCmd string
CreateStagingPathCmd string
// Timeout for the executed commands for path creation.
CreatePathCmdTimeout int
CreatePathCmdTimeout time.Duration

// Commands to be executed for customized removal of the target and staging
// paths. Thie command must be available on the host where sanity runs.
RemoveTargetPathCmd string
RemoveStagingPathCmd string
// Timeout for the executed commands for path removal.
RemovePathCmdTimeout int
RemovePathCmdTimeout time.Duration

// IDGen is an interface for callers to provide a
// generator for valid Volume and Node IDs. Defaults to
@@ -167,8 +167,8 @@ func NewTestConfig() TestConfig {
return TestConfig{
TargetPath: os.TempDir() + "/csi-mount",
StagingPath: os.TempDir() + "/csi-staging",
CreatePathCmdTimeout: 10,
RemovePathCmdTimeout: 10,
CreatePathCmdTimeout: 10 * time.Second,
RemovePathCmdTimeout: 10 * time.Second,
TestVolumeSize: 10 * 1024 * 1024 * 1024, // 10 GiB
IDGen: &DefaultIDGenerator{},
}
@@ -310,7 +310,7 @@ func (sc *TestContext) Finalize() {
// createMountTargetLocation takes a target path parameter and creates the
// target path using a custom command, custom function or falls back to the
// default using mkdir and returns the new target path.
func createMountTargetLocation(targetPath string, createPathCmd string, customCreateDir func(string) (string, error), timeout int) (string, error) {
func createMountTargetLocation(targetPath string, createPathCmd string, customCreateDir func(string) (string, error), timeout time.Duration) (string, error) {

// Return the target path if empty.
if targetPath == "" {
@@ -321,7 +321,7 @@ func createMountTargetLocation(targetPath string, createPathCmd string, customCr

if createPathCmd != "" {
// Create the target path using the create path command.
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

cmd := exec.CommandContext(ctx, createPathCmd, targetPath)
@@ -355,13 +355,13 @@ func createMountTargetLocation(targetPath string, createPathCmd string, customCr
// removeMountTargetLocation takes a target path parameter and removes the path
// using a custom command, custom function or falls back to the default removal
// by deleting the path on the host.
func removeMountTargetLocation(targetPath string, removePathCmd string, customRemovePath func(string) error, timeout int) error {
func removeMountTargetLocation(targetPath string, removePathCmd string, customRemovePath func(string) error, timeout time.Duration) error {
if targetPath == "" {
return nil
}

if removePathCmd != "" {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

cmd := exec.CommandContext(ctx, removePathCmd, targetPath)

0 comments on commit 81bc939

Please sign in to comment.
You can’t perform that action at this time.