55 "io"
66 "os"
77 "path/filepath"
8- "strconv"
98 "strings"
109 "testing"
1110 "time"
@@ -19,27 +18,50 @@ import (
1918 "github.com/tidwall/gjson"
2019)
2120
22- func VerifyGrpNameChng (t * testing.T , groupEndpoint string , newGroupName string ) (int , error ) {
21+ func VerifyGroupChange (t * testing.T , groupEndpoint string , newGroupName string ) (bool , error ) {
2322 client := req .C ().
2423 SetCommonDigestAuth ("admin" , "admin" ).
25- SetCommonRetryCount (10 ).
24+ SetCommonRetryCount (5 ).
2625 SetCommonRetryFixedInterval (10 * time .Second )
2726
2827 t .Logf (`Endpoint: %s` , groupEndpoint )
29- strJSONData := fmt .Sprintf (`{"group-name":"%s"}` , newGroupName )
3028
31- resp , err := client .R ().
29+ groupChanged := false
30+
31+ _ , err := client .R ().
3232 SetContentType ("application/json" ).
33- SetBodyJsonString (strJSONData ).
34- Put (groupEndpoint )
33+ AddRetryCondition (func (resp * req.Response , err error ) bool {
34+ if err != nil {
35+ t .Logf ("error in getting group config: %s" , err .Error ())
36+ return true
37+ }
38+ if resp == nil || resp .Body == nil {
39+ t .Logf ("error in getting response body" )
40+ return true
41+ }
42+ body , err := io .ReadAll (resp .Body )
43+ if body == nil || err != nil {
44+ t .Logf ("error in read response body" )
45+ return true
46+ }
47+ groupName := gjson .Get (string (body ), `group-name` )
48+ t .Logf ("current group name: %s" , groupName )
49+ if groupName .Str != newGroupName {
50+ t .Logf ("group name is not updated yet. retrying..." )
51+ return true
52+ }
53+ groupChanged = true
54+ return false
55+ }).
56+ Get (groupEndpoint )
3557 if err != nil {
3658 t .Fatal (err .Error ())
37- return ( resp . GetStatusCode ()) , err
59+ return false , err
3860 }
39- return resp . GetStatusCode (), resp . Err
61+ return groupChanged , nil
4062}
4163
42- func TestSingleGrpCfgChng (t * testing.T ) {
64+ func TestSingleGroupChange (t * testing.T ) {
4365 // Path to the helm chart we will test
4466 helmChartPath , e := filepath .Abs ("../../charts" )
4567 if e != nil {
@@ -87,38 +109,44 @@ func TestSingleGrpCfgChng(t *testing.T) {
87109 t .Logf ("====Installing Helm Chart" )
88110 podZeroName := testUtil .HelmInstall (t , options , releaseName , kubectlOptions , helmChartPath )
89111
90- // wait until the pod is in Ready status
91112 k8s .WaitUntilPodAvailable (t , kubectlOptions , podZeroName , 15 , 20 * time .Second )
113+
114+ newGroupName := "new_group"
115+
116+ helmUpgradeOptions := & helm.Options {
117+ KubectlOptions : kubectlOptions ,
118+ SetValues : map [string ]string {
119+ "group.name" : newGroupName ,
120+ },
121+ }
122+ helm .Upgrade (t , helmUpgradeOptions , helmChartPath , releaseName )
123+
124+ k8s .RunKubectl (t , kubectlOptions , "delete" , "pod" , podZeroName )
125+
126+ k8s .WaitUntilPodAvailable (t , kubectlOptions , podZeroName , 15 , 20 * time .Second )
127+
128+ // wait until the pod is in Ready status
92129 tunnel := k8s .NewTunnel (
93130 kubectlOptions , k8s .ResourceTypePod , podZeroName , 8002 , 8002 )
94131 defer tunnel .Close ()
95132 tunnel .ForwardPort (t )
96133
97134 // change the group name for dnode and verify it passes
98- newgroupName := "newDefault"
99- t .Logf ("====Test updating group name for %s to %s" , groupName , newgroupName )
100- groupEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/%s/properties" , tunnel .Endpoint (), groupName )
101- responseCode , err := VerifyGrpNameChng (t , groupEndpoint , newgroupName )
135+ t .Logf ("====Test updating group name for %s to %s" , groupName , newGroupName )
136+ groupEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/%s/properties?format=json" , tunnel .Endpoint (), newGroupName )
137+ groupChangedResult , err := VerifyGroupChange (t , groupEndpoint , newGroupName )
102138 if err != nil {
103- t .Fatalf (err .Error ())
104- }
105- if responseCode != 204 {
106- t .Fatal ("Failed to change group name" )
139+ t .Fatalf ("Error in changing group name: %s" , err .Error ())
107140 }
141+ assert .Equal (t , true , groupChangedResult , "Group name change failed" )
108142}
109143
110- func TestMultiGroupCfgChng (t * testing.T ) {
144+ func TestMultipleGroupChange (t * testing.T ) {
111145 username := "admin"
112146 password := "admin"
113147 imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
114148 imageTag , tagPres := os .LookupEnv ("dockerVersion" )
115149 var initialChartVersion string
116- upgradeHelm , _ := os .LookupEnv ("upgradeTest" )
117- runUpgradeTest , _ := strconv .ParseBool (upgradeHelm )
118- if runUpgradeTest {
119- initialChartVersion , _ = os .LookupEnv ("initialChartVersion" )
120- t .Logf ("====Setting initial Helm chart version: %s" , initialChartVersion )
121- }
122150 namespaceName := "ml-" + strings .ToLower (random .UniqueId ())
123151 kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
124152 dnodeGrpName := "dnode"
@@ -169,54 +197,19 @@ func TestMultiGroupCfgChng(t *testing.T) {
169197
170198 // wait until the pod is in ready status
171199 k8s .WaitUntilPodAvailable (t , kubectlOptions , dnodePodName , 15 , 20 * time .Second )
172- tunnel := k8s .NewTunnel (
173- kubectlOptions , k8s .ResourceTypePod , dnodePodName , 8002 , 8002 )
174- defer tunnel .Close ()
175- tunnel .ForwardPort (t )
176-
177- // change the group name for dnode and verify it passes
178- newDnodeGrpName := "newDnode"
179- t .Logf ("====Test updating group name for %s to %s" , dnodeGrpName , newDnodeGrpName )
180- groupEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/%s/properties" , tunnel .Endpoint (), dnodeGrpName )
181- responseCode , err := VerifyGrpNameChng (t , groupEndpoint , newDnodeGrpName )
182- if err != nil {
183- t .Fatalf (err .Error ())
184- }
185- if responseCode != 204 {
186- t .Fatal ("Failed to change group name" )
187- }
188-
189- hostsEndpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?format=json" , tunnel .Endpoint ())
190- t .Logf (`Endpoint: %s` , hostsEndpoint )
191-
192- client := req .C ().
193- SetCommonDigestAuth (username , password ).
194- SetCommonRetryCount (10 ).
195- SetCommonRetryFixedInterval (10 * time .Second )
196- resp , err := client .R ().
197- Get (hostsEndpoint )
198- if err != nil {
199- t .Fatalf (err .Error ())
200- }
201- defer resp .Body .Close ()
202- body , err := io .ReadAll (resp .Body )
203- if err != nil {
204- t .Fatalf (err .Error ())
205- }
206- bootstrapHost := gjson .Get (string (body ), `host-default-list.list-items.list-item.#(roleref="bootstrap").nameref` )
207- t .Logf ("bootstrapHost: %s" , bootstrapHost )
208200
201+ bootstrapHost := fmt .Sprintf ("%s-0.%s.%s.svc.cluster.local" , dnodeReleaseName , dnodeReleaseName , namespaceName )
209202 enodeOptions := & helm.Options {
210203 KubectlOptions : kubectlOptions ,
211204 SetValues : map [string ]string {
212205 "persistence.enabled" : "true" ,
213- "replicaCount" : "2 " ,
206+ "replicaCount" : "1 " ,
214207 "image.repository" : imageRepo ,
215208 "image.tag" : imageTag ,
216209 "auth.adminUsername" : username ,
217210 "auth.adminPassword" : password ,
218211 "group.name" : enodeGrpName ,
219- "bootstrapHostName" : bootstrapHost . Str ,
212+ "bootstrapHostName" : bootstrapHost ,
220213 "group.enableXdqpSsl" : "false" ,
221214 "logCollection.enabled" : "false" ,
222215 },
@@ -227,24 +220,54 @@ func TestMultiGroupCfgChng(t *testing.T) {
227220 // wait until the first enode pod is in Ready status
228221 k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName0 , 15 , 20 * time .Second )
229222
230- // change the enode group name to a existing group name in the cluster and verify it fails
231- t .Logf ("====Test updating group name for %s to an existing group name(%s) should fail" , enodeGrpName , newDnodeGrpName )
232- groupEndpoint = fmt .Sprintf ("http://%s/manage/v2/groups/%s/properties" , tunnel .Endpoint (), enodeGrpName )
233- responseCode , err = VerifyGrpNameChng (t , groupEndpoint , newDnodeGrpName )
234- if err != nil {
235- t .Fatalf (err .Error ())
223+ newDnodeGroupName := "newDnode"
224+ newEnodeGroupName := "newEnode"
225+
226+ helmUpgradeOptionsDnode := & helm.Options {
227+ KubectlOptions : kubectlOptions ,
228+ SetValues : map [string ]string {
229+ "group.name" : newDnodeGroupName ,
230+ },
236231 }
237- assert . Equal (t , 400 , responseCode )
232+ helm . Upgrade (t , helmUpgradeOptionsDnode , helmChartPath , dnodeReleaseName )
238233
239- // change the enode group name to a new group name and verify it passes
240- newEnodeGrpName := "newEnode"
241- t .Logf ("====Test updating group name for %s to %s" , enodeGrpName , newEnodeGrpName )
242- groupEndpoint = fmt .Sprintf ("http://%s/manage/v2/groups/%s/properties" , tunnel .Endpoint (), enodeGrpName )
243- responseCode , err = VerifyGrpNameChng (t , groupEndpoint , newEnodeGrpName )
234+ k8s .RunKubectl (t , kubectlOptions , "delete" , "pod" , dnodePodName )
235+
236+ k8s .WaitUntilPodAvailable (t , kubectlOptions , dnodePodName , 15 , 20 * time .Second )
237+
238+ tunnel := k8s .NewTunnel (
239+ kubectlOptions , k8s .ResourceTypePod , dnodePodName , 8002 , 8002 )
240+ defer tunnel .Close ()
241+ tunnel .ForwardPort (t )
242+
243+ // change the group name for dnode and verify it passes
244+ t .Logf ("====Test updating group name for %s to %s" , dnodeGrpName , newDnodeGroupName )
245+ groupDnodeEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/%s/properties?format=json" , tunnel .Endpoint (), newDnodeGroupName )
246+ groupChangedResult , err := VerifyGroupChange (t , groupDnodeEndpoint , newDnodeGroupName )
244247 if err != nil {
245- t .Fatalf (err .Error ())
248+ t .Fatalf ("Error in changing group name: %s" , err .Error ())
249+ }
250+ assert .Equal (t , true , groupChangedResult , "dnode Group name change failed" )
251+
252+ helmUpgradeOptionsEnode := & helm.Options {
253+ KubectlOptions : kubectlOptions ,
254+ SetValues : map [string ]string {
255+ "group.name" : newEnodeGroupName ,
256+ },
246257 }
247- if responseCode != 204 {
248- t .Fatal ("Failed to change group name" )
258+ helm .Upgrade (t , helmUpgradeOptionsEnode , helmChartPath , enodeReleaseName )
259+
260+ k8s .RunKubectl (t , kubectlOptions , "delete" , "pod" , enodePodName0 )
261+
262+ k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName0 , 15 , 20 * time .Second )
263+
264+ // change the group name for dnode and verify it passes
265+ t .Logf ("====Test updating group name for %s to %s" , enodeGrpName , newEnodeGroupName )
266+ groupEnodeEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/%s/properties?format=json" , tunnel .Endpoint (), newEnodeGroupName )
267+ groupChangedResult , err = VerifyGroupChange (t , groupEnodeEndpoint , newEnodeGroupName )
268+ if err != nil {
269+ t .Fatalf ("Error in changing group name: %s" , err .Error ())
249270 }
271+ assert .Equal (t , true , groupChangedResult , "enode Group name change failed" )
272+
250273}
0 commit comments