Skip to content

Commit

Permalink
Issue crc-org#786 Integration: Install operator from marketplace user…
Browse files Browse the repository at this point in the history
… story
  • Loading branch information
jsliacan committed Nov 22, 2019
1 parent 872b647 commit 01f4364
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/integration/crcsuite/crcsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func FeatureContext(s *godog.Suite) {
CheckClusterOperatorsWithRetry)
s.Step(`^with up to "(\d+)" retries with wait period of "(\d*(?:ms|s|m))" http response from "(.*)" has status code "(\d+)"$`,
CheckHTTPResponseWithRetry)
s.Step(`^with up to "(\d+)" retries with wait period of "(\d*(?:ms|s|m))" command "(.*)" output (?:should match|matches) "(.*)"$`,
s.Step(`^with up to "(\d+)" retries with wait period of "(\d*(?:ms|s|m))" command "(.*)" output (should match|matches|should not match|does not match) "(.*)"$`,
CheckOutputMatchWithRetry)
s.Step(`stdout (?:should contain|contains) "(.*)" if bundle (is|is not) embedded$`,
StdoutContainsIfBundleEmbeddedOrNot)
Expand Down Expand Up @@ -140,7 +140,6 @@ func FeatureContext(s *godog.Suite) {
if err != nil {
fmt.Println(err)
}

})

