Skip to content

Commit 9f33082

Browse files
committed
Test infrastructure changes to support multizone and topology
1 parent 5d7e92b commit 9f33082

File tree

5 files changed

+48
-19
lines changed

5 files changed

+48
-19
lines changed

test/binremote/instance.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,33 @@ type InstanceInfo struct {
4646
zone string
4747
name string
4848

49+
// External IP is filled in after instance creation
50+
// TODO: Maybe combine create instance and create instance info so all fields are set up at the same time...
4951
externalIP string
5052

5153
computeService *compute.Service
5254
}
5355

54-
func CreateInstanceInfo(project, zone, name string) (*InstanceInfo, error) {
55-
cs, err := getComputeClient()
56-
if err != nil {
57-
return nil, err
58-
}
56+
func (i *InstanceInfo) GetIdentity() (string, string, string) {
57+
return i.project, i.zone, i.name
58+
}
59+
60+
func (i *InstanceInfo) GetName() string {
61+
return i.name
62+
}
63+
64+
func CreateInstanceInfo(project, instanceZone, name string, cs *compute.Service) (*InstanceInfo, error) {
5965
return &InstanceInfo{
6066
project: project,
61-
zone: zone,
67+
zone: instanceZone,
6268
name: name,
6369

6470
computeService: cs,
6571
}, nil
6672
}
6773

6874
// Provision a gce instance using image
69-
func (i *InstanceInfo) CreateInstance(serviceAccount string) error {
75+
func (i *InstanceInfo) CreateOrGetInstance(serviceAccount string) error {
7076
var err error
7177
var instance *compute.Instance
7278
glog.V(4).Infof("Creating instance: %v", i.name)
@@ -236,7 +242,7 @@ func (i *InstanceInfo) createDefaultFirewallRule() error {
236242
return nil
237243
}
238244

239-
func getComputeClient() (*compute.Service, error) {
245+
func GetComputeClient() (*compute.Service, error) {
240246
const retries = 10
241247
const backoff = time.Second * 6
242248

test/e2e/utils/client_wrappers.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ func (c *CsiClient) CloseConn() error {
8787
return c.conn.Close()
8888
}
8989

90-
func (c *CsiClient) CreateVolume(volName string) (string, error) {
90+
func (c *CsiClient) CreateVolume(volName string, topReq *csipb.TopologyRequirement) (string, error) {
9191
cvr := &csipb.CreateVolumeRequest{
9292
Name: volName,
9393
VolumeCapabilities: stdVolCaps,
9494
}
95+
if topReq != nil {
96+
cvr.AccessibilityRequirements = topReq
97+
}
9598
cresp, err := c.ctrlClient.CreateVolume(context.Background(), cvr)
9699
if err != nil {
97100
return "", err
@@ -166,3 +169,8 @@ func (c *CsiClient) NodePublishVolume(volumeId, stageDir, publishDir string) err
166169
_, err := c.nodeClient.NodePublishVolume(context.Background(), nodePublishReq)
167170
return err
168171
}
172+
173+
func (c *CsiClient) NodeGetInfo() (*csipb.NodeGetInfoResponse, error) {
174+
resp, err := c.nodeClient.NodeGetInfo(context.Background(), &csipb.NodeGetInfoRequest{})
175+
return resp, err
176+
}

test/e2e/utils/utils.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ package utils
1717
import (
1818
"context"
1919
"fmt"
20+
"math/rand"
2021
"os"
2122
"path"
2223
"time"
2324

2425
"github.com/golang/glog"
2526
"golang.org/x/oauth2/google"
2627
cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1"
28+
compute "google.golang.org/api/compute/v1"
2729
boskosclient "k8s.io/test-infra/boskos/client"
2830
remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/binremote"
2931
)
@@ -36,21 +38,28 @@ const (
3638
archiveName = "e2e_gce_pd_test.tar.gz"
3739
)
3840

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) {
4047
// Create the instance in the requisite zone
41-
instance, err := remote.CreateInstanceInfo(instanceProject, instanceZone, instanceName)
48+
instance, err := remote.CreateInstanceInfo(instanceProject, instanceZone, instanceName, cs)
4249
if err != nil {
4350
return nil, err
4451
}
4552

46-
err = instance.CreateInstance(instanceServiceAccount)
47-
53+
err = instance.CreateOrGetInstance(instanceServiceAccount)
4854
if err != nil {
4955
return nil, err
5056
}
57+
return instance, nil
58+
}
5159

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))
5463
goPath, ok := os.LookupEnv("GOPATH")
5564
if !ok {
5665
return nil, fmt.Errorf("Could not find environment variable GOPATH")
@@ -72,7 +81,7 @@ func SetupInstanceAndDriver(instanceProject, instanceZone, instanceName, port, i
7281
endpoint := fmt.Sprintf("tcp://localhost:%s", port)
7382
workspace := remote.NewWorkspaceDir("gce-pd-e2e-")
7483
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)
7685
err = instance.UploadAndRun(archivePath, workspace, driverRunCmd)
7786
if err != nil {
7887
return nil, err
@@ -84,7 +93,13 @@ func SetupInstanceAndDriver(instanceProject, instanceZone, instanceName, port, i
8493
return nil, fmt.Errorf("SSH Tunnel pid %v encountered error: %v", res, err)
8594
}
8695

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
88103
}
89104

90105
func SetupProwConfig() (project, serviceAccount string) {

test/run-e2e-local.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -o errexit
55

66
readonly PKGDIR=sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
77

8-
go test --v=true "${PKGDIR}/test/e2e/tests" --logtostderr --project ${PROJECT} --service-account ${IAM_NAME}
8+
ginkgo -v "test/e2e/tests" --logtostderr -- --project ${PROJECT} --service-account ${IAM_NAME}

test/run-e2e.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -x
55

66
readonly PKGDIR=sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
77

8-
go test --v=true "${PKGDIR}/test/e2e/tests" --logtostderr --run-in-prow=true
8+
go test --v=true "${PKGDIR}/test/e2e/tests" --logtostderr --run-in-prow=true --delete-instances=true

0 commit comments

Comments
 (0)