forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forcepull.go
126 lines (97 loc) · 3.9 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
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) {
// 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("[Feature:Builds] forcePull should affect pulling builder images", func() {
defer g.GinkgoRecover()
var oc = exutil.NewCLI("forcepull", exutil.KubeConfigPath())
g.Context("", func() {
g.BeforeEach(func() {
exutil.DumpDockerInfo()
g.By("granting system:build-strategy-custom")
binding := fmt.Sprintf("custombuildaccess-%s", oc.Username())
err := oc.AsAdmin().Run("create").Args("clusterrolebinding", binding, "--clusterrole", "system:build-strategy-custom", "--user", oc.Username()).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for openshift/ruby:latest ImageStreamTag")
err = exutil.WaitForAnImageStreamTag(oc, "openshift", "ruby", "latest")
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.AfterEach(func() {
binding := fmt.Sprintf("custombuildaccess-%s", oc.Username())
err := oc.AsAdmin().Run("delete").Args("clusterrolebinding", binding).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
})
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)
})
})
})