Browse code

Tests: don't clone openshift/origin where possible

The jenkins/kubernetes_plugin.go test works now, remove it from the list
of excluded tests.

Martin Milata authored on 2016/10/17 22:17:32
Showing 8 changed files
... ...
@@ -45,7 +45,7 @@ var _ = g.Describe("[builds][Slow] s2i build with environment file in sources",
45 45
 			o.Expect(err).NotTo(o.HaveOccurred())
46 46
 
47 47
 			g.By("starting a test build")
48
-			br, _ := exutil.StartBuildAndWait(oc, "test")
48
+			br, _ := exutil.StartBuildAndWait(oc, "test", "--from-dir", "test/extended/testdata/sti-environment-build-app")
49 49
 			br.AssertSuccess()
50 50
 
51 51
 			g.By("getting the Docker image reference from ImageStream")
... ...
@@ -1,7 +1,10 @@
1 1
 package jenkins
2 2
 
3 3
 import (
4
+	"encoding/json"
4 5
 	"fmt"
6
+	"io/ioutil"
7
+	"os"
5 8
 	"path/filepath"
6 9
 	"strings"
7 10
 	"time"
... ...
@@ -13,28 +16,75 @@ import (
13 13
 	"k8s.io/kubernetes/pkg/util/wait"
14 14
 )
15 15
 
16
+// patchTemplate finds BuildConfigs in a template, changes their source type to Binary, and removes all triggers
17
+func patchTemplate(filename string, outDir string) string {
18
+	inputJson, err := ioutil.ReadFile(filename)
19
+	o.Expect(err).ToNot(o.HaveOccurred())
20
+
21
+	var template map[string]interface{}
22
+	err = json.Unmarshal(inputJson, &template)
23
+	o.Expect(err).ToNot(o.HaveOccurred())
24
+
25
+	for _, obj := range template["objects"].([]interface{}) {
26
+		bc := obj.(map[string]interface{})
27
+		if kind := bc["kind"].(string); kind != "BuildConfig" {
28
+			continue
29
+		}
30
+		spec := bc["spec"].(map[string]interface{})
31
+		spec["triggers"] = []interface{}{}
32
+
33
+		source := spec["source"].(map[string]interface{})
34
+		source["type"] = "Binary"
35
+		delete(source, "git")
36
+		delete(source, "contextDir")
37
+	}
38
+
39
+	outputJson, err := json.MarshalIndent(template, "", "  ")
40
+	o.Expect(err).ToNot(o.HaveOccurred())
41
+
42
+	basename := filepath.Base(filename)
43
+	outputFile := filepath.Join(outDir, basename)
44
+	err = ioutil.WriteFile(outputFile, outputJson, 0644)
45
+	o.Expect(err).ToNot(o.HaveOccurred())
46
+
47
+	return outputFile
48
+}
49
+
16 50
 var _ = g.Describe("[jenkins] schedule jobs on pod slaves", func() {
17 51
 	defer g.GinkgoRecover()
18 52
 
19 53
 	var (
20
-		jenkinsExampleDir           = filepath.Join("examples", "jenkins-master")
21
-		jenkinsMasterTemplate       = filepath.Join(jenkinsExampleDir, "jenkins-master-template.json")
22
-		jenkinsSlaveBuilderTemplate = filepath.Join(jenkinsExampleDir, "jenkins-slave-template.json")
23
-
24
-		oc = exutil.NewCLI("jenkins-kube", exutil.KubeConfigPath())
54
+		jenkinsExampleDir = filepath.Join("examples", "jenkins", "master-slave")
55
+		oc                = exutil.NewCLI("jenkins-kube", exutil.KubeConfigPath())
25 56
 	)
26 57
 
27
-	var waitForBuildComplete = func(name string) (bool, error) {
28
-		out, err := oc.Run("get").Args("build", name, "-o", "template", "--template", "{{ .status.phase }}").Output()
29
-		if err != nil {
30
-			return false, nil
31
-		}
32
-		return strings.Contains(out, "Complete"), nil
33
-	}
58
+	var (
59
+		jenkinsMasterTemplate       string
60
+		jenkinsSlaveBuilderTemplate string
61
+		jsonTempDir                 string
62
+	)
34 63
 
35 64
 	g.Describe("use of jenkins with kubernetes plugin", func() {
36 65
 		oc.SetOutputDir(exutil.TestContext.OutputDir)
37 66
 
67
+		g.BeforeEach(func() {
68
+			var err error
69
+			jsonTempDir, err = ioutil.TempDir(exutil.TestContext.OutputDir, "jenkins-kubernetes-")
70
+			o.Expect(err).NotTo(o.HaveOccurred())
71
+
72
+			// We need to prepare the templates first in order to use binary builds:
73
+			// 1. remove BuildConfig triggers to not start build immediately after instantiating template,
74
+			// 2. remove contextDir so that we can send just that directory as a binary, not whole repo.
75
+			jenkinsMasterTemplate = patchTemplate(filepath.Join(jenkinsExampleDir, "jenkins-master-template.json"), jsonTempDir)
76
+			jenkinsSlaveBuilderTemplate = patchTemplate(filepath.Join(jenkinsExampleDir, "jenkins-slave-template.json"), jsonTempDir)
77
+		})
78
+
79
+		g.AfterEach(func() {
80
+			if len(jsonTempDir) > 0 {
81
+				os.RemoveAll(jsonTempDir)
82
+			}
83
+		})
84
+
38 85
 		g.It("by creating slave from existing builder and adding it to Jenkins master", func() {
39 86
 
40 87
 			g.By("create the jenkins slave builder template")
... ...
@@ -45,28 +95,26 @@ var _ = g.Describe("[jenkins] schedule jobs on pod slaves", func() {
45 45
 			err = oc.Run("create").Args("-f", jenkinsMasterTemplate).Execute()
46 46
 			o.Expect(err).NotTo(o.HaveOccurred())
47 47
 
48
-			g.By("build the Jenkins slave for ruby-22-centos7")
48
+			g.By("instantiate the slave template")
49 49
 			err = oc.Run("new-app").Args("--template", "jenkins-slave-builder").Execute()
50 50
 			o.Expect(err).NotTo(o.HaveOccurred())
51 51
 
52
-			g.By("wait for the slave to be built")
53
-			err = wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
54
-				return waitForBuildComplete("ruby-22-centos7-slave-1")
55
-			})
52
+			g.By("build the Jenkins slave for ruby-22-centos7")
53
+			br, err := exutil.StartBuildAndWait(oc, "ruby-22-centos7-jenkins-slave", "--wait", "--from-dir", "examples/jenkins/master-slave/slave")
54
+			br.AssertSuccess()
56 55
 			o.Expect(err).NotTo(o.HaveOccurred())
57 56
 
58 57
 			g.By("grant service account in jenkins container access to API")
59 58
 			err = oc.Run("policy").Args("add-role-to-user", "edit", "system:serviceaccount:"+oc.Namespace()+":default", "-n", oc.Namespace()).Execute()
60 59
 			o.Expect(err).NotTo(o.HaveOccurred())
61 60
 
62
-			g.By("build the Jenkins master")
61
+			g.By("instantiate the master template")
63 62
 			err = oc.Run("new-app").Args("--template", "jenkins-master").Execute()
64 63
 			o.Expect(err).NotTo(o.HaveOccurred())
65 64
 
66
-			g.By("wait for the master to be built")
67
-			err = wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
68
-				return waitForBuildComplete("jenkins-master-1")
69
-			})
65
+			g.By("build the Jenkins master")
66
+			br, err = exutil.StartBuildAndWait(oc, "jenkins-master", "--wait", "--from-dir", "examples/jenkins/master-slave")
67
+			br.AssertSuccess()
70 68
 			o.Expect(err).NotTo(o.HaveOccurred())
71 69
 
72 70
 			g.By("wait for jenkins deployment")
... ...
@@ -259,7 +259,6 @@ readonly EXCLUDED_TESTS=(
259 259
 	SSH                     # TRIAGE
260 260
 	"\[Feature:Upgrade\]"   # TRIAGE
261 261
 	"SELinux relabeling"    # started failing
262
-	"schedule jobs on pod slaves use of jenkins with kubernetes plugin by creating slave from existing builder and adding it to Jenkins master" # https://github.com/openshift/origin/issues/7619
263 262
 	"openshift mongodb replication creating from a template" # flaking on deployment
264 263
 	"Update Demo should do a rolling update of a replication controller" # this is flaky and needs triaging
265 264
 
... ...
@@ -8,11 +8,8 @@
8 8
     "completionDeadlineSeconds": 5,
9 9
     "triggers":[],
10 10
     "source":{
11
-      "type":"Git",
12
-      "git":{
13
-        "uri":"https://github.com/openshift/origin"
14
-      },
15
-      "contextDir":"test/extended/testdata/test-build-app"
11
+      "type":"Dockerfile",
12
+      "dockerfile":"FROM centos:7\nRUN sleep 10m"
16 13
     },
17 14
     "strategy":{
18 15
       "type":"Docker",
... ...
@@ -23,11 +23,9 @@
23 23
       "spec": {
24 24
         "completionDeadlineSeconds": 5,
25 25
         "triggers": [],
26
-        "source": {
27
-          "type": "Git",
28
-          "git": {
29
-            "uri": "git://github.com/openshift/ruby-hello-world.git"
30
-          }
26
+        "source":{
27
+          "type":"Dockerfile",
28
+          "dockerfile":"FROM centos:7\nRUN sleep 10m"
31 29
         },
32 30
         "strategy": {
33 31
           "type": "Source",
... ...
@@ -12,16 +12,16 @@
12 12
     "source":{
13 13
       "type":"Git",
14 14
       "git":{
15
-        "uri":"https://github.com/openshift/origin"
15
+        "uri":"https://github.com/sclorg/s2i-ruby-container"
16 16
       },
17
-      "contextDir":"test/extended/testdata/test-build-app"
17
+      "contextDir":"2.3"
18 18
     },
19 19
     "strategy":{
20 20
       "type":"Docker",
21 21
       "dockerStrategy":{
22 22
         "from":{
23 23
           "kind":"DockerImage",
24
-          "name":"centos/ruby-22-centos7"
24
+          "name":"openshift/base-centos7"
25 25
         }
26 26
       }
27 27
     },
... ...
@@ -10,11 +10,7 @@
10 10
   "spec":{
11 11
     "triggers":[],
12 12
     "source":{
13
-      "type":"Git",
14
-      "git":{
15
-        "uri":"https://github.com/openshift/origin"
16
-      },
17
-      "contextDir":"test/extended/testdata/sti-environment-build-app"
13
+      "type":"Binary"
18 14
     },
19 15
     "strategy":{
20 16
       "type":"Source",
... ...
@@ -12,9 +12,9 @@
12 12
     "source": {
13 13
       "type": "Git",
14 14
       "git": {
15
-        "uri": "https://github.com/openshift/origin"
15
+        "uri":"https://github.com/sclorg/s2i-ruby-container"
16 16
       },
17
-      "contextDir": "test/extended/testdata/test-build-app"
17
+      "contextDir": "2.3/test/puma-test-app"
18 18
     },
19 19
     "strategy": {
20 20
       "type": "Source",
... ...
@@ -27,7 +27,7 @@
27 27
         ],
28 28
         "from": {
29 29
           "kind": "DockerImage",
30
-          "name": "centos/ruby-22-centos7"
30
+          "name": "centos/ruby-23-centos7"
31 31
         }
32 32
       }
33 33
     },