Skip to content

Commit 2d203c4

Browse files
committed
Implement skunkworks cluster upgrade test
1 parent c87497d commit 2d203c4

File tree

5 files changed

+166
-14
lines changed

5 files changed

+166
-14
lines changed

integration/framework.go

+57
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,60 @@ func WithMiniInfrastructure(distro linuxDistro, provisioner infrastructureProvis
115115

116116
f(nodes.worker[0], sshKey)
117117
}
118+
119+
// SubDescribe allows you to define specifications inside another spec.
120+
// We have found the need for this because Gingko does not support
121+
// serializing a subset of tests when running in parallel. This means
122+
// that we must define multiple specs inside a parent It() block.
123+
// Use this when it is truly needed.
124+
//
125+
// Example:
126+
// Describe("the foo service", func() {
127+
// It("should be deployed successfully", func() {
128+
// // some assertions here...
129+
// sub := SubDescribe("should return 200", func() error {
130+
// // call service and return error if not 200
131+
// })
132+
// })
133+
// })
134+
func SubDescribe(name string) *subTest {
135+
return &subTest{name: name}
136+
}
137+
138+
type subTest struct {
139+
name string
140+
specs []string
141+
errors []error
142+
}
143+
144+
func (sub *subTest) It(name string, f func() error) {
145+
By(fmt.Sprintf("Running spec: %s - %s", sub.name, name))
146+
sub.specs = append(sub.specs, name)
147+
sub.errors = append(sub.errors, f())
148+
}
149+
150+
func (sub *subTest) Check() {
151+
var failed bool
152+
for _, e := range sub.errors {
153+
if e != nil {
154+
failed = true
155+
break
156+
}
157+
}
158+
if failed {
159+
// Print report and fail test
160+
sub.printReport()
161+
Fail("Failed: " + sub.name)
162+
}
163+
}
164+
165+
func (sub *subTest) printReport() {
166+
fmt.Println(sub.name)
167+
for i, spec := range sub.specs {
168+
if sub.errors[i] != nil {
169+
fmt.Printf("%s: FAILED: %v\n", spec, sub.errors[i])
170+
} else {
171+
fmt.Printf("%s: PASSED\n", spec)
172+
}
173+
}
174+
}

integration/install.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package integration
33
import (
44
"bufio"
55
"html/template"
6-
"log"
76
"os"
87
"os/exec"
98
"path/filepath"
109
"time"
1110

1211
homedir "github.com/mitchellh/go-homedir"
1312
. "github.com/onsi/ginkgo"
13+
. "github.com/onsi/gomega"
1414
)
1515

1616
func leaveIt() bool {
@@ -169,11 +169,8 @@ func completesInTime(dothis func(), howLong time.Duration) bool {
169169
}
170170
}
171171

