This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain_test.go
990 lines (947 loc) · 41 KB
/
main_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
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
/**
* Copyright 2016, 2017 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main_test
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/IBM/ubiquity/resources"
)
var _ = Describe("Main", func() {
BeforeEach(func() {
//time for server to initialize
time.Sleep(time.Millisecond * 1000)
})
Context("on normal startup", func() {
It("spectrum plugin server does not exit", func() {
Expect(doesProcessExist(spectrumCommand.Process.Pid)).To(Equal(true))
})
It("should get a 404 for root", func() {
_, status, err := submitRequest("GET", "/")
Expect(err).ToNot(HaveOccurred())
Expect(status).To(ContainSubstring("404"))
})
Context("on activate", func() {
It("does not error when mount is successful", func() {
body, status, err := submitRequest("POST", "/Plugin.Activate")
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var activateResponse resources.ActivateResponse
err = json.Unmarshal([]byte(body), &activateResponse)
Expect(err).ToNot(HaveOccurred())
Expect(len(activateResponse.Implements)).To(Equal(1))
Expect(activateResponse.Implements[0]).To(Equal("VolumeDriver"))
})
It("does not error when previously mounted (duplicate activate)", func() {
body, status, err := submitRequest("POST", "/Plugin.Activate")
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var activateResponse resources.ActivateResponse
err = json.Unmarshal([]byte(body), &activateResponse)
Expect(err).ToNot(HaveOccurred())
Expect(len(activateResponse.Implements)).To(Equal(1))
Expect(activateResponse.Implements[0]).To(Equal("VolumeDriver"))
//second activate
body, status, err = submitRequest("POST", "/Plugin.Activate")
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
err = json.Unmarshal([]byte(body), &activateResponse)
Expect(err).ToNot(HaveOccurred())
Expect(len(activateResponse.Implements)).To(Equal(1))
Expect(activateResponse.Implements[0]).To(Equal("VolumeDriver"))
})
Context("on successful activation", func() {
var (
volumeName string
filesetVolume string
ltwtVolume string
filesetWithQuotaVolume string
opts map[string]interface{}
)
BeforeEach(func() {
body, status, err := submitRequest("POST", "/Plugin.Activate")
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var activateResponse resources.ActivateResponse
err = json.Unmarshal([]byte(body), &activateResponse)
Expect(err).ToNot(HaveOccurred())
Expect(len(activateResponse.Implements)).To(Equal(1))
Expect(activateResponse.Implements[0]).To(Equal("VolumeDriver"))
})
Context(".Create", func() {
BeforeEach(func() {
volumeName = fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
})
It("should not error on create with valid opts", func() {
successfulCreateRequest(volumeName)
successfulRemoveRequest(volumeName)
})
It("should not error if volume already exists", func() {
successfulCreateRequest(volumeName)
createRequest := resources.CreateVolumeRequest{Name: volumeName, Opts: map[string]interface{}{"backend": spectrumBackend}}
createRequestBody, err := json.Marshal(createRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Create", createRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var createResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &createResponse)
Expect(err).ToNot(HaveOccurred())
Expect(createResponse.Err).To(Equal(fmt.Sprintf("Volume `%s` already exists", volumeName)))
successfulRemoveRequest(volumeName)
})
It("should not error on creating fileset volume using type opt", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
It("should not error on creating fileset volume with user, group permissions", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem1
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
It("should not error on creating independent fileset volume using fileset-type opt", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem1
opts["fileset-type"] = "independent"
opts["inode-limit"] = inodeLimit
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
It("should not error on creating lightweight volume using type opt", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["fileset"] = volumeName
opts["type"] = "lightweight"
opts["filesystem"] = filesystem1
newVolumeName := fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
successfulCreateWithOptsRequest(newVolumeName, opts)
successfulRemoveRequest(newVolumeName)
successfulRemoveRequest(volumeName)
})
It("should not error on creating lightweight volume with user, group permissions", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["fileset"] = volumeName
opts["type"] = "lightweight"
opts["filesystem"] = filesystem1
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
newVolumeName := fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
successfulCreateWithOptsRequest(newVolumeName, opts)
successfulRemoveRequest(newVolumeName)
successfulRemoveRequest(volumeName)
})
It("should error on creating lightweight volume if fileset not specified", func() {
opts = make(map[string]interface{})
opts["type"] = "lightweight"
opts["filesystem"] = filesystem1
opts["backend"] = spectrumBackend
createRequest := resources.CreateVolumeRequest{Name: volumeName, Opts: opts}
createRequestBody, err := json.Marshal(createRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Create", createRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var createResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &createResponse)
Expect(err).ToNot(HaveOccurred())
Expect(createResponse.Err).To(Equal("'filesystem' and 'fileset' are required opts for using lightweight volumes"))
})
It("should not error on creating quota based volume using type and fileset opt", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
It("should not error on creating quota based volume with user, group permissions", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
It("should not error on creating quota and independent fileset based volume", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
opts["fileset-type"] = "independent"
opts["inode-limit"] = inodeLimit
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
It("should error on creating quota based volume using type lightweight", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["fileset"] = volumeName
opts["type"] = "lightweight"
opts["filesystem"] = filesystem1
newVolumeName := fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
opts["quota"] = "1G"
opts["backend"] = spectrumBackend
createRequest := resources.CreateVolumeRequest{Name: newVolumeName, Opts: opts}
createRequestBody, err := json.Marshal(createRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Create", createRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var createResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &createResponse)
Expect(err).ToNot(HaveOccurred())
Expect(createResponse.Err).To(Equal("'quota' is not supported for lightweight volumes"))
successfulRemoveRequest(volumeName)
})
It("should error on creating quota based volume using type fileset but invalid quota", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "invalid-quota"
opts["backend"] = spectrumBackend
createRequest := resources.CreateVolumeRequest{Name: volumeName, Opts: opts}
createRequestBody, err := json.Marshal(createRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Create", createRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var createResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &createResponse)
Expect(err).ToNot(HaveOccurred())
if (connector == "REST") {
Expect(createResponse.Err).To(Equal(fmt.Sprintf("Unable to set quota for fileset %s:[EFSSP1101C CLI: The value \"invalid-quota\" specified for \"s\" is invalid. ]. Please refer Ubiquity server logs for more details",volumeName)))
} else {
Expect(createResponse.Err).To(Equal(fmt.Sprintf("Failed to set quota 'invalid-quota' for fileset '%s': exit status 1", volumeName)))
}
})
It("should error on create with invalid type in opt", func() {
opts = make(map[string]interface{})
opts["type"] = "invalid-type"
opts["backend"] = spectrumBackend
createRequest := resources.CreateVolumeRequest{Name: volumeName, Opts: opts}
createRequestBody, err := json.Marshal(createRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Create", createRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var createResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &createResponse)
Expect(err).ToNot(HaveOccurred())
Expect(createResponse.Err).To(Equal("Unknown 'type' = invalid-type specified"))
})
})
Context(".Remove", func() {
BeforeEach(func() {
volumeName = fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
})
It("should not error when removing an existing volume", func() {
successfulCreateRequest(volumeName)
successfulRemoveRequest(volumeName)
})
It("should error if volume does not exist", func() {
removeRequest := resources.GenericRequest{Name: volumeName}
removeRequestBody, err := json.Marshal(removeRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Remove", removeRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var removeResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &removeResponse)
Expect(err).ToNot(HaveOccurred())
Expect(removeResponse.Err).To(Equal("Volume not found"))
})
It("should not error when removing an existing fileset volume, which was created using type opt", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
It("should not error when removing an existing lightweight volume, which was created using type opt", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["fileset"] = volumeName
opts["type"] = "lightweight"
opts["filesystem"] = filesystem1
newVolumeName := fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
successfulCreateWithOptsRequest(newVolumeName, opts)
successfulRemoveRequest(volumeName)
successfulRemoveRequest(newVolumeName)
})
It("should not error when removing an exisiting quota based volume, which was created using type and fileset opt", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(volumeName, opts)
successfulRemoveRequest(volumeName)
})
})
Context(".List", func() {
BeforeEach(func() {
volumeName = fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
filesetVolume = fmt.Sprintf("some-filesetvolume-%d", time.Now().Nanosecond())
ltwtVolume = fmt.Sprintf("some-ltwvolume-%d", time.Now().Nanosecond())
filesetWithQuotaVolume = fmt.Sprintf("some-filesetwithquotavolume-%d", time.Now().Nanosecond())
})
It("should list volumes", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem1
successfulCreateWithOptsRequest(filesetVolume, opts)
opts["fileset"] = volumeName
opts["type"] = "lightweight"
successfulCreateWithOptsRequest(ltwtVolume, opts)
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
opts["quota"] = "1G"
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.List", nil)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var listResponse resources.ListResponse
err = json.Unmarshal([]byte(body), &listResponse)
Expect(err).ToNot(HaveOccurred())
Expect(listResponse.Err).To(Equal(""))
Expect(listResponse.Volumes).ToNot(Equal(nil))
//loop thru and find
//Expect(listResponse.Volumes[0].Name).To(Equal(volumeName))
successfulRemoveRequest(volumeName)
successfulRemoveRequest(filesetVolume)
successfulRemoveRequest(ltwtVolume)
successfulRemoveRequest(filesetWithQuotaVolume)
})
//It("should not error if no volumes exist", func() {
//
// body, status, err := submitRequestWithBody("POST", "/VolumeDriver.List", nil)
// Expect(err).ToNot(HaveOccurred())
// Expect(status).To(Equal("200 OK"))
// var listResponse resources.ListResponse
// err = json.Unmarshal([]byte(body), &listResponse)
// Expect(err).ToNot(HaveOccurred())
// Expect(listResponse.Err).To(Equal(""))
// Expect(listResponse.Volumes).ToNot(Equal(nil))
// //loop thru and ensure does not exist
//})
})
Context(".Get", func() {
BeforeEach(func() {
volumeName = fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
filesetVolume = fmt.Sprintf("some-filesetvolume-%d", time.Now().Nanosecond())
ltwtVolume = fmt.Sprintf("some-ltwvolume-%d", time.Now().Nanosecond())
filesetWithQuotaVolume = fmt.Sprintf("some-filesetwithquotavolume-%d", time.Now().Nanosecond())
})
It("should be able to Get volume details", func() {
successfulCreateRequest(volumeName)
successfulGetRequest(volumeName)
successfulRemoveRequest(volumeName)
})
It("should error if volume does not exist", func() {
getRequest := resources.GenericRequest{Name: "non-existent-volume"}
getRequestBody, err := json.Marshal(getRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Get", getRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var getResponse resources.GetResponse
err = json.Unmarshal([]byte(body), &getResponse)
Expect(err).ToNot(HaveOccurred())
Expect(getResponse.Err).To(Equal("Volume not found"))
})
It("should be able to Get Fileset type volume details", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulGetRequest(filesetVolume)
successfulRemoveRequest(filesetVolume)
})
It("should be able to Get lightweight type volume details", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["filesystem"] = filesystem1
opts["fileset"] = volumeName
opts["type"] = "lightweight"
successfulCreateWithOptsRequest(ltwtVolume, opts)
successfulGetRequest(ltwtVolume)
successfulRemoveRequest(ltwtVolume)
successfulRemoveRequest(volumeName)
})
It("should be able to Get Fileset with quota type volume details", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulGetRequest(filesetVolume)
successfulRemoveRequest(filesetVolume)
})
})
Context(".Mount", func() {
BeforeEach(func() {
volumeName = fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
filesetVolume = fmt.Sprintf("some-filesetvolume-%d", time.Now().Nanosecond())
ltwtVolume = fmt.Sprintf("some-ltwvolume-%d", time.Now().Nanosecond())
filesetWithQuotaVolume = fmt.Sprintf("some-filesetwithquotavolume-%d", time.Now().Nanosecond())
})
It("should be able to link volume", func() {
successfulCreateRequest(volumeName)
successfulMountRequest(volumeName)
// successfulUnmountRequest(volumeName)
// successfulRemoveRequest(volumeName)
})
It("should be able to link volume of type fileset", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
//successfulUnmountRequest(filesetVolume)
//successfulRemoveRequest(filesetVolume)
})
It("should be able to link volume of type fileset with user and group permissions", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
//successfulUnmountRequest(filesetVolume)
//successfulRemoveRequest(filesetVolume)
})
It("should be able to link volume of type independent fileset", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
opts["fileset-type"] = "independent"
opts["inode-limit"] = inodeLimit
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
//successfulUnmountRequest(filesetVolume)
//successfulRemoveRequest(filesetVolume)
})
It("should be able to link volume of type lightweight", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["filesystem"] = filesystem1
opts["fileset"] = volumeName
opts["type"] = "lightweight"
successfulCreateWithOptsRequest(ltwtVolume, opts)
successfulMountRequest(ltwtVolume)
//successfulUnmountRequest(ltwtVolume)
//successfulRemoveRequest(ltwtVolume)
})
It("should be able to link volume of type lightweight, with user and group permissions", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["filesystem"] = filesystem1
opts["fileset"] = volumeName
opts["type"] = "lightweight"
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(ltwtVolume, opts)
successfulMountRequest(ltwtVolume)
//successfulUnmountRequest(ltwtVolume)
//successfulRemoveRequest(ltwtVolume)
})
It("should be able to link volume of type fileset with quota", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
//successfulUnmountRequest(filesetWithQuotaVolume)
//successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should be able to link volume of type fileset with quota, with user and group permissions", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
//successfulUnmountRequest(filesetWithQuotaVolume)
//successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should be able to link volume of type independent fileset with quota", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
opts["fileset-type"] = "independent"
opts["inode-limit"] = inodeLimit
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
//successfulUnmountRequest(filesetWithQuotaVolume)
//successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should not error if volume is already linked", func() {
successfulCreateRequest(volumeName)
successfulMountRequest(volumeName)
successfulMountRequest(volumeName)
successfulUnmountRequest(volumeName)
successfulRemoveRequest(volumeName)
})
It("should not error if volume of type fileset is already linked", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
successfulMountRequest(filesetVolume)
successfulUnmountRequest(filesetVolume)
successfulRemoveRequest(filesetVolume)
})
It("should not error if volume of type lightweight is already linked", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["filesystem"] = filesystem1
opts["fileset"] = volumeName
opts["type"] = "lightweight"
successfulCreateWithOptsRequest(ltwtVolume, opts)
successfulMountRequest(ltwtVolume)
successfulMountRequest(ltwtVolume)
successfulUnmountRequest(ltwtVolume)
successfulRemoveRequest(ltwtVolume)
successfulRemoveRequest(volumeName)
})
It("should not error if volume of type fileset with quota is already linked", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
successfulMountRequest(filesetWithQuotaVolume)
successfulUnmountRequest(filesetWithQuotaVolume)
successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should error if volume does not exist", func() {
mountRequest := resources.GenericRequest{Name: volumeName}
mountRequestBody, err := json.Marshal(mountRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Mount", mountRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var mountResponse resources.MountResponse
err = json.Unmarshal([]byte(body), &mountResponse)
Expect(err).ToNot(HaveOccurred())
Expect(mountResponse.Err).To(Equal("Volume not found"))
})
})
Context(".Unmount", func() {
BeforeEach(func() {
volumeName = fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
filesetVolume = fmt.Sprintf("some-filesetvolume-%d", time.Now().Nanosecond())
ltwtVolume = fmt.Sprintf("some-ltwvolume-%d", time.Now().Nanosecond())
filesetWithQuotaVolume = fmt.Sprintf("some-filesetwithquotavolume-%d", time.Now().Nanosecond())
})
It("should be able to unlink volume", func() {
successfulCreateRequest(volumeName)
successfulMountRequest(volumeName)
successfulUnmountRequest(volumeName)
successfulRemoveRequest(volumeName)
})
It("should be able to unlink volume of type fileset", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
successfulUnmountRequest(filesetVolume)
successfulRemoveRequest(filesetVolume)
})
It("should be able to unlink volume of type fileset with user and group permissions", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
successfulUnmountRequest(filesetVolume)
successfulRemoveRequest(filesetVolume)
})
It("should be able to unlink volume of type independent fileset", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
opts["fileset-type"] = "independent"
opts["inode-limit"] = inodeLimit
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
successfulUnmountRequest(filesetVolume)
successfulRemoveRequest(filesetVolume)
})
It("should be able to unlink volume of type lightweight", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["filesystem"] = filesystem1
opts["fileset"] = volumeName
opts["type"] = "lightweight"
successfulCreateWithOptsRequest(ltwtVolume, opts)
successfulMountRequest(ltwtVolume)
successfulUnmountRequest(ltwtVolume)
successfulRemoveRequest(ltwtVolume)
successfulRemoveRequest(volumeName)
})
It("should be able to unlink volume of type lightweight with user and group permissions", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["filesystem"] = filesystem1
opts["fileset"] = volumeName
opts["type"] = "lightweight"
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(ltwtVolume, opts)
successfulMountRequest(ltwtVolume)
successfulUnmountRequest(ltwtVolume)
successfulRemoveRequest(ltwtVolume)
successfulRemoveRequest(volumeName)
})
It("should be able to unlink volume of type fileset with quota", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
successfulUnmountRequest(filesetWithQuotaVolume)
successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should be able to unlink volume of type fileset with quota with user and group permissions", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
opts["uid"] = "ubiquity"
opts["gid"] = "ubiquity"
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
successfulUnmountRequest(filesetWithQuotaVolume)
successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should be able to unlink volume of type independent fileset with quota", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
opts["fileset-type"] = "independent"
opts["inode-limit"] = inodeLimit
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
successfulUnmountRequest(filesetWithQuotaVolume)
successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should error when volume is not linked", func() {
if spectrumBackend != "spectrum-scale" {
Skip("Testcase applies to spectrum-scale native impl only.")
}
successfulCreateRequest(volumeName)
if (connector != "REST") {
failedUnmountRequest(volumeName)
}
successfulRemoveRequest(volumeName)
})
It("should error when volume of type fileset is not linked", func() {
if spectrumBackend != "spectrum-scale" {
Skip("Testcase applies to spectrum-scale native impl only.")
}
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
if (connector != "REST") {
failedUnmountRequest(filesetVolume)
}
successfulRemoveRequest(filesetVolume)
})
It("should error when volume of type fileset with quota is not linked", func() {
if spectrumBackend != "spectrum-scale" {
Skip("Testcase applies to spectrum-scale native impl only.")
}
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
if (connector != "REST") {
failedUnmountRequest(filesetWithQuotaVolume)
}
successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should error when volume does not exist", func() {
unmountRequest := resources.GenericRequest{Name: volumeName}
unmountRequestBody, err := json.Marshal(unmountRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Unmount", unmountRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var unmountResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &unmountResponse)
Expect(err).ToNot(HaveOccurred())
Expect(unmountResponse.Err).To(Equal("Volume not found"))
})
})
Context(".Path", func() {
BeforeEach(func() {
volumeName = fmt.Sprintf("some-testvolume-%d", time.Now().Nanosecond())
filesetVolume = fmt.Sprintf("some-filesetvolume-%d", time.Now().Nanosecond())
ltwtVolume = fmt.Sprintf("some-ltwvolume-%d", time.Now().Nanosecond())
filesetWithQuotaVolume = fmt.Sprintf("some-filesetwithquotavolume-%d", time.Now().Nanosecond())
})
It("should return path when volume is linked", func() {
successfulCreateRequest(volumeName)
successfulMountRequest(volumeName)
successfulPathRequest(volumeName)
successfulUnmountRequest(volumeName)
successfulRemoveRequest(volumeName)
})
It("should return path when volume of type fileset is linked", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
successfulMountRequest(filesetVolume)
successfulPathRequest(filesetVolume)
successfulUnmountRequest(filesetVolume)
successfulRemoveRequest(filesetVolume)
})
It("should return path when volume of type lightweight is linked", func() {
successfulCreateRequest(volumeName)
opts = make(map[string]interface{})
opts["filesystem"] = filesystem1
opts["fileset"] = volumeName
opts["type"] = "lightweight"
successfulCreateWithOptsRequest(ltwtVolume, opts)
successfulMountRequest(ltwtVolume)
successfulPathRequest(ltwtVolume)
successfulUnmountRequest(ltwtVolume)
successfulRemoveRequest(ltwtVolume)
successfulRemoveRequest(volumeName)
})
It("should return path when volume of type fileset with quota is linked", func() {
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
successfulMountRequest(filesetWithQuotaVolume)
successfulPathRequest(filesetWithQuotaVolume)
successfulUnmountRequest(filesetWithQuotaVolume)
successfulRemoveRequest(filesetWithQuotaVolume)
})
It("should error when volume is not linked", func() {
if spectrumBackend != "spectrum-scale" {
Skip("Testcase applies to spectrum-scale native impl only.")
}
successfulCreateRequest(volumeName)
if (connector != "REST") {
failedPathRequest(volumeName)
}
successfulRemoveRequest(volumeName)
})
It("should error when volume of type fileset is not linked", func() {
if spectrumBackend != "spectrum-scale" {
Skip("Testcase applies to spectrum-scale native impl only.")
}
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetVolume, opts)
if (connector != "REST") {
failedPathRequest(filesetVolume)
}
successfulRemoveRequest(filesetVolume)
})
It("should error when volume of type fileset with quota is not linked", func() {
if spectrumBackend != "spectrum-scale" {
Skip("Testcase applies to spectrum-scale native impl only.")
}
opts = make(map[string]interface{})
opts["type"] = "fileset"
opts["quota"] = "1G"
opts["filesystem"] = filesystem2
successfulCreateWithOptsRequest(filesetWithQuotaVolume, opts)
if (connector != "REST") {
failedPathRequest(filesetWithQuotaVolume)
}
successfulRemoveRequest(filesetWithQuotaVolume)
})
})
})
})
})
})
func doesProcessExist(pid int) bool {
_, err := os.FindProcess(pid)
if err != nil {
return false
}
return true
}
func submitRequest(reqType string, path string) (body string, status string, err error) {
req, _ := http.NewRequest(reqType, fmt.Sprintf("http://%s:%d%s", listenAddr, listenPort, path), nil)
response, err := (&http.Client{}).Do(req)
if err != nil {
testLogger.Println(err.Error())
return "", "", err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
return string(bodyBytes[:]), response.Status, err
}
func submitRequestWithBody(reqType string, path string, requestBody []byte) (body string, status string, err error) {
req, _ := http.NewRequest(reqType, fmt.Sprintf("http://%s:%d%s", listenAddr, listenPort, path), bytes.NewBuffer(requestBody))
response, err := (&http.Client{}).Do(req)
if err != nil {
testLogger.Println(err.Error())
return "", "", err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
return string(bodyBytes[:]), response.Status, err
}
func successfulCreateRequest(volumeName string) {
opts := make(map[string]interface{})
opts["backend"] = spectrumBackend
successfulCreateWithOptsRequest(volumeName, opts)
}
func successfulCreateWithOptsRequest(volumeName string, opts map[string]interface{}) {
opts["backend"] = spectrumBackend
createRequest := resources.CreateVolumeRequest{Name: volumeName, Opts: opts}
createRequestBody, err := json.Marshal(createRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Create", createRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var createResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &createResponse)
Expect(err).ToNot(HaveOccurred())
Expect(createResponse.Err).To(Equal(""))
}
func successfulGetRequest(volumeName string) {
getRequest := resources.GenericRequest{Name: volumeName}
getRequestBody, err := json.Marshal(getRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Get", getRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var getResponse resources.GetResponse
err = json.Unmarshal([]byte(body), &getResponse)
Expect(err).ToNot(HaveOccurred())
Expect(getResponse.Err).To(Equal(""))
Expect(getResponse.Volume).ToNot(Equal(nil))
Expect(getResponse.Volume.Name).To(Equal(volumeName))
}
func successfulMountRequest(volumeName string) {
mountRequest := resources.GenericRequest{Name: volumeName}
mountRequestBody, err := json.Marshal(mountRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Mount", mountRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var mountResponse resources.MountResponse
err = json.Unmarshal([]byte(body), &mountResponse)
Expect(err).ToNot(HaveOccurred())
Expect(mountResponse.Err).To(Equal(""))
Expect(mountResponse.Mountpoint).ToNot(Equal(nil))
Expect(mountResponse.Mountpoint).ToNot(Equal(""))
Expect(len(mountResponse.Mountpoint)).To(BeNumerically(">", 0))
}
func successfulUnmountRequest(volumeName string) {
unmountRequest := resources.GenericRequest{Name: volumeName}
unmountRequestBody, err := json.Marshal(unmountRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Unmount", unmountRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var unmountResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &unmountResponse)
Expect(err).ToNot(HaveOccurred())
Expect(unmountResponse.Err).To(Equal(""))
}
func failedUnmountRequest(volumeName string) {
unmountRequest := resources.GenericRequest{Name: volumeName}
unmountRequestBody, err := json.Marshal(unmountRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Unmount", unmountRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var unmountResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &unmountResponse)
Expect(err).ToNot(HaveOccurred())
Expect(unmountResponse.Err).To(Equal("volume not attached"))
}
func successfulPathRequest(volumeName string) {
pathRequest := resources.GenericRequest{Name: volumeName}
pathRequestBody, err := json.Marshal(pathRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Path", pathRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var pathResponse resources.MountResponse
err = json.Unmarshal([]byte(body), &pathResponse)
Expect(err).ToNot(HaveOccurred())
Expect(pathResponse.Err).To(Equal(""))
Expect(pathResponse.Mountpoint).ToNot(Equal(""))
}
func failedPathRequest(volumeName string) {
pathRequest := resources.GenericRequest{Name: volumeName}
pathRequestBody, err := json.Marshal(pathRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Path", pathRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("400 Bad Request"))
var pathResponse resources.MountResponse
err = json.Unmarshal([]byte(body), &pathResponse)
Expect(err).ToNot(HaveOccurred())
Expect(pathResponse.Err).To(Equal("volume not mounted"))
}
func successfulRemoveRequest(volumeName string) {
removeRequest := resources.GenericRequest{Name: volumeName}
removeRequestBody, err := json.Marshal(removeRequest)
Expect(err).ToNot(HaveOccurred())
body, status, err := submitRequestWithBody("POST", "/VolumeDriver.Remove", removeRequestBody)
Expect(err).ToNot(HaveOccurred())
Expect(status).To(Equal("200 OK"))
var removeResponse resources.GenericResponse
err = json.Unmarshal([]byte(body), &removeResponse)
Expect(err).ToNot(HaveOccurred())
Expect(removeResponse.Err).To(Equal(""))
}