@@ -20,15 +20,15 @@ import (
20
20
"strings"
21
21
22
22
"k8s.io/apimachinery/pkg/util/uuid"
23
- remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/binremote "
23
+ gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider "
24
24
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
25
25
26
+ csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
26
27
. "github.com/onsi/ginkgo"
27
28
. "github.com/onsi/gomega"
28
29
)
29
30
30
31
const (
31
- network = "unix"
32
32
testNamePrefix = "gcepd-csi-e2e-"
33
33
34
34
defaultSizeGb int64 = 5
@@ -37,83 +37,48 @@ const (
37
37
ssdDiskType = "pd-ssd"
38
38
)
39
39
40
- var (
41
- client * utils.CsiClient
42
- instance * remote.InstanceInfo
43
- //gceCloud *gce.CloudProvider
44
- nodeID string
45
- )
46
-
47
- var _ = BeforeSuite (func () {
48
- var err error
49
- // TODO(dyzz): better defaults
50
- nodeID = "gce-pd-csi-e2e-us-central1-c"
51
- port := "2000"
52
- if * runInProw {
53
- * project , * serviceAccount = utils .SetupProwConfig ()
54
- }
55
-
56
- Expect (* project ).ToNot (BeEmpty (), "Project should not be empty" )
57
- Expect (* serviceAccount ).ToNot (BeEmpty (), "Service account should not be empty" )
58
-
59
- instance , err = utils .SetupInstanceAndDriver (* project , "us-central1-c" , nodeID , port , * serviceAccount )
60
- Expect (err ).To (BeNil ())
61
-
62
- client = utils .CreateCSIClient (fmt .Sprintf ("localhost:%s" , port ))
63
- })
64
-
65
- var _ = AfterSuite (func () {
66
- // Close the client
67
- err := client .CloseConn ()
68
- if err != nil {
69
- Logf ("Failed to close the client" )
70
- } else {
71
- Logf ("Closed the client" )
72
- }
73
-
74
- // instance.DeleteInstance()
75
- })
76
-
77
40
var _ = Describe ("GCE PD CSI Driver" , func () {
78
41
79
- BeforeEach (func () {
80
- err := client .AssertCSIConnection ()
81
- Expect (err ).To (BeNil (), "Failed to assert csi client connection: %v" , err )
82
- })
83
-
84
42
It ("Should create->attach->stage->mount volume and check if it is writable, then unmount->unstage->detach->delete and check disk is deleted" , func () {
43
+ // Create new driver and client
44
+ // TODO: Should probably actual have some object that includes both client and instance so we can relate the two??
45
+ Expect (testInstances ).NotTo (BeEmpty ())
46
+ testContext , err := utils .SetupNewDriverAndClient (testInstances [0 ])
47
+ Expect (err ).To (BeNil (), "Set up new Driver and Client failed with error" )
48
+ p , z , _ := testContext .Instance .GetIdentity ()
49
+ client := testContext .Client
50
+ instance := testContext .Instance
51
+
85
52
// Create Disk
86
53
volName := testNamePrefix + string (uuid .NewUUID ())
87
- volId , err := client .CreateVolume (volName )
54
+ volId , err := client .CreateVolume (volName , nil )
88
55
Expect (err ).To (BeNil (), "CreateVolume failed with error: %v" , err )
89
56
90
57
// TODO: Validate Disk Created
91
- /* cloudDisk, err := gceCloud.GetDiskOrError(context.Background(), gceCloud.GetZone() , volName)
58
+ cloudDisk , err := computeService . Disks . Get ( p , z , volName ). Do ( )
92
59
Expect (err ).To (BeNil (), "Could not get disk from cloud directly" )
93
60
Expect (cloudDisk .Type ).To (ContainSubstring (standardDiskType ))
94
61
Expect (cloudDisk .Status ).To (Equal (readyState ))
95
62
Expect (cloudDisk .SizeGb ).To (Equal (defaultSizeGb ))
96
- Expect(cloudDisk.Name).To(Equal(volName))*/
63
+ Expect (cloudDisk .Name ).To (Equal (volName ))
97
64
98
65
defer func () {
99
66
// Delete Disk
100
67
client .DeleteVolume (volId )
101
68
Expect (err ).To (BeNil (), "DeleteVolume failed" )
102
69
103
70
// TODO: Validate Disk Deleted
104
- /*_, err = gceCloud.GetDiskOrError(context.Background(), gceCloud.GetZone(), volName)
105
- serverError, ok := status.FromError(err)
106
- Expect(ok).To(BeTrue())
107
- Expect(serverError.Code()).To(Equal(codes.NotFound))*/
71
+ _ , err = computeService .Disks .Get (p , z , volName ).Do ()
72
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
108
73
}()
109
74
110
75
// Attach Disk
111
- err = client .ControllerPublishVolume (volId , nodeID )
76
+ err = client .ControllerPublishVolume (volId , instance . GetName () )
112
77
Expect (err ).To (BeNil (), "ControllerPublishVolume failed with error" )
113
78
114
79
defer func () {
115
80
// Detach Disk
116
- err := client .ControllerUnpublishVolume (volId , nodeID )
81
+ err := client .ControllerUnpublishVolume (volId , instance . GetName () )
117
82
Expect (err ).To (BeNil (), "ControllerUnpublishVolume failed with error" )
118
83
}()
119
84
@@ -166,6 +131,37 @@ var _ = Describe("GCE PD CSI Driver", func() {
166
131
167
132
})
168
133
134
+ It ("Should create disks in correct zones when toplogy is specified" , func () {
135
+ ///
136
+ Expect (testInstances ).NotTo (BeEmpty ())
137
+ testContext , err := utils .SetupNewDriverAndClient (testInstances [0 ])
138
+ Expect (err ).To (BeNil (), "Failed to set up new driver and client" )
139
+ p , _ , _ := testContext .Instance .GetIdentity ()
140
+
141
+ zones := []string {"us-central1-c" , "us-central1-b" , "us-central1-a" }
142
+
143
+ for _ , zone := range zones {
144
+ volName := testNamePrefix + string (uuid .NewUUID ())
145
+ topReq := & csi.TopologyRequirement {
146
+ Requisite : []* csi.Topology {
147
+ {
148
+ Segments : map [string ]string {"zone" : zone },
149
+ },
150
+ },
151
+ }
152
+ volID , err := testContext .Client .CreateVolume (volName , topReq )
153
+ Expect (err ).To (BeNil (), "Failed to create volume" )
154
+ defer func () {
155
+ err = testContext .Client .DeleteVolume (volID )
156
+ Expect (err ).To (BeNil (), "Failed to delete volume" )
157
+ }()
158
+
159
+ _ , err = computeService .Disks .Get (p , zone , volName ).Do ()
160
+ Expect (err ).To (BeNil (), "Could not find disk in correct zone" )
161
+ }
162
+
163
+ })
164
+
169
165
// Test volume already exists
170
166
171
167
// Test volume with op pending
0 commit comments