172-
func FailIfError(err error, message ...string) {
173-
if err != nil {
174-
log.Printf(message[0]+": %v\n%v", err, message[1:])
175-
Fail(message[0])
176-
}
172+
func FailIfError(err error, message ...interface{}) {
173+
Expect(err).ToNot(HaveOccurred(), message...)
177174
}
178175

179176
func FailIfSuccess(err error) {

integration/storage.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func verifyGlusterVolume(storageNode NodeDeets, sshKey string, name string, repl
9595
FailIfError(err, "Gluster volume verification failed")
9696
}
9797

98-
func createVolume(planFile *os.File, name string, replicationCount int, distributionCount int, allowAddress string) {
98+
func createVolume(planFile *os.File, name string, replicationCount int, distributionCount int, allowAddress string) error {
9999
cmd := exec.Command("./kismatic", "volume", "add",
100100
"-f", planFile.Name(),
101101
"--replica-count", strconv.Itoa(replicationCount),
@@ -107,8 +107,7 @@ func createVolume(planFile *os.File, name string, replicationCount int, distribu
107107
}
108108
cmd.Stdout = os.Stdout
109109
cmd.Stderr = os.Stderr
110-
err := cmd.Run()
111-
FailIfError(err, "Error running volume add command")
110+
return cmd.Run()
112111
}
113112

114113
func standupGlusterCluster(planFile *os.File, nodes []NodeDeets, sshKey string, distro linuxDistro) {

integration/upgrade.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package integration
2+
3+
import (
4+
"encoding/json"
5+
"os/exec"
6+
7+
. "github.com/onsi/ginkgo"
8+
. "github.com/onsi/gomega"
9+
)
10+
11+
type infoOutput struct {
12+
EarliestVersion string
13+
LatestVersion string
14+
Nodes []struct {
15+
Version string
16+
}
17+
}
18+
19+
type versionOutput struct {
20+
Version string
21+
}
22+
23+
func assertClusterVersionIsCurrent() {
24+
By("Calling ./kismatic version to get Kismatic version")
25+
cmd := exec.Command("./kismatic", "version", "-o", "json")
26+
out, err := cmd.Output()
27+
FailIfError(err)
28+
ver := versionOutput{}
29+
err = json.Unmarshal(out, &ver)
30+
FailIfError(err)
31+
assertClusterVersion(ver.Version)
32+
}
33+
34+
func assertClusterVersion(version string) {
35+
By("Calling ./kismatic info to get the cluster's version")
36+
cmd := exec.Command("./kismatic", "info", "-f", "kismatic-testing.yaml", "-o", "json")
37+
out, err := cmd.Output()
38+
FailIfError(err)
39+
info := infoOutput{}
40+
err = json.Unmarshal(out, &info)
41+
FailIfError(err)
42+
43+
Expect(info.EarliestVersion).To(Equal(version))
44+
Expect(info.LatestVersion).To(Equal(version))
45+
for _, n := range info.Nodes {
46+
Expect(n.Version).To(Equal(version))
47+
}
48+
}

integration/upgrade_test.go

+56-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import (
88
. "github.com/onsi/gomega"
99
)
1010

11-
var _ = Describe("kismatic upgrade tests", func() {
11+
var _ = Describe("Upgrade", func() {
1212
BeforeEach(func() {
1313
dir := setupTestWorkingDirWithVersion("v1.2.2")
1414
os.Chdir(dir)
1515
})
16-
17-
Describe("Doing an offline upgrade of a kubernetes cluster", func() {
16+
Describe("Upgrading a cluster using offline mode", func() {
1817
Context("Using a minikube layout", func() {
1918
Context("Using Ubuntu 16.04", func() {
20-
ItOnAWS("should result in an upgraded cluster [slow] [upgrade]", func(aws infrastructureProvisioner) {
19+
ItOnAWS("should be upgraded [slow] [upgrade]", func(aws infrastructureProvisioner) {
2120
WithMiniInfrastructure(Ubuntu1604LTS, aws, func(node NodeDeets, sshKey string) {
2221
// Install previous version cluster
2322
err := installKismaticMini(node, sshKey)
@@ -40,7 +39,7 @@ var _ = Describe("kismatic upgrade tests", func() {
4039
})
4140

4241
Context("Using CentOS 7", func() {
43-
ItOnAWS("should result in an upgraded cluster [slow] [upgrade]", func(aws infrastructureProvisioner) {
42+
ItOnAWS("should be upgraded [slow] [upgrade]", func(aws infrastructureProvisioner) {
4443
WithMiniInfrastructure(CentOS7, aws, func(node NodeDeets, sshKey string) {
4544
// Install previous version cluster
4645
err := installKismaticMini(node, sshKey)
@@ -63,5 +62,57 @@ var _ = Describe("kismatic upgrade tests", func() {
6362
})
6463
})
6564

65+
// This spec will be used for testing non-destructive kismatic features on
66+
// an upgraded cluster.
67+
// This spec is open to modification when new assertions have to be made.
68+
Context("Using a skunkworks cluster", func() {
69+
ItOnAWS("should result in an upgraded cluster [slow] [upgrade]", func(aws infrastructureProvisioner) {
70+
WithInfrastructureAndDNS(NodeCount{Etcd: 3, Master: 2, Worker: 3, Ingress: 2, Storage: 2}, CentOS7, aws, func(nodes provisionedNodes, sshKey string) {
71+
opts := installOptions{allowPackageInstallation: true}
72+
err := installKismatic(nodes, opts, sshKey)
73+
FailIfError(err)
74+
75+
pwd, err := os.Getwd()
76+
FailIfError(err)
77+
err = extractCurrentKismatic(pwd)
78+
FailIfError(err)
79+
80+
cmd := exec.Command("./kismatic", "upgrade", "offline", "-f", "kismatic-testing.yaml")
81+
cmd.Stdout = os.Stdout
82+
cmd.Stderr = os.Stderr
83+
err = cmd.Run()
84+
FailIfError(err)
85+
86+
assertClusterVersionIsCurrent()
87+
88+
sub := SubDescribe("Using an upgraded cluster")
89+
defer sub.Check()
90+
91+
sub.It("should allow adding a new storage volume", func() error {
92+
planFile, err := os.Open("kismatic-testing.yaml")
93+
if err != nil {
94+
return err
95+
}
96+
return createVolume(planFile, "test-vol", 1, 1, "")
97+
})
98+
99+
sub.It("should allow adding a worker node", func() error {
100+
return nil
101+
})
102+
103+
sub.It("should have an accessible dashboard", func() error {
104+
return nil
105+
})
106+
107+
sub.It("should be able to deploy a workload with ingress", func() error {
108+
return nil
109+
})
110+
111+
sub.It("should not have kube-apiserver systemd service", func() error {
112+
return nil
113+
})
114+
})
115+
})
116+
})
66117
})
67118
})

0 commit comments

Comments
 (0)