Skip to content

Commit 5e358ca

Browse files
Jakub Sliacananjannath
authored andcommitted
Issue #370 Add test story to check cluster health
1 parent f674354 commit 5e358ca

File tree

7 files changed

+128
-7
lines changed

7 files changed

+128
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require (
55
github.com/DATA-DOG/godog v0.7.13
66
github.com/YourFin/binappend v0.0.0-20181105185800-0add4bf0b9ad
77
github.com/cavaliercoder/grab v2.0.0+incompatible
8-
github.com/code-ready/clicumber v0.0.0-20190503113956-2563aed4ef12
8+
github.com/code-ready/clicumber v0.0.0-20190801094041-02a92c8f7ece
99
github.com/code-ready/goodhosts v0.0.0-20190712111040-f090f3f77c26
1010
github.com/code-ready/machine v0.0.0-20190731093717-b6d974ad44d0
1111
github.com/docker/go-units v0.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ github.com/cavaliercoder/grab v2.0.0+incompatible h1:wZHbBQx56+Yxjx2TCGDcenhh3cJ
1313
github.com/cavaliercoder/grab v2.0.0+incompatible/go.mod h1:tTBkfNqSBfuMmMBFaO2phgyhdYhiZQ/+iXCZDzcDsMI=
1414
github.com/code-ready/clicumber v0.0.0-20190503113956-2563aed4ef12 h1:h7ppinXfQf2BuaKRqdgA+BjWEL5H5LICRL0Ubq920ys=
1515
github.com/code-ready/clicumber v0.0.0-20190503113956-2563aed4ef12/go.mod h1:bjcKpFX8OebrlwSDgDAf0KAqpdVPGQssQk+IcVwlcog=
16+
github.com/code-ready/clicumber v0.0.0-20190801094041-02a92c8f7ece h1:ZuvFtsdv+H0JlBkKU+M6zGZOH0JcH7hnIvVNy5PQZro=
17+
github.com/code-ready/clicumber v0.0.0-20190801094041-02a92c8f7ece/go.mod h1:bjcKpFX8OebrlwSDgDAf0KAqpdVPGQssQk+IcVwlcog=
1618
github.com/code-ready/goodhosts v0.0.0-20190712111040-f090f3f77c26 h1:rNdqNBHRAAuGv68zZCX0rQAekl0g4qwnseA8OFM2j54=
1719
github.com/code-ready/goodhosts v0.0.0-20190712111040-f090f3f77c26/go.mod h1:kc1Z2UDuIlxPOo7VWCIkYPOaD55KPX0t5qS5cmLBe8Y=
1820
github.com/code-ready/machine v0.0.0-20190513092840-66a8c3b3c494 h1:Krl/Ub9djuzrYW49kUgyroWDMlrqeagL2QrNCjgx1mA=

test/integration/crcsuite/crcsuite.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ package crcsuite
1919

2020
import (
2121
"fmt"
22+
"io/ioutil"
2223
"os"
2324
"path/filepath"
25+
"strings"
26+
"time"
2427

2528
"github.com/DATA-DOG/godog"
2629
"github.com/DATA-DOG/godog/gherkin"
2730

2831
clicumber "github.com/code-ready/clicumber/testsuite"
32+
"github.com/code-ready/crc/pkg/crc/oc"
2933
)
3034

3135
var (
@@ -47,6 +51,10 @@ func FeatureContext(s *godog.Suite) {
4751
StartCRCWithDefaultBundleAndHypervisorSucceedsOrFails)
4852
s.Step(`^setting config property "(.*)" to value "(.*)" (succeeds|fails)$`,
4953
SetConfigPropertyToValueSucceedsOrFails)
54+
s.Step(`^login to the oc cluster (succeeds|fails)$`,
55+
LoginToOcClusterSucceedsOrFails)
56+
s.Step(`^with up to "(\d+)" retries with wait period of "(\d*(?:ms|s|m))" all cluster operators are running$`,
57+
CheckClusterOperatorsWithRetry)
5058

5159
// CRC file operations
5260
s.Step(`^file "([^"]*)" exists in CRC home folder$`,
@@ -96,6 +104,28 @@ func FeatureContext(s *godog.Suite) {
96104
})
97105
}
98106

107+
func CheckClusterOperatorsWithRetry(retryCount int, retryWait string) error {
108+
109+
retryDuration, err := time.ParseDuration(retryWait)
110+
if err != nil {
111+
return err
112+
}
113+
114+
ocConfig := oc.UseOCWithConfig("crc")
115+
for i := 0; i < retryCount; i++ {
116+
s, err := oc.GetClusterOperatorStatus(ocConfig)
117+
if err != nil {
118+
return err
119+
}
120+
if s == true {
121+
return nil
122+
}
123+
time.Sleep(retryDuration)
124+
}
125+
126+
return fmt.Errorf("Some cluster operators are still not running.\n")
127+
}
128+
99129
func DeleteFileFromCRCHome(fileName string) error {
100130

101131
theFile := filepath.Join(CRCHome, fileName)
@@ -175,9 +205,31 @@ func ConfigFileInCRCHomeContainsKey(format string, configFile string, condition
175205
return nil
176206
}
177207

208+
func LoginToOcClusterSucceedsOrFails(expected string) error {
209+
210+
bundle := strings.Split(bundleName, ".crcbundle")[0]
211+
pswdLocation := filepath.Join(CRCHome, "cache", bundle, "kubeadmin-password")
212+
213+
pswdFile, err := os.Open(pswdLocation)
214+
if err != nil {
215+
return err
216+
}
217+
defer pswdFile.Close()
218+
219+
pswd, err := ioutil.ReadAll(pswdFile)
220+
if err != nil {
221+
return err
222+
}
223+
224+
cmd := fmt.Sprintf("oc login --insecure-skip-tls-verify -u kubeadmin -p %s https://api.crc.testing:6443", pswd)
225+
err = clicumber.ExecuteCommandSucceedsOrFails(cmd, expected)
226+
227+
return err
228+
}
229+
178230
func StartCRCWithDefaultBundleAndDefaultHypervisorSucceedsOrFails(expected string) error {
179231

180-
cmd := fmt.Sprintf("crc start -b %s -p '%s'", bundleName, pullSecretFile)
232+
cmd := fmt.Sprintf("crc start -b %s -p '%s' --log-level debug", bundleName, pullSecretFile)
181233
err := clicumber.ExecuteCommandSucceedsOrFails(cmd, expected)
182234

183235
return err
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Feature:
2+
End-to-end health check. Set-up and start CRC. Then create a
3+
project and deploy an app. Check on the app and delete the
4+
project. Stop and delete CRC.
5+
6+
Scenario Outline: Start CRC
7+
Given executing "crc setup" succeeds
8+
When starting CRC with default bundle and hypervisor "<vm-driver>" succeeds
9+
Then stdout should contain "CodeReady Containers instance is running"
10+
And executing "eval $(crc oc-env)" succeeds
11+
When with up to "4" retries with wait period of "2m" command "crc status" output should contain "Running (v4.x)"
12+
Then login to the oc cluster succeeds
13+
14+
@darwin
15+
Examples:
16+
| vm-driver |
17+
| hyperkit |
18+
19+
@linux
20+
Examples:
21+
| vm-driver |
22+
| libvirt |
23+
24+
@darwin @linux
25+
Scenario: Check cluster health
26+
Given executing "crc status" succeeds
27+
And stdout contains "Running (v4.x)"
28+
When executing "oc get nodes"
29+
Then stdout contains "Ready"
30+
And stdout does not contain "Not ready"
31+
# next line checks similar things as `crc status` except gives more informative output
32+
And with up to "5" retries with wait period of "1m" all cluster operators are running
33+
34+
@darwin @linux
35+
Scenario: Create project
36+
When executing "oc new-project testproj" succeeds
37+
Then stdout should contain
38+
"""
39+
Now using project "testproj" on server "https://api.crc.testing:6443".
40+
"""
41+
And stdout should contain "You can add applications to this project with the 'new-app' command."
42+
43+
@darwin @linux
44+
Scenario: Create and test app
45+
When executing "oc new-app centos/httpd-24-centos7~https://github.com/sclorg/httpd-ex" succeeds
46+
Then stdout should contain "Creating resources"
47+
And stdout should contain
48+
"""
49+
service "httpd-ex" created
50+
"""
51+
When executing "oc rollout status dc/httpd-ex" succeeds
52+
Then stdout should contain "successfully rolled out"
53+
And executing "oc expose svc/httpd-ex" succeeds
54+
And with up to "2" retries with wait period of "60s" command "curl -kI http://httpd-ex-testproj.apps-crc.testing" output should contain "HTTP/1.1 200 OK"
55+
56+
Scenario: Clean up
57+
Given executing "oc delete project testproj" succeeds
58+
When executing "crc stop -f" succeeds
59+
Then stdout should contain "CodeReady Containers instance stopped"
60+
When executing "crc delete" succeeds
61+
Then stdout should contain "CodeReady Containers instance deleted"

vendor/github.com/code-ready/clicumber/testsuite/shell.go

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/code-ready/clicumber/testsuite/testsuite.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ github.com/DATA-DOG/godog/colors
66
github.com/YourFin/binappend
77
# github.com/cavaliercoder/grab v2.0.0+incompatible
88
github.com/cavaliercoder/grab
9-
# github.com/code-ready/clicumber v0.0.0-20190503113956-2563aed4ef12
9+
# github.com/code-ready/clicumber v0.0.0-20190801094041-02a92c8f7ece
1010
github.com/code-ready/clicumber/testsuite
1111
github.com/code-ready/clicumber/util
1212
# github.com/code-ready/goodhosts v0.0.0-20190712111040-f090f3f77c26

0 commit comments

Comments
 (0)