github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/ingress/console/console_ingress_test.go (about)

     1  // Copyright (c) 2021, 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 ingress
     5  
     6  import (
     7  	"fmt"
     8  	dump "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/clusterdump"
     9  	"time"
    10  
    11  	"github.com/verrazzano/verrazzano/pkg/k8s/resource"
    12  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    13  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework/metrics"
    14  
    15  	. "github.com/onsi/ginkgo/v2"
    16  	. "github.com/onsi/gomega"
    17  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    18  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    19  	v1 "k8s.io/api/core/v1"
    20  	"k8s.io/apimachinery/pkg/api/errors"
    21  )
    22  
    23  const (
    24  	shortWaitTimeout     = 10 * time.Minute
    25  	shortPollingInterval = 10 * time.Second
    26  	longWaitTimeout      = 20 * time.Minute
    27  	longPollingInterval  = 20 * time.Second
    28  	namespace            = "console-ingress"
    29  )
    30  
    31  var t = framework.NewTestFramework("ingress")
    32  
    33  var beforeSuite = t.BeforeSuiteFunc(func() {
    34  	deployApplication()
    35  	beforeSuitePassed = true
    36  })
    37  
    38  var _ = BeforeSuite(beforeSuite)
    39  
    40  var failed = false
    41  var beforeSuitePassed = false
    42  
    43  var _ = t.AfterEach(func() {
    44  	failed = failed || CurrentSpecReport().Failed()
    45  })
    46  
    47  var afterSuite = t.AfterSuiteFunc(func() {
    48  	if failed || !beforeSuitePassed {
    49  		dump.ExecuteBugReport(namespace)
    50  	}
    51  	undeployApplication()
    52  })
    53  
    54  var _ = AfterSuite(afterSuite)
    55  
    56  func deployApplication() {
    57  	t.Logs.Info("Deploy test application")
    58  	wlsUser := "weblogic"
    59  	wlsPass := pkg.GetRequiredEnvVarOrFail("WEBLOGIC_PSW")
    60  	dbPass := pkg.GetRequiredEnvVarOrFail("DATABASE_PSW")
    61  	regServ := pkg.GetRequiredEnvVarOrFail("OCR_REPO")
    62  	regUser := pkg.GetRequiredEnvVarOrFail("OCR_CREDS_USR")
    63  	regPass := pkg.GetRequiredEnvVarOrFail("OCR_CREDS_PSW")
    64  
    65  	start := time.Now()
    66  	// Wait for namespace to finish deletion possibly from a prior run.
    67  	Eventually(func() bool {
    68  		_, err := pkg.GetNamespace(namespace)
    69  		return err != nil && errors.IsNotFound(err)
    70  	}, shortWaitTimeout, shortPollingInterval).Should(BeTrue())
    71  
    72  	t.Logs.Info("Create namespace")
    73  	Eventually(func() (*v1.Namespace, error) {
    74  		nsLabels := map[string]string{
    75  			"verrazzano-managed": "true",
    76  			"istio-injection":    istioInjection}
    77  		return pkg.CreateNamespace(namespace, nsLabels)
    78  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(BeNil())
    79  
    80  	t.Logs.Info("Create Docker repository secret")
    81  	Eventually(func() (*v1.Secret, error) {
    82  		return pkg.CreateDockerSecret(namespace, "tododomain-repo-credentials", regServ, regUser, regPass)
    83  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(BeNil())
    84  
    85  	t.Logs.Info("Create WebLogic credentials secret")
    86  	Eventually(func() (*v1.Secret, error) {
    87  		return pkg.CreateCredentialsSecret(namespace, "tododomain-weblogic-credentials", wlsUser, wlsPass, nil)
    88  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(BeNil())
    89  
    90  	t.Logs.Info("Create database credentials secret")
    91  	Eventually(func() (*v1.Secret, error) {
    92  		return pkg.CreateCredentialsSecret(namespace, "tododomain-jdbc-tododb", wlsUser, dbPass, map[string]string{"weblogic.domainUID": "cidomain"})
    93  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(BeNil())
    94  
    95  	t.Logs.Info("Create encryption credentials secret")
    96  	Eventually(func() (*v1.Secret, error) {
    97  		return pkg.CreatePasswordSecret(namespace, "tododomain-runtime-encrypt-secret", wlsPass, map[string]string{"weblogic.domainUID": "cidomain"})
    98  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(BeNil())
    99  
   100  	t.Logs.Info("Create component resources")
   101  	Eventually(func() error {
   102  		file, err := pkg.FindTestDataFile("testdata/ingress/console/components.yaml")
   103  		if err != nil {
   104  			return err
   105  		}
   106  		return resource.CreateOrUpdateResourceFromFile(file, t.Logs)
   107  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(HaveOccurred())
   108  
   109  	t.Logs.Info("Create application resources")
   110  	Eventually(func() error {
   111  		file, err := pkg.FindTestDataFile("testdata/ingress/console/application.yaml")
   112  		if err != nil {
   113  			return err
   114  		}
   115  		return resource.CreateOrUpdateResourceFromFile(file, t.Logs)
   116  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(HaveOccurred())
   117  
   118  	// Verify cidomain-adminserver and mysql pods are running
   119  	Eventually(func() bool {
   120  		result, err := pkg.PodsRunning(namespace, []string{"mysql", "cidomain-adminserver"})
   121  		if err != nil {
   122  			AbortSuite(fmt.Sprintf("One or more pods are not running in the namespace: %v, error: %v", namespace, err))
   123  		}
   124  		return result
   125  	}, longWaitTimeout, longPollingInterval).Should(BeTrue())
   126  	metrics.Emit(t.Metrics.With("deployment_elapsed_time", time.Since(start).Milliseconds()))
   127  }
   128  
   129  func undeployApplication() {
   130  	t.Logs.Info("Delete application")
   131  	start := time.Now()
   132  	Eventually(func() error {
   133  		file, err := pkg.FindTestDataFile("testdata/ingress/console/application.yaml")
   134  		if err != nil {
   135  			return err
   136  		}
   137  		return resource.DeleteResourceFromFile(file, t.Logs)
   138  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(HaveOccurred())
   139  
   140  	t.Logs.Info("Delete components")
   141  	Eventually(func() error {
   142  		file, err := pkg.FindTestDataFile("testdata/ingress/console/components.yaml")
   143  		if err != nil {
   144  			return err
   145  		}
   146  		return resource.DeleteResourceFromFile(file, t.Logs)
   147  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(HaveOccurred())
   148  
   149  	t.Logs.Info("Wait for application pods to terminate")
   150  	Eventually(func() bool {
   151  		podsTerminated, _ := pkg.PodsNotRunning(namespace, []string{"mysql", "cidomain-adminserver"})
   152  		return podsTerminated
   153  	}, shortWaitTimeout, shortPollingInterval).Should(BeTrue())
   154  
   155  	t.Logs.Info("Delete namespace")
   156  	Eventually(func() error {
   157  		return pkg.DeleteNamespace(namespace)
   158  	}, shortWaitTimeout, shortPollingInterval).ShouldNot(HaveOccurred())
   159  
   160  	t.Logs.Info("Wait for Finalizer to be removed")
   161  	Eventually(func() bool {
   162  		return pkg.CheckNamespaceFinalizerRemoved(namespace)
   163  	}, shortWaitTimeout, shortPollingInterval).Should(BeTrue())
   164  
   165  	Eventually(func() bool {
   166  		_, err := pkg.GetNamespace(namespace)
   167  		return err != nil && errors.IsNotFound(err)
   168  	}, shortWaitTimeout, shortPollingInterval).Should(BeTrue())
   169  	metrics.Emit(t.Metrics.With("deployment_elapsed_time", time.Since(start).Milliseconds()))
   170  }
   171  
   172  var _ = t.Describe("console-ingress app test", Label("f:app-lcm.oam",
   173  	"f:app-lcm.weblogic-workload"), func() {
   174  
   175  	t.Context("Ingress.", Label("f:mesh.ingress",
   176  		"f:ui.console"), func() {
   177  		var host = ""
   178  		var err error
   179  		// Get the host from the Istio gateway resource.
   180  		// GIVEN the Istio gateway for the test namespace
   181  		// WHEN GetHostnameFromGateway is called
   182  		// THEN return the host name found in the gateway.
   183  		t.BeforeEach(func() {
   184  			Eventually(func() (string, error) {
   185  				host, err = k8sutil.GetHostnameFromGateway(namespace, "")
   186  				return host, err
   187  			}, shortWaitTimeout, shortPollingInterval).Should(Not(BeEmpty()))
   188  		})
   189  
   190  		// Verify the console endpoint is working.
   191  		// GIVEN the app is deployed
   192  		// WHEN the console endpoint is accessed
   193  		// THEN the expected results should be returned
   194  		t.It("Verify '/console' endpoint is working.", func() {
   195  			Eventually(func() (*pkg.HTTPResponse, error) {
   196  				url := fmt.Sprintf("https://%s/console/login/LoginForm.jsp", host)
   197  				return pkg.GetWebPage(url, host)
   198  			}, longWaitTimeout, longPollingInterval).Should(And(pkg.HasStatus(200), pkg.BodyContains("Oracle WebLogic Server Administration Console")))
   199  		})
   200  
   201  		// Verify the application REST endpoint is working.
   202  		// GIVEN the app is deployed
   203  		// WHEN the REST endpoint is accessed
   204  		// THEN the expected results should be returned
   205  		t.It("Verify '/todo/rest/items' REST endpoint is working.", func() {
   206  			Eventually(func() (*pkg.HTTPResponse, error) {
   207  				url := fmt.Sprintf("https://%s/todo/rest/items", host)
   208  				return pkg.GetWebPage(url, host)
   209  			}, longWaitTimeout, longPollingInterval).Should(And(pkg.HasStatus(200), pkg.BodyContains("["), pkg.BodyContains("]")))
   210  		})
   211  	})
   212  })