github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/upgrade/pre-upgrade/opensearch-dashboards/opensearch_dashboards_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 dashboards
     5  
     6  import (
     7  	"bufio"
     8  	"fmt"
     9  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    10  	"os"
    11  	"strings"
    12  	"time"
    13  
    14  	. "github.com/onsi/ginkgo/v2"
    15  	. "github.com/onsi/gomega"
    16  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    17  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    18  )
    19  
    20  const (
    21  	waitTimeout                 = 3 * time.Minute
    22  	pollingInterval             = 10 * time.Second
    23  	oldPatternsTestDataFile     = "testdata/upgrade/opensearch-dashboards/old-index-patterns.txt"
    24  	updatedPatternsTestDataFile = "testdata/upgrade/opensearch-dashboards/updated-index-patterns.txt"
    25  	// post 1.5 verrazzano-system and verrazzano-application* patterns are created by default
    26  	post15PatternsTestDataFile = "testdata/upgrade/opensearch-dashboards/post-1.5-index-patterns.txt"
    27  )
    28  
    29  var t = framework.NewTestFramework("opensearch-dashboards")
    30  
    31  var _ = t.Describe("Pre Upgrade OpenSearch Dashboards Setup", Label("f:observability.logging.kibana"), func() {
    32  	// GIVEN the OpenSearchDashboards pod
    33  	// WHEN the index patterns are created
    34  	// THEN verify that they are created successfully
    35  	It("Create Index Patterns", func() {
    36  		Eventually(func() bool {
    37  			kubeConfigPath, _ := k8sutil.GetKubeConfigLocation()
    38  			if pkg.IsOpenSearchDashboardsEnabled(kubeConfigPath) {
    39  				isVersionAbove1_3_0, err := pkg.IsVerrazzanoMinVersion("1.3.0", kubeConfigPath)
    40  				if err != nil {
    41  					pkg.Log(pkg.Error, fmt.Sprintf("failed to find the verrazzano version: %v", err))
    42  					return false
    43  				}
    44  				isVersionAbove1_5_0, err := pkg.IsVerrazzanoMinVersion("1.5.0", kubeConfigPath)
    45  				if err != nil {
    46  					pkg.Log(pkg.Error, fmt.Sprintf("failed to find the verrazzano version: %v", err))
    47  					return false
    48  				}
    49  				patternFile := oldPatternsTestDataFile
    50  				if isVersionAbove1_3_0 {
    51  					patternFile = updatedPatternsTestDataFile
    52  				}
    53  				if isVersionAbove1_5_0 {
    54  					patternFile = post15PatternsTestDataFile
    55  				}
    56  				file, err := pkg.FindTestDataFile(patternFile)
    57  				if err != nil {
    58  					pkg.Log(pkg.Error, fmt.Sprintf("failed to find test data file: %v", err))
    59  					return false
    60  				}
    61  				found, err := os.Open(file)
    62  				if err != nil {
    63  					pkg.Log(pkg.Error, fmt.Sprintf("failed to open test data file: %v", err))
    64  					return false
    65  				}
    66  				reader := bufio.NewScanner(found)
    67  				reader.Split(bufio.ScanLines)
    68  				defer found.Close()
    69  
    70  				for reader.Scan() {
    71  					line := strings.TrimSpace(reader.Text())
    72  					// skip empty lines
    73  					if len(line) == 0 {
    74  						continue
    75  					}
    76  					// ignore lines starting with "#"
    77  					if strings.HasPrefix(line, "#") {
    78  						continue
    79  					}
    80  					// Create index pattern
    81  					result := pkg.CreateIndexPattern(line)
    82  					if result == nil {
    83  						pkg.Log(pkg.Error, fmt.Sprintf("failed to create index pattern %s: %v", line, err))
    84  						return false
    85  					}
    86  				}
    87  			}
    88  			return true
    89  		}).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue(), "Expected not to fail creation of index patterns")
    90  	})
    91  })