github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/upgrade/pre-upgrade/opensearch/opensearch_test.go (about)

     1  // Copyright (c) 2022, 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package opensearch
     5  
     6  import (
     7  	"fmt"
     8  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
     9  	"os"
    10  	"time"
    11  
    12  	. "github.com/onsi/ginkgo/v2"
    13  	. "github.com/onsi/gomega"
    14  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    15  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    16  )
    17  
    18  const (
    19  	waitTimeout     = 3 * time.Minute
    20  	pollingInterval = 10 * time.Second
    21  	documentFile    = "testdata/upgrade/opensearch/document1.json"
    22  	ismTemplateFile = "testdata/upgrade/opensearch/policy.json"
    23  )
    24  
    25  var t = framework.NewTestFramework("opensearch")
    26  
    27  var _ = t.Describe("Pre Upgrade OpenSearch", Label("f:observability.logging.es"), func() {
    28  	// GIVEN the OpenSearch pod
    29  	// THEN verify that the data can be written to indices successfully
    30  	It("OpenSearch Write data", func() {
    31  		Eventually(func() bool {
    32  			kubeConfigPath, _ := k8sutil.GetKubeConfigLocation()
    33  			isOSEnabled, err := pkg.IsOpenSearchEnabled(kubeConfigPath)
    34  			if err != nil {
    35  				pkg.Log(pkg.Error, err.Error())
    36  				return false
    37  			}
    38  			if isOSEnabled {
    39  				indexName, err := pkg.GetOpenSearchSystemIndex(pkg.VerrazzanoNamespace)
    40  				if err != nil {
    41  					pkg.Log(pkg.Error, fmt.Sprintf("error getting the system index: %v", err))
    42  					return false
    43  				}
    44  				file, err := pkg.FindTestDataFile(documentFile)
    45  				if err != nil {
    46  					pkg.Log(pkg.Error, fmt.Sprintf("failed to find test data file: %v", err))
    47  					return false
    48  				}
    49  				data, err := os.ReadFile(file)
    50  				if err != nil {
    51  					pkg.Log(pkg.Error, fmt.Sprintf("failed to read test data file: %v", err))
    52  					return false
    53  				}
    54  				resp, err := pkg.PostOpensearch(fmt.Sprintf("%s/_doc", indexName), string(data))
    55  				if err != nil {
    56  					pkg.Log(pkg.Error, fmt.Sprintf("Failed to write to OpenSearch: %v", err))
    57  					return false
    58  				}
    59  				if resp.StatusCode != 201 {
    60  					pkg.Log(pkg.Error, fmt.Sprintf("Failed to write to OpenSearch: status=%d: body=%s", resp.StatusCode, string(resp.Body)))
    61  					return false
    62  				}
    63  			}
    64  			return true
    65  		}).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue(), "Expected not to fail while writing data to OpenSearch")
    66  	})
    67  
    68  	kubeConfigPath, err := k8sutil.GetKubeConfigLocation()
    69  	if err != nil {
    70  		Expect(err).To(BeNil(), fmt.Sprintf(pkg.KubeConfigErrorFmt, err))
    71  	}
    72  	t.ItMinimumVersion("Verify OpenSearch plugins have been installed", "1.6.0", kubeConfigPath, func() {
    73  		pkg.TestOpenSearchPlugins(pollingInterval, waitTimeout)
    74  	})
    75  })
    76  var _ = t.Describe("Pre Upgrade OpenSearch", Label("f:observability.logging.es"), func() {
    77  	// GIVEN the OpenSearch pod
    78  	// THEN verify that the ism policy  can be written to successfully
    79  	It("OpenSearch ISM policy", func() {
    80  		Eventually(func() bool {
    81  			kubeConfigPath, _ := k8sutil.GetKubeConfigLocation()
    82  			isOSEnabled, err := pkg.IsOpenSearchEnabled(kubeConfigPath)
    83  			if err != nil {
    84  				pkg.Log(pkg.Error, err.Error())
    85  				return false
    86  			}
    87  			if isOSEnabled {
    88  				file, err := pkg.FindTestDataFile(ismTemplateFile)
    89  				if err != nil {
    90  					pkg.Log(pkg.Error, fmt.Sprintf("failed to find test data file: %v", err))
    91  					return false
    92  				}
    93  				data, err := os.ReadFile(file)
    94  				if err != nil {
    95  					pkg.Log(pkg.Error, fmt.Sprintf("failed to read test data file: %v", err))
    96  					return false
    97  				}
    98  				resp, err := pkg.PutISMPolicy(string(data), "vz-custom")
    99  				if err != nil {
   100  					pkg.Log(pkg.Error, fmt.Sprintf("Failed to create to ISM: %v", err))
   101  					return false
   102  				}
   103  				if resp.StatusCode != 201 {
   104  					pkg.Log(pkg.Error, fmt.Sprintf("Failed to write to OpenSearch: status=%d: body=%s", resp.StatusCode, string(resp.Body)))
   105  					return false
   106  				}
   107  			}
   108  			return true
   109  		}).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue(), "Expected not to fail when creating ISM policies in OpenSearch")
   110  	})
   111  })