-
Notifications
You must be signed in to change notification settings - Fork 1
/
forcepull.go
134 lines (100 loc) · 4.15 KB
/
forcepull.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
package builds
import (
"fmt"
"strings"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"
)
const (
buildPrefixTS = "ruby-sample-build-ts"
buildPrefixTD = "ruby-sample-build-td"
buildPrefixTC = "ruby-sample-build-tc"
)
func scrapeLogs(bldPrefix string, oc *exutil.CLI) {
// kick off the app/lang build and verify the builder image accordingly
br, err := exutil.StartBuildAndWait(oc, bldPrefix)
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
out, err := br.Logs()
o.Expect(err).NotTo(o.HaveOccurred())
lines := strings.Split(out, "\n")
found := false
for _, line := range lines {
if strings.Contains(line, "Pulling image") && strings.Contains(line, "centos/ruby") {
fmt.Fprintf(g.GinkgoWriter, "\n\nfound pull image line %s\n\n", line)
found = true
break
}
}
if !found {
fmt.Fprintf(g.GinkgoWriter, "\n\n build log dump on failed test: %s\n\n", out)
o.Expect(found).To(o.BeTrue())
}
}
func checkPodFlag(bldPrefix string, oc *exutil.CLI) {
if bldPrefix == buildPrefixTC {
// grant access to the custom build strategy
err := oc.AsAdmin().Run("adm").Args("policy", "add-cluster-role-to-user", "system:build-strategy-custom", oc.Username()).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
defer func() {
err = oc.AsAdmin().Run("adm").Args("policy", "remove-cluster-role-from-user", "system:build-strategy-custom", oc.Username()).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
}()
}
// kick off the app/lang build and verify the builder image accordingly
_, err := exutil.StartBuildAndWait(oc, bldPrefix)
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
out, err := oc.Run("get").Args("pods", bldPrefix+"-1-build", "-o", "jsonpath='{.spec.containers[0].imagePullPolicy}'").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.Equal("'Always'"))
}
/*
If docker.io is not responding to requests in a timely manner, this test suite will be adversely affected.
If you suspect such a situation, attempt pulling some openshift images other than ruby-22-centos7
while this test is running and compare results. Restarting your docker daemon, assuming you can ping docker.io quickly, could
be a quick fix.
*/
var _ = g.Describe("[builds] forcePull should affect pulling builder images", func() {
defer g.GinkgoRecover()
var oc = exutil.NewCLI("forcepull", exutil.KubeConfigPath())
g.BeforeEach(func() {
g.By("waiting for openshift/ruby:latest ImageStreamTag")
err := exutil.WaitForAnImageStreamTag(oc, "openshift", "ruby", "latest")
o.Expect(err).NotTo(o.HaveOccurred())
// grant access to the custom build strategy
g.By("granting system:build-strategy-custom")
err = oc.AsAdmin().Run("adm").Args("policy", "add-cluster-role-to-user", "system:build-strategy-custom", oc.Username()).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
defer func() {
err = oc.AsAdmin().Run("adm").Args("policy", "remove-cluster-role-from-user", "system:build-strategy-custom", oc.Username()).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
}()
g.By("create application build configs for 3 strategies")
apps := exutil.FixturePath("testdata", "forcepull-test.json")
err = exutil.CreateResource(apps, oc)
o.Expect(err).NotTo(o.HaveOccurred())
})
g.Context("ForcePull test context ", func() {
g.JustBeforeEach(func() {
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.AdminKubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.It("ForcePull test case execution s2i", func() {
g.By("when s2i force pull is true")
// run twice to ensure the builder image gets pulled even if it already exists on the node
scrapeLogs(buildPrefixTS, oc)
scrapeLogs(buildPrefixTS, oc)
})
g.It("ForcePull test case execution docker", func() {
g.By("docker when force pull is true")
// run twice to ensure the builder image gets pulled even if it already exists on the node
scrapeLogs(buildPrefixTD, oc)
scrapeLogs(buildPrefixTD, oc)
})
g.It("ForcePull test case execution custom", func() {
g.By("when custom force pull is true")
checkPodFlag(buildPrefixTC, oc)
})
})
})