Skip to content

Commit

Permalink
Use Redis operator to test odo service create with parameters (redh…
Browse files Browse the repository at this point in the history
…at-developer#5142)

* Do not install PG operator

* Rewrite tests with Redis operator
  • Loading branch information
feloy committed Oct 13, 2021
1 parent 07d2b80 commit 56741d6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 123 deletions.
28 changes: 0 additions & 28 deletions scripts/configure-cluster/common/setup-postgres-operator.sh

This file was deleted.

7 changes: 0 additions & 7 deletions scripts/configure-installer-tests-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ set -x
LIBDIR="./scripts/configure-cluster"
LIBCOMMON="$LIBDIR/common"
SETUP_OPERATORS="$LIBCOMMON/setup-operators.sh"
SETUP_POSTGRES_OPERATOR="$LIBCOMMON/setup-postgres-operator.sh"
AUTH_SCRIPT="$LIBCOMMON/auth.sh"
KUBEADMIN_SCRIPT="$LIBCOMMON/kubeconfigandadmin.sh"
POSTGRES_OPERATOR_PROJECT="odo-operator-test"

# list of namespace to create
IMAGE_TEST_NAMESPACES="openjdk-11-rhel8 nodejs-12-rhel7 nodejs-12 openjdk-11 nodejs-14"

. $KUBEADMIN_SCRIPT

. $SETUP_POSTGRES_OPERATOR

# Setup the cluster for Operator tests
sh $SETUP_OPERATORS

oc new-project $POSTGRES_OPERATOR_PROJECT
# Let developer user have access to the project
oc adm policy add-role-to-user edit developer

install_postgres_operator $POSTGRES_OPERATOR_PROJECT

# OperatorHub setup complete

# Create the namespace for e2e image test apply pull secret to the namespace
Expand Down
11 changes: 0 additions & 11 deletions scripts/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export ARTIFACTS_DIR="`pwd`/artifacts"
export CUSTOM_HOMEDIR=$ARTIFACT_DIR
LIBDIR="./scripts/configure-cluster"
LIBCOMMON="$LIBDIR/common"
SETUP_POSTGRES_OPERATOR="$LIBCOMMON/setup-postgres-operator.sh"

# This si one of the variables injected by ci-firewall. Its purpose is to allow scripts to handle uniqueness as needed
SCRIPT_IDENTITY=${SCRIPT_IDENTITY:-"def-id"}
Expand Down Expand Up @@ -92,7 +91,6 @@ export REDHAT_OPENJDK11_UBI8_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr
export REDHAT_NODEJS12_RHEL7_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"
export REDHAT_NODEJS12_UBI8_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"
export REDHAT_NODEJS14_UBI8_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"
export REDHAT_POSTGRES_OPERATOR_PROJECT="${SCRIPT_IDENTITY}$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1)"

# Create the namespace for e2e image test apply pull secret to the namespace
for i in `echo "$REDHAT_OPENJDK11_RHEL8_PROJECT $REDHAT_NODEJS12_RHEL7_PROJECT $REDHAT_NODEJS12_UBI8_PROJECT $REDHAT_OPENJDK11_UBI8_PROJECT $REDHAT_NODEJS14_UBI8_PROJECT $REDHAT_POSTGRES_OPERATOR_PROJECT"`; do
Expand All @@ -104,15 +102,6 @@ for i in `echo "$REDHAT_OPENJDK11_RHEL8_PROJECT $REDHAT_NODEJS12_RHEL7_PROJECT $
oc adm policy add-role-to-user edit developer
done

#---------------------------------------------------------------------

# Install namespace specific operators

. $SETUP_POSTGRES_OPERATOR

install_postgres_operator $REDHAT_POSTGRES_OPERATOR_PROJECT


#---------------------------------------------------------------------

shout "Logging into 4x cluster as developer (logs hidden)"
Expand Down
126 changes: 49 additions & 77 deletions tests/integration/operatorhub/cmd_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,83 +46,6 @@ var _ = Describe("odo service command tests for OperatorHub", func() {
Expect(stdOut).To(ContainSubstring("service can be created/deleted from a valid component directory only"))
})

Context("a namespace specific operator is installed", func() {

var postgresOperator string
var postgresDatabase string
var projectName string

BeforeEach(func() {
if os.Getenv("KUBERNETES") == "true" {
Skip("This is a OpenShift specific scenario, skipping")
}
projectName = util.GetEnvWithDefault("REDHAT_POSTGRES_OPERATOR_PROJECT", "odo-operator-test")
helper.GetCliRunner().SetProject(projectName)
operators := helper.Cmd("odo", "catalog", "list", "services").ShouldPass().Out()
postgresOperator = regexp.MustCompile(`postgresql-operator\.*[a-z][0-9]\.[0-9]\.[0-9]`).FindString(operators)
postgresDatabase = fmt.Sprintf("%s/Database", postgresOperator)
})

When("a nodejs component is created", func() {

BeforeEach(func() {
helper.CopyExample(filepath.Join("source", "nodejs"), commonVar.Context)
// change the app name to avoid conflicts
appName := helper.RandString(5)
helper.Cmd("odo", "create", "nodejs", "--app", appName, "--context", commonVar.Context, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-registry.yaml")).ShouldPass().Out()
helper.Cmd("odo", "config", "set", "Memory", "300M", "-f", "--context", commonVar.Context).ShouldPass()
})

AfterEach(func() {
// we do this because for these specific tests we dont delete the project
helper.Cmd("odo", "delete", "--all", "-f", "--context", commonVar.Context).ShouldPass().Out()
})

It("should try to create a service in dry run mode with some provided params", func() {
serviceName := helper.RandString(10)
output := helper.Cmd("odo", "service", "create", postgresDatabase, serviceName, "-p",
"databaseName=odo", "-p", "size=1", "-p", "databaseUser=odo", "-p",
"databaseStorageRequest=1Gi", "-p", "databasePassword=odopasswd", "--dry-run", "--context", commonVar.Context).ShouldPass().Out()
helper.MatchAllInOutput(output, []string{fmt.Sprintf("name: %s", serviceName), "odo", "odopasswd", "1Gi"})
})

When("creating a postgres operand with params", func() {
var operandName string

BeforeEach(func() {
operandName = helper.RandString(10)
helper.Cmd("odo", "service", "create", postgresDatabase, operandName, "-p",
"databaseName=odo", "-p", "size=1", "-p", "databaseUser=odo", "-p",
"databaseStorageRequest=1Gi", "-p", "databasePassword=odopasswd", "--context", commonVar.Context).ShouldPass().Out()

})

AfterEach(func() {
helper.Cmd("odo", "service", "delete", fmt.Sprintf("Database/%s", operandName), "-f", "--context", commonVar.Context).ShouldPass().Out()
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
})

When("odo push is executed", func() {
BeforeEach(func() {
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
})

It("should create pods in running state and list the service", func() {
commonVar.CliRunner.PodsShouldBeRunning(projectName, fmt.Sprintf(`%s-.[\-a-z0-9]*`, operandName))
// TODO(feloy) These 2 tests cannot run in parallel on the same namespace. Rollback when using a multi-namespace operator
// })
//
// It("should list the service", func() {
stdOut := helper.Cmd("odo", "service", "list", "--context", commonVar.Context).ShouldPass().Out()
Expect(stdOut).To(ContainSubstring(fmt.Sprintf("Database/%s", operandName)))
})
})

})

})
})

Context("a specific operator is installed", func() {
var redisOperator string
var redisCluster string
Expand Down Expand Up @@ -209,6 +132,55 @@ var _ = Describe("odo service command tests for OperatorHub", func() {
"-p", "securityContext.runAsUser=1000").ShouldPass()
})

It("should try to create a service in dry run mode with some provided params", func() {
serviceName := helper.RandString(10)
output := helper.Cmd("odo", "service", "create", fmt.Sprintf("%s/Redis", redisOperator), serviceName,
"-p", "kubernetesConfig.image=quay.io/opstree/redis:v6.2.5",
"-p", "redisExporter.image=quay.io/opstree/redis-exporter:1.0",
"-p", "kubernetesConfig.serviceType=ClusterIP",
"-p", "kubernetesConfig.resources.requests.cpu=100m",
"-p", "kubernetesConfig.resources.requests.memory=128Mi",
"--dry-run", "--context", commonVar.Context).ShouldPass().Out()
helper.MatchAllInOutput(output, []string{fmt.Sprintf("name: %s", serviceName), "quay.io/opstree/redis:v6.2.5", "ClusterIP", "100m", "128Mi"})
})

When("creating a postgres operand with params", func() {
var operandName string

BeforeEach(func() {
operandName = helper.RandString(10)
helper.Cmd("odo", "service", "create", fmt.Sprintf("%s/Redis", redisOperator), operandName,
"-p", "kubernetesConfig.image=quay.io/opstree/redis:v6.2.5",
"-p", "redisExporter.image=quay.io/opstree/redis-exporter:1.0",
"-p", "kubernetesConfig.serviceType=ClusterIP",
"-p", "kubernetesConfig.resources.requests.cpu=100m",
"-p", "kubernetesConfig.resources.requests.memory=128Mi",
"--context", commonVar.Context).ShouldPass().Out()

})

AfterEach(func() {
helper.Cmd("odo", "service", "delete", fmt.Sprintf("Redis/%s", operandName), "-f", "--context", commonVar.Context).ShouldPass().Out()
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
})

When("odo push is executed", func() {
BeforeEach(func() {
helper.Cmd("odo", "push", "--context", commonVar.Context).ShouldPass().Out()
})

It("should create pods in running state", func() {
commonVar.CliRunner.PodsShouldBeRunning(commonVar.Project, fmt.Sprintf(`%s-0`, operandName))
})

It("should list the service", func() {
stdOut := helper.Cmd("odo", "service", "list", "--context", commonVar.Context).ShouldPass().Out()
Expect(stdOut).To(ContainSubstring(fmt.Sprintf("Redis/%s", operandName)))
})
})

})

When("odo push is executed", func() {
BeforeEach(func() {
helper.Cmd("odo", "push").ShouldPass()
Expand Down

0 comments on commit 56741d6

Please sign in to comment.