@@ -3,53 +3,55 @@ package sanity
33import (
44 "context"
55 "fmt"
6- //"strconv"
76 "sync"
87 "time"
98
109 api "github.com/libopenstorage/openstorage-sdk-clients/sdk/golang"
11-
10+ common "github.com/libopenstorage/sdk-test/pkg/common"
1211 . "github.com/onsi/ginkgo"
1312 . "github.com/onsi/gomega"
1413)
1514
1615var scaleUsers map [string ]string
16+ var userVolumeMap * common.ConcMap
17+
18+ type VolumeRequest struct {
19+ VolID string
20+ CreateRequest * api.SdkVolumeCreateRequest
21+ Token string
22+ }
23+
1724var _ = Describe ("Security Scale" , func () {
1825 var (
1926 c api.OpenStorageVolumeClient
2027 ic api.OpenStorageIdentityClient
21- // ma api.OpenStorageMountAttachClient
2228 )
2329
24- fmt .Println ("\n It is going to run security scale tests..." )
25-
2630 BeforeEach (func () {
2731 c = api .NewOpenStorageVolumeClient (conn )
2832 ic = api .NewOpenStorageIdentityClient (conn )
29- By ("creating users" )
30- scaleUsers = createXUsersTokens ("scaleUsers" , 10 )
31- fmt .Printf ("scaleUsers: %v\n " , scaleUsers )
32- // ma = api.NewOpenStorageMountAttachClient(conn)
33-
3433 isSupported := isCapabilitySupported (
3534 ic ,
3635 api .SdkServiceCapability_OpenStorageService_VOLUME ,
3736 )
38-
3937 if ! isSupported {
40- Skip ("Volume capability not supported , skipping related tests" )
38+ Fail ("Volume capability not supported , skipping related tests" )
4139 }
4240 })
4341
4442 AfterEach (func () {
45- fmt .Println ("\n Security tests are done" )
4643 })
4744
4845 Describe ("Security" , func () {
4946
5047 BeforeEach (func () {
5148 })
52- It ("Should be able to create the created Volume" , func () {
49+
50+ It ("Should be able to create the users" , func () {
51+ By ("Creating users" )
52+ scaleUsers = createXUsersTokens ("scaleUsers" , 30 )
53+ })
54+ It ("Should be able to create the volumes" , func () {
5355 By ("Creating volumes" )
5456 err := createVolumesConcurrently (c )
5557 Expect (err ).NotTo (HaveOccurred ())
@@ -59,34 +61,36 @@ var _ = Describe("Security Scale", func() {
5961 err := inspectVolumesConcurrently (c )
6062 Expect (err ).NotTo (HaveOccurred ())
6163 })
64+ It ("Owner Should be able to delete its own Volume" , func () {
65+ By ("Deleting volumes" )
66+ err := deleteVolumesConcurrently (c )
67+ Expect (err ).NotTo (HaveOccurred ())
68+ })
6269 })
6370
6471})
6572
6673func createVolumesConcurrently (c api.OpenStorageVolumeClient ) error {
74+ //userVolumeMap is mapping user'name to volumes' ID
75+ userVolumeMap = common .NewConcMap ()
76+ var volErrorMap = common .NewConcStringErrChanMap ()
6777 var wg sync.WaitGroup
6878 for name , userToken := range scaleUsers {
6979 userName := name
7080 token := userToken
7181 wg .Add (1 )
7282 go func (userName string , token string ) {
73- fmt .Printf ("It is going to create volume by %s\n " , userName )
7483 defer wg .Done ()
7584 t := time .Now ()
7685 tstr := t .Format ("20060102150405" )
77- time .Sleep (2 * time .Second )
7886 req := & api.SdkVolumeCreateRequest {
79- Name : "inspect -vol-" + tstr + "-" + userName ,
87+ Name : "sdk -vol-" + tstr + "-" + userName ,
8088 Spec : & api.VolumeSpec {
8189 Size : uint64 (5 * GIGABYTE ),
8290 HaLevel : 2 ,
8391 },
8492 }
8593 createResponse , err := c .Create (setContextWithToken (context .Background (), token ), req )
86- Expect (err ).NotTo (HaveOccurred ())
87- Expect (createResponse ).NotTo (BeNil ())
88- Expect (createResponse .VolumeId ).NotTo (BeEmpty ())
89-
9094 volID := createResponse .VolumeId
9195 resp , err := c .Inspect (
9296 setContextWithToken (context .Background (), token ),
@@ -95,28 +99,67 @@ func createVolumesConcurrently(c api.OpenStorageVolumeClient) error {
9599 },
96100 )
97101 printVolumeDetails (resp .Volume )
98- o := resp .GetVolume ().GetId ()
99- name := resp .GetName ()
100- fmt .Printf ("volume name: %s id is %v\n " , name , o )
102+ userVolumeMap .Add (userName , resp .GetVolume ().GetId ())
103+ errChan := make (chan (error ), 1 )
104+ errChan <- err
105+ volErrorMap .Add (volID , errChan )
101106 }(userName , token )
102107 }
103108 wg .Wait ()
104- fmt .Printf ("All volumes created\n " )
105- return nil
109+ for user , volID := range userVolumeMap .GetKeyValMap () {
110+ fmt .Printf ("\n user %s createdvolume ->: %s" , user , volID )
111+ }
112+ return summarizeErrorsFromStringErrorChanMap (volErrorMap .GetKeyValMap ())
106113}
107114
108115func inspectVolumesConcurrently (c api.OpenStorageVolumeClient ) error {
109- fmt .Printf ("All volumes inspected. To be implemented\n " )
110- return nil
116+ var wg sync.WaitGroup
117+ var volErrorMap = common .NewConcStringErrChanMap ()
118+ for user , id := range userVolumeMap .GetKeyValMap () {
119+ userName := user .(string )
120+ volID := id .(string )
121+ fmt .Printf ("\n Now user %s is going to inspect volume %s" , userName , volID )
122+ token := scaleUsers [userName ]
123+ wg .Add (1 )
124+ go func (userName string , volID string , token string ) {
125+ defer wg .Done ()
126+ _ , err := c .Inspect (
127+ setContextWithToken (context .Background (), token ),
128+ & api.SdkVolumeInspectRequest {
129+ VolumeId : volID ,
130+ },
131+ )
132+ errChan := make (chan (error ), 1 )
133+ errChan <- err
134+ volErrorMap .Add (volID , errChan )
135+ }(userName , volID , token )
136+ }
137+ wg .Wait ()
138+ //Receiving all errors from channels
139+ return summarizeErrorsFromStringErrorChanMap (volErrorMap .GetKeyValMap ())
111140}
112141
113- func getUsernames (amount int ) []string {
114- var userNames []string
115- if amount < 1 {
116- return userNames
117- }
118- for i := 1 ; i <= amount ; i ++ {
119- userNames = append (userNames , fmt .Sprintf ("user%d" , i ))
142+ func deleteVolumesConcurrently (c api.OpenStorageVolumeClient ) error {
143+ var wg sync.WaitGroup
144+ var volErrorMap = common .NewConcStringErrChanMap ()
145+ for user , id := range userVolumeMap .GetKeyValMap () {
146+ userName := user .(string )
147+ volID := id .(string )
148+ token := scaleUsers [userName ]
149+ fmt .Printf ("\n Now user %s is going to delete volume %s" , userName , volID )
150+ wg .Add (1 )
151+ go func (userName string , volID string , token string ) {
152+ defer wg .Done ()
153+ err := deleteVol (
154+ setContextWithToken (context .Background (), token ),
155+ c ,
156+ volID ,
157+ )
158+ errChan := make (chan (error ), 1 )
159+ errChan <- err
160+ volErrorMap .Add (volID , errChan )
161+ }(userName , volID , token )
120162 }
121- return userNames
163+ wg .Wait ()
164+ return summarizeErrorsFromStringErrorChanMap (volErrorMap .GetKeyValMap ())
122165}
0 commit comments