github.com/verrazzano/verrazzano@v1.7.1/tools/psr/tests/scenarios/common/scenario_common.go (about)

     1  // Copyright (c) 2022, 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 common
     5  
     6  import (
     7  	"github.com/onsi/gomega"
     8  	"github.com/verrazzano/verrazzano/pkg/log/vzlog"
     9  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    10  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    11  	"github.com/verrazzano/verrazzano/tools/psr/tests/pkg/psrctlcli"
    12  	"github.com/verrazzano/verrazzano/tools/psr/tests/pkg/secrets"
    13  )
    14  
    15  var (
    16  	NamespaceLabels = map[string]string{
    17  		"istio-injection":    "enabled",
    18  		"verrazzano-managed": "true",
    19  	}
    20  )
    21  
    22  // InitScenario Starts a PSR scenario in the specified namespace; if skipStartScenario is true, the scenario start is skipped
    23  // - Creates and labels and the namespace if necessary
    24  // - If the env var IMAGE_PULL_SECRET is defined, we attempt to create the image pull secret in the target namespace
    25  func InitScenario(t *framework.TestFramework, log vzlog.VerrazzanoLogger, scenarioID string, namespace string, kubeconfig string, skipStartScenario bool) {
    26  	_, err := pkg.CreateOrUpdateNamespace(namespace, NamespaceLabels, nil)
    27  	gomega.Expect(err).To(gomega.Not(gomega.HaveOccurred()))
    28  
    29  	err = secrets.CreateOrUpdatePipelineImagePullSecret(log, namespace, kubeconfig)
    30  	gomega.Expect(err).To(gomega.Not(gomega.HaveOccurred()))
    31  
    32  	if skipStartScenario {
    33  		return
    34  	}
    35  
    36  	if !psrctlcli.IsScenarioRunning(log, scenarioID, namespace) {
    37  		stdout, stderr, err := psrctlcli.StartScenario(log, scenarioID, namespace)
    38  		t.Logs.Infof("StartScenario %s/%s, stdout: %s, stderr: %s", namespace, scenarioID, stdout, stderr)
    39  		gomega.Expect(err).To(gomega.Not(gomega.HaveOccurred()))
    40  	}
    41  }
    42  
    43  // StopScenario - Stops a scenario if it is running in the specified namespace; if skipStopScenario is true, we don't shut it down
    44  func StopScenario(t *framework.TestFramework, log vzlog.VerrazzanoLogger, scenarioID string, namespace string, skipStopScenario bool) {
    45  	if skipStopScenario {
    46  		t.Logs.Info("Skip stop scenario")
    47  		return
    48  	}
    49  	if psrctlcli.IsScenarioRunning(log, scenarioID, namespace) {
    50  		stdout, stderr, err := psrctlcli.StopScenario(log, scenarioID, namespace)
    51  		t.Logs.Infof("StopScenario %s/%s, stdout: %s, stderr: %s", namespace, scenarioID, stdout, stderr)
    52  		gomega.Expect(err).To(gomega.Not(gomega.HaveOccurred()))
    53  	}
    54  }