-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgce_test.go
More file actions
830 lines (811 loc) · 25.5 KB
/
Copy pathgce_test.go
File metadata and controls
830 lines (811 loc) · 25.5 KB
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
package storagemanager
import (
"fmt"
"github.com/libopenstorage/openstorage/api"
"reflect"
"testing"
"github.com/libopenstorage/cloudops"
"github.com/libopenstorage/cloudops/pkg/parser"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)
const (
testSpecPath = "testspecs/gce.yaml"
)
var (
storageManager cloudops.StorageManager
)
type updateTestInput struct {
expectedErr error
request *cloudops.StoragePoolUpdateRequest
response *cloudops.StoragePoolUpdateResponse
}
func TestGCEStorageManager(t *testing.T) {
t.Run("setup", setup)
t.Run("storageDistribution", storageDistribution)
t.Run("storageUpdate", storageUpdate)
}
func setup(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
decisionMatrix, err := parser.NewStorageDecisionMatrixParser().UnmarshalFromYaml(testSpecPath)
require.NoError(t, err, "Unexpected error on yaml parser")
storageManager, err = NewStorageManager(*decisionMatrix)
require.NoError(t, err, "Unexpected error on creating GCE storage manager")
}
func storageDistribution(t *testing.T) {
testMatrix := []struct {
expectedErr error
request *cloudops.StorageDistributionRequest
response *cloudops.StorageDistributionResponse
}{
{
// Test1: chose the right size of disk giving the highest priority to IOPS
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 1000,
MinCapacity: 1024,
MaxCapacity: 4096,
},
},
InstanceType: "foo",
InstancesPerZone: 1,
ZoneCount: 1,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 1267,
DriveType: GCEDriveTypeStandard,
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 951,
},
},
},
expectedErr: nil,
},
// Test2: choose the right size of the disk by updating the instances per zone
// in case of a conflict with two configurations providing the same IOPS
// and min capacity choose based of priority.
{
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 500,
MinCapacity: 1024,
MaxCapacity: 100000,
},
},
InstanceType: GCEDriveTypeStandard,
InstancesPerZone: 3,
ZoneCount: 3,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 600,
DriveType: GCEDriveTypeStandard,
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 450,
},
},
},
expectedErr: nil,
},
{
// Test3: user wants 1TiB on all the nodes
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 2900,
MinCapacity: 9216,
MaxCapacity: 100000,
},
},
InstanceType: "foo",
InstancesPerZone: 3,
ZoneCount: 3,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 3800,
DriveType: GCEDriveTypeStandard,
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 2850,
},
},
},
expectedErr: nil,
},
{
// Test4: choose the configuration which is closest to the requested IOPS
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 5700,
MinCapacity: 8000,
MaxCapacity: 100000,
},
},
InstanceType: "foo",
InstancesPerZone: 2,
ZoneCount: 2,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 7534,
DriveType: GCEDriveTypeStandard,
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 5651,
},
},
},
expectedErr: nil,
},
{
// Test5: choose upper bound IOPS when you cannot uniformly distribute storage
// across nodes for the provided IOPS
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 800,
MinCapacity: 2096,
MaxCapacity: 10000,
},
},
InstanceType: "foo",
InstancesPerZone: 2,
ZoneCount: 3,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 1000,
DriveType: GCEDriveTypeStandard,
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 750,
},
},
},
expectedErr: nil,
},
/*
{
// Test6: reduce the number of instances per zone if the IOPS and min capacity are not met
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 7500,
MinCapacity: 4096,
MaxCapacity: 100000,
},
},
InstanceType: "foo",
InstancesPerZone: 2,
ZoneCount: 2,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 9934,
DriveType: GCEDriveTypeStandard,
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 7451,
},
},
},
expectedErr: nil,
},
*/
{
// Test7: provision an io1 drive if the IOPS is not achievable
// by the provided size
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 7500,
MinCapacity: 1000,
MaxCapacity: 2000,
DriveType: genDriveType(GCEDriveTypeSSD),
},
},
InstanceType: "foo",
InstancesPerZone: 3,
ZoneCount: 3,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 249,
DriveType: genDriveType(GCEDriveTypeSSD),
InstancesPerZone: 2,
DriveCount: 1,
IOPS: 7470,
},
},
},
expectedErr: nil,
},
{
// Test8: Multiple user storage specs in a single request
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 500,
MinCapacity: 1000,
MaxCapacity: 100000,
DriveType: genDriveType(GCEDriveTypeStandard),
},
&cloudops.StorageSpec{
IOPS: 5000,
MinCapacity: 9216,
MaxCapacity: 100000,
},
},
InstanceType: "foo",
InstancesPerZone: 3,
ZoneCount: 3,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 600,
DriveType: genDriveType(GCEDriveTypeStandard),
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 450,
},
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 6600,
DriveType: GCEDriveTypeStandard, // no drive type in this request, so response contains pd-standard only, url will be generated later in porx
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 4950,
},
},
},
expectedErr: nil,
},
{
// Test9: Fail the request even if one of the user specs fails
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 500,
MinCapacity: 10,
MaxCapacity: 30,
},
&cloudops.StorageSpec{
IOPS: 7500,
MinCapacity: 2048,
MaxCapacity: 100000,
},
},
InstanceType: "foo",
InstancesPerZone: 3,
ZoneCount: 3,
},
expectedErr: &cloudops.ErrStorageDistributionCandidateNotFound{},
},
{
// Test10: Install with lower sized disks
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 300,
MinCapacity: 150,
MaxCapacity: 300,
DriveType: GCEDriveTypeSSD,
},
},
InstanceType: "foo",
InstancesPerZone: 1,
ZoneCount: 3,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 10,
DriveType: GCEDriveTypeSSD,
InstancesPerZone: 1,
DriveCount: 5,
IOPS: 300,
},
},
},
expectedErr: nil,
},
{
// Test11: Install for specific drive type
request: &cloudops.StorageDistributionRequest{
UserStorageSpec: []*cloudops.StorageSpec{
&cloudops.StorageSpec{
IOPS: 2500,
MinCapacity: 150,
MaxCapacity: 300,
DriveType: genDriveType(GCEDriveTypeSSD),
},
},
InstanceType: "foo",
InstancesPerZone: 1,
ZoneCount: 3,
},
response: &cloudops.StorageDistributionResponse{
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 82,
DriveType: genDriveType(GCEDriveTypeSSD),
InstancesPerZone: 1,
DriveCount: 1,
IOPS: 2460,
},
},
},
expectedErr: nil,
},
}
for j, test := range testMatrix {
fmt.Println("Executing test case: ", j+1)
response, err := storageManager.GetStorageDistribution(test.request)
if test.expectedErr == nil {
require.NoError(t, err, "Unexpected error on GetStorageDistribution")
require.NotNil(t, response, "got nil response from GetStorageDistribution")
require.Equal(t, len(test.response.InstanceStorage), len(response.InstanceStorage), "unequal response lengths")
for i := range test.response.InstanceStorage {
require.True(t, reflect.DeepEqual(*response.InstanceStorage[i], *test.response.InstanceStorage[i]),
"Test Case %v Expected Response: %+v . Actual Response %+v", j+1,
test.response.InstanceStorage[i], response.InstanceStorage[i])
}
} else {
require.NotNil(t, err, "GetStorageDistribution should have returned an error")
require.Equal(t, test.expectedErr, err, "received unexpected type of error")
}
}
}
func storageUpdate(t *testing.T) {
testMatrix := []updateTestInput{
{
// ***** TEST: 1
// Instance has 3 x 256 GiB
// Update from 768GiB to 1536 GiB by resizing disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 1536,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
CurrentDriveSize: 256,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentIOPS: 192,
CurrentDriveCount: 3,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 512,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 3,
IOPS: 384,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 2
// Instance has 2 x 350 GiB
// Update from 700GiB to 800 GiB by resizing disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 800,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
CurrentDriveSize: 350,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 2,
TotalDrivesOnNode: 2,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 400,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 2,
IOPS: 300,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 3
// Instance has 3 x 300 GiB
// Update from 900GiB to 1200 GiB by resizing disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 1200,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
CurrentDriveSize: 300,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 3,
TotalDrivesOnNode: 3,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 400,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 3,
IOPS: 300,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 4
// Instances has 2 x 1024 GiB
// Update from 2048 GiB to 4096 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 4096,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveSize: 1024,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 2,
TotalDrivesOnNode: 2,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 1024,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 2,
IOPS: 768,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 5
// Instances has 2 x 1024 GiB
// Update from 2048 GiB to 3072 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 3072,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveSize: 1024,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 2,
TotalDrivesOnNode: 2,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 1024,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 1,
IOPS: 768,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 6
// Instances has 3 x 600 GiB
// Update from 1800 GiB to 2000 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 2000,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveSize: 600,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 3,
TotalDrivesOnNode: 3,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 600,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 1,
IOPS: 450,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 7
// Instances has no existing drives
// Update from 0 GiB to 700 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 700,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
TotalDrivesOnNode: 0,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 700,
DriveType: GCEDriveTypeStandard, // don't return a drive type as url, AddDrive function will manage this later
DriveCount: 1,
IOPS: 525,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 8
// Instance has 1 x 256 GiB
// Update from 256GiB to 280 GiB by resizing disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 280,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
CurrentDriveSize: 256,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 1,
TotalDrivesOnNode: 1,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 280,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 1,
IOPS: 210,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 9 -> lower sized disks
// Instance has 1 x 200 GiB
// Update from 200GiB to 400 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 400,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveSize: 200,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 1,
TotalDrivesOnNode: 1,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 200,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 1,
IOPS: 150,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 11 -> ask for one more GiB
// Instance has 2 x 200 GiB
// Update from 400 GiB to 401 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 401,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveSize: 200,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 2,
TotalDrivesOnNode: 2,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 200,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 1,
IOPS: 150,
},
},
},
expectedErr: nil,
},
{
// ***** TEST: 12 instance is already at higher capacity than requested
// Instance has 3 x 200 GiB
// Update from 600 GiB to 401 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 401,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveSize: 200,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 3,
TotalDrivesOnNode: 3,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: nil,
},
expectedErr: &cloudops.ErrCurrentCapacityHigherThanDesired{Current: 600, Desired: 401},
},
{
// ***** TEST: instance is already at higher capacity than requested
// Instance has 3 x 200 GiB
// Update from 600 GiB to 401 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
DesiredCapacity: 401,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveSize: 200,
CurrentDriveType: genDriveType(GCEDriveTypeBalanced),
CurrentDriveCount: 3,
TotalDrivesOnNode: 3,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: nil,
},
expectedErr: &cloudops.ErrCurrentCapacityHigherThanDesired{Current: 600, Desired: 401},
},
{
// ***** TEST:
// Instances has 2 x 1024 GiB
// Update from 2048 GiB to 4096 GiB by adding disks
request: &cloudops.StoragePoolUpdateRequest{
CurrentDriveSize: 1024,
DesiredCapacity: 4096,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveType: genDriveType(GCEDriveTypeBalanced),
CurrentDriveCount: 2,
TotalDrivesOnNode: 2,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 1024,
DriveType: genDriveType(GCEDriveTypeBalanced),
DriveCount: 2,
IOPS: 6144,
},
},
},
expectedErr: nil,
},
{
// ***** TEST:
request: &cloudops.StoragePoolUpdateRequest{
CurrentDriveSize: 1024,
DesiredCapacity: 64000,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
CurrentDriveType: genDriveType(GCEDriveTypeBalanced),
CurrentDriveCount: 1,
TotalDrivesOnNode: 1,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 64000,
DriveType: genDriveType(GCEDriveTypeBalanced),
DriveCount: 1,
IOPS: GCEBalancedMaxIopsMost,
},
},
},
expectedErr: nil,
},
{
// ***** TEST:
request: &cloudops.StoragePoolUpdateRequest{
CurrentDriveSize: 64 * 1000,
DesiredCapacity: 3 * 64 * 1000,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveType: genDriveType(GCEDriveTypeBalanced),
CurrentDriveCount: 1,
TotalDrivesOnNode: 1,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 64 * 1000,
DriveType: genDriveType(GCEDriveTypeBalanced),
DriveCount: 2,
IOPS: GCEBalancedMaxIopsMost,
},
},
},
expectedErr: nil,
},
{
// ***** TEST:
request: &cloudops.StoragePoolUpdateRequest{
CurrentDriveSize: 64 * 1000,
DesiredCapacity: 3 * 64 * 1000,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveType: genDriveType(GCEDriveTypeStandard),
CurrentDriveCount: 1,
TotalDrivesOnNode: 1,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 64 * 1000,
DriveType: genDriveType(GCEDriveTypeStandard),
DriveCount: 2,
IOPS: GCEStandardMaxIops,
},
},
},
expectedErr: nil,
},
{
// ***** TEST:
request: &cloudops.StoragePoolUpdateRequest{
CurrentDriveSize: 64 * 1000,
DesiredCapacity: 3 * 64 * 1000,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
CurrentDriveType: genDriveType(GCEDriveTypeSSD),
CurrentDriveCount: 1,
TotalDrivesOnNode: 1,
},
response: &cloudops.StoragePoolUpdateResponse{
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_ADD_DISK,
InstanceStorage: []*cloudops.StoragePoolSpec{
&cloudops.StoragePoolSpec{
DriveCapacityGiB: 64 * 1000,
DriveType: genDriveType(GCEDriveTypeSSD),
DriveCount: 2,
IOPS: GCESSDMaxIopsMost,
},
},
},
expectedErr: nil,
},
{
// ***** TEST:
request: &cloudops.StoragePoolUpdateRequest{
CurrentDriveSize: 64 * 1000,
DesiredCapacity: 3 * 64 * 1000,
ResizeOperationType: api.SdkStoragePool_RESIZE_TYPE_RESIZE_DISK,
CurrentDriveType: genDriveType(GCEDriveTypeBalanced),
CurrentDriveCount: 1,
TotalDrivesOnNode: 1,
},
response: &cloudops.StoragePoolUpdateResponse{},
expectedErr: &cloudops.ErrStorageDistributionCandidateNotFound{Reason: "cannot reach target drive size of 192000, max supported drive size for drive type pd-balanced: 64000"},
},
}
for j, test := range testMatrix {
fmt.Println("Executing test case: ", j+1)
response, err := storageManager.RecommendStoragePoolUpdate(test.request)
if test.expectedErr == nil {
require.Nil(t, err, "RecommendStoragePoolUpdate returned an error")
require.NotNil(t, response, "RecommendStoragePoolUpdate returned empty response")
require.Equal(t, len(test.response.InstanceStorage), len(response.InstanceStorage), "length of expected and actual response not equal")
for i := range test.response.InstanceStorage {
require.True(t, reflect.DeepEqual(*response.InstanceStorage[i], *test.response.InstanceStorage[i]),
"Test Case %v Expected Response: %+v . Actual Response %+v", j+1,
test.response.InstanceStorage[i], response.InstanceStorage[i])
}
} else {
require.NotNil(t, err, "RecommendInstanceStorageUpdate should have returned an error")
require.Equal(t, test.expectedErr.Error(), err.Error(), "received unexpected type of error")
}
}
}
func genDriveType(dType string) string {
// the gce drive path comes as https://www.googleapis.com/compute/v1/projects/portworx-eng/zones/us-east1-b/diskTypes/pd-standard
// or https://www.googleapis.com/compute/v1/projects/portworx-eng/zones/us-east1-b/diskTypes/pd-ssd
return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/portworx-eng/zones/us-east1-b/diskTypes/%s", dType)
}