Skip to content

Commit 8ab1572

Browse files
committed
Regional PD Testing Changes
1 parent a40d2a5 commit 8ab1572

11 files changed

+714
-111
lines changed

pkg/gce-pd-csi-driver/controller_test.go

+394-35
Large diffs are not rendered by default.

pkg/gce-pd-csi-driver/gce-pd-driver_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func initGCEDriver(t *testing.T) *GCEDriver {
2828
if err != nil {
2929
t.Fatalf("Failed to create fake cloud provider: %v", err)
3030
}
31-
err = gceDriver.SetupGCEDriver(fakeCloudProvider, nil, nil, metadataservice.NewFakeService(), driver, node, vendorVersion)
31+
err = gceDriver.SetupGCEDriver(fakeCloudProvider, nil, nil, metadataservice.NewFakeService(), driver, vendorVersion)
3232
if err != nil {
3333
t.Fatalf("Failed to setup GCE Driver: %v", err)
3434
}

pkg/gce-pd-csi-driver/identity_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
func TestGetPluginInfo(t *testing.T) {
2626
vendorVersion := "test-vendor"
2727
gceDriver := GetGCEDriver()
28-
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), driver, node, vendorVersion)
28+
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), driver, vendorVersion)
2929
if err != nil {
3030
t.Fatalf("Failed to setup GCE Driver: %v", err)
3131
}
@@ -47,7 +47,7 @@ func TestGetPluginInfo(t *testing.T) {
4747

4848
func TestGetPluginCapabilities(t *testing.T) {
4949
gceDriver := GetGCEDriver()
50-
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), driver, node, "test-vendor")
50+
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), driver, "test-vendor")
5151
if err != nil {
5252
t.Fatalf("Failed to setup GCE Driver: %v", err)
5353
}
@@ -69,7 +69,7 @@ func TestGetPluginCapabilities(t *testing.T) {
6969

7070
func TestProbe(t *testing.T) {
7171
gceDriver := GetGCEDriver()
72-
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), driver, node, "test-vendor")
72+
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), driver, "test-vendor")
7373
if err != nil {
7474
t.Fatalf("Failed to setup GCE Driver: %v", err)
7575
}

test/e2e/tests/multi_zone_e2e_test.go

+155
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ limitations under the License.
1515
package tests
1616

1717
import (
18+
"path/filepath"
19+
"strings"
20+
21+
csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
1822
. "github.com/onsi/ginkgo"
1923
. "github.com/onsi/gomega"
24+
"k8s.io/apimachinery/pkg/util/uuid"
2025
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
26+
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
2127
testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
2228
remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote"
2329
)
@@ -57,4 +63,153 @@ var _ = Describe("GCE PD CSI Driver Multi-Zone", func() {
5763

5864
})
5965

66+
It("Should successfully run through entire lifecycle of an RePD volume on instances in 2 zones", func() {
67+
// Create new driver and client
68+
69+
Expect(testInstances).NotTo(BeEmpty())
70+
71+
zoneToContext := map[string]*remote.TestContext{}
72+
zones := []string{}
73+
74+
for _, i := range testInstances {
75+
_, z, _ := i.GetIdentity()
76+
// Zone hasn't been seen before
77+
if _, ok := zoneToContext[z]; !ok {
78+
c, err := testutils.GCEClientAndDriverSetup(i)
79+
Expect(err).To(BeNil(), "Set up new Driver and Client failed with error")
80+
zoneToContext[z] = c
81+
zones = append(zones, z)
82+
83+
defer func() {
84+
err := remote.TeardownDriverAndClient(c)
85+
Expect(err).To(BeNil(), "Teardown Driver and Client failed with error")
86+
}()
87+
}
88+
if len(zoneToContext) == 2 {
89+
break
90+
}
91+
}
92+
93+
Expect(len(zoneToContext)).To(Equal(2), "Must have instances in exactly 2 zones")
94+
95+
controllerContext := zoneToContext[zones[0]]
96+
controllerClient := controllerContext.Client
97+
controllerInstance := controllerContext.Instance
98+
99+
p, _, _ := controllerInstance.GetIdentity()
100+
101+
region, err := common.GetRegionFromZones(zones)
102+
Expect(err).To(BeNil(), "Failed to get region from zones")
103+
104+
// Create Disk
105+
volName := testNamePrefix + string(uuid.NewUUID())
106+
volId, err := controllerClient.CreateVolume(volName, map[string]string{
107+
common.ParameterKeyReplicationType: "regional-pd",
108+
}, defaultSizeGb, &csi.TopologyRequirement{
109+
Requisite: []*csi.Topology{
110+
{
111+
Segments: map[string]string{common.TopologyKeyZone: zones[0]},
112+
},
113+
{
114+
Segments: map[string]string{common.TopologyKeyZone: zones[1]},
115+
},
116+
},
117+
})
118+
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
119+
120+
// TODO: Validate Disk Created
121+
cloudDisk, err := betaComputeService.RegionDisks.Get(p, region, volName).Do()
122+
Expect(err).To(BeNil(), "Could not get disk from cloud directly")
123+
Expect(cloudDisk.Type).To(ContainSubstring(standardDiskType))
124+
Expect(cloudDisk.Status).To(Equal(readyState))
125+
Expect(cloudDisk.SizeGb).To(Equal(defaultSizeGb))
126+
Expect(cloudDisk.Name).To(Equal(volName))
127+
128+
defer func() {
129+
// Delete Disk
130+
controllerClient.DeleteVolume(volId)
131+
Expect(err).To(BeNil(), "DeleteVolume failed")
132+
133+
// TODO: Validate Disk Deleted
134+
_, err = betaComputeService.RegionDisks.Get(p, region, volName).Do()
135+
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
136+
}()
137+
138+
// For each of the two instances
139+
i := 0
140+
for _, testContext := range zoneToContext {
141+
readOnly := false
142+
if i >= 1 {
143+
readOnly = true
144+
}
145+
testAttachWriteReadDetach(volId, volName, testContext.Instance, testContext.Client, readOnly)
146+
i = i + 1
147+
}
148+
149+
})
150+
60151
})
152+
153+
func testAttachWriteReadDetach(volId string, volName string, instance *remote.InstanceInfo, client *remote.CsiClient, readOnly bool) {
154+
var err error
155+
156+
// Attach Disk
157+
err = client.ControllerPublishVolume(volId, instance.GetNodeID())
158+
Expect(err).To(BeNil(), "ControllerPublishVolume failed with error")
159+
160+
defer func() {
161+
162+
// Detach Disk
163+
err = client.ControllerUnpublishVolume(volId, instance.GetNodeID())
164+
Expect(err).To(BeNil(), "ControllerUnpublishVolume failed with error")
165+
}()
166+
167+
// Stage Disk
168+
stageDir := filepath.Join("/tmp/", volName, "stage")
169+
client.NodeStageVolume(volId, stageDir)
170+
Expect(err).To(BeNil(), "NodeStageVolume failed with error")
171+
172+
defer func() {
173+
// Unstage Disk
174+
err = client.NodeUnstageVolume(volId, stageDir)
175+
Expect(err).To(BeNil(), "NodeUnstageVolume failed with error")
176+
err = testutils.RmAll(instance, filepath.Join("/tmp/", volName))
177+
Expect(err).To(BeNil(), "Failed to remove temp directory")
178+
}()
179+
180+
// Mount Disk
181+
publishDir := filepath.Join("/tmp/", volName, "mount")
182+
err = client.NodePublishVolume(volId, stageDir, publishDir)
183+
Expect(err).To(BeNil(), "NodePublishVolume failed with error")
184+
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
185+
Expect(err).To(BeNil(), "Chmod failed with error")
186+
testFileContents := "test"
187+
if !readOnly {
188+
// Write a file
189+
testFile := filepath.Join(publishDir, "testfile")
190+
err = testutils.WriteFile(instance, testFile, testFileContents)
191+
Expect(err).To(BeNil(), "Failed to write file")
192+
}
193+
194+
// Unmount Disk
195+
err = client.NodeUnpublishVolume(volId, publishDir)
196+
Expect(err).To(BeNil(), "NodeUnpublishVolume failed with error")
197+
198+
// Mount disk somewhere else
199+
secondPublishDir := filepath.Join("/tmp/", volName, "secondmount")
200+
err = client.NodePublishVolume(volId, stageDir, secondPublishDir)
201+
Expect(err).To(BeNil(), "NodePublishVolume failed with error")
202+
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
203+
Expect(err).To(BeNil(), "Chmod failed with error")
204+
205+
// Read File
206+
secondTestFile := filepath.Join(secondPublishDir, "testfile")
207+
readContents, err := testutils.ReadFile(instance, secondTestFile)
208+
Expect(err).To(BeNil(), "ReadFile failed with error")
209+
Expect(strings.TrimSpace(string(readContents))).To(Equal(testFileContents))
210+
211+
// Unmount Disk
212+
err = client.NodeUnpublishVolume(volId, secondPublishDir)
213+
Expect(err).To(BeNil(), "NodeUnpublishVolume failed with error")
214+
215+
}

test/e2e/tests/setup_e2e_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
. "github.com/onsi/ginkgo"
2525
. "github.com/onsi/gomega"
26+
computebeta "google.golang.org/api/compute/v0.beta"
2627
compute "google.golang.org/api/compute/v1"
2728
testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
2829
remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote"
@@ -34,8 +35,9 @@ var (
3435
runInProw = flag.Bool("run-in-prow", false, "If true, use a Boskos loaned project and special CI service accounts and ssh keys")
3536
deleteInstances = flag.Bool("delete-instances", false, "Delete the instances after tests run")
3637

37-
testInstances = []*remote.InstanceInfo{}
38-
computeService *compute.Service
38+
testInstances = []*remote.InstanceInfo{}
39+
computeService *compute.Service
40+
betaComputeService *computebeta.Service
3941
)
4042

4143
func TestE2E(t *testing.T) {
@@ -53,6 +55,9 @@ var _ = BeforeSuite(func() {
5355
computeService, err = remote.GetComputeClient()
5456
Expect(err).To(BeNil())
5557

58+
betaComputeService, err = remote.GetBetaComputeClient()
59+
Expect(err).To(BeNil())
60+
5661
for _, zone := range zones {
5762
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", zone)
5863

0 commit comments

Comments
 (0)