5
5
"io"
6
6
"os"
7
7
"path/filepath"
8
- "strconv"
9
8
"strings"
10
9
"testing"
11
10
"time"
@@ -19,27 +18,50 @@ import (
19
18
"github.com/tidwall/gjson"
20
19
)
21
20
22
- func VerifyGrpNameChng (t * testing.T , groupEndpoint string , newGroupName string ) (int , error ) {
21
+ func VerifyGroupChange (t * testing.T , groupEndpoint string , newGroupName string ) (bool , error ) {
23
22
client := req .C ().
24
23
SetCommonDigestAuth ("admin" , "admin" ).
25
- SetCommonRetryCount (10 ).
24
+ SetCommonRetryCount (5 ).
26
25
SetCommonRetryFixedInterval (10 * time .Second )
27
26
28
27
t .Logf (`Endpoint: %s` , groupEndpoint )
29
- strJSONData := fmt .Sprintf (`{"group-name":"%s"}` , newGroupName )
30
28
31
- resp , err := client .R ().
29
+ groupChanged := false
30
+
31
+ _ , err := client .R ().
32
32
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 )
35
57
if err != nil {
36
58
t .Fatal (err .Error ())
37
- return ( resp . GetStatusCode ()) , err
59
+ return false , err
38
60
}
39
- return resp . GetStatusCode (), resp . Err
61
+ return groupChanged , nil
40
62
}
41
63
42
- func TestSingleGrpCfgChng (t * testing.T ) {
64
+ func TestSingleGroupChange (t * testing.T ) {
43
65
// Path to the helm chart we will test
44
66
helmChartPath , e := filepath .Abs ("../../charts" )
45
67
if e != nil {
@@ -87,38 +109,44 @@ func TestSingleGrpCfgChng(t *testing.T) {
87
109
t .Logf ("====Installing Helm Chart" )
88
110
podZeroName := testUtil .HelmInstall (t , options , releaseName , kubectlOptions , helmChartPath )
89
111
90
- // wait until the pod is in Ready status
91
112
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
92
129
tunnel := k8s .NewTunnel (
93
130
kubectlOptions , k8s .ResourceTypePod , podZeroName , 8002 , 8002 )
94
131
defer tunnel .Close ()
95
132
tunnel .ForwardPort (t )
96
133
97
134
// 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 )
102
138
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 ())
107
140
}
141
+ assert .Equal (t , true , groupChangedResult , "Group name change failed" )
108
142
}
109
143
110
- func TestMultiGroupCfgChng (t * testing.T ) {
144
+ func TestMultipleGroupChange (t * testing.T ) {
111
145
username := "admin"
112
146
password := "admin"
113
147
imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
114
148
imageTag , tagPres := os .LookupEnv ("dockerVersion" )
115
149
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
- }
122
150
namespaceName := "ml-" + strings .ToLower (random .UniqueId ())
123
151
kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
124
152
dnodeGrpName := "dnode"
@@ -169,54 +197,19 @@ func TestMultiGroupCfgChng(t *testing.T) {
169
197
170
198
// wait until the pod is in ready status
171
199
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 )
208
200
201
+ bootstrapHost := fmt .Sprintf ("%s-0.%s.%s.svc.cluster.local" , dnodeReleaseName , dnodeReleaseName , namespaceName )
209
202
enodeOptions := & helm.Options {
210
203
KubectlOptions : kubectlOptions ,
211
204
SetValues : map [string ]string {
212
205
"persistence.enabled" : "true" ,
213
- "replicaCount" : "2 " ,
206
+ "replicaCount" : "1 " ,
214
207
"image.repository" : imageRepo ,
215
208
"image.tag" : imageTag ,
216
209
"auth.adminUsername" : username ,
217
210
"auth.adminPassword" : password ,
218
211
"group.name" : enodeGrpName ,
219
- "bootstrapHostName" : bootstrapHost . Str ,
212
+ "bootstrapHostName" : bootstrapHost ,
220
213
"group.enableXdqpSsl" : "false" ,
221
214
"logCollection.enabled" : "false" ,
222
215
},
@@ -227,24 +220,54 @@ func TestMultiGroupCfgChng(t *testing.T) {
227
220
// wait until the first enode pod is in Ready status
228
221
k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName0 , 15 , 20 * time .Second )
229
222
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
+ },
236
231
}
237
- assert . Equal (t , 400 , responseCode )
232
+ helm . Upgrade (t , helmUpgradeOptionsDnode , helmChartPath , dnodeReleaseName )
238
233
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 )
244
247
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
+ },
246
257
}
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 ())
249
270
}
271
+ assert .Equal (t , true , groupChangedResult , "enode Group name change failed" )
272
+
250
273
}
0 commit comments