forked from thecodeteam/goisilon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume_test.go
834 lines (761 loc) · 24.8 KB
/
volume_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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
package goisilon
import (
"bytes"
"context"
"fmt"
"os"
"path"
"testing"
"github.com/stretchr/testify/assert"
apiv2 "github.com/thecodeteam/goisilon/api/v2"
)
func TestVolumeList(*testing.T) {
volumeName1 := "test_get_volumes_name1"
volumeName2 := "test_get_volumes_name2"
// identify all volumes on the cluster
volumeMap := make(map[string]bool)
volumes, err := client.GetVolumes(defaultCtx)
if err != nil {
panic(err)
}
for _, volume := range volumes {
volumeMap[volume.Name] = true
}
initialVolumeCount := len(volumes)
// Add the test volumes
testVolume1, err := client.CreateVolume(defaultCtx, volumeName1)
if err != nil {
panic(err)
}
testVolume2, err := client.CreateVolume(defaultCtx, volumeName2)
if err != nil {
panic(err)
}
// make sure we clean up when we're done
defer client.DeleteVolume(defaultCtx, volumeName1)
defer client.DeleteVolume(defaultCtx, volumeName2)
// get the updated volume list
volumes, err = client.GetVolumes(defaultCtx)
if err != nil {
panic(err)
}
// verify that the new volumes are there as well as all the old volumes.
if len(volumes) != initialVolumeCount+2 {
panic(fmt.Sprintf("Incorrect number of volumes. Expected: %d Actual: %d\n", initialVolumeCount+2, len(volumes)))
}
// remove the original volumes and add the new ones. in the end, we
// should only have the volumes we just created and nothing more.
for _, volume := range volumes {
if _, found := volumeMap[volume.Name]; found == true {
// this volume existed prior to the test start
delete(volumeMap, volume.Name)
} else {
// this volume is new
volumeMap[volume.Name] = true
}
}
if len(volumeMap) != 2 {
panic(fmt.Sprintf("Incorrect number of new volumes. Expected: 2 Actual: %d\n", len(volumeMap)))
}
if _, found := volumeMap[testVolume1.Name]; found == false {
panic(fmt.Sprintf("testVolume1 was not in the volume list\n"))
}
if _, found := volumeMap[testVolume2.Name]; found == false {
panic(fmt.Sprintf("testVolume2 was not in the volume list\n"))
}
}
func TestVolumeGetCreate(*testing.T) {
volumeName := "test_get_create_volume_name"
// make sure the volume doesn't exist yet
volume, err := client.GetVolume(defaultCtx, volumeName, volumeName)
if err == nil && volume != nil {
panic(fmt.Sprintf("Volume (%s) already exists.\n", volumeName))
}
// Add the test volume
testVolume, err := client.CreateVolume(defaultCtx, volumeName)
if err != nil {
panic(err)
}
// make sure we clean up when we're done
defer client.DeleteVolume(defaultCtx, testVolume.Name)
// get the new volume
volume, err = client.GetVolume(defaultCtx, volumeName, volumeName)
if err != nil {
panic(err)
}
if volume == nil {
panic(fmt.Sprintf("Volume (%s) was not created.\n", volumeName))
}
if volume.Name != volumeName {
panic(fmt.Sprintf("Volume name not set properly. Expected: (%s) Actual: (%s)\n", volumeName, volume.Name))
}
}
func TestVolumeDelete(*testing.T) {
volumeName := "test_remove_volume_name"
// make sure the volume exists
client.CreateVolume(defaultCtx, volumeName)
volume, err := client.GetVolume(defaultCtx, volumeName, volumeName)
if err != nil {
panic(err)
}
if volume == nil {
panic(fmt.Sprintf("Test not setup properly. No test volume (%s).", volumeName))
}
// remove the volume
err = client.DeleteVolume(defaultCtx, volumeName)
if err != nil {
panic(err)
}
// make sure the volume was removed
volume, err = client.GetVolume(defaultCtx, volumeName, volumeName)
if err == nil {
panic(fmt.Sprintf("Attempting to get a removed volume should return an error but returned nil"))
}
if volume != nil {
panic(fmt.Sprintf("Volume (%s) was not removed.\n%+v\n", volumeName, volume))
}
}
func TestVolumeCopy(*testing.T) {
sourceVolumeName := "test_copy_source_volume_name"
destinationVolumeName := "test_copy_destination_volume_name"
subDirectoryName := "test_sub_directory"
sourceSubDirectoryPath := fmt.Sprintf("%s/%s", sourceVolumeName, subDirectoryName)
destinationSubDirectoryPath := fmt.Sprintf("%s/%s", destinationVolumeName, subDirectoryName)
// make sure the destination volume doesn't exist yet
destinationVolume, err := client.GetVolume(
defaultCtx, destinationVolumeName, destinationVolumeName)
if err == nil && destinationVolume != nil {
panic(fmt.Sprintf("Volume (%s) already exists.\n", destinationVolumeName))
}
// Add the test volume
sourceTestVolume, err := client.CreateVolume(defaultCtx, sourceVolumeName)
if err != nil {
panic(err)
}
// make sure we clean up when we're done
defer client.DeleteVolume(defaultCtx, sourceTestVolume.Name)
// add a sub directory to the source volume
_, err = client.CreateVolume(defaultCtx, sourceSubDirectoryPath)
if err != nil {
panic(err)
}
// copy the source volume to the test volume
destinationTestVolume, err := client.CopyVolume(
defaultCtx, sourceVolumeName, destinationVolumeName)
if err != nil {
panic(err)
}
defer client.DeleteVolume(defaultCtx, destinationTestVolume.Name)
// verify the copied volume is the same as the source volume
if destinationTestVolume == nil {
panic(fmt.Sprintf("Destination volume (%s) was not created.\n", destinationVolumeName))
}
if destinationTestVolume.Name != destinationVolumeName {
panic(fmt.Sprintf("Destination volume name not set properly. Expected: (%s) Actual: (%s)\n", destinationVolumeName, destinationTestVolume.Name))
}
// make sure the destination volume contains the sub-directory
subTestVolume, err := client.GetVolume(
defaultCtx, "", destinationSubDirectoryPath)
if err != nil {
panic(err)
}
// verify the copied subdirectory is the same as int the source volume
if subTestVolume == nil {
panic(fmt.Sprintf("Destination sub directory (%s) was not created.\n", subDirectoryName))
}
if subTestVolume.Name != destinationSubDirectoryPath {
panic(fmt.Sprintf("Destination sub directory name not set properly. Expected: (%s) Actual: (%s)\n", destinationSubDirectoryPath, subTestVolume.Name))
}
}
func TestVolumeExport(*testing.T) {
// TODO: Make this more robust
_, err := client.ExportVolume(defaultCtx, "testing")
if err != nil {
panic(err)
}
}
func TestVolumeUnexport(*testing.T) {
// TODO: Make this more robust
err := client.UnexportVolume(defaultCtx, "testing")
if err != nil {
panic(err)
}
}
func TestVolumePath(*testing.T) {
// TODO: Make this more robust
fmt.Println(client.API.VolumePath("testing"))
}
func TestVolumeGetExportMap(t *testing.T) {
// TODO: Make this more robust
volExMap, err := client.GetVolumeExportMap(defaultCtx, false)
assertNoError(t, err)
for v := range volExMap {
t.Logf("volName=%s, volPath=%s", v.Name, client.API.VolumePath(v.Name))
}
}
func TestVolumeQueryChildren(t *testing.T) {
var (
ctx = defaultCtx
//context.WithValue(defaultCtx, log.LevelKey(), log.InfoLevel)
err error
volume Volume
children VolumeChildrenMap
volumeName = "test_volume_query_children"
dirPath0 = "dA"
dirPath0a = "dA/dAA"
dirPath1 = "dA/dAA/dAAA"
dirPath2 = "dB/dBB"
dirPath3 = "dC"
dirPath4 = "dC/dCC"
fileName0 = "an_empty_file"
fileName1 = fileName0
fileName2 = fileName0
fileName3 = fileName0
volDirPath0 = path.Join(volumeName, dirPath0)
volDirPath0a = path.Join(volumeName, dirPath0a)
volDirPath1 = path.Join(volumeName, dirPath1)
volDirPath2 = path.Join(volumeName, dirPath2)
volDirPath3 = path.Join(volumeName, dirPath3)
volDirPath4 = path.Join(volumeName, dirPath4)
volFilePath0 = path.Join(volumeName, fileName0)
volFilePath1 = path.Join(volDirPath2, fileName1)
volFilePath2 = path.Join(volDirPath3, fileName2)
volFilePath3 = path.Join(volDirPath4, fileName3)
dirPath0Key = path.Join(client.API.VolumePath(volumeName), dirPath0)
dirPath0aKey = path.Join(client.API.VolumePath(volumeName), dirPath0a)
dirPath1Key = path.Join(client.API.VolumePath(volumeName), dirPath1)
dirPath2Key = path.Join(client.API.VolumePath(volumeName), dirPath2)
dirPath3Key = path.Join(client.API.VolumePath(volumeName), dirPath3)
dirPath4Key = path.Join(client.API.VolumePath(volumeName), dirPath4)
filePath0Key = path.Join(client.API.VolumePath(volumeName), fileName0)
filePath1Key = path.Join(dirPath2Key, fileName1)
filePath2Key = path.Join(dirPath3Key, fileName2)
filePath3Key = path.Join(dirPath4Key, fileName3)
newUserName = client.API.User()
newGroupName = newUserName
badUserID = "999"
badGroupID = "999"
badUserName = "Unknown User"
badGroupName = "Unknown Group"
volChildCount = 9
newDirMode = apiv2.FileMode(0755)
newFileMode = apiv2.FileMode(0644)
badDirMode = apiv2.FileMode(0700)
badFileMode = apiv2.FileMode(0400)
newDirACL = &apiv2.ACL{
Action: &apiv2.PActionTypeReplace,
Authoritative: &apiv2.PAuthoritativeTypeMode,
Owner: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: newUserName,
Type: apiv2.PersonaIDTypeUser,
},
},
Group: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: newGroupName,
Type: apiv2.PersonaIDTypeGroup,
},
},
Mode: &newDirMode,
}
newFileACL = &apiv2.ACL{
Action: &apiv2.PActionTypeReplace,
Authoritative: &apiv2.PAuthoritativeTypeMode,
Owner: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: newUserName,
Type: apiv2.PersonaIDTypeUser,
},
},
Group: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: newGroupName,
Type: apiv2.PersonaIDTypeGroup,
},
},
Mode: &newFileMode,
}
badDirACL = &apiv2.ACL{
Action: &apiv2.PActionTypeReplace,
Authoritative: &apiv2.PAuthoritativeTypeMode,
Owner: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: badUserID,
Type: apiv2.PersonaIDTypeUID,
},
},
Group: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: badGroupID,
Type: apiv2.PersonaIDTypeGID,
},
},
Mode: &badDirMode,
}
badFileACL = &apiv2.ACL{
Action: &apiv2.PActionTypeReplace,
Authoritative: &apiv2.PAuthoritativeTypeMode,
Owner: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: badUserID,
Type: apiv2.PersonaIDTypeUID,
},
},
Group: &apiv2.Persona{
ID: &apiv2.PersonaID{
ID: badGroupID,
Type: apiv2.PersonaIDTypeGID,
},
},
Mode: &badFileMode,
}
)
defer client.ForceDeleteVolume(ctx, volumeName)
setACLsWithPaths := func(
ctx context.Context, acl *apiv2.ACL, paths ...string) {
for _, p := range paths {
assertNoError(
t,
apiv2.ACLUpdate(ctx, client.API, p, acl))
}
}
assertNewFileACL := func(cm map[string]*apiv2.ContainerChild, k string) {
if !assert.Equal(t, newFileMode, *cm[k].Mode) ||
!assert.Equal(t, newUserName, *cm[k].Owner) ||
!assert.Equal(t, newGroupName, *cm[k].Group) {
t.FailNow()
}
}
assertBadFileACL := func(cm map[string]*apiv2.ContainerChild, k string) {
if !assert.Equal(t, badFileMode, *cm[k].Mode) ||
!assert.Equal(t, badUserName, *cm[k].Owner) ||
!assert.Equal(t, badGroupName, *cm[k].Group) {
t.FailNow()
}
}
assertNewDirACL := func(cm map[string]*apiv2.ContainerChild, k string) {
if !assert.Equal(t, newDirMode, *cm[k].Mode) ||
!assert.Equal(t, newUserName, *cm[k].Owner) ||
!assert.Equal(t, newGroupName, *cm[k].Group) {
t.FailNow()
}
}
assertBadDirACL := func(cm map[string]*apiv2.ContainerChild, k string) {
if !assert.Equal(t, badDirMode, *cm[k].Mode) ||
!assert.Equal(t, badUserName, *cm[k].Owner) ||
!assert.Equal(t, badGroupName, *cm[k].Group) {
t.FailNow()
}
}
createObjs := func(ctx context.Context, createType int) {
// make sure the volume exists
client.CreateVolume(ctx, volumeName)
volume, err = client.GetVolume(ctx, volumeName, volumeName)
assertNoError(t, err)
assertNotNil(t, volume)
// assert the volume has no children
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 0)
switch createType {
case 0:
// create dirPath1
assertError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath1,
os.FileMode(newDirMode),
false,
false))
// create dirPath1 again, recursively
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath1,
os.FileMode(newDirMode),
false,
true))
// create the second directory path
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath2,
os.FileMode(newDirMode),
true,
true))
// create file0
assertNoError(t, apiv2.ContainerCreateFile(
ctx,
client.API,
volumeName,
fileName0,
0,
newFileMode,
&bufReadCloser{&bytes.Buffer{}},
false))
// create file1
assertNoError(t, apiv2.ContainerCreateFile(
ctx,
client.API,
volDirPath2,
fileName1,
0,
newFileMode,
&bufReadCloser{&bytes.Buffer{}},
false))
// try and create file1 again; should fail
assertError(t, apiv2.ContainerCreateFile(
ctx,
client.API,
volDirPath2,
fileName1,
0,
newFileMode,
&bufReadCloser{&bytes.Buffer{}},
false))
// try and create file1 again; should work
assertNoError(t, apiv2.ContainerCreateFile(
ctx,
client.API,
volDirPath2,
fileName1,
0,
newFileMode,
&bufReadCloser{&bytes.Buffer{}},
true))
// create the third directory path
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath4,
os.FileMode(newDirMode),
true,
true))
setACLsWithPaths(
ctx, newDirACL,
volDirPath0, volDirPath1, volDirPath2, volDirPath3, volDirPath4)
setACLsWithPaths(ctx, newFileACL, volFilePath0, volFilePath1)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, volChildCount)
assertNewDirACL(children, dirPath0Key)
assertNewDirACL(children, dirPath1Key)
assertNewDirACL(children, dirPath2Key)
assertNewDirACL(children, dirPath3Key)
assertNewDirACL(children, dirPath4Key)
assertNewFileACL(children, filePath0Key)
assertNewFileACL(children, filePath1Key)
case 1:
// test a single root dir with good perms that has an empty sub-dir
// with bad perms
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath4,
os.FileMode(newDirMode),
true,
true))
setACLsWithPaths(ctx, newDirACL, volDirPath3, volDirPath4)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 2)
assertNewDirACL(children, dirPath3Key)
assertNewDirACL(children, dirPath4Key)
case 2:
// test a single, empty root dir with bad perms
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath3,
os.FileMode(newDirMode),
true,
true))
setACLsWithPaths(ctx, newDirACL, volDirPath3)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 1)
assertNewDirACL(children, dirPath3Key)
case 3:
// test a single, root dir with bad perms that has a single file in
// it where the file has good perms
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath3,
os.FileMode(newDirMode),
true,
true))
assertNoError(t, apiv2.ContainerCreateFile(
ctx,
client.API,
volDirPath3,
fileName2,
0,
newFileMode,
&bufReadCloser{&bytes.Buffer{}},
true))
setACLsWithPaths(ctx, newFileACL, volFilePath2)
setACLsWithPaths(ctx, newDirACL, volDirPath3)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 2)
assertNewDirACL(children, dirPath3Key)
assertNewFileACL(children, filePath2Key)
case 4:
// test a single, root dir with bad perms that has a single sub-dir
// with good perms, and the sub-dir contains a file with good perms
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath4,
os.FileMode(newDirMode),
true,
true))
assertNoError(t, apiv2.ContainerCreateFile(
ctx,
client.API,
volDirPath4,
fileName3,
0,
newFileMode,
&bufReadCloser{&bytes.Buffer{}},
true))
setACLsWithPaths(ctx, newFileACL, volFilePath3)
setACLsWithPaths(ctx, newDirACL, volDirPath3, volDirPath4)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertNewDirACL(children, dirPath3Key)
assertNewDirACL(children, dirPath4Key)
assertNewFileACL(children, filePath3Key)
case 5:
// test a single, root dir with good perms that has a single sub-dir
// with bad perms, and the sub-dir contains a file with good perms
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath4,
os.FileMode(newDirMode),
true,
true))
assertNoError(t, apiv2.ContainerCreateFile(
ctx,
client.API,
volDirPath4,
fileName3,
0,
newFileMode,
&bufReadCloser{&bytes.Buffer{}},
true))
setACLsWithPaths(ctx, newFileACL, volFilePath3)
setACLsWithPaths(ctx, newDirACL, volDirPath3, volDirPath4)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertNewDirACL(children, dirPath3Key)
assertNewDirACL(children, dirPath4Key)
assertNewFileACL(children, filePath3Key)
case 6:
// test /dA/dAA/dAAA where dA has bad perms; the volume delete
// should fail
assertNoError(t, client.CreateVolumeDir(
ctx,
volumeName,
dirPath1,
os.FileMode(newDirMode),
true,
true))
}
}
// assert that ForceDeleteVolume works
createObjs(ctx, 0)
setACLsWithPaths(ctx, badFileACL, volFilePath0, volFilePath1)
setACLsWithPaths(ctx,
badDirACL, volDirPath4, volDirPath3, volDirPath1, volDirPath0)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, volChildCount)
assertBadDirACL(children, dirPath0Key)
assertBadDirACL(children, dirPath1Key)
assertBadDirACL(children, dirPath3Key)
assertBadDirACL(children, dirPath4Key)
assertBadFileACL(children, filePath0Key)
assertBadFileACL(children, filePath1Key)
// force delete the volume
assertNoError(t, client.ForceDeleteVolume(ctx, volumeName))
// assert that an initial delete will result in the removal of files
// and directories not in conflict
createObjs(ctx, 0)
setACLsWithPaths(ctx, badFileACL, volFilePath0, volFilePath1)
setACLsWithPaths(ctx,
badDirACL, volDirPath4, volDirPath3, volDirPath1, volDirPath0)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, volChildCount)
assertBadDirACL(children, dirPath0Key)
assertBadDirACL(children, dirPath1Key)
assertBadDirACL(children, dirPath3Key)
assertBadDirACL(children, dirPath4Key)
assertBadFileACL(children, filePath0Key)
assertBadFileACL(children, filePath1Key)
// attempt to delete the volume; should fail, but the following paths
// will have been removed:
//
// - /dB
// - /dB/dBB
// - /dB/dBB/an_empty_file
// - /an_empty_file
assertError(t, client.DeleteVolume(ctx, volumeName))
setACLsWithPaths(
ctx, newDirACL,
volDirPath0, volDirPath1, volDirPath3, volDirPath4)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, volChildCount-4)
assertNewDirACL(children, dirPath0Key)
assertNewDirACL(children, dirPath1Key)
assertNewDirACL(children, dirPath3Key)
assertNewDirACL(children, dirPath4Key)
// attempt to delete the volume; should succeed
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert that a file with bad perms deep in the hierarchy won't prevent
// a delete
createObjs(ctx, 0)
setACLsWithPaths(ctx, badFileACL, volFilePath1)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, volChildCount)
assertBadFileACL(children, filePath1Key)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert that a root file with bad perms will not prevent a delete
createObjs(ctx, 0)
setACLsWithPaths(ctx, badFileACL, volFilePath0)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, volChildCount)
assertBadFileACL(children, filePath0Key)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert that a root-directory with an empty sub-dir with bad perms will
// not prevent a delete
createObjs(ctx, 1)
setACLsWithPaths(ctx, badDirACL, volDirPath4)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 2)
assertBadDirACL(children, dirPath4Key)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert that an empty root-directory with bad perms will not prevent a
// delete
createObjs(ctx, 2)
setACLsWithPaths(ctx, badDirACL, volDirPath3)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 1)
assertBadDirACL(children, dirPath3Key)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert that a root-directory with bad perms that contains a file with
// good perms will prevent a delete
createObjs(ctx, 3)
setACLsWithPaths(ctx, badDirACL, volDirPath3)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 2)
assertBadDirACL(children, dirPath3Key)
assertNewFileACL(children, filePath2Key)
assertError(t, client.DeleteVolume(ctx, volumeName))
setACLsWithPaths(ctx, newDirACL, volDirPath3)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert the previous scenario will be handled by a force delete
createObjs(ctx, 3)
setACLsWithPaths(ctx, badDirACL, volDirPath3)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 2)
assertBadDirACL(children, dirPath3Key)
assertNewFileACL(children, filePath2Key)
assertNoError(t, client.ForceDeleteVolume(ctx, volumeName))
// assert that a root-directory with bad perms that contains a sub-dir
// with good perms that contains a file with good perms prevents a
// delete
createObjs(ctx, 4)
setACLsWithPaths(ctx, badDirACL, volDirPath3)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertBadDirACL(children, dirPath3Key)
assertNewDirACL(children, dirPath4Key)
assertNewFileACL(children, filePath3Key)
assertError(t, client.DeleteVolume(ctx, volumeName))
setACLsWithPaths(ctx, newDirACL, volDirPath3)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert the previous scenario will be handled by a force delete
createObjs(ctx, 4)
setACLsWithPaths(ctx, badDirACL, volDirPath3)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertBadDirACL(children, dirPath3Key)
assertNewDirACL(children, dirPath4Key)
assertNewFileACL(children, filePath3Key)
assertNoError(t, client.ForceDeleteVolume(ctx, volumeName))
// assert a single, root dir with good perms that has a single sub-dir
// with bad perms, and the sub-dir contains a file with good perms prevents
// a delete
createObjs(ctx, 5)
setACLsWithPaths(ctx, badDirACL, volDirPath4)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertNewDirACL(children, dirPath3Key)
assertBadDirACL(children, dirPath4Key)
assertNewFileACL(children, filePath3Key)
assertError(t, client.DeleteVolume(ctx, volumeName))
setACLsWithPaths(ctx, newDirACL, volDirPath4)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert the previous scenario will be handled by a force delete
createObjs(ctx, 5)
setACLsWithPaths(ctx, badDirACL, volDirPath4)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertNewDirACL(children, dirPath3Key)
assertBadDirACL(children, dirPath4Key)
assertNewFileACL(children, filePath3Key)
assertNoError(t, client.ForceDeleteVolume(ctx, volumeName))
// test /dA/dAA/dAAA where dA has bad perms; the volume delete
// should fail
createObjs(ctx, 6)
setACLsWithPaths(ctx, badDirACL, volDirPath0a)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertNewDirACL(children, dirPath0Key)
assertBadDirACL(children, dirPath0aKey)
assertNewDirACL(children, dirPath1Key)
assertError(t, client.DeleteVolume(ctx, volumeName))
setACLsWithPaths(ctx, newDirACL, volDirPath0a)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertNoError(t, client.DeleteVolume(ctx, volumeName))
// assert the previous scenario will be handled by a force delete
createObjs(ctx, 6)
setACLsWithPaths(ctx, badDirACL, volDirPath0a)
children, err = client.QueryVolumeChildren(ctx, volumeName)
assertNoError(t, err)
assertLen(t, children, 3)
assertNewDirACL(children, dirPath0Key)
assertBadDirACL(children, dirPath0aKey)
assertNewDirACL(children, dirPath1Key)
assertNoError(t, client.ForceDeleteVolume(ctx, volumeName))
}
type bufReadCloser struct {
b *bytes.Buffer
}
func (b *bufReadCloser) Read(p []byte) (n int, err error) {
return b.b.Read(p)
}
func (b *bufReadCloser) Close() error {
return nil
}