@@ -171,3 +171,141 @@ func TestSeparateEDnode(t *testing.T) {
171
171
t .Errorf ("enode hosts does not exists on cluster" )
172
172
}
173
173
}
174
+
175
+ func TestIncorrectBootsrapHostname (t * testing.T ) {
176
+ var resp * http.Response
177
+ var body []byte
178
+ var err error
179
+
180
+ username := "admin"
181
+ password := "admin"
182
+ imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
183
+ imageTag , tagPres := os .LookupEnv ("dockerVersion" )
184
+ namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
185
+ kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
186
+ dnodeReleaseName := "test-dnode-group"
187
+ enodeReleaseName := "test-enode-group"
188
+ dnodePodName := dnodeReleaseName + "-marklogic-0"
189
+
190
+ // Incorrect boostrap hostname for negative test
191
+ bootstrapHost := "Incorrect Host Name"
192
+
193
+ // Path to the helm chart we will test
194
+ helmChartPath , e := filepath .Abs ("../../charts" )
195
+
196
+ if e != nil {
197
+ t .Fatalf (e .Error ())
198
+ }
199
+
200
+ if ! repoPres {
201
+ imageRepo = "marklogic-centos/marklogic-server-centos"
202
+ t .Logf ("No imageRepo variable present, setting to default value: " + imageRepo )
203
+ }
204
+
205
+ if ! tagPres {
206
+ imageTag = "10-internal"
207
+ t .Logf ("No imageTag variable present, setting to default value: " + imageTag )
208
+ }
209
+
210
+ // Helm options for dnode creation
211
+ options := & helm.Options {
212
+ KubectlOptions : kubectlOptions ,
213
+ SetValues : map [string ]string {
214
+ "persistence.enabled" : "false" ,
215
+ "replicaCount" : "1" ,
216
+ "image.repository" : imageRepo ,
217
+ "image.tag" : imageTag ,
218
+ "auth.adminUsername" : username ,
219
+ "auth.adminPassword" : password ,
220
+ "group.name" : "dnode" ,
221
+ "logCollection.enabled" : "false" ,
222
+ },
223
+ }
224
+
225
+ t .Logf ("====Creating namespace: " + namespaceName )
226
+ k8s .CreateNamespace (t , kubectlOptions , namespaceName )
227
+
228
+ defer t .Logf ("====Deleting namespace: " + namespaceName )
229
+ defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
230
+
231
+ t .Logf ("====Installing D Node Helm Chart" + dnodeReleaseName )
232
+ helm .Install (t , options , helmChartPath , dnodeReleaseName )
233
+
234
+ // wait until the pod is in ready status
235
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , dnodePodName , 10 , 20 * time .Second )
236
+
237
+ tunnel := k8s .NewTunnel (
238
+ kubectlOptions , k8s .ResourceTypePod , dnodePodName , 8002 , 8002 )
239
+
240
+ defer tunnel .Close ()
241
+
242
+ tunnel .ForwardPort (t )
243
+ hostsEndpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?format=json" , tunnel .Endpoint ())
244
+ t .Logf (`Endpoint: %s` , hostsEndpoint )
245
+
246
+ getHostsRequest := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
247
+
248
+ if resp , err = getHostsRequest .Execute (); err != nil {
249
+ t .Fatalf (err .Error ())
250
+ }
251
+
252
+ defer resp .Body .Close ()
253
+
254
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
255
+ t .Fatalf (err .Error ())
256
+ }
257
+
258
+ t .Logf ("Response:\n " + string (body ))
259
+ t .Logf (`BootstrapHost: = %s` , bootstrapHost )
260
+
261
+ // Helm options for enode creation
262
+ enodeOptions := & helm.Options {
263
+ KubectlOptions : kubectlOptions ,
264
+ SetValues : map [string ]string {
265
+ "persistence.enabled" : "false" ,
266
+ "replicaCount" : "1" ,
267
+ "image.repository" : imageRepo ,
268
+ "image.tag" : imageTag ,
269
+ "auth.adminUsername" : username ,
270
+ "auth.adminPassword" : password ,
271
+ "group.name" : "enode" ,
272
+ "bootstrapHostName" : bootstrapHost ,
273
+ "logCollection.enabled" : "false" ,
274
+ },
275
+ }
276
+
277
+ t .Logf ("====Installing E Node Helm Chart" + enodeReleaseName )
278
+ helm .Install (t , enodeOptions , helmChartPath , enodeReleaseName )
279
+
280
+ // Give pod time to fail before checking if it did
281
+ time .Sleep (20 * time .Second )
282
+
283
+ // Verify clustering failed given incorrect hostname
284
+ clusterStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2?view=status" , tunnel .Endpoint ())
285
+ clusterStatus := digestAuth .NewRequest (username , password , "GET" , clusterStatusEndpoint , "" )
286
+ t .Logf (`clusterStatusEndpoint: %s` , clusterStatusEndpoint )
287
+ if resp , err = clusterStatus .Execute (); err != nil {
288
+ t .Fatalf (err .Error ())
289
+ }
290
+ totalHostsJson := gjson .Get (string (body ), "host-default-list.list-items.list-count.value" )
291
+ // Total hosts be one as second host should have failed to create
292
+ if (totalHostsJson .Num != 1 ) {
293
+ t .Errorf ("Wrong number of hosts: %v instead of 1" , totalHostsJson .Num )
294
+ }
295
+ t .Logf ("\n Cluster Status Response:\n \n " + string (body ))
296
+
297
+ // Verify enode group creation failed given incorrect hostname
298
+ enodeGroupStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/enode" , tunnel .Endpoint ())
299
+ groupStatus := digestAuth .NewRequest (username , password , "GET" , enodeGroupStatusEndpoint , "" )
300
+ t .Logf (`enodeGroupStatusEndpoint: %s` , enodeGroupStatusEndpoint )
301
+ if resp , err = groupStatus .Execute (); err != nil {
302
+ t .Fatalf (err .Error ())
303
+ }
304
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
305
+ t .Fatalf (err .Error ())
306
+ }
307
+ if (! strings .Contains (string (body ), "404" )) {
308
+ t .Errorf ("Enode group should not exist" )
309
+ }
310
+ t .Logf ("\n Enode Group Status Response:\n \n " + string (body ))
311
+ }
0 commit comments