@@ -18,19 +18,27 @@ import (
18
18
)
19
19
20
20
func TestSeparateEDnode (t * testing.T ) {
21
- // Path to the helm chart we will test
22
- helmChartPath , e := filepath .Abs ("../../charts" )
23
- if e != nil {
24
- t .Fatalf (e .Error ())
25
- }
26
- username := "admin"
27
- password := "admin"
28
21
var resp * http.Response
29
22
var body []byte
30
23
var err error
31
24
25
+ username := "admin"
26
+ password := "admin"
32
27
imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
33
28
imageTag , tagPres := os .LookupEnv ("dockerVersion" )
29
+ namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
30
+ kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
31
+ dnodeReleaseName := "test-dnode-group"
32
+ enodeReleaseName := "test-enode-group"
33
+ dnodePodName := dnodeReleaseName + "-marklogic-0"
34
+ enodePodName0 := enodeReleaseName + "-marklogic-0"
35
+ enodePodName1 := enodeReleaseName + "-marklogic-1"
36
+
37
+ // Path to the helm chart we will test
38
+ helmChartPath , e := filepath .Abs ("../../charts" )
39
+ if e != nil {
40
+ t .Fatalf (e .Error ())
41
+ }
34
42
35
43
if ! repoPres {
36
44
imageRepo = "marklogic-centos/marklogic-server-centos"
@@ -42,8 +50,6 @@ func TestSeparateEDnode(t *testing.T) {
42
50
t .Logf ("No imageTag variable present, setting to default value: " + imageTag )
43
51
}
44
52
45
- namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
46
- kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
47
53
options := & helm.Options {
48
54
KubectlOptions : kubectlOptions ,
49
55
SetValues : map [string ]string {
@@ -64,39 +70,35 @@ func TestSeparateEDnode(t *testing.T) {
64
70
defer t .Logf ("====Deleting namespace: " + namespaceName )
65
71
defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
66
72
67
- dnodeReleaseName := "test-dnode-group"
68
- t .Logf ("====Installing Helm Chart" + dnodeReleaseName )
73
+ t .Logf ("====Installing Helm Chart " + dnodeReleaseName )
69
74
helm .Install (t , options , helmChartPath , dnodeReleaseName )
70
75
71
- dnodePodName := dnodeReleaseName + "-marklogic-0"
72
-
73
- // wait until the pod is in Ready status
76
+ // wait until the pod is in ready status
74
77
k8s .WaitUntilPodAvailable (t , kubectlOptions , dnodePodName , 10 , 20 * time .Second )
75
78
76
- time .Sleep (10 * time .Second )
77
79
tunnel := k8s .NewTunnel (
78
80
kubectlOptions , k8s .ResourceTypePod , dnodePodName , 8002 , 8002 )
79
81
defer tunnel .Close ()
80
82
tunnel .ForwardPort (t )
83
+
81
84
hostsEndpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?format=json" , tunnel .Endpoint ())
82
85
t .Logf (`Endpoint: %s` , hostsEndpoint )
83
86
84
- dr := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
87
+ getHostsDR := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
85
88
86
- if resp , err = dr .Execute (); err != nil {
89
+ if resp , err = getHostsDR .Execute (); err != nil {
87
90
t .Fatalf (err .Error ())
88
91
}
89
92
defer resp .Body .Close ()
90
-
91
93
if body , err = ioutil .ReadAll (resp .Body ); err != nil {
92
94
t .Fatalf (err .Error ())
93
95
}
94
- t .Logf ("Response:\n " + string (body ))
95
- bootstrapHost := gjson .Get (string (body ), `host-default-list.list-items.list-item.#(roleref="bootstrap").nameref` )
96
- t .Logf (`BootstrapHost: = %s` , bootstrapHost )
96
+ t .Logf ("Get hosts response:\n " + string (body ))
97
97
98
+ bootstrapHostJSON := gjson .Get (string (body ), `host-default-list.list-items.list-item.#(roleref="bootstrap").nameref` )
99
+ t .Logf (`BootstrapHost: = %s` , bootstrapHostJSON )
98
100
// verify bootstrap host exists on the cluster
99
- if bootstrapHost . String () == "" {
101
+ if bootstrapHostJSON . Str == "" {
100
102
t .Errorf ("Bootstrap does not exists on cluster" )
101
103
}
102
104
@@ -110,64 +112,196 @@ func TestSeparateEDnode(t *testing.T) {
110
112
"auth.adminUsername" : username ,
111
113
"auth.adminPassword" : password ,
112
114
"group.name" : "enode" ,
113
- "bootstrapHostName" : bootstrapHost . String () ,
115
+ "bootstrapHostName" : bootstrapHostJSON . Str ,
114
116
"logCollection.enabled" : "false" ,
115
117
},
116
118
}
117
- enodeReleaseName := "test-enode-group"
118
119
t .Logf ("====Installing Helm Chart " + enodeReleaseName )
119
120
helm .Install (t , enodeOptions , helmChartPath , enodeReleaseName )
120
121
121
- enodePodName0 := enodeReleaseName + "-marklogic-0"
122
-
123
122
// wait until the first enode pod is in Ready status
124
123
k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName0 , 45 , 20 * time .Second )
125
124
126
125
groupEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups" , tunnel .Endpoint ())
127
126
t .Logf (`Endpoint: %s` , groupEndpoint )
128
127
129
- drGroups := digestAuth .NewRequest (username , password , "GET" , groupEndpoint , "" )
128
+ getGroupsDR := digestAuth .NewRequest (username , password , "GET" , groupEndpoint , "" )
130
129
131
- if resp , err = drGroups .Execute (); err != nil {
130
+ if resp , err = getGroupsDR .Execute (); err != nil {
132
131
t .Fatalf (err .Error ())
133
132
}
134
133
defer resp .Body .Close ()
135
-
136
134
if body , err = ioutil .ReadAll (resp .Body ); err != nil {
137
135
t .Fatalf (err .Error ())
138
136
}
139
- t .Logf ("Response :\n " + string (body ))
137
+ t .Logf ("Groups status response :\n " + string (body ))
140
138
141
139
// verify groups dnode, enode exists on the cluster
142
140
if ! strings .Contains (string (body ), "<nameref>dnode</nameref>" ) && ! strings .Contains (string (body ), "<nameref>enode</nameref>" ) {
143
141
t .Errorf ("Groups does not exists on cluster" )
144
142
}
145
143
146
- enodePodName1 := enodeReleaseName + "-marklogic-1"
147
-
148
144
// wait until the second enode pod is in Ready status
149
145
k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName1 , 45 , 20 * time .Second )
150
146
151
147
enodeEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/enode?format=json" , tunnel .Endpoint ())
152
148
t .Logf (`Endpoint: %s` , enodeEndpoint )
153
149
154
- drEnode := digestAuth .NewRequest (username , password , "GET" , enodeEndpoint , "" )
150
+ getEnodeDR := digestAuth .NewRequest (username , password , "GET" , enodeEndpoint , "" )
155
151
156
- if resp , err = drEnode .Execute (); err != nil {
152
+ if resp , err = getEnodeDR .Execute (); err != nil {
157
153
t .Fatalf (err .Error ())
158
154
}
159
155
defer resp .Body .Close ()
160
156
161
157
if body , err = ioutil .ReadAll (resp .Body ); err != nil {
162
158
t .Fatalf (err .Error ())
163
159
}
164
- t .Logf ("Response :\n " + string (body ))
160
+ t .Logf ("Get enode group response :\n " + string (body ))
165
161
166
- enodeHostCount := gjson .Get (string (body ), `group-default.relations.relation-group.#(typeref="hosts").relation-count.value` )
167
- t .Logf (`enodeHostCount: = %s` , enodeHostCount )
162
+ enodeHostCountJSON := gjson .Get (string (body ), `group-default.relations.relation-group.#(typeref="hosts").relation-count.value` )
163
+ t .Logf (`enodeHostCount: = %s` , enodeHostCountJSON )
168
164
169
165
// verify bootstrap host exists on the cluster
170
- if ! strings . Contains ( enodeHostCount . String (), "2" ) {
166
+ if enodeHostCountJSON . Num != 2 {
171
167
t .Errorf ("enode hosts does not exists on cluster" )
172
168
}
173
169
}
170
+
171
+ func TestIncorrectBootsrapHostname (t * testing.T ) {
172
+ var resp * http.Response
173
+ var body []byte
174
+ var err error
175
+
176
+ username := "admin"
177
+ password := "admin"
178
+ imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
179
+ imageTag , tagPres := os .LookupEnv ("dockerVersion" )
180
+ namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
181
+ kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
182
+ dnodeReleaseName := "test-dnode-group"
183
+ enodeReleaseName := "test-enode-group"
184
+ dnodePodName := dnodeReleaseName + "-marklogic-0"
185
+
186
+ // Incorrect boostrap hostname for negative test
187
+ bootstrapHost := "Incorrect Host Name"
188
+
189
+ // Path to the helm chart we will test
190
+ helmChartPath , e := filepath .Abs ("../../charts" )
191
+
192
+ if e != nil {
193
+ t .Fatalf (e .Error ())
194
+ }
195
+
196
+ if ! repoPres {
197
+ imageRepo = "marklogic-centos/marklogic-server-centos"
198
+ t .Logf ("No imageRepo variable present, setting to default value: " + imageRepo )
199
+ }
200
+
201
+ if ! tagPres {
202
+ imageTag = "10-internal"
203
+ t .Logf ("No imageTag variable present, setting to default value: " + imageTag )
204
+ }
205
+
206
+ // Helm options for dnode creation
207
+ options := & helm.Options {
208
+ KubectlOptions : kubectlOptions ,
209
+ SetValues : map [string ]string {
210
+ "persistence.enabled" : "false" ,
211
+ "replicaCount" : "1" ,
212
+ "image.repository" : imageRepo ,
213
+ "image.tag" : imageTag ,
214
+ "auth.adminUsername" : username ,
215
+ "auth.adminPassword" : password ,
216
+ "group.name" : "dnode" ,
217
+ "logCollection.enabled" : "false" ,
218
+ },
219
+ }
220
+
221
+ t .Logf ("====Creating namespace: " + namespaceName )
222
+ k8s .CreateNamespace (t , kubectlOptions , namespaceName )
223
+
224
+ defer t .Logf ("====Deleting namespace: " + namespaceName )
225
+ defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
226
+
227
+ t .Logf ("====Installing D Node Helm Chart " + dnodeReleaseName )
228
+ helm .Install (t , options , helmChartPath , dnodeReleaseName )
229
+
230
+ // wait until the pod is in ready status
231
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , dnodePodName , 10 , 20 * time .Second )
232
+
233
+ tunnel := k8s .NewTunnel (
234
+ kubectlOptions , k8s .ResourceTypePod , dnodePodName , 8002 , 8002 )
235
+
236
+ defer tunnel .Close ()
237
+
238
+ tunnel .ForwardPort (t )
239
+ hostsEndpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?format=json" , tunnel .Endpoint ())
240
+ t .Logf (`Endpoint: %s` , hostsEndpoint )
241
+
242
+ getHostsRequest := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
243
+
244
+ if resp , err = getHostsRequest .Execute (); err != nil {
245
+ t .Fatalf (err .Error ())
246
+ }
247
+
248
+ defer resp .Body .Close ()
249
+
250
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
251
+ t .Fatalf (err .Error ())
252
+ }
253
+
254
+ t .Logf ("Response:\n " + string (body ))
255
+ t .Logf (`BootstrapHost: = %s` , bootstrapHost )
256
+
257
+ // Helm options for enode creation
258
+ enodeOptions := & helm.Options {
259
+ KubectlOptions : kubectlOptions ,
260
+ SetValues : map [string ]string {
261
+ "persistence.enabled" : "false" ,
262
+ "replicaCount" : "1" ,
263
+ "image.repository" : imageRepo ,
264
+ "image.tag" : imageTag ,
265
+ "auth.adminUsername" : username ,
266
+ "auth.adminPassword" : password ,
267
+ "group.name" : "enode" ,
268
+ "bootstrapHostName" : bootstrapHost ,
269
+ "logCollection.enabled" : "false" ,
270
+ },
271
+ }
272
+
273
+ t .Logf ("====Installing E Node Helm Chart " + enodeReleaseName )
274
+ helm .Install (t , enodeOptions , helmChartPath , enodeReleaseName )
275
+
276
+ // Give pod time to fail before checking if it did
277
+ time .Sleep (20 * time .Second )
278
+
279
+ // Verify clustering failed given incorrect hostname
280
+ clusterStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2?view=status" , tunnel .Endpoint ())
281
+ clusterStatus := digestAuth .NewRequest (username , password , "GET" , clusterStatusEndpoint , "" )
282
+ t .Logf (`clusterStatusEndpoint: %s` , clusterStatusEndpoint )
283
+ if resp , err = clusterStatus .Execute (); err != nil {
284
+ t .Fatalf (err .Error ())
285
+ }
286
+ totalHostsJSON := gjson .Get (string (body ), "host-default-list.list-items.list-count.value" )
287
+ // Total hosts be one as second host should have failed to create
288
+ if totalHostsJSON .Num != 1 {
289
+ t .Errorf ("Wrong number of hosts: %v instead of 1" , totalHostsJSON .Num )
290
+ }
291
+ t .Logf ("\n Cluster Status Response:\n \n " + string (body ))
292
+
293
+ // Verify enode group creation failed given incorrect hostname
294
+ enodeGroupStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/enode" , tunnel .Endpoint ())
295
+ groupStatus := digestAuth .NewRequest (username , password , "GET" , enodeGroupStatusEndpoint , "" )
296
+ t .Logf (`enodeGroupStatusEndpoint: %s` , enodeGroupStatusEndpoint )
297
+ if resp , err = groupStatus .Execute (); err != nil {
298
+ t .Fatalf (err .Error ())
299
+ }
300
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
301
+ t .Fatalf (err .Error ())
302
+ }
303
+ if ! strings .Contains (string (body ), "404" ) {
304
+ t .Errorf ("Enode group should not exist" )
305
+ }
306
+ t .Logf ("Enode group status response:\n " + string (body ))
307
+ }
0 commit comments