s.AfterSuite(func() {
Expand All @@ -152,6 +151,9 @@ func FeatureContext(s *godog.Suite) {

s.BeforeFeature(func(this *gherkin.Feature) {

// copy data/config files to test dir
CopyFilesToTestDir()

if bundleEmbedded == false {
if _, err := os.Stat(bundleName); os.IsNotExist(err) {
// Obtain the bundle to current dir
Expand Down Expand Up @@ -221,7 +223,7 @@ func CheckHTTPResponseWithRetry(retryCount int, retryWait string, address string
return fmt.Errorf("Got %d as Status Code instead of expected %d.", resp.StatusCode, expectedStatusCode)
}

func CheckOutputMatchWithRetry(retryCount int, retryTime string, command string, expected string) error {
func CheckOutputMatchWithRetry(retryCount int, retryTime string, command string, expected string, expectedOutput string) error {

retryDuration, err := time.ParseDuration(retryTime)
if err != nil {
Expand All @@ -233,7 +235,11 @@ func CheckOutputMatchWithRetry(retryCount int, retryTime string, command string,
for i := 0; i < retryCount; i++ {
exec_err := clicumber.ExecuteCommand(command)
if exec_err == nil {
match_err = clicumber.CommandReturnShouldMatch("stdout", expected)
if strings.Contains(expected, " not ") {
match_err = clicumber.CommandReturnShouldNotMatch("stdout", expectedOutput)
} else {
match_err = clicumber.CommandReturnShouldMatch("stdout", expectedOutput)
}
if match_err == nil {
return nil
}
Expand Down
56 changes: 56 additions & 0 deletions test/integration/crcsuite/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"

"github.com/code-ready/crc/pkg/download"
Expand Down Expand Up @@ -56,6 +58,60 @@ func DownloadBundle(bundleLocation string, bundleDestination string) (string, er
return filename, nil
}

func CopyFilesToTestDir() {

pwd, err := os.Getwd()
if err != nil {
fmt.Printf("Error retrieving current dir: %s", err)
os.Exit(1)
}
pDir := path.Dir(pwd)
pDir = path.Dir(pDir)
pDir = path.Dir(pDir)
dataDir := filepath.Join(pDir, "testdata")
fmt.Printf("dataDir: %s\n", dataDir)

files, err := ioutil.ReadDir(dataDir)
if err != nil {
fmt.Printf("Error occured loading data files: %s", err)
os.Exit(1)
}

for _, file := range files {

sFileName := filepath.Join(dataDir, file.Name())
destLoc, _ := os.Getwd()
fmt.Printf("Copying %s to %s\n", sFileName, destLoc)

sFile, err := os.Open(sFileName)
if err != nil {
fmt.Printf("Error occured opening file: %s", err)
os.Exit(1)
}
defer sFile.Close()

_, dFileName := filepath.Split(sFileName)
dFile, err := os.Create(dFileName)
if err != nil {
fmt.Printf("Error occured creating file: %s", err)
os.Exit(1)
}
defer dFile.Close()

_, err = io.Copy(dFile, sFile) // ignore num of bytes
if err != nil {
fmt.Printf("Error occured copying file: %s", err)
os.Exit(1)
}

err = dFile.Sync()
if err != nil {
fmt.Printf("Error occured syncing file: %s", err)
os.Exit(1)
}
}
}

func ParseFlags() {

flag.StringVar(&bundleURL, "bundle-location", "embedded", "Path to the bundle to be used in tests")
Expand Down
74 changes: 74 additions & 0 deletions test/integration/features/story_marketplace.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@story_marketplace
Feature:
Install OpenShift operator from OperatorHub and use it to manage
admin tasks.

Scenario Outline: Start CRC and login to cluster
Given executing "crc setup" succeeds
When starting CRC with default bundle and hypervisor "<vm-driver>" succeeds
Then stdout should contain "Started the OpenShift cluster"
And executing "eval $(crc oc-env)" succeeds
When with up to "4" retries with wait period of "2m" command "crc status" output matches ".*Running \(v\d+\.\d+\.\d+.*\).*"
Then login to the oc cluster succeeds

@darwin
Examples:
| vm-driver |
| hyperkit |

@linux
Examples:
| vm-driver |
| libvirt |

@windows
Scenario: Start CRC on Windows
Given executing "crc setup" succeeds
When starting CRC with default bundle and nameserver "10.75.5.25" succeeds
Then stdout should contain "Started the OpenShift cluster"
And executing "crc oc-env | Invoke-Expression" succeeds
When with up to "4" retries with wait period of "2m" command "crc status" output matches ".*Running \(v\d+\.\d+\.\d+.*\).*"
Then login to the oc cluster succeeds

@darwin @linux @windows
Scenario: Install new operator
Given executing "oc apply -f etcdop-csc.yaml" succeeds
When executing "oc apply -f etcdop-sub.yaml" succeeds
# check if cluster operator is running
Then with up to "20" retries with wait period of "30s" command "oc get csv" output matches ".*etcdoperator\.(.*)Succeeded$"

@darwin @linux @windows
Scenario: Scale up
# start cluster with 3 pods
When executing "oc apply -f etcd-cluster3.yaml" succeeds
Then with up to "10" retries with wait period of "30s" command "oc get pods" output matches "(?s)(.*example-[a-z0-9]* *1/1 *Running.*){3}"
# reconfigure cluster to 5 pods
When executing "oc apply -f etcd-cluster5.yaml" succeeds
Then with up to "10" retries with wait period of "30s" command "oc get pods" output matches "(?s)(.*example-[a-z0-9]* *1/1 *Running.*){5}"

@darwin @linux @windows
Scenario: Failover
# simulate failure of 1 pod, check that it was replaced
When executing "POD=$(oc get pod -o jsonpath="{.items[0].metadata.name}")" succeeds
And executing "echo $POD" succeeds
And executing "oc delete pod $POD --now" succeeds
Then stdout should match "^pod(.*)deleted$"
# after a while 5 pods should be up & running again
And with up to "10" retries with wait period of "30s" command "oc get pods" output matches "(?s)(.*example-[a-z0-9]* *1/1 *Running.*){5}"
# but the deleted pod should not be up, it was replaced
But executing "oc get pods $POD" fails
And stderr matches "(.*)pods (.*) not found$"

@darwin @linux @windows
Scenario: Scale down
# scale back down to 3 pods
When executing "oc apply -f etcd-cluster3.yaml" succeeds
Then with up to "10" retries with wait period of "30s" command "oc get pods" output matches "(?s)(.*example-[a-z0-9]* *1/1 *Running.*){3}"
But with up to "10" retries with wait period of "30s" command "oc get pods" output does not match "(?s)(.*example-[a-z0-9]* *1/1 *Running.*){4}"

@darwin @linux @windows
Scenario: Clean up
When executing "crc stop -f" succeeds
Then stdout should match "(.*)[Ss]topped the OpenShift cluster"
When executing "crc delete -f" succeeds
Then stdout should contain "Deleted the OpenShift cluster"
10 changes: 10 additions & 0 deletions test/testdata/etcd-cluster3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: etcd.database.coreos.com/v1beta2
kind: EtcdCluster
metadata:
name: example
annotations:
etcd.database.coreos.com/scope: clusterwide
namespace: default
spec:
size: 3
version: 3.2.13
10 changes: 10 additions & 0 deletions test/testdata/etcd-cluster5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: etcd.database.coreos.com/v1beta2
kind: EtcdCluster
metadata:
name: example
annotations:
etcd.database.coreos.com/scope: clusterwide
namespace: default
spec:
size: 5
version: 3.2.13
9 changes: 9 additions & 0 deletions test/testdata/etcdop-csc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: operators.coreos.com/v1
kind: CatalogSourceConfig
metadata:
name: etcd
namespace: openshift-marketplace
spec:
targetNamespace: openshift-operators
packages: etcd
source: community-operators
12 changes: 12 additions & 0 deletions test/testdata/etcdop-sub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: etcd
namespace: openshift-operators
spec:
channel: clusterwide-alpha
installPlanApproval: Automatic
name: etcd
source: community-operators
sourceNamespace: openshift-marketplace
startingCSV: etcdoperator.v0.9.4-clusterwide

0 comments on commit 01f4364

Please sign in to comment.