|
| 1 | +package builds |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "time" |
| 6 | + |
| 7 | + g "github.com/onsi/ginkgo" |
| 8 | + o "github.com/onsi/gomega" |
| 9 | + |
| 10 | + kapi "k8s.io/kubernetes/pkg/api" |
| 11 | + |
| 12 | + imageeco "github.com/openshift/origin/test/extended/image_ecosystem" |
| 13 | + exutil "github.com/openshift/origin/test/extended/util" |
| 14 | +) |
| 15 | + |
| 16 | +var _ = g.Describe("[builds][Slow] builds with a context directory", func() { |
| 17 | + defer g.GinkgoRecover() |
| 18 | + var ( |
| 19 | + appFixture = exutil.FixturePath("testdata", "test-context-build.json") |
| 20 | + oc = exutil.NewCLI("contextdir", exutil.KubeConfigPath()) |
| 21 | + s2iBuildConfigName = "s2icontext" |
| 22 | + s2iBuildName = "s2icontext-1" |
| 23 | + dcName = "frontend" |
| 24 | + deploymentName = "frontend-1" |
| 25 | + dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", deploymentName)) |
| 26 | + serviceName = "frontend" |
| 27 | + dockerBuildConfigName = "dockercontext" |
| 28 | + dockerBuildName = "dockercontext-1" |
| 29 | + ) |
| 30 | + g.Describe("s2i context directory build", func() { |
| 31 | + g.It(fmt.Sprintf("should s2i build an application using a context directory"), func() { |
| 32 | + oc.SetOutputDir(exutil.TestContext.OutputDir) |
| 33 | + |
| 34 | + exutil.CheckOpenShiftNamespaceImageStreams(oc) |
| 35 | + g.By(fmt.Sprintf("calling oc create -f %q", appFixture)) |
| 36 | + err := oc.Run("create").Args("-f", appFixture).Execute() |
| 37 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 38 | + |
| 39 | + g.By("starting a build") |
| 40 | + err = oc.Run("start-build").Args(s2iBuildConfigName).Execute() |
| 41 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 42 | + |
| 43 | + g.By("waiting for build to finish") |
| 44 | + err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), s2iBuildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn, nil) |
| 45 | + if err != nil { |
| 46 | + exutil.DumpBuildLogs("s2icontext", oc) |
| 47 | + } |
| 48 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 49 | + |
| 50 | + // oc.KubeFramework().WaitForAnEndpoint currently will wait forever; for now, prefacing with our WaitForADeploymentToComplete, |
| 51 | + // which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment |
| 52 | + g.By("waiting for a deployment") |
| 53 | + err = exutil.WaitForADeploymentToComplete(oc.KubeClient().Core().ReplicationControllers(oc.Namespace()), dcName, oc) |
| 54 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 55 | + |
| 56 | + g.By("waiting for endpoint") |
| 57 | + err = oc.KubeFramework().WaitForAnEndpoint(serviceName) |
| 58 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 59 | + |
| 60 | + assertPageContent := func(content string) { |
| 61 | + _, err := exutil.WaitForPods(oc.KubeClient().Core().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute) |
| 62 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 63 | + |
| 64 | + result, err := imageeco.CheckPageContains(oc, "frontend", "", content) |
| 65 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 66 | + o.Expect(result).To(o.BeTrue()) |
| 67 | + } |
| 68 | + |
| 69 | + g.By("testing application content") |
| 70 | + assertPageContent("Hello world!") |
| 71 | + |
| 72 | + g.By("checking the pod count") |
| 73 | + pods, err := oc.KubeClient().Core().Pods(oc.Namespace()).List(kapi.ListOptions{LabelSelector: dcLabel}) |
| 74 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 75 | + o.Expect(len(pods.Items)).To(o.Equal(1)) |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + g.Describe("docker context directory build", func() { |
| 80 | + g.It(fmt.Sprintf("should docker build an application using a context directory"), func() { |
| 81 | + oc.SetOutputDir(exutil.TestContext.OutputDir) |
| 82 | + |
| 83 | + exutil.CheckOpenShiftNamespaceImageStreams(oc) |
| 84 | + g.By(fmt.Sprintf("calling oc create -f %q", appFixture)) |
| 85 | + err := oc.Run("create").Args("-f", appFixture).Execute() |
| 86 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 87 | + |
| 88 | + g.By("starting a build") |
| 89 | + err = oc.Run("start-build").Args(dockerBuildConfigName).Execute() |
| 90 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 91 | + |
| 92 | + // build will fail if we don't use the right context dir because there won't be a dockerfile present. |
| 93 | + g.By("waiting for build to finish") |
| 94 | + err = exutil.WaitForABuild(oc.Client().Builds(oc.Namespace()), dockerBuildName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn, nil) |
| 95 | + if err != nil { |
| 96 | + exutil.DumpBuildLogs("dockercontext", oc) |
| 97 | + } |
| 98 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 99 | + }) |
| 100 | + }) |
| 101 | +}) |
0 commit comments