-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_zone_e2e_test.go
196 lines (158 loc) · 6.55 KB
/
single_zone_e2e_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package tests
import (
"fmt"
"strings"
"k8s.io/apimachinery/pkg/util/uuid"
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
const (
testNamePrefix = "gcepd-csi-e2e-"
defaultSizeGb int64 = 5
readyState = "READY"
standardDiskType = "pd-standard"
ssdDiskType = "pd-ssd"
)
var _ = Describe("GCE PD CSI Driver", func() {
It("Should create->attach->stage->mount volume and check if it is writable, then unmount->unstage->detach->delete and check disk is deleted", func() {
testContext := getRandomTestContext()
p, z, _ := testContext.Instance.GetIdentity()
client := testContext.Client
instance := testContext.Instance
// Create Disk
volName := testNamePrefix + string(uuid.NewUUID())
volID, err := client.CreateVolume(volName, nil, defaultSizeGb,
&csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{common.TopologyKeyZone: z},
},
},
})
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
// Validate Disk Created
cloudDisk, err := computeService.Disks.Get(p, z, volName).Do()
Expect(err).To(BeNil(), "Could not get disk from cloud directly")
Expect(cloudDisk.Type).To(ContainSubstring(standardDiskType))
Expect(cloudDisk.Status).To(Equal(readyState))
Expect(cloudDisk.SizeGb).To(Equal(defaultSizeGb))
Expect(cloudDisk.Name).To(Equal(volName))
defer func() {
// Delete Disk
client.DeleteVolume(volID)
Expect(err).To(BeNil(), "DeleteVolume failed")
// Validate Disk Deleted
_, err = computeService.Disks.Get(p, z, volName).Do()
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
}()
// Attach Disk
testAttachWriteReadDetach(volID, volName, instance, client, false /* readOnly */)
})
It("Should create disks in correct zones when topology is specified", func() {
Expect(testContexts).ToNot(BeEmpty())
testContext := getRandomTestContext()
p, _, _ := testContext.Instance.GetIdentity()
zones := []string{"us-central1-c", "us-central1-b", "us-central1-a"}
for _, zone := range zones {
volName := testNamePrefix + string(uuid.NewUUID())
topReq := &csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{common.TopologyKeyZone: zone},
},
},
}
volID, err := testContext.Client.CreateVolume(volName, nil, defaultSizeGb, topReq)
Expect(err).To(BeNil(), "Failed to create volume")
defer func() {
err = testContext.Client.DeleteVolume(volID)
Expect(err).To(BeNil(), "Failed to delete volume")
}()
_, err = computeService.Disks.Get(p, zone, volName).Do()
Expect(err).To(BeNil(), "Could not find disk in correct zone")
}
})
It("Should successfully create RePD in two zones in the drivers region when none are specified", func() {
Expect(testContexts).ToNot(BeEmpty())
testContext := getRandomTestContext()
controllerInstance := testContext.Instance
controllerClient := testContext.Client
p, z, _ := controllerInstance.GetIdentity()
region, err := common.GetRegionFromZones([]string{z})
Expect(err).To(BeNil(), "Failed to get region from zones")
// Create Disk
volName := testNamePrefix + string(uuid.NewUUID())
volID, err := controllerClient.CreateVolume(volName, map[string]string{
common.ParameterKeyReplicationType: "regional-pd",
}, defaultSizeGb, nil)
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
// Validate Disk Created
cloudDisk, err := betaComputeService.RegionDisks.Get(p, region, volName).Do()
Expect(err).To(BeNil(), "Could not get disk from cloud directly")
Expect(cloudDisk.Type).To(ContainSubstring(standardDiskType))
Expect(cloudDisk.Status).To(Equal(readyState))
Expect(cloudDisk.SizeGb).To(Equal(defaultSizeGb))
Expect(cloudDisk.Name).To(Equal(volName))
Expect(len(cloudDisk.ReplicaZones)).To(Equal(2))
for _, replicaZone := range cloudDisk.ReplicaZones {
tokens := strings.Split(replicaZone, "/")
actualZone := tokens[len(tokens)-1]
gotRegion, err := common.GetRegionFromZones([]string{actualZone})
Expect(err).To(BeNil(), "failed to get region from actual zone %v", actualZone)
Expect(gotRegion).To(Equal(region), "Got region from replica zone that did not match supplied region")
}
defer func() {
// Delete Disk
controllerClient.DeleteVolume(volID)
Expect(err).To(BeNil(), "DeleteVolume failed")
// Validate Disk Deleted
_, err = betaComputeService.RegionDisks.Get(p, region, volName).Do()
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
}()
})
It("Should create and delete disk with default zone", func() {
Expect(testContexts).ToNot(BeEmpty())
testContext := getRandomTestContext()
p, z, _ := testContext.Instance.GetIdentity()
client := testContext.Client
// Create Disk
volName := testNamePrefix + string(uuid.NewUUID())
volID, err := client.CreateVolume(volName, nil, defaultSizeGb, nil)
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
// Validate Disk Created
cloudDisk, err := computeService.Disks.Get(p, z, volName).Do()
Expect(err).To(BeNil(), "Could not get disk from cloud directly")
Expect(cloudDisk.Type).To(ContainSubstring(standardDiskType))
Expect(cloudDisk.Status).To(Equal(readyState))
Expect(cloudDisk.SizeGb).To(Equal(defaultSizeGb))
Expect(cloudDisk.Name).To(Equal(volName))
defer func() {
// Delete Disk
client.DeleteVolume(volID)
Expect(err).To(BeNil(), "DeleteVolume failed")
// Validate Disk Deleted
_, err = computeService.Disks.Get(p, z, volName).Do()
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
}()
})
// Test volume already exists idempotency
// Test volume with op pending
})
func Logf(format string, args ...interface{}) {
fmt.Fprintf(GinkgoWriter, format, args...)
}