forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.go
165 lines (136 loc) · 6.32 KB
/
pipeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package builds
import (
"fmt"
"strings"
"sync"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"
"github.com/openshift/origin/test/extended/util/jenkins"
)
var _ = g.Describe("[builds][Slow] openshift pipeline build", func() {
defer g.GinkgoRecover()
var (
jenkinsTemplatePath = exutil.FixturePath("..", "..", "examples", "jenkins", "jenkins-ephemeral-template.json")
mavenSlavePipelinePath = exutil.FixturePath("..", "..", "examples", "jenkins", "pipeline", "maven-pipeline.yaml")
orchestrationPipelinePath = exutil.FixturePath("..", "..", "examples", "jenkins", "pipeline", "mapsapp-pipeline.yaml")
blueGreenPipelinePath = exutil.FixturePath("..", "..", "examples", "jenkins", "pipeline", "bluegreen-pipeline.yaml")
oc = exutil.NewCLI("jenkins-pipeline", exutil.KubeConfigPath())
)
g.JustBeforeEach(func() {
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.Context("Pipeline with maven slave", func() {
g.It("Should build and complete successfully", func() {
// Deploy Jenkins
g.By(fmt.Sprintf("calling oc new-app -f %q", jenkinsTemplatePath))
err := oc.Run("new-app").Args("-f", jenkinsTemplatePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// instantiate the template
g.By(fmt.Sprintf("calling oc new-app -f %q", mavenSlavePipelinePath))
err = oc.Run("new-app").Args("-f", mavenSlavePipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// start the build
g.By("starting the pipeline build and waiting for it to complete")
br, _ := exutil.StartBuildAndWait(oc, "openshift-jee-sample")
br.AssertSuccess()
// wait for the service to be running
g.By("expecting the openshift-jee-sample service to be deployed and running")
_, err = exutil.GetEndpointAddress(oc, "openshift-jee-sample")
o.Expect(err).NotTo(o.HaveOccurred())
})
})
g.Context("Orchestration pipeline", func() {
g.It("Should build and complete successfully", func() {
// Deploy Jenkins
g.By(fmt.Sprintf("calling oc new-app -f %q", jenkinsTemplatePath))
err := oc.Run("new-app").Args("-f", jenkinsTemplatePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// instantiate the template
g.By(fmt.Sprintf("calling oc new-app -f %q", orchestrationPipelinePath))
err = oc.Run("new-app").Args("-f", orchestrationPipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// start the build
g.By("starting the pipeline build and waiting for it to complete")
br, _ := exutil.StartBuildAndWait(oc, "mapsapp-pipeline")
br.AssertSuccess()
// wait for the service to be running
g.By("expecting the parksmap-web service to be deployed and running")
_, err = exutil.GetEndpointAddress(oc, "parksmap")
o.Expect(err).NotTo(o.HaveOccurred())
})
})
g.Context("Blue-green pipeline", func() {
g.It("Should build and complete successfully", func() {
// Deploy Jenkins without oauth
g.By(fmt.Sprintf("calling oc new-app -f %q -p ENABLE_OAUTH=false", jenkinsTemplatePath))
err := oc.Run("new-app").Args("-f", jenkinsTemplatePath, "-p", "ENABLE_OAUTH=false").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
j := jenkins.NewRef(oc)
// instantiate the template
g.By(fmt.Sprintf("calling oc new-app -f %q", blueGreenPipelinePath))
err = oc.Run("new-app").Args("-f", blueGreenPipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
wg := &sync.WaitGroup{}
wg.Add(1)
// start the build
go func() {
g.By("starting the bluegreen pipeline build and waiting for it to complete")
br, _ := exutil.StartBuildAndWait(oc, "bluegreen-pipeline")
br.AssertSuccess()
g.By("verifying that the main route has been switched to green")
value, err := oc.Run("get").Args("route", "nodejs-mongodb-example", "-o", "jsonpath={ .spec.to.name }").Output()
o.Expect(err).NotTo(o.HaveOccurred())
activeRoute := strings.TrimSpace(value)
g.By("verifying that the active route is 'nodejs-mongodb-example-green'")
o.Expect(activeRoute).To(o.Equal("nodejs-mongodb-example-green"))
wg.Done()
}()
// wait for the green service to be available
g.By("waiting for the nodejs-mongodb-example-green service to be available")
_, err = exutil.GetEndpointAddress(oc, "nodejs-mongodb-example-green")
o.Expect(err).NotTo(o.HaveOccurred())
// approve the Jenkins pipeline
g.By("Waiting for the approval prompt")
jobName := oc.Namespace() + "-bluegreen-pipeline"
_, err = j.WaitForContent("Approve?", 200, 10*time.Minute, "job/%s/lastBuild/consoleText", jobName)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("Approving the current build")
_, _, err = j.Post(nil, fmt.Sprintf("job/%s/lastBuild/input/Approval/proceedEmpty", jobName), "")
o.Expect(err).NotTo(o.HaveOccurred())
// wait for first build completion and verification
g.By("Waiting for the build to complete successfully")
wg.Wait()
wg = &sync.WaitGroup{}
wg.Add(1)
// start the build again
go func() {
g.By("starting the bluegreen pipeline build and waiting for it to complete")
br, _ := exutil.StartBuildAndWait(oc, "bluegreen-pipeline")
br.AssertSuccess()
g.By("verifying that the main route has been switched to blue")
value, err := oc.Run("get").Args("route", "nodejs-mongodb-example", "-o", "jsonpath={ .spec.to.name }").Output()
o.Expect(err).NotTo(o.HaveOccurred())
activeRoute := strings.TrimSpace(value)
g.By("verifying that the active route is 'nodejs-mongodb-example-blue'")
o.Expect(activeRoute).To(o.Equal("nodejs-mongodb-example-blue"))
wg.Done()
}()
// wait for the blue service to be available
g.By("waiting for the nodejs-mongodb-example-blue service to be available")
_, err = exutil.GetEndpointAddress(oc, "nodejs-mongodb-example-blue")
o.Expect(err).NotTo(o.HaveOccurred())
// approve the Jenkins pipeline
g.By("Waiting for the approval prompt")
_, err = j.WaitForContent("Approve?", 200, 10*time.Minute, "job/%s/lastBuild/consoleText", jobName)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("Approving the current build")
_, _, err = j.Post(nil, fmt.Sprintf("job/%s/lastBuild/input/Approval/proceedEmpty", jobName), "")
o.Expect(err).NotTo(o.HaveOccurred())
wg.Wait()
})
})
})