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