@@ -59,11 +59,14 @@ const (
5959)
6060
6161var _ = Describe ("DataExports" , label .Slow (), Label (precheck .PrecheckSVDM , precheck .PrecheckSnapshot ), func () {
62- var f * framework.Framework
63-
62+ var (
63+ f * framework.Framework
64+ ctx context.Context
65+ )
6466 BeforeEach (func () {
67+ ctx = context .Background ()
6568 f = framework .NewFramework ("data-exports" )
66- moduleEnabled , err := checkStorageVolumeDataManagerEnabled ()
69+ moduleEnabled , err := checkStorageVolumeDataManagerEnabled (ctx )
6770 Expect (err ).NotTo (HaveOccurred (), "Failed to get modules" )
6871 if ! moduleEnabled {
6972 Skip ("Module 'storage-volume-data-manager' is disabled. Skipping all tests with using this module." )
@@ -92,7 +95,7 @@ var _ = Describe("DataExports", label.Slow(), Label(precheck.PrecheckSVDM, prech
9295 vdbuilder .WithPersistentVolumeClaim (nil , ptr .To (resource .MustParse ("51Mi" ))),
9396 )
9497
95- err := f .CreateWithDeferredDeletion (context . Background () , vdRoot , vdData )
98+ err := f .CreateWithDeferredDeletion (ctx , vdRoot , vdData )
9699 Expect (err ).NotTo (HaveOccurred ())
97100 })
98101
@@ -112,17 +115,17 @@ var _ = Describe("DataExports", label.Slow(), Label(precheck.PrecheckSVDM, prech
112115 vmbuilder .WithProvisioningUserData (object .UbuntuCloudInit ),
113116 )
114117
115- err := f .CreateWithDeferredDeletion (context . Background () , vm )
118+ err := f .CreateWithDeferredDeletion (ctx , vm )
116119 Expect (err ).NotTo (HaveOccurred ())
117120 })
118121
119122 By ("Waiting for VM agent to be ready" , func () {
120- util .UntilVMAgentReady (crclient .ObjectKeyFromObject (vm ), framework .LongTimeout )
123+ util .UntilVMAgentReady (ctx , crclient .ObjectKeyFromObject (vm ), framework .LongTimeout )
121124 })
122125
123126 By ("Writing test data to the data disk" , func () {
124- util .CreateBlockDeviceFilesystem (f , vm , v1alpha2 .DiskDevice , vdData .Name , "ext4" )
125- util .MountBlockDevice (f , vm , v1alpha2 .DiskDevice , vdData .Name , mountPointData )
127+ util .CreateBlockDeviceFilesystem (ctx , f , vm , v1alpha2 .DiskDevice , vdData .Name , "ext4" )
128+ util .MountBlockDevice (ctx , f , vm , v1alpha2 .DiskDevice , vdData .Name , mountPointData )
126129 util .WriteFile (f , vm , fileDataPath , testFileValue )
127130 util .UnmountBlockDevice (f , vm , mountPointData )
128131 })
@@ -134,11 +137,11 @@ var _ = Describe("DataExports", label.Slow(), Label(precheck.PrecheckSVDM, prech
134137 vmopbuilder .WithType (v1alpha2 .VMOPTypeStop ),
135138 vmopbuilder .WithVirtualMachine (vm .Name ),
136139 )
137- err := f .CreateWithDeferredDeletion (context . Background () , vmopStop )
140+ err := f .CreateWithDeferredDeletion (ctx , vmopStop )
138141 Expect (err ).NotTo (HaveOccurred ())
139142
140- util .UntilObjectPhase (string (v1alpha2 .VMOPPhaseCompleted ), framework .LongTimeout , vmopStop )
141- util .UntilObjectPhase (string (v1alpha2 .MachineStopped ), framework .ShortTimeout , vm )
143+ util .UntilObjectPhase (ctx , string (v1alpha2 .VMOPPhaseCompleted ), framework .LongTimeout , vmopStop )
144+ util .UntilObjectPhase (ctx , string (v1alpha2 .MachineStopped ), framework .ShortTimeout , vm )
142145 })
143146
144147 By ("Creating snapshot of the data disk" , func () {
@@ -149,26 +152,26 @@ var _ = Describe("DataExports", label.Slow(), Label(precheck.PrecheckSVDM, prech
149152 vdsnapshotbuilder .WithRequiredConsistency (true ),
150153 )
151154
152- err := f .CreateWithDeferredDeletion (context . Background () , vdSnapshot )
155+ err := f .CreateWithDeferredDeletion (ctx , vdSnapshot )
153156 Expect (err ).NotTo (HaveOccurred ())
154- util .UntilObjectPhase (string (v1alpha2 .VirtualDiskSnapshotPhaseReady ), framework .ShortTimeout , vdSnapshot )
157+ util .UntilObjectPhase (ctx , string (v1alpha2 .VirtualDiskSnapshotPhaseReady ), framework .ShortTimeout , vdSnapshot )
155158 })
156159
157160 By ("Exporting VirtualDisk to local file" , func () {
158- exportData (f , "vd" , vdData .Name , exportedDiskFile )
161+ exportData (ctx , f , "vd" , vdData .Name , exportedDiskFile )
159162 })
160163
161164 By ("Exporting VirtualDiskSnapshot to local file" , func () {
162- exportData (f , "vds" , vdSnapshot .Name , exportedSnapshotFile )
165+ exportData (ctx , f , "vds" , vdSnapshot .Name , exportedSnapshotFile )
163166 })
164167
165168 By ("Deleting the original data disk" , func () {
166- err := f .Delete (context . Background () , vdData )
169+ err := f .Delete (ctx , vdData )
167170 Expect (err ).NotTo (HaveOccurred ())
168171
169172 Eventually (func (g Gomega ) {
170173 var vd v1alpha2.VirtualDisk
171- err := f .Clients .GenericClient ().Get (context . Background () , types.NamespacedName {
174+ err := f .Clients .GenericClient ().Get (ctx , types.NamespacedName {
172175 Namespace : vdData .Namespace ,
173176 Name : vdData .Name ,
174177 }, & vd )
@@ -178,31 +181,31 @@ var _ = Describe("DataExports", label.Slow(), Label(precheck.PrecheckSVDM, prech
178181 })
179182
180183 By ("Creating disk from exported VirtualDisk" , func () {
181- vdFromDiskExport = createUploadDisk (f , "vd-restored-from-disk" )
184+ vdFromDiskExport = createUploadDisk (ctx , f , "vd-restored-from-disk" )
182185 })
183186
184187 By ("Uploading exported disk image" , func () {
185- uploadFile (f , vdFromDiskExport , exportedDiskFile )
188+ uploadFile (ctx , f , vdFromDiskExport , exportedDiskFile )
186189 })
187190
188191 By ("Waiting for disk from VirtualDisk export to be ready" , func () {
189- util .UntilObjectPhase (util .GetExpectedDiskPhaseByVolumeBindingMode (), framework .LongTimeout , vdFromDiskExport )
192+ util .UntilObjectPhase (ctx , util .GetExpectedDiskPhaseByVolumeBindingMode (), framework .LongTimeout , vdFromDiskExport )
190193 })
191194
192195 By ("Creating disk from exported VirtualDiskSnapshot" , func () {
193- vdFromSnapshotExport = createUploadDisk (f , "vd-restored-from-snapshot" )
196+ vdFromSnapshotExport = createUploadDisk (ctx , f , "vd-restored-from-snapshot" )
194197 })
195198
196199 By ("Uploading exported snapshot image" , func () {
197- uploadFile (f , vdFromSnapshotExport , exportedSnapshotFile )
200+ uploadFile (ctx , f , vdFromSnapshotExport , exportedSnapshotFile )
198201 })
199202
200203 By ("Waiting for disk from snapshot export to be ready" , func () {
201- util .UntilObjectPhase (util .GetExpectedDiskPhaseByVolumeBindingMode (), framework .LongTimeout , vdFromSnapshotExport )
204+ util .UntilObjectPhase (ctx , util .GetExpectedDiskPhaseByVolumeBindingMode (), framework .LongTimeout , vdFromSnapshotExport )
202205 })
203206
204207 By ("Attaching restored disks to VM" , func () {
205- err := f .Clients .GenericClient ().Get (context . Background () , crclient .ObjectKeyFromObject (vm ), vm )
208+ err := f .Clients .GenericClient ().Get (ctx , crclient .ObjectKeyFromObject (vm ), vm )
206209 Expect (err ).NotTo (HaveOccurred ())
207210
208211 vm .Spec .BlockDeviceRefs = []v1alpha2.BlockDeviceSpecRef {
@@ -211,24 +214,24 @@ var _ = Describe("DataExports", label.Slow(), Label(precheck.PrecheckSVDM, prech
211214 {Kind : v1alpha2 .DiskDevice , Name : vdFromSnapshotExport .Name },
212215 }
213216
214- err = f .Clients .GenericClient ().Update (context . Background () , vm )
217+ err = f .Clients .GenericClient ().Update (ctx , vm )
215218 Expect (err ).NotTo (HaveOccurred ())
216219 })
217220
218221 By ("Starting the VM" , func () {
219- util .StartVirtualMachine (f , vm )
220- util .UntilVMAgentReady (crclient .ObjectKeyFromObject (vm ), framework .LongTimeout )
222+ util .StartVirtualMachine (ctx , f , vm )
223+ util .UntilVMAgentReady (ctx , crclient .ObjectKeyFromObject (vm ), framework .LongTimeout )
221224 })
222225
223226 By ("Verifying data on disk restored from VirtualDisk export" , func () {
224- util .MountBlockDevice (f , vm , v1alpha2 .DiskDevice , vdFromDiskExport .Name , mountPointData )
227+ util .MountBlockDevice (ctx , f , vm , v1alpha2 .DiskDevice , vdFromDiskExport .Name , mountPointData )
225228 restoredValue := util .ReadFile (f , vm , fileDataPath )
226229 Expect (restoredValue ).To (Equal (testFileValue ), "Data should match original" )
227230 util .UnmountBlockDevice (f , vm , mountPointData )
228231 })
229232
230233 By ("Verifying data on disk restored from VirtualDiskSnapshot export" , func () {
231- util .MountBlockDevice (f , vm , v1alpha2 .DiskDevice , vdFromSnapshotExport .Name , mountPointData )
234+ util .MountBlockDevice (ctx , f , vm , v1alpha2 .DiskDevice , vdFromSnapshotExport .Name , mountPointData )
232235 restoredValue := util .ReadFile (f , vm , fileDataPath )
233236 Expect (restoredValue ).To (Equal (testFileValue ), "Data should match original" )
234237 util .UnmountBlockDevice (f , vm , mountPointData )
@@ -244,12 +247,12 @@ func IsNFS() bool {
244247 return sc .Provisioner == framework .NFS
245248}
246249
247- func needPublishOption (f * framework.Framework ) bool {
250+ func needPublishOption (ctx context. Context , f * framework.Framework ) bool {
248251 hostname , err := os .Hostname ()
249252 Expect (err ).NotTo (HaveOccurred (), "Failed to get hostname" )
250253 var node corev1.Node
251254 err = f .Clients .GenericClient ().Get (
252- context . Background () ,
255+ ctx ,
253256 types.NamespacedName {Name : hostname },
254257 & node ,
255258 )
@@ -260,11 +263,11 @@ func needPublishOption(f *framework.Framework) bool {
260263 return false
261264}
262265
263- func exportData (f * framework.Framework , resourceType , name , outputFile string ) {
266+ func exportData (ctx context. Context , f * framework.Framework , resourceType , name , outputFile string ) {
264267 opts := d8.DataExportOptions {
265268 Namespace : f .Namespace ().Name ,
266269 OutputFile : outputFile ,
267- Publish : needPublishOption (f ),
270+ Publish : needPublishOption (ctx , f ),
268271 Timeout : framework .LongTimeout ,
269272 Cleanup : true ,
270273 }
@@ -280,7 +283,7 @@ func exportData(f *framework.Framework, resourceType, name, outputFile string) {
280283 })
281284}
282285
283- func createUploadDisk (f * framework.Framework , name string ) * v1alpha2.VirtualDisk {
286+ func createUploadDisk (ctx context. Context , f * framework.Framework , name string ) * v1alpha2.VirtualDisk {
284287 vd := vdbuilder .New (
285288 vdbuilder .WithName (name ),
286289 vdbuilder .WithNamespace (f .Namespace ().Name ),
@@ -289,15 +292,15 @@ func createUploadDisk(f *framework.Framework, name string) *v1alpha2.VirtualDisk
289292 }),
290293 )
291294
292- err := f .CreateWithDeferredDeletion (context . Background () , vd )
295+ err := f .CreateWithDeferredDeletion (ctx , vd )
293296 Expect (err ).NotTo (HaveOccurred ())
294- util .UntilObjectPhase (string (v1alpha2 .DiskWaitForUserUpload ), framework .LongTimeout , vd )
297+ util .UntilObjectPhase (ctx , string (v1alpha2 .DiskWaitForUserUpload ), framework .LongTimeout , vd )
295298
296299 return vd
297300}
298301
299- func uploadFile (f * framework.Framework , vd * v1alpha2.VirtualDisk , filePath string ) {
300- err := f .Clients .GenericClient ().Get (context . Background () , crclient .ObjectKeyFromObject (vd ), vd )
302+ func uploadFile (ctx context. Context , f * framework.Framework , vd * v1alpha2.VirtualDisk , filePath string ) {
303+ err := f .Clients .GenericClient ().Get (ctx , crclient .ObjectKeyFromObject (vd ), vd )
301304 Expect (err ).NotTo (HaveOccurred ())
302305 Expect (vd .Status .ImageUploadURLs ).NotTo (BeNil (), "ImageUploadURLs should be set" )
303306 Expect (vd .Status .ImageUploadURLs .External ).NotTo (BeEmpty (), "External upload URL should be set" )
@@ -366,8 +369,8 @@ func handleUploadResponse(resp *http.Response) error {
366369 return fmt .Errorf ("upload failed with status %d: %s" , resp .StatusCode , body )
367370}
368371
369- func checkStorageVolumeDataManagerEnabled () (bool , error ) {
370- sdnModule , err := framework .NewFramework ("" ).GetModuleConfig (context . Background () , "storage-volume-data-manager" )
372+ func checkStorageVolumeDataManagerEnabled (ctx context. Context ) (bool , error ) {
373+ sdnModule , err := framework .NewFramework ("" ).GetModuleConfig (ctx , "storage-volume-data-manager" )
371374 if err != nil {
372375 return false , err
373376 }
0 commit comments