Skip to content

Commit

Permalink
Merge pull request #11392 from mmilata/dont-clone-origin-in-extendedt…
Browse files Browse the repository at this point in the history
…ests

Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Oct 24, 2016
2 parents 10ab3d7 + 53b0a7e commit d50865b
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 45 deletions.
2 changes: 1 addition & 1 deletion test/extended/builds/s2i_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = g.Describe("[builds][Slow] s2i build with environment file in sources",
o.Expect(err).NotTo(o.HaveOccurred())

g.By("starting a test build")
br, _ := exutil.StartBuildAndWait(oc, "test")
br, _ := exutil.StartBuildAndWait(oc, "test", "--from-dir", "test/extended/testdata/sti-environment-build-app")
br.AssertSuccess()

g.By("getting the Docker image reference from ImageStream")
Expand Down
92 changes: 70 additions & 22 deletions test/extended/jenkins/kubernetes_plugin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package jenkins

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
Expand All @@ -13,28 +16,75 @@ import (
"k8s.io/kubernetes/pkg/util/wait"
)

// patchTemplate finds BuildConfigs in a template, changes their source type to Binary, and removes all triggers
func patchTemplate(filename string, outDir string) string {
inputJson, err := ioutil.ReadFile(filename)
o.Expect(err).ToNot(o.HaveOccurred())

var template map[string]interface{}
err = json.Unmarshal(inputJson, &template)
o.Expect(err).ToNot(o.HaveOccurred())

for _, obj := range template["objects"].([]interface{}) {
bc := obj.(map[string]interface{})
if kind := bc["kind"].(string); kind != "BuildConfig" {
continue
}
spec := bc["spec"].(map[string]interface{})
spec["triggers"] = []interface{}{}

source := spec["source"].(map[string]interface{})
source["type"] = "Binary"
delete(source, "git")
delete(source, "contextDir")
}

outputJson, err := json.MarshalIndent(template, "", " ")
o.Expect(err).ToNot(o.HaveOccurred())

basename := filepath.Base(filename)
outputFile := filepath.Join(outDir, basename)
err = ioutil.WriteFile(outputFile, outputJson, 0644)
o.Expect(err).ToNot(o.HaveOccurred())

return outputFile
}

var _ = g.Describe("[jenkins] schedule jobs on pod slaves", func() {
defer g.GinkgoRecover()

var (
jenkinsExampleDir = filepath.Join("examples", "jenkins-master")
jenkinsMasterTemplate = filepath.Join(jenkinsExampleDir, "jenkins-master-template.json")
jenkinsSlaveBuilderTemplate = filepath.Join(jenkinsExampleDir, "jenkins-slave-template.json")

oc = exutil.NewCLI("jenkins-kube", exutil.KubeConfigPath())
jenkinsExampleDir = filepath.Join("examples", "jenkins", "master-slave")
oc = exutil.NewCLI("jenkins-kube", exutil.KubeConfigPath())
)

var waitForBuildComplete = func(name string) (bool, error) {
out, err := oc.Run("get").Args("build", name, "-o", "template", "--template", "{{ .status.phase }}").Output()
if err != nil {
return false, nil
}
return strings.Contains(out, "Complete"), nil
}
var (
jenkinsMasterTemplate string
jenkinsSlaveBuilderTemplate string
jsonTempDir string
)

g.Describe("use of jenkins with kubernetes plugin", func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)

g.BeforeEach(func() {
var err error
jsonTempDir, err = ioutil.TempDir(exutil.TestContext.OutputDir, "jenkins-kubernetes-")
o.Expect(err).NotTo(o.HaveOccurred())

// We need to prepare the templates first in order to use binary builds:
// 1. remove BuildConfig triggers to not start build immediately after instantiating template,
// 2. remove contextDir so that we can send just that directory as a binary, not whole repo.
jenkinsMasterTemplate = patchTemplate(filepath.Join(jenkinsExampleDir, "jenkins-master-template.json"), jsonTempDir)
jenkinsSlaveBuilderTemplate = patchTemplate(filepath.Join(jenkinsExampleDir, "jenkins-slave-template.json"), jsonTempDir)
})

g.AfterEach(func() {
if len(jsonTempDir) > 0 {
os.RemoveAll(jsonTempDir)
}
})

g.It("by creating slave from existing builder and adding it to Jenkins master", func() {

g.By("create the jenkins slave builder template")
Expand All @@ -45,28 +95,26 @@ var _ = g.Describe("[jenkins] schedule jobs on pod slaves", func() {
err = oc.Run("create").Args("-f", jenkinsMasterTemplate).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("build the Jenkins slave for ruby-22-centos7")
g.By("instantiate the slave template")
err = oc.Run("new-app").Args("--template", "jenkins-slave-builder").Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("wait for the slave to be built")
err = wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
return waitForBuildComplete("ruby-22-centos7-slave-1")
})
g.By("build the Jenkins slave for ruby-22-centos7")
br, err := exutil.StartBuildAndWait(oc, "ruby-22-centos7-jenkins-slave", "--wait", "--from-dir", "examples/jenkins/master-slave/slave")
br.AssertSuccess()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("grant service account in jenkins container access to API")
err = oc.Run("policy").Args("add-role-to-user", "edit", "system:serviceaccount:"+oc.Namespace()+":default", "-n", oc.Namespace()).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("build the Jenkins master")
g.By("instantiate the master template")
err = oc.Run("new-app").Args("--template", "jenkins-master").Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("wait for the master to be built")
err = wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
return waitForBuildComplete("jenkins-master-1")
})
g.By("build the Jenkins master")
br, err = exutil.StartBuildAndWait(oc, "jenkins-master", "--wait", "--from-dir", "examples/jenkins/master-slave")
br.AssertSuccess()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("wait for jenkins deployment")
Expand Down
1 change: 0 additions & 1 deletion test/extended/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ readonly EXCLUDED_TESTS=(
SSH # TRIAGE
"\[Feature:Upgrade\]" # TRIAGE
"SELinux relabeling" # started failing
"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
"openshift mongodb replication creating from a template" # flaking on deployment
"Update Demo should do a rolling update of a replication controller" # this is flaky and needs triaging

Expand Down
7 changes: 2 additions & 5 deletions test/extended/testdata/test-cds-dockerbuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
"completionDeadlineSeconds": 5,
"triggers":[],
"source":{
"type":"Git",
"git":{
"uri":"https://github.com/openshift/origin"
},
"contextDir":"test/extended/testdata/test-build-app"
"type":"Dockerfile",
"dockerfile":"FROM centos:7\nRUN sleep 10m"
},
"strategy":{
"type":"Docker",
Expand Down
8 changes: 3 additions & 5 deletions test/extended/testdata/test-cds-sourcebuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
"spec": {
"completionDeadlineSeconds": 5,
"triggers": [],
"source": {
"type": "Git",
"git": {
"uri": "git://github.com/openshift/ruby-hello-world.git"
}
"source":{
"type":"Dockerfile",
"dockerfile":"FROM centos:7\nRUN sleep 10m"
},
"strategy": {
"type": "Source",
Expand Down
6 changes: 3 additions & 3 deletions test/extended/testdata/test-docker-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"source":{
"type":"Git",
"git":{
"uri":"https://github.com/openshift/origin"
"uri":"https://github.com/sclorg/s2i-ruby-container"
},
"contextDir":"test/extended/testdata/test-build-app"
"contextDir":"2.3"
},
"strategy":{
"type":"Docker",
"dockerStrategy":{
"from":{
"kind":"DockerImage",
"name":"centos/ruby-22-centos7"
"name":"openshift/base-centos7"
}
}
},
Expand Down
6 changes: 1 addition & 5 deletions test/extended/testdata/test-env-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
"spec":{
"triggers":[],
"source":{
"type":"Git",
"git":{
"uri":"https://github.com/openshift/origin"
},
"contextDir":"test/extended/testdata/sti-environment-build-app"
"type":"Binary"
},
"strategy":{
"type":"Source",
Expand Down
6 changes: 3 additions & 3 deletions test/extended/testdata/test-s2i-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"source": {
"type": "Git",
"git": {
"uri": "https://github.com/openshift/origin"
"uri":"https://github.com/sclorg/s2i-ruby-container"
},
"contextDir": "test/extended/testdata/test-build-app"
"contextDir": "2.3/test/puma-test-app"
},
"strategy": {
"type": "Source",
Expand All @@ -27,7 +27,7 @@
],
"from": {
"kind": "DockerImage",
"name": "centos/ruby-22-centos7"
"name": "centos/ruby-23-centos7"
}
}
},
Expand Down

0 comments on commit d50865b

Please sign in to comment.