|
| 1 | +package hugePages |
| 2 | + |
| 3 | +import ( |
| 4 | + "crypto/tls" |
| 5 | + "fmt" |
| 6 | + "io" |
| 7 | + "os" |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | + "time" |
| 11 | + |
| 12 | + http_helper "github.com/gruntwork-io/terratest/modules/http-helper" |
| 13 | + "github.com/gruntwork-io/terratest/modules/k8s" |
| 14 | + "github.com/gruntwork-io/terratest/modules/random" |
| 15 | + "github.com/marklogic/marklogic-kubernetes/test/testUtil" |
| 16 | + "github.com/stretchr/testify/assert" |
| 17 | + digestAuth "github.com/xinsnake/go-http-digest-auth-client" |
| 18 | +) |
| 19 | + |
| 20 | +func TestHugePagesSettings(t *testing.T) { |
| 21 | + // var resp *http.Response |
| 22 | + var body []byte |
| 23 | + var err error |
| 24 | + var podName string |
| 25 | + imageRepo, repoPres := os.LookupEnv("dockerRepository") |
| 26 | + imageTag, tagPres := os.LookupEnv("dockerVersion") |
| 27 | + |
| 28 | + if !repoPres { |
| 29 | + imageRepo = "marklogicdb/marklogic-db" |
| 30 | + t.Logf("No imageRepo variable present, setting to default value: " + imageRepo) |
| 31 | + } |
| 32 | + |
| 33 | + if !tagPres { |
| 34 | + imageTag = "latest" |
| 35 | + t.Logf("No imageTag variable present, setting to default value: " + imageTag) |
| 36 | + } |
| 37 | + |
| 38 | + username := "admin" |
| 39 | + password := "admin" |
| 40 | + |
| 41 | + options := map[string]string{ |
| 42 | + "persistence.enabled": "false", |
| 43 | + "replicaCount": "1", |
| 44 | + "image.repository": imageRepo, |
| 45 | + "image.tag": imageTag, |
| 46 | + "auth.adminUsername": username, |
| 47 | + "auth.adminPassword": password, |
| 48 | + "logCollection.enabled": "false", |
| 49 | + "hugepages.enabled": "true", |
| 50 | + "hugepages.mountPath": "/dev/hugepages", |
| 51 | + "resources.limits.hugepages-2Mi": "1Gi", |
| 52 | + "resources.limits.memory": "8Gi", |
| 53 | + "resources.requests.memory": "8Gi", |
| 54 | + } |
| 55 | + t.Logf("====Installing Helm Chart") |
| 56 | + releaseName := "hugepages" |
| 57 | + |
| 58 | + namespaceName := "ml-" + strings.ToLower(random.UniqueId()) |
| 59 | + kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName) |
| 60 | + |
| 61 | + t.Logf("====Creating namespace: " + namespaceName) |
| 62 | + k8s.CreateNamespace(t, kubectlOptions, namespaceName) |
| 63 | + |
| 64 | + defer t.Logf("====Deleting namespace: " + namespaceName) |
| 65 | + defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName) |
| 66 | + |
| 67 | + podName = testUtil.HelmInstall(t, options, releaseName, kubectlOptions) |
| 68 | + |
| 69 | + t.Logf("====Describe pod for verifying huge pages") |
| 70 | + k8s.RunKubectl(t, kubectlOptions, "describe", "pod", podName) |
| 71 | + |
| 72 | + tlsConfig := tls.Config{} |
| 73 | + // wait until the pod is in Ready status |
| 74 | + k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second) |
| 75 | + |
| 76 | + tunnel7997 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997) |
| 77 | + defer tunnel7997.Close() |
| 78 | + tunnel7997.ForwardPort(t) |
| 79 | + endpoint7997 := fmt.Sprintf("http://%s", tunnel7997.Endpoint()) |
| 80 | + |
| 81 | + // verify if 7997 health check endpoint returns 200 |
| 82 | + http_helper.HttpGetWithRetryWithCustomValidation( |
| 83 | + t, |
| 84 | + endpoint7997, |
| 85 | + &tlsConfig, |
| 86 | + 10, |
| 87 | + 15*time.Second, |
| 88 | + func(statusCode int, body string) bool { |
| 89 | + return statusCode == 200 |
| 90 | + }, |
| 91 | + ) |
| 92 | + tunnel8002 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002) |
| 93 | + defer tunnel8002.Close() |
| 94 | + tunnel8002.ForwardPort(t) |
| 95 | + endpointManage := fmt.Sprintf("http://%s/manage/v2/logs?format=text&filename=ErrorLog.txt", tunnel8002.Endpoint()) |
| 96 | + request := digestAuth.NewRequest(username, password, "GET", endpointManage, "") |
| 97 | + response, err := request.Execute() |
| 98 | + if err != nil { |
| 99 | + t.Fatalf(err.Error()) |
| 100 | + } |
| 101 | + defer response.Body.Close() |
| 102 | + assert.Equal(t, 200, response.StatusCode) |
| 103 | + |
| 104 | + body, err = io.ReadAll(response.Body) |
| 105 | + t.Log(string(body)) |
| 106 | + |
| 107 | + // Verify if Huge pages are configured on the MarkLogic node |
| 108 | + if !strings.Contains(string(body), "Linux Huge Pages: detected 1280") { |
| 109 | + t.Errorf("Huge Pages not configured for the node") |
| 110 | + } |
| 111 | +} |
0 commit comments