// NewSampleRepoTest creates a function for a new ginkgo test case that will instantiate a template // from a url, kick off the buildconfig defined in that template, wait for the build/deploy, // and then confirm the application is serving an expected string value. func NewSampleRepoTest(c SampleRepoConfig) func() { return func() { defer g.GinkgoRecover() var oc = exutil.NewCLI(c.repoName+"-repo-test", exutil.KubeConfigPath()) g.JustBeforeEach(func() { g.By("Waiting for builder service account") err := exutil.WaitForBuilderAccount(oc.KubeREST().ServiceAccounts(oc.Namespace())) o.Expect(err).NotTo(o.HaveOccurred()) }) g.Describe("Building "+c.repoName+" app from new-app", func() { g.It(fmt.Sprintf("should build a "+c.repoName+" image and run it in a pod"), func() { oc.SetOutputDir(exutil.TestContext.OutputDir) exutil.CheckOpenShiftNamespaceImageStreams(oc) g.By(fmt.Sprintf("calling oc new-app with the " + c.repoName + " example template")) err := oc.Run("new-app").Args("-f", c.templateURL).Execute() o.Expect(err).NotTo(o.HaveOccurred()) // all the templates automatically start a build. buildName := c.buildConfigName + "-1" g.By("expecting the build is in the Complete phase") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs(c.buildConfigName, oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the app deployment to be complete") err = exutil.WaitForADeploymentToComplete(oc.KubeREST().ReplicationControllers(oc.Namespace()), c.deploymentConfigName, oc) o.Expect(err).NotTo(o.HaveOccurred()) if len(c.dbDeploymentConfigName) > 0 { g.By("expecting the db deployment to be complete") err = exutil.WaitForADeploymentToComplete(oc.KubeREST().ReplicationControllers(oc.Namespace()), c.dbDeploymentConfigName, oc) o.Expect(err).NotTo(o.HaveOccurred()) } g.By("expecting the service is available") serviceIP, err := oc.Run("get").Args("service", c.serviceName).Template("{{ .spec.clusterIP }}").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(serviceIP).ShouldNot(o.Equal("")) g.By("expecting an endpoint is available") err = oc.KubeFramework().WaitForAnEndpoint(c.serviceName) o.Expect(err).NotTo(o.HaveOccurred()) g.By("verifying string from app request") response, err := exutil.FetchURL("http://"+serviceIP+":8080"+c.appPath, time.Duration(30*time.Second)) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(response).Should(o.ContainSubstring(c.expectedString)) }) }) } }
g.It("should create a docker build that pulls using a secret run it", func() { oc.SetOutputDir(exutil.TestContext.OutputDir) g.By(fmt.Sprintf("calling oc create -f %q", buildFixture)) err := oc.Run("create").Args("-f", buildFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build") out, err := oc.Run("start-build").Args("docker-build").Output() fmt.Fprintf(g.GinkgoWriter, "\nstart-build output:\n%s\n", out) o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build succeeds") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "docker-build-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("docker-build", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a second build that pulls the image from the first build") out, err = oc.Run("start-build").Args("docker-build-pull").Output() fmt.Fprintf(g.GinkgoWriter, "\nstart-build output:\n%s\n", out) o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build succeeds") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "docker-build-pull-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("docker-build-pull", oc) } o.Expect(err).NotTo(o.HaveOccurred()) })
dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", dcName)) ) g.Describe("Dancer example", func() { g.It(fmt.Sprintf("should work with hot deploy"), func() { oc.SetOutputDir(exutil.TestContext.OutputDir) exutil.CheckOpenShiftNamespaceImageStreams(oc) g.By(fmt.Sprintf("calling oc new-app -f %q", dancerTemplate)) err := oc.Run("new-app").Args("-f", dancerTemplate).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for build to finish") err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), "dancer-mysql-example-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("dancer-mysql-example", oc) } o.Expect(err).NotTo(o.HaveOccurred()) // oc.KubeFramework().WaitForAnEndpoint currently will wait forever; for now, prefacing with our WaitForADeploymentToComplete, // which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment err = exutil.WaitForADeploymentToComplete(oc.KubeClient().Core().ReplicationControllers(oc.Namespace()), "dancer-mysql-example", oc) o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for endpoint") err = oc.KubeFramework().WaitForAnEndpoint("dancer-mysql-example") o.Expect(err).NotTo(o.HaveOccurred()) assertPageCountIs := func(i int) { _, err := exutil.WaitForPods(oc.KubeClient().Core().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute) o.Expect(err).NotTo(o.HaveOccurred())
g.It("should create a docker build with a quota and run it", func() { oc.SetOutputDir(exutil.TestContext.OutputDir) g.By(fmt.Sprintf("calling oc create -f %q", buildFixture)) err := oc.Run("create").Args("-f", buildFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build") _, err = oc.Run("start-build").Args("docker-build-quota", "--from-dir", exutil.FixturePath("testdata", "build-quota")).Output() o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build is in Failed phase") // note that success and fail functions are intentionally reversed because we want to wait for failure. err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "docker-build-quota-1", exutil.CheckBuildFailedFn, exutil.CheckBuildSuccessFn) if err != nil { exutil.DumpBuildLogs("docker-build-quota", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build logs to contain the correct cgroups values") out, err := oc.Run("logs").Args(fmt.Sprintf("build/docker-build-quota-1")).Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(out).To(o.ContainSubstring("MEMORY=209715200")) o.Expect(out).To(o.ContainSubstring("MEMORYSWAP=209715200")) o.Expect(out).To(o.ContainSubstring("SHARES=61")) o.Expect(out).To(o.ContainSubstring("PERIOD=100000")) o.Expect(out).To(o.ContainSubstring("QUOTA=6000")) }) }) })
g.By("waiting for builder service account") err := exutil.WaitForBuilderAccount(oc.KubeREST().ServiceAccounts(oc.Namespace())) o.Expect(err).NotTo(o.HaveOccurred()) oc.Run("create").Args("-f", buildFixture).Execute() }) g.Describe("oc start-build --wait", func() { g.It("should start a build and wait for the build to complete", func() { g.By("starting the build with --wait flag") out, err := oc.Run("start-build").Args("sample-build", "--wait").Output() o.Expect(err).NotTo(o.HaveOccurred()) g.By(fmt.Sprintf("verifying the build %q status", out)) err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "sample-build-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("sample-build", oc) } o.Expect(err).NotTo(o.HaveOccurred()) }) g.It("should start a build and wait for the build to fail", func() { g.By("starting the build with --wait flag but wrong --commit") out, err := oc.Run("start-build"). Args("sample-build", "--wait", "--commit", "fffffff"). Output() o.Expect(err).To(o.HaveOccurred()) o.Expect(out).Should(o.ContainSubstring(`status is "Failed"`)) }) }) g.Describe("override environment", func() {
dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", dcName)) ) g.Describe("Django example", func() { g.It(fmt.Sprintf("should work with hot deploy"), func() { oc.SetOutputDir(exutil.TestContext.OutputDir) err := exutil.WaitForOpenShiftNamespaceImageStreams(oc) o.Expect(err).NotTo(o.HaveOccurred()) g.By(fmt.Sprintf("calling oc new-app %s", djangoRepository)) err = oc.Run("new-app").Args(djangoRepository, "--strategy=source").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for build to finish") err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), "django-ex-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("django-ex", oc) } o.Expect(err).NotTo(o.HaveOccurred()) // oc.KubeFramework().WaitForAnEndpoint currently will wait forever; for now, prefacing with our WaitForADeploymentToComplete, // which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment err = exutil.WaitForADeploymentToComplete(oc.KubeClient().Core().ReplicationControllers(oc.Namespace()), "django-ex", oc) o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for endpoint") err = oc.KubeFramework().WaitForAnEndpoint("django-ex") o.Expect(err).NotTo(o.HaveOccurred()) assertPageCountIs := func(i int) { _, err := exutil.WaitForPods(oc.KubeClient().Core().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute) o.Expect(err).NotTo(o.HaveOccurred())
removeCommand = []string{"rm", "-f", "public/index.html"} dcName = "rails-postgresql-example-1" dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", dcName)) ) g.Describe("Rails example", func() { g.It(fmt.Sprintf("should work with hot deploy"), func() { oc.SetOutputDir(exutil.TestContext.OutputDir) g.By(fmt.Sprintf("calling oc new-app -f %q", railsTemplate)) err := oc.Run("new-app").Args("-f", railsTemplate).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for build to finish") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), dcName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("rails-postgresql-example", oc) } o.Expect(err).NotTo(o.HaveOccurred()) // oc.KubeFramework().WaitForAnEndpoint currently will wait forever; for now, prefacing with our WaitForADeploymentToComplete, // which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment err = exutil.WaitForADeploymentToComplete(oc.KubeREST().ReplicationControllers(oc.Namespace()), "rails-postgresql-example") if err != nil { exutil.DumpDeploymentLogs("rails-postgresql-example", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for endpoint") err = oc.KubeFramework().WaitForAnEndpoint("rails-postgresql-example") o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(err).NotTo(o.HaveOccurred()) }) g.Describe("s2i build with a rootable builder", func() { g.It("should not be able to switch to root with an assemble script", func() { g.By("calling oc new-build for rootable-builder") err := oc.Run("new-build").Args("--binary", "--name=rootable-ruby").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting the rootable-ruby build with --wait flag") err = oc.Run("start-build").Args("rootable-ruby", fmt.Sprintf("--from-dir=%s", s2ibuilderFixture), "--wait").Execute() // debug for failures on jenkins if err != nil { exutil.DumpBuildLogs("rootable-ruby", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("creating a build that tries to gain root access via su") err = oc.Run("create").Args("-f", rootAccessBuildFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("start the root-access-build with the --wait flag") err = oc.Run("start-build").Args("root-access-build", "--wait").Execute() // debug for failures on jenkins if err == nil { exutil.DumpBuildLogs("root-access-build", oc) } o.Expect(err).To(o.HaveOccurred())
oc.SetOutputDir(exutil.TestContext.OutputDir) g.It(fmt.Sprintf("should create an image from %q docker template without an output image reference defined", dockerImageFixture), func() { err := oc.Run("create").Args("-f", dockerImageFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting build to pass without an output image reference specified") out, err := oc.Run("start-build").Args("test-docker").Output() fmt.Fprintf(g.GinkgoWriter, "\nstart-build output:\n%s\n", out) o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for the build to complete") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "test-docker-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("test-docker", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("verifying the build test-docker-1 output") buildLog, err := oc.Run("logs").Args("-f", "bc/test-docker").Output() fmt.Fprintf(g.GinkgoWriter, "\nbuild log:\n%s\n", buildLog) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(buildLog).Should(o.ContainSubstring(`Build complete, no image push requested`)) }) g.It(fmt.Sprintf("should create an image from %q S2i template without an output image reference defined", s2iImageFixture), func() { err := oc.Run("create").Args("-f", s2iImageFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for builder service account") err := exutil.WaitForBuilderAccount(oc.KubeREST().ServiceAccounts(oc.Namespace())) o.Expect(err).NotTo(o.HaveOccurred()) oc.Run("create").Args("-f", buildFixture).Execute() }) g.Describe("started build", func() { g.It("should build even with an empty source in build config", func() { g.By("starting the empty source build") out, err := oc.Run("start-build").Args("nosrc-build", fmt.Sprintf("--from-dir=%s", exampleBuild)).Output() fmt.Fprintf(g.GinkgoWriter, "\nstart-build output:\n%s\n", out) o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for build to complete") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "nosrc-build-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("nosrc-build", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By(fmt.Sprintf("verifying the build %q status", "nosrc-build-1")) build, err := oc.REST().Builds(oc.Namespace()).Get("nosrc-build-1") o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(build.Spec.Source.Dockerfile).To(o.BeNil()) o.Expect(build.Spec.Source.Git).To(o.BeNil()) o.Expect(build.Spec.Source.Images).To(o.BeNil()) o.Expect(build.Spec.Source.Binary).NotTo(o.BeNil()) }) }) })
} return false, nil }) g.By("running the build") out, err := oc.Run("start-build").Args(buildConfigName).Output() if err != nil { fmt.Fprintf(g.GinkgoWriter, "\nstart-build output:\n%s\n", out) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for the build to complete") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs(buildConfigName, oc) } o.Expect(err).NotTo(o.HaveOccurred()) buildLog, err := oc.Run("logs").Args("--follow", "build/"+buildName).Output() if err != nil { e2e.Failf("Failed to fetch build logs of %q: %v", buildLog, err) } g.By("expecting that .s2i/bin/assemble-runtime was executed") o.Expect(buildLog).To(o.ContainSubstring(`Using "assemble-runtime" installed from "<source-dir>/.s2i/bin/assemble-runtime"`)) o.Expect(buildLog).To(o.ContainSubstring(".s2i/bin/assemble-runtime: assembling app within runtime image")) g.By("expecting that environment variable from BuildConfig is available") o.Expect(buildLog).To(o.ContainSubstring(".s2i/bin/assemble-runtime: USING_ENV_FROM_BUILD_CONFIG=yes"))
err := oc.Run("new-build").Args("-D", "-", "--to", "jenkins:custom").InputString(testDockerfile).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build") bc, err := oc.REST().BuildConfigs(oc.Namespace()).Get("jenkins") o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(bc.Spec.Source.Git).To(o.BeNil()) o.Expect(bc.Spec.Source.Dockerfile).NotTo(o.BeNil()) o.Expect(*bc.Spec.Source.Dockerfile).To(o.Equal(testDockerfile)) buildName := "jenkins-1" g.By("expecting the Dockerfile build is in Complete phase") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) //debug for failures on jenkins if err != nil { exutil.DumpBuildLogs("jenkins", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("getting the build Docker image reference from ImageStream") image, err := oc.REST().ImageStreamTags(oc.Namespace()).Get("jenkins", "custom") o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(image.Image.DockerImageMetadata.Config.User).To(o.Equal("1001")) }) g.It("should create a image via new-build and infer the origin tag", func() { g.By(fmt.Sprintf("calling oc new-build with Dockerfile that uses the same tag as the output")) err := oc.Run("new-build").Args("-D", "-").InputString(testDockerfile2).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build")
g.Describe("Building from a template", func() { g.It("should create an s2i build with a quota and run it", func() { oc.SetOutputDir(exutil.TestContext.OutputDir) g.By(fmt.Sprintf("calling oc create -f %q", buildFixture)) err := oc.Run("create").Args("-f", buildFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build") _, err = oc.Run("start-build").Args("s2i-build-quota", "--from-dir", exutil.FixturePath("fixtures", "build-quota")).Output() o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build is in Complete phase") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "s2i-build-quota-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("s2i-build-quota", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build logs to contain the correct cgroups values") out, err := oc.Run("logs").Args(fmt.Sprintf("build/s2i-build-quota-1")).Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(out).To(o.ContainSubstring("MEMORY=209715200")) o.Expect(out).To(o.ContainSubstring("MEMORYSWAP=209715200")) o.Expect(out).To(o.ContainSubstring("SHARES=61")) o.Expect(out).To(o.ContainSubstring("PERIOD=100000")) o.Expect(out).To(o.ContainSubstring("QUOTA=6000")) }) }) })
err := oc.Run("new-build").Args("-D", "-", "--to", "origin-base:custom").InputString(testDockerfile).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build") bc, err := oc.REST().BuildConfigs(oc.Namespace()).Get("origin-base") o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(bc.Spec.Source.Git).To(o.BeNil()) o.Expect(bc.Spec.Source.Dockerfile).NotTo(o.BeNil()) o.Expect(*bc.Spec.Source.Dockerfile).To(o.Equal(testDockerfile)) buildName := "origin-base-1" g.By("expecting the Dockerfile build is in Complete phase") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) //debug for failures on jenkins if err != nil { exutil.DumpBuildLogs("origin-base", oc) } o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(err).NotTo(o.HaveOccurred()) g.By("getting the build Docker image reference from ImageStream") image, err := oc.REST().ImageStreamTags(oc.Namespace()).Get("origin-base", "custom") o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(image.Image.DockerImageMetadata.Config.User).To(o.Equal("1001")) }) g.It("should create a image via new-build and infer the origin tag", func() { g.By(fmt.Sprintf("calling oc new-build with Dockerfile that uses the same tag as the output")) err := oc.Run("new-build").Args("-D", "-").InputString(testDockerfile2).Execute() o.Expect(err).NotTo(o.HaveOccurred())
dcName = "cakephp-mysql-example-1" dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", dcName)) ) g.Describe("CakePHP example", func() { g.It(fmt.Sprintf("should work with hot deploy"), func() { oc.SetOutputDir(exutil.TestContext.OutputDir) exutil.CheckOpenShiftNamespaceImageStreams(oc) g.By(fmt.Sprintf("calling oc new-app -f %q -p %q", cakephpTemplate, hotDeployParam)) err := oc.Run("new-app").Args("-f", cakephpTemplate, "-p", hotDeployParam).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for build to finish") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), dcName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("cakephp-mysql-example", oc) } o.Expect(err).NotTo(o.HaveOccurred()) // oc.KubeFramework().WaitForAnEndpoint currently will wait forever; for now, prefacing with our WaitForADeploymentToComplete, // which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment err = exutil.WaitForADeploymentToComplete(oc.KubeREST().ReplicationControllers(oc.Namespace()), "cakephp-mysql-example", oc) o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for endpoint") err = oc.KubeFramework().WaitForAnEndpoint("cakephp-mysql-example") o.Expect(err).NotTo(o.HaveOccurred()) assertPageCountIs := func(i int) { _, err := exutil.WaitForPods(oc.KubeREST().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute) o.Expect(err).NotTo(o.HaveOccurred())
g.It(fmt.Sprintf("should create a build from %q template and run it", templateFixture), func() { oc.SetOutputDir(exutil.TestContext.OutputDir) g.By(fmt.Sprintf("calling oc new-app -f %q", templateFixture)) err := oc.Run("new-app").Args("-f", templateFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build") out, err := oc.Run("start-build").Args("initial-build").Output() fmt.Fprintf(g.GinkgoWriter, "\ninitial-build start-build output:\n%s\n", out) o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build is in Complete phase") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "initial-build-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("initial-build", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build using the image produced by the last build") out, err = oc.Run("start-build").Args("internal-build").Output() fmt.Fprintf(g.GinkgoWriter, "\ninternal-build start-build output:\n%s\n", out) o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build is in Complete phase") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "internal-build-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("internal-build", oc) } o.Expect(err).NotTo(o.HaveOccurred())
err = exutil.WaitForAnImageStream(oc.AdminREST().ImageStreams("openshift"), "jenkins", exutil.CheckImageStreamLatestTagPopulatedFn, exutil.CheckImageStreamTagNotFoundFn) o.Expect(err).NotTo(o.HaveOccurred()) }) g.Describe("build with image source", func() { g.It("should complete successfully and contain the expected file", func() { g.By("Creating build configs for source build") err := oc.Run("create").Args("-f", buildFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting the source strategy build") err = oc.Run("start-build").Args("imagesourcebuild").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the builds to complete successfully") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), "imagesourcebuild-1", exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("imagesourcebuild", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the pod to deploy successfully") pods, err := exutil.WaitForPods(oc.KubeREST().Pods(oc.Namespace()), imageSourceLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(len(pods)).To(o.Equal(1)) pod, err := oc.KubeREST().Pods(oc.Namespace()).Get(pods[0]) o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the pod to contain the file from the input image") out, err := oc.Run("exec").Args(pod.Name, "-c", pod.Spec.Containers[0].Name, "--", "ls", "injected/dir").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(out).To(o.ContainSubstring("jenkins.war")) })
err := oc.Run("create").Args("-f", imageStreamFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By(fmt.Sprintf("calling oc create -f %q", stiEnvBuildFixture)) err = oc.Run("create").Args("-f", stiEnvBuildFixture).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("starting a test build") buildName, err := oc.Run("start-build").Args("test").Output() fmt.Fprintf(g.GinkgoWriter, "\nstart-build output:\n%s\n", buildName) o.Expect(err).NotTo(o.HaveOccurred()) g.By("expecting the build is in Complete phase") err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn) if err != nil { exutil.DumpBuildLogs("test", oc) } o.Expect(err).NotTo(o.HaveOccurred()) g.By("getting the Docker image reference from ImageStream") imageName, err := exutil.GetDockerImageReference(oc.REST().ImageStreams(oc.Namespace()), "test", "latest") o.Expect(err).NotTo(o.HaveOccurred()) g.By("instantiating a pod and service with the new image") err = oc.Run("new-app").Args("-f", podAndServiceFixture, "-p", "IMAGE_NAME="+imageName).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("waiting for the service to become available") err = oc.KubeFramework().WaitForAnEndpoint(buildTestService) o.Expect(err).NotTo(o.HaveOccurred())