@@ -17,13 +17,15 @@ package utils
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "math/rand"
20
21
"os"
21
22
"path"
22
23
"time"
23
24
24
25
"github.com/golang/glog"
25
26
"golang.org/x/oauth2/google"
26
27
cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1"
28
+ compute "google.golang.org/api/compute/v1"
27
29
boskosclient "k8s.io/test-infra/boskos/client"
28
30
remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/binremote"
29
31
)
@@ -36,21 +38,28 @@ const (
36
38
archiveName = "e2e_gce_pd_test.tar.gz"
37
39
)
38
40
39
- func SetupInstanceAndDriver (instanceProject , instanceZone , instanceName , port , instanceServiceAccount string ) (* remote.InstanceInfo , error ) {
41
+ type TestContext struct {
42
+ Instance * remote.InstanceInfo
43
+ Client * CsiClient
44
+ }
45
+
46
+ func SetupInstance (instanceProject , instanceZone , instanceName , instanceServiceAccount string , cs * compute.Service ) (* remote.InstanceInfo , error ) {
40
47
// Create the instance in the requisite zone
41
- instance , err := remote .CreateInstanceInfo (instanceProject , instanceZone , instanceName )
48
+ instance , err := remote .CreateInstanceInfo (instanceProject , instanceZone , instanceName , cs )
42
49
if err != nil {
43
50
return nil , err
44
51
}
45
52
46
- err = instance .CreateInstance (instanceServiceAccount )
47
-
53
+ err = instance .CreateOrGetInstance (instanceServiceAccount )
48
54
if err != nil {
49
55
return nil , err
50
56
}
57
+ return instance , nil
58
+ }
51
59
52
- // Create Driver Archive
53
-
60
+ // TODO: Need a function to clean up this driver from the instance
61
+ func SetupNewDriverAndClient (instance * remote.InstanceInfo ) (* TestContext , error ) {
62
+ port := fmt .Sprintf ("%v" , 1024 + rand .Intn (10000 ))
54
63
goPath , ok := os .LookupEnv ("GOPATH" )
55
64
if ! ok {
56
65
return nil , fmt .Errorf ("Could not find environment variable GOPATH" )
@@ -72,7 +81,7 @@ func SetupInstanceAndDriver(instanceProject, instanceZone, instanceName, port, i
72
81
endpoint := fmt .Sprintf ("tcp://localhost:%s" , port )
73
82
workspace := remote .NewWorkspaceDir ("gce-pd-e2e-" )
74
83
driverRunCmd := fmt .Sprintf ("sh -c '/usr/bin/nohup %s/gce-pd-csi-driver --endpoint=%s --nodeid=%s > %s/prog.out 2> %s/prog.err < /dev/null &'" ,
75
- workspace , endpoint , instanceName , workspace , workspace )
84
+ workspace , endpoint , instance . GetName () , workspace , workspace )
76
85
err = instance .UploadAndRun (archivePath , workspace , driverRunCmd )
77
86
if err != nil {
78
87
return nil , err
@@ -84,7 +93,13 @@ func SetupInstanceAndDriver(instanceProject, instanceZone, instanceName, port, i
84
93
return nil , fmt .Errorf ("SSH Tunnel pid %v encountered error: %v" , res , err )
85
94
}
86
95
87
- return instance , nil
96
+ client := CreateCSIClient (fmt .Sprintf ("localhost:%s" , port ))
97
+ err = client .AssertCSIConnection ()
98
+ if err != nil {
99
+ return nil , fmt .Errorf ("asserting csi connection failed with: %v" , err )
100
+ }
101
+
102
+ return & TestContext {Instance : instance , Client : client }, nil
88
103
}
89
104
90
105
func SetupProwConfig () (project , serviceAccount string ) {
0 commit comments