Skip to content

Commit a1d6f88

Browse files
authored
Merge pull request #104 from davidz627/fix/testImage
Test contexts are now initialized once on startup in parallel instead of per-test, Chose a better boot disk image.
2 parents eff4ab7 + 4198d90 commit a1d6f88

File tree

5 files changed

+71
-98
lines changed

5 files changed

+71
-98
lines changed

test/e2e/tests/multi_zone_e2e_test.go

+21-35
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,11 @@ import (
3131

3232
var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
3333
BeforeEach(func() {
34-
Expect(len(testInstances)).To(BeNumerically(">", 1))
34+
Expect(len(testContexts)).To(BeNumerically(">", 1))
3535
})
3636

3737
It("Should get reasonable topology from nodes with NodeGetInfo", func() {
38-
for _, instance := range testInstances {
39-
testContext, err := testutils.GCEClientAndDriverSetup(instance)
40-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
41-
defer func() {
42-
err := remote.TeardownDriverAndClient(testContext)
43-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
44-
}()
45-
38+
for _, testContext := range testContexts {
4639
resp, err := testContext.Client.NodeGetInfo()
4740
Expect(err).To(BeNil())
4841

@@ -65,24 +58,17 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
6558
It("Should successfully run through entire lifecycle of an RePD volume on instances in 2 zones", func() {
6659
// Create new driver and client
6760

68-
Expect(testInstances).NotTo(BeEmpty())
61+
Expect(testContexts).NotTo(BeEmpty())
6962

7063
zoneToContext := map[string]*remote.TestContext{}
7164
zones := []string{}
7265

73-
for _, i := range testInstances {
74-
_, z, _ := i.GetIdentity()
66+
for _, tc := range testContexts {
67+
_, z, _ := tc.Instance.GetIdentity()
7568
// Zone hasn't been seen before
7669
if _, ok := zoneToContext[z]; !ok {
77-
c, err := testutils.GCEClientAndDriverSetup(i)
78-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
79-
zoneToContext[z] = c
70+
zoneToContext[z] = tc
8071
zones = append(zones, z)
81-
82-
defer func() {
83-
err := remote.TeardownDriverAndClient(c)
84-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
85-
}()
8672
}
8773
if len(zoneToContext) == 2 {
8874
break
@@ -102,7 +88,7 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
10288

10389
// Create Disk
10490
volName := testNamePrefix + string(uuid.NewUUID())
105-
volId, err := controllerClient.CreateVolume(volName, map[string]string{
91+
volID, err := controllerClient.CreateVolume(volName, map[string]string{
10692
common.ParameterKeyReplicationType: "regional-pd",
10793
}, defaultSizeGb, &csi.TopologyRequirement{
10894
Requisite: []*csi.Topology{
@@ -133,7 +119,7 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
133119

134120
defer func() {
135121
// Delete Disk
136-
controllerClient.DeleteVolume(volId)
122+
controllerClient.DeleteVolume(volID)
137123
Expect(err).To(BeNil(), "DeleteVolume failed")
138124

139125
// Validate Disk Deleted
@@ -148,45 +134,45 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
148134
if i >= 1 {
149135
readOnly = true
150136
}
151-
testAttachWriteReadDetach(volId, volName, testContext.Instance, testContext.Client, readOnly)
137+
testAttachWriteReadDetach(volID, volName, testContext.Instance, testContext.Client, readOnly)
152138
i = i + 1
153139
}
154140

155141
})
156142

157143
})
158144

159-
func testAttachWriteReadDetach(volId string, volName string, instance *remote.InstanceInfo, client *remote.CsiClient, readOnly bool) {
145+
func testAttachWriteReadDetach(volID string, volName string, instance *remote.InstanceInfo, client *remote.CsiClient, readOnly bool) {
160146
var err error
161147

162-
Logf("Starting testAttachWriteReadDetach with volume %v node %v with readonly %v\n", volId, instance.GetNodeID(), readOnly)
148+
Logf("Starting testAttachWriteReadDetach with volume %v node %v with readonly %v\n", volID, instance.GetNodeID(), readOnly)
163149
// Attach Disk
164-
err = client.ControllerPublishVolume(volId, instance.GetNodeID())
165-
Expect(err).To(BeNil(), "ControllerPublishVolume failed with error for disk %v on node %v", volId, instance.GetNodeID())
150+
err = client.ControllerPublishVolume(volID, instance.GetNodeID())
151+
Expect(err).To(BeNil(), "ControllerPublishVolume failed with error for disk %v on node %v", volID, instance.GetNodeID())
166152

167153
defer func() {
168154

169155
// Detach Disk
170-
err = client.ControllerUnpublishVolume(volId, instance.GetNodeID())
156+
err = client.ControllerUnpublishVolume(volID, instance.GetNodeID())
171157
Expect(err).To(BeNil(), "ControllerUnpublishVolume failed with error")
172158
}()
173159

174160
// Stage Disk
175161
stageDir := filepath.Join("/tmp/", volName, "stage")
176-
client.NodeStageVolume(volId, stageDir)
162+
client.NodeStageVolume(volID, stageDir)
177163
Expect(err).To(BeNil(), "NodeStageVolume failed with error")
178164

179165
defer func() {
180166
// Unstage Disk
181-
err = client.NodeUnstageVolume(volId, stageDir)
167+
err = client.NodeUnstageVolume(volID, stageDir)
182168
Expect(err).To(BeNil(), "NodeUnstageVolume failed with error")
183169
err = testutils.RmAll(instance, filepath.Join("/tmp/", volName))
184170
Expect(err).To(BeNil(), "Failed to remove temp directory")
185171
}()
186172

187173
// Mount Disk
188174
publishDir := filepath.Join("/tmp/", volName, "mount")
189-
err = client.NodePublishVolume(volId, stageDir, publishDir)
175+
err = client.NodePublishVolume(volID, stageDir, publishDir)
190176
Expect(err).To(BeNil(), "NodePublishVolume failed with error")
191177
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
192178
Expect(err).To(BeNil(), "Chmod failed with error")
@@ -199,12 +185,12 @@ func testAttachWriteReadDetach(volId string, volName string, instance *remote.In
199185
}
200186

201187
// Unmount Disk
202-
err = client.NodeUnpublishVolume(volId, publishDir)
188+
err = client.NodeUnpublishVolume(volID, publishDir)
203189
Expect(err).To(BeNil(), "NodeUnpublishVolume failed with error")
204190

205191
// Mount disk somewhere else
206192
secondPublishDir := filepath.Join("/tmp/", volName, "secondmount")
207-
err = client.NodePublishVolume(volId, stageDir, secondPublishDir)
193+
err = client.NodePublishVolume(volID, stageDir, secondPublishDir)
208194
Expect(err).To(BeNil(), "NodePublishVolume failed with error")
209195
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
210196
Expect(err).To(BeNil(), "Chmod failed with error")
@@ -216,8 +202,8 @@ func testAttachWriteReadDetach(volId string, volName string, instance *remote.In
216202
Expect(strings.TrimSpace(string(readContents))).To(Equal(testFileContents))
217203

218204
// Unmount Disk
219-
err = client.NodeUnpublishVolume(volId, secondPublishDir)
205+
err = client.NodeUnpublishVolume(volID, secondPublishDir)
220206
Expect(err).To(BeNil(), "NodeUnpublishVolume failed with error")
221207

222-
Logf("Completed testAttachWriteReadDetach with volume %v node %v\n", volId, instance.GetNodeID())
208+
Logf("Completed testAttachWriteReadDetach with volume %v node %v\n", volID, instance.GetNodeID())
223209
}

test/e2e/tests/setup_e2e_test.go

+33-16
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var (
3535
runInProw = flag.Bool("run-in-prow", false, "If true, use a Boskos loaned project and special CI service accounts and ssh keys")
3636
deleteInstances = flag.Bool("delete-instances", false, "Delete the instances after tests run")
3737

38-
testInstances = []*remote.InstanceInfo{}
38+
testContexts = []*remote.TestContext{}
3939
computeService *compute.Service
4040
betaComputeService *computebeta.Service
4141
)
@@ -48,6 +48,9 @@ func TestE2E(t *testing.T) {
4848

4949
var _ = BeforeSuite(func() {
5050
var err error
51+
tcc := make(chan *remote.TestContext)
52+
defer close(tcc)
53+
5154
zones := []string{"us-central1-c", "us-central1-b"}
5255

5356
rand.Seed(time.Now().UnixNano())
@@ -68,27 +71,41 @@ var _ = BeforeSuite(func() {
6871
Logf("Running in project %v with service account %v\n\n", *project, *serviceAccount)
6972

7073
for _, zone := range zones {
71-
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", zone)
72-
73-
i, err := remote.SetupInstance(*project, zone, nodeID, *serviceAccount, computeService)
74-
Expect(err).To(BeNil())
75-
76-
testInstances = append(testInstances, i)
74+
go func(curZone string) {
75+
defer GinkgoRecover()
76+
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", curZone)
77+
Logf("Setting up node %s\n", nodeID)
78+
79+
i, err := remote.SetupInstance(*project, curZone, nodeID, *serviceAccount, computeService)
80+
Expect(err).To(BeNil())
81+
82+
// Create new driver and client
83+
testContext, err := testutils.GCEClientAndDriverSetup(i)
84+
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
85+
tcc <- testContext
86+
}(zone)
7787
}
7888

89+
for i := 0; i < len(zones); i++ {
90+
tc := <-tcc
91+
Logf("Test Context for node %s set up\n", tc.Instance.GetName())
92+
testContexts = append(testContexts, tc)
93+
}
7994
})
8095

8196
var _ = AfterSuite(func() {
82-
/*
83-
err := node.client.CloseConn()
84-
if err != nil {
85-
Logf("Failed to close the client")
86-
} else {
87-
Logf("Closed the client")
88-
*/
89-
for _, i := range testInstances {
97+
98+
for _, tc := range testContexts {
99+
err := remote.TeardownDriverAndClient(tc)
100+
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
90101
if *deleteInstances {
91-
i.DeleteInstance()
102+
tc.Instance.DeleteInstance()
92103
}
93104
}
94105
})
106+
107+
func getRandomTestContext() *remote.TestContext {
108+
Expect(testContexts).ToNot(BeEmpty())
109+
rn := rand.Intn(len(testContexts))
110+
return testContexts[rn]
111+
}

test/e2e/tests/single_zone_e2e_test.go

+14-41
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"k8s.io/apimachinery/pkg/util/uuid"
2222
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
2323
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
24-
testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
25-
remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote"
2624

2725
csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
2826
. "github.com/onsi/ginkgo"
@@ -41,22 +39,15 @@ const (
4139
var _ = Describe("GCE PD CSI Driver", func() {
4240

4341
It("Should create->attach->stage->mount volume and check if it is writable, then unmount->unstage->detach->delete and check disk is deleted", func() {
44-
// Create new driver and client
45-
Expect(testInstances).NotTo(BeEmpty())
46-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
47-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
48-
defer func() {
49-
err := remote.TeardownDriverAndClient(testContext)
50-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
51-
}()
42+
testContext := getRandomTestContext()
5243

5344
p, z, _ := testContext.Instance.GetIdentity()
5445
client := testContext.Client
5546
instance := testContext.Instance
5647

5748
// Create Disk
5849
volName := testNamePrefix + string(uuid.NewUUID())
59-
volId, err := client.CreateVolume(volName, nil, defaultSizeGb,
50+
volID, err := client.CreateVolume(volName, nil, defaultSizeGb,
6051
&csi.TopologyRequirement{
6152
Requisite: []*csi.Topology{
6253
{
@@ -76,7 +67,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
7667

7768
defer func() {
7869
// Delete Disk
79-
client.DeleteVolume(volId)
70+
client.DeleteVolume(volID)
8071
Expect(err).To(BeNil(), "DeleteVolume failed")
8172

8273
// Validate Disk Deleted
@@ -85,19 +76,13 @@ var _ = Describe("GCE PD CSI Driver", func() {
8576
}()
8677

8778
// Attach Disk
88-
testAttachWriteReadDetach(volId, volName, instance, client, false /* readOnly */)
79+
testAttachWriteReadDetach(volID, volName, instance, client, false /* readOnly */)
8980

9081
})
9182

9283
It("Should create disks in correct zones when topology is specified", func() {
93-
///
94-
Expect(testInstances).NotTo(BeEmpty())
95-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
96-
Expect(err).To(BeNil(), "Failed to set up new driver and client")
97-
defer func() {
98-
err := remote.TeardownDriverAndClient(testContext)
99-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
100-
}()
84+
Expect(testContexts).ToNot(BeEmpty())
85+
testContext := getRandomTestContext()
10186

10287
p, _, _ := testContext.Instance.GetIdentity()
10388

@@ -126,14 +111,8 @@ var _ = Describe("GCE PD CSI Driver", func() {
126111
})
127112

128113
It("Should successfully create RePD in two zones in the drivers region when none are specified", func() {
129-
// Create new driver and client
130-
Expect(testInstances).NotTo(BeEmpty())
131-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
132-
Expect(err).To(BeNil(), "Failed to set up new driver and client")
133-
defer func() {
134-
err := remote.TeardownDriverAndClient(testContext)
135-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
136-
}()
114+
Expect(testContexts).ToNot(BeEmpty())
115+
testContext := getRandomTestContext()
137116

138117
controllerInstance := testContext.Instance
139118
controllerClient := testContext.Client
@@ -145,7 +124,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
145124

146125
// Create Disk
147126
volName := testNamePrefix + string(uuid.NewUUID())
148-
volId, err := controllerClient.CreateVolume(volName, map[string]string{
127+
volID, err := controllerClient.CreateVolume(volName, map[string]string{
149128
common.ParameterKeyReplicationType: "regional-pd",
150129
}, defaultSizeGb, nil)
151130
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
@@ -167,7 +146,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
167146
}
168147
defer func() {
169148
// Delete Disk
170-
controllerClient.DeleteVolume(volId)
149+
controllerClient.DeleteVolume(volID)
171150
Expect(err).To(BeNil(), "DeleteVolume failed")
172151

173152
// Validate Disk Deleted
@@ -177,21 +156,15 @@ var _ = Describe("GCE PD CSI Driver", func() {
177156
})
178157

179158
It("Should create and delete disk with default zone", func() {
180-
// Create new driver and client
181-
Expect(testInstances).NotTo(BeEmpty())
182-
testContext, err := testutils.GCEClientAndDriverSetup(testInstances[0])
183-
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
184-
defer func() {
185-
err := remote.TeardownDriverAndClient(testContext)
186-
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
187-
}()
159+
Expect(testContexts).ToNot(BeEmpty())
160+
testContext := getRandomTestContext()
188161

189162
p, z, _ := testContext.Instance.GetIdentity()
190163
client := testContext.Client
191164

192165
// Create Disk
193166
volName := testNamePrefix + string(uuid.NewUUID())
194-
volId, err := client.CreateVolume(volName, nil, defaultSizeGb, nil)
167+
volID, err := client.CreateVolume(volName, nil, defaultSizeGb, nil)
195168
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
196169

197170
// Validate Disk Created
@@ -204,7 +177,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
204177

205178
defer func() {
206179
// Delete Disk
207-
client.DeleteVolume(volId)
180+
client.DeleteVolume(volID)
208181
Expect(err).To(BeNil(), "DeleteVolume failed")
209182

210183
// Validate Disk Deleted

test/remote/instance.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ func (i *InstanceInfo) CreateOrGetInstance(serviceAccount string) error {
8888
return fmt.Errorf("Failed to create firewall rule: %v", err)
8989
}
9090

91-
// TODO(#97): Pick a better boot disk image
92-
imageURL := "projects/ml-images/global/images/family/tf-1-9"
91+
imageURL := "projects/ubuntu-os-cloud/global/images/family/ubuntu-minimal-1804-lts"
9392
inst := &compute.Instance{
9493
Name: i.name,
9594
MachineType: machineType(i.zone, ""),

test/remote/setup-teardown.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ import (
2222

2323
"github.com/golang/glog"
2424
compute "google.golang.org/api/compute/v1"
25-
)
26-
27-
const (
28-
archiveName = "e2e_driver_binaries.tar.gz"
25+
"k8s.io/apimachinery/pkg/util/uuid"
2926
)
3027

3128
// TestContext holds the CSI Client handle to a remotely connected Driver
@@ -75,6 +72,7 @@ func SetupInstance(instanceProject, instanceZone, instanceName, instanceServiceA
7572
// a CSI client to it through SHH tunnelling. It returns a TestContext with both a handle to the instance
7673
// that the driver is on and the CSI Client object to make CSI calls to the remote driver.
7774
func SetupNewDriverAndClient(instance *InstanceInfo, config *ClientConfig) (*TestContext, error) {
75+
archiveName := fmt.Sprintf("e2e_driver_binaries_%s.tar.gz", uuid.NewUUID())
7876
archivePath, err := CreateDriverArchive(archiveName, config.PkgPath, config.BinPath)
7977
if err != nil {
8078
return nil, err

0 commit comments

Comments
 (0)