Skip to content

Commit d242792

Browse files
author
Barkha Choithani
committed
added tests for separate e/d node and check for group configure
1 parent c41fa40 commit d242792

File tree

3 files changed

+144
-11
lines changed

3 files changed

+144
-11
lines changed

charts/templates/statefulset.yaml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ spec:
3131
- |
3232
echo '### Begin configuring group ###'
3333
34-
GROUP_CFG_TEMPLATE='{"group-name":"%s"}'
35-
GROUP_CFG=$(printf "$GROUP_CFG_TEMPLATE" "$MARKLOGIC_GROUP")
34+
HOST_RESP_CODE=`curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" -X GET http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/hosts --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
35+
if [[ ${HOST_RESP_CODE} -eq 200 ]]; then
36+
GROUP_CFG_TEMPLATE='{"group-name":"%s"}'
37+
GROUP_CFG=$(printf "$GROUP_CFG_TEMPLATE" "$MARKLOGIC_GROUP")
38+
GROUP_RESP_CODE=`curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" -X GET http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/${MARKLOGIC_GROUP} --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
3639
37-
GROUP_RESP_CODE=`curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" -X GET http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/${MARKLOGIC_GROUP} --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
38-
39-
if [[ ${GROUP_RESP_CODE} -eq 200 ]]; then
40-
echo "Group $MARKLOGIC_GROUP is already configured on the MarkLogic cluster."
40+
if [[ ${GROUP_RESP_CODE} -eq 200 ]]; then
41+
echo "Group $MARKLOGIC_GROUP is already configured on the MarkLogic cluster."
42+
else
43+
echo "Group $MARKLOGIC_GROUP does not exist, creating $MARKLOGIC_GROUP on the MarkLogic cluster"
44+
curl --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD} -m 20 -s -X POST -d "${GROUP_CFG}" -H "Content-type: application/json" http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups
45+
fi
4146
else
42-
echo "Group $MARKLOGIC_GROUP does not exist, creating $MARKLOGIC_GROUP on the MarkLogic cluster"
43-
curl --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD} -m 20 -s -X POST -d "${GROUP_CFG}" -H "Content-type: application/json" http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups
47+
echo "Bootstrap host not found"
4448
fi
4549
echo '### init container execution completed ###'
4650
env:
@@ -123,17 +127,16 @@ spec:
123127
log "Info: [poststart] Begin Poststart Hook Execution"
124128
if [[ $MARKLOGIC_GROUP == "Default" || $POD_NAME != *-0 ]]; then
125129
log "Info: [poststart] This is not a bootstrap host or group specified is Default"
126-
exit 1
127130
else
128131
while [ ! -f /var/opt/MarkLogic/ready ]; do
129132
sleep 5s
130133
done
131134
132135
GROUP_CFG_TEMPLATE='{"group-name":"%s"}'
133136
GROUP_CFG=$(printf "$GROUP_CFG_TEMPLATE" "$MARKLOGIC_GROUP")
134-
137+
135138
log "Info: [poststart] Updating Default group on cluster"
136-
curl --anyauth -m 20 -s -X PUT -H "Content-type: application/json" -d "${GROUP_CFG}" http://localhost:8002/manage/v2/groups/Default/properties --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}
139+
curl --anyauth -m 20 -s -X PUT -H "Content-type: application/json" -d "${GROUP_CFG}" http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/Default/properties --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}
137140
sleep 10s
138141
fi
139142
log "Info: [poststart] Poststart Hook Execution Completed"

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ require (
4343
github.com/pquerna/otp v1.2.0 // indirect
4444
github.com/russross/blackfriday/v2 v2.1.0 // indirect
4545
github.com/spf13/pflag v1.0.5 // indirect
46+
github.com/tidwall/gjson v1.14.3 // indirect
47+
github.com/tidwall/match v1.1.1 // indirect
48+
github.com/tidwall/pretty v1.2.0 // indirect
4649
github.com/urfave/cli v1.22.2 // indirect
4750
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
4851
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect

test/e2e/separate_nodes_test.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"path/filepath"
8+
"strings"
9+
"testing"
10+
"time"
11+
12+
"github.com/gruntwork-io/terratest/modules/helm"
13+
"github.com/gruntwork-io/terratest/modules/k8s"
14+
"github.com/gruntwork-io/terratest/modules/random"
15+
digest_auth "github.com/xinsnake/go-http-digest-auth-client"
16+
"github.com/tidwall/gjson"
17+
)
18+
19+
func TestSeparateEDnode(t *testing.T) {
20+
// Path to the helm chart we will test
21+
helmChartPath, e := filepath.Abs("../../charts")
22+
if (e != nil) {
23+
t.Fatalf(e.Error())
24+
}
25+
username := "admin"
26+
password := "admin"
27+
var resp *http.Response
28+
var body []byte
29+
var err error
30+
31+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
32+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
33+
options := &helm.Options{
34+
KubectlOptions: kubectlOptions,
35+
SetValues: map[string]string{
36+
"persistence.enabled": "false",
37+
"replicaCount": "1",
38+
"image.repository": "marklogic-centos/marklogic-server-centos",
39+
"image.tag": "10-internal",
40+
"auth.adminUsername": username,
41+
"auth.adminPassword": password,
42+
"group.name": "dnode",
43+
"logCollection.enabled": "false",
44+
},
45+
}
46+
47+
t.Logf("====Creating namespace: " + namespaceName)
48+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
49+
50+
defer t.Logf("====Deleting namespace: " + namespaceName)
51+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
52+
53+
releaseName := "test-dnode-group"
54+
t.Logf("====Installing Helm Chart" + releaseName)
55+
helm.Install(t, options, helmChartPath, releaseName)
56+
57+
podName := releaseName + "-marklogic-0"
58+
59+
// wait until the pod is in Ready status
60+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
61+
62+
time.Sleep(10 * time.Second)
63+
tunnel := k8s.NewTunnel(
64+
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
65+
defer tunnel.Close()
66+
tunnel.ForwardPort(t)
67+
hosts_endpoint := fmt.Sprintf("http://%s/manage/v2/hosts?format=json", tunnel.Endpoint())
68+
t.Logf(`Endpoint: %s`, hosts_endpoint)
69+
70+
dr := digest_auth.NewRequest(username, password, "GET", hosts_endpoint, "")
71+
72+
if resp, err = dr.Execute(); err != nil {
73+
t.Fatalf(err.Error())
74+
}
75+
defer resp.Body.Close()
76+
77+
if body, err = ioutil.ReadAll(resp.Body); err != nil {
78+
t.Fatalf(err.Error())
79+
}
80+
t.Logf("Response:\n" + string(body))
81+
bootstrapHost := gjson.Get(string(body), `host-default-list.list-items.list-item.#(roleref="bootstrap").nameref`)
82+
t.Logf(`BootstrapHost: = %s` , bootstrapHost)
83+
84+
enodeOptions := &helm.Options{
85+
KubectlOptions: kubectlOptions,
86+
SetValues: map[string]string{
87+
"persistence.enabled": "false",
88+
"replicaCount": "2",
89+
"image.repository": "marklogic-centos/marklogic-server-centos",
90+
"image.tag": "10-internal",
91+
"auth.adminUsername": username,
92+
"auth.adminPassword": password,
93+
"group.name": "enode",
94+
"bootstrapHostName": bootstrapHost.String(),
95+
"logCollection.enabled": "false",
96+
},
97+
}
98+
releaseName2 := "test-enode-group"
99+
t.Logf("====Installing Helm Chart " + releaseName2)
100+
helm.Install(t, enodeOptions, helmChartPath, releaseName2)
101+
102+
enodePodName := releaseName2 + "-marklogic-0"
103+
104+
// wait until the pod is in Ready status
105+
k8s.WaitUntilPodAvailable(t, kubectlOptions, enodePodName, 15, 20*time.Second)
106+
107+
group_endpoint := fmt.Sprintf("http://%s/manage/v2/groups", tunnel.Endpoint())
108+
t.Logf(`Endpoint: %s`, group_endpoint)
109+
110+
dr_groups := digest_auth.NewRequest(username, password, "GET", group_endpoint, "")
111+
112+
if resp, err = dr_groups.Execute(); err != nil {
113+
t.Fatalf(err.Error())
114+
}
115+
defer resp.Body.Close()
116+
117+
if body, err = ioutil.ReadAll(resp.Body); err != nil {
118+
t.Fatalf(err.Error())
119+
}
120+
t.Logf("Response:\n" + string(body))
121+
122+
// verify groups dnode, enode exists on the cluster
123+
if !strings.Contains(string(body), "<nameref>dnode</nameref>") && !strings.Contains(string(body), "<nameref>enode</nameref>") {
124+
t.Errorf("Groups does not exists on cluster")
125+
}
126+
127+
}

0 commit comments

Comments
 (0)