@@ -17,13 +17,16 @@ package tests
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "path/filepath"
20
21
"strings"
21
22
"time"
22
23
23
24
"k8s.io/apimachinery/pkg/util/uuid"
24
25
"k8s.io/apimachinery/pkg/util/wait"
26
+ "k8s.io/klog"
25
27
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
26
28
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
29
+ testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
27
30
28
31
csi "github.com/container-storage-interface/spec/lib/go/csi"
29
32
. "github.com/onsi/ginkgo"
@@ -98,6 +101,114 @@ var _ = Describe("GCE PD CSI Driver", func() {
98
101
99
102
})
100
103
104
+ It ("Should resize controller and node" , func () {
105
+ testContext := getRandomTestContext ()
106
+
107
+ p , z , _ := testContext .Instance .GetIdentity ()
108
+ client := testContext .Client
109
+ instance := testContext .Instance
110
+
111
+ // Create Disk
112
+ volName := testNamePrefix + string (uuid .NewUUID ())
113
+ volID , err := client .CreateVolume (volName , nil , defaultSizeGb ,
114
+ & csi.TopologyRequirement {
115
+ Requisite : []* csi.Topology {
116
+ {
117
+ Segments : map [string ]string {common .TopologyKeyZone : z },
118
+ },
119
+ },
120
+ })
121
+ Expect (err ).To (BeNil (), "CreateVolume failed with error: %v" , err )
122
+
123
+ // Validate Disk Created
124
+ cloudDisk , err := computeService .Disks .Get (p , z , volName ).Do ()
125
+ Expect (err ).To (BeNil (), "Could not get disk from cloud directly" )
126
+ Expect (cloudDisk .Type ).To (ContainSubstring (standardDiskType ))
127
+ Expect (cloudDisk .Status ).To (Equal (readyState ))
128
+ Expect (cloudDisk .SizeGb ).To (Equal (defaultSizeGb ))
129
+ Expect (cloudDisk .Name ).To (Equal (volName ))
130
+
131
+ defer func () {
132
+ // Delete Disk
133
+ client .DeleteVolume (volID )
134
+ Expect (err ).To (BeNil (), "DeleteVolume failed" )
135
+
136
+ // Validate Disk Deleted
137
+ _ , err = computeService .Disks .Get (p , z , volName ).Do ()
138
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
139
+ }()
140
+
141
+ // Attach Disk
142
+ err = client .ControllerPublishVolume (volID , instance .GetNodeID ())
143
+ Expect (err ).To (BeNil (), "Controller publish volume failed" )
144
+
145
+ defer func () {
146
+ // Detach Disk
147
+ err = client .ControllerUnpublishVolume (volID , instance .GetNodeID ())
148
+ if err != nil {
149
+ klog .Errorf ("Failed to detach disk: %v" , err )
150
+ }
151
+
152
+ }()
153
+
154
+ // Stage Disk
155
+ stageDir := filepath .Join ("/tmp/" , volName , "stage" )
156
+ err = client .NodeStageVolume (volID , stageDir )
157
+ Expect (err ).To (BeNil (), "Node Stage volume failed" )
158
+
159
+ defer func () {
160
+ // Unstage Disk
161
+ err = client .NodeUnstageVolume (volID , stageDir )
162
+ if err != nil {
163
+ klog .Errorf ("Failed to unstage volume: %v" , err )
164
+ }
165
+ fp := filepath .Join ("/tmp/" , volName )
166
+ err = testutils .RmAll (instance , fp )
167
+ if err != nil {
168
+ klog .Errorf ("Failed to rm file path %s: %v" , fp , err )
169
+ }
170
+ }()
171
+
172
+ // Mount Disk
173
+ publishDir := filepath .Join ("/tmp/" , volName , "mount" )
174
+ err = client .NodePublishVolume (volID , stageDir , publishDir )
175
+ Expect (err ).To (BeNil (), "Node publish volume failed" )
176
+
177
+ defer func () {
178
+ // Unmount Disk
179
+ err = client .NodeUnpublishVolume (volID , publishDir )
180
+ if err != nil {
181
+ klog .Errorf ("NodeUnpublishVolume failed with error: %v" , err )
182
+ }
183
+ }()
184
+
185
+ // Verify pre-resize fs size
186
+ sizeGb , err := testutils .GetFSSizeInGb (instance , publishDir )
187
+ Expect (err ).To (BeNil (), "Failed to get FSSize in GB" )
188
+ Expect (sizeGb ).To (Equal (defaultSizeGb ))
189
+
190
+ // Resize controller
191
+ var newSizeGb int64 = 10
192
+ err = client .ControllerExpandVolume (volID , newSizeGb )
193
+
194
+ Expect (err ).To (BeNil (), "Controller expand volume failed" )
195
+
196
+ // Verify cloud size
197
+ cloudDisk , err = computeService .Disks .Get (p , z , volName ).Do ()
198
+ Expect (err ).To (BeNil (), "Get cloud disk failed" )
199
+ Expect (cloudDisk .SizeGb ).To (Equal (newSizeGb ))
200
+
201
+ // Resize node
202
+ err = client .NodeExpandVolume (volID , publishDir , newSizeGb )
203
+ Expect (err ).To (BeNil (), "Node expand volume failed" )
204
+
205
+ // Verify disk size
206
+ sizeGb , err = testutils .GetFSSizeInGb (instance , publishDir )
207
+ Expect (err ).To (BeNil (), "Failed to get FSSize in GB" )
208
+ Expect (sizeGb ).To (Equal (newSizeGb ))
209
+
210
+ })
211
+
101
212
It ("Should create disks in correct zones when topology is specified" , func () {
102
213
Expect (testContexts ).ToNot (BeEmpty ())
103
214
testContext := getRandomTestContext ()
0 commit comments