|
| 1 | +package integration_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "os/exec" |
| 5 | + "path/filepath" |
| 6 | + |
| 7 | + "github.com/cloudfoundry/libbuildpack/cutlass" |
| 8 | + |
| 9 | + . "github.com/onsi/ginkgo" |
| 10 | + . "github.com/onsi/gomega" |
| 11 | +) |
| 12 | + |
| 13 | +var _ = Describe("CF Python Buildpack", func() { |
| 14 | + var app *cutlass.App |
| 15 | + var createdServices []string |
| 16 | + |
| 17 | + BeforeEach(func() { |
| 18 | + //app = cutlass.New(Fixtures("flask")) |
| 19 | + app = cutlass.New(filepath.Join(bpDir, "fixtures", "flask")) |
| 20 | + app.SetEnv("BP_DEBUG", "true") |
| 21 | + PushAppAndConfirm(app) |
| 22 | + |
| 23 | + createdServices = make([]string, 0) |
| 24 | + }) |
| 25 | + |
| 26 | + AfterEach(func() { |
| 27 | + if app != nil { |
| 28 | + app.Destroy() |
| 29 | + } |
| 30 | + app = nil |
| 31 | + |
| 32 | + for _, service := range createdServices { |
| 33 | + command := exec.Command("cf", "delete-service", "-f", service) |
| 34 | + _, err := command.Output() |
| 35 | + Expect(err).To(BeNil()) |
| 36 | + } |
| 37 | + }) |
| 38 | + |
| 39 | + Context("deploying a Python app with Dynatrace agent with single credentials service", func() { |
| 40 | + It("checks if Dynatrace injection was successful", func() { |
| 41 | + serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 42 | + command := exec.Command("cf", "cups", serviceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'") |
| 43 | + _, err := command.CombinedOutput() |
| 44 | + Expect(err).To(BeNil()) |
| 45 | + createdServices = append(createdServices, serviceName) |
| 46 | + |
| 47 | + command = exec.Command("cf", "bind-service", app.Name, serviceName) |
| 48 | + _, err = command.CombinedOutput() |
| 49 | + Expect(err).To(BeNil()) |
| 50 | + command = exec.Command("cf", "restage", app.Name) |
| 51 | + _, err = command.Output() |
| 52 | + Expect(err).To(BeNil()) |
| 53 | + |
| 54 | + Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed()) |
| 55 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent.")) |
| 56 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer")) |
| 57 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 58 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed.")) |
| 59 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up.")) |
| 60 | + }) |
| 61 | + }) |
| 62 | + |
| 63 | + Context("deploying a Python app with Dynatrace agent with two credentials services", func() { |
| 64 | + It("checks if detection of second service with credentials works", func() { |
| 65 | + CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 66 | + command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'") |
| 67 | + _, err := command.CombinedOutput() |
| 68 | + Expect(err).To(BeNil()) |
| 69 | + createdServices = append(createdServices, CredentialsServiceName) |
| 70 | + |
| 71 | + duplicateCredentialsServiceName := "dynatrace-dupe-" + cutlass.RandStringRunes(20) + "-service" |
| 72 | + command = exec.Command("cf", "cups", duplicateCredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'") |
| 73 | + _, err = command.CombinedOutput() |
| 74 | + Expect(err).To(BeNil()) |
| 75 | + createdServices = append(createdServices, duplicateCredentialsServiceName) |
| 76 | + |
| 77 | + command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName) |
| 78 | + _, err = command.CombinedOutput() |
| 79 | + Expect(err).To(BeNil()) |
| 80 | + command = exec.Command("cf", "bind-service", app.Name, duplicateCredentialsServiceName) |
| 81 | + _, err = command.CombinedOutput() |
| 82 | + Expect(err).To(BeNil()) |
| 83 | + |
| 84 | + command = exec.Command("cf", "restage", app.Name) |
| 85 | + _, err = command.Output() |
| 86 | + Expect(err).To(BeNil()) |
| 87 | + |
| 88 | + Expect(app.Stdout.String()).To(ContainSubstring("More than one matching service found!")) |
| 89 | + }) |
| 90 | + }) |
| 91 | + |
| 92 | + Context("deploying a Python app with Dynatrace agent with failing agent download and ignoring errors", func() { |
| 93 | + It("checks if skipping download errors works", func() { |
| 94 | + CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 95 | + command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paasFAILING/manifest\",\"environmentid\":\"envid\",\"skiperrors\":\"true\"}'") |
| 96 | + _, err := command.CombinedOutput() |
| 97 | + Expect(err).To(BeNil()) |
| 98 | + createdServices = append(createdServices, CredentialsServiceName) |
| 99 | + |
| 100 | + command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName) |
| 101 | + _, err = command.CombinedOutput() |
| 102 | + Expect(err).To(BeNil()) |
| 103 | + |
| 104 | + command = exec.Command("cf", "restage", app.Name) |
| 105 | + _, err = command.Output() |
| 106 | + Expect(err).To(BeNil()) |
| 107 | + |
| 108 | + Expect(app.Stdout.String()).To(ContainSubstring("Download returned with status 404")) |
| 109 | + Expect(app.Stdout.String()).To(ContainSubstring("Error during installer download, skipping installation")) |
| 110 | + }) |
| 111 | + }) |
| 112 | + |
| 113 | + Context("deploying a Python app with Dynatrace agent with two dynatrace services", func() { |
| 114 | + It("check if service detection isn't disturbed by a service with tags", func() { |
| 115 | + CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 116 | + command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'") |
| 117 | + _, err := command.CombinedOutput() |
| 118 | + Expect(err).To(BeNil()) |
| 119 | + createdServices = append(createdServices, CredentialsServiceName) |
| 120 | + |
| 121 | + tagsServiceName := "dynatrace-tags-" + cutlass.RandStringRunes(20) + "-service" |
| 122 | + command = exec.Command("cf", "cups", tagsServiceName, "-p", "'{\"tag:dttest\":\"dynatrace_test\"}'") |
| 123 | + _, err = command.CombinedOutput() |
| 124 | + Expect(err).To(BeNil()) |
| 125 | + createdServices = append(createdServices, tagsServiceName) |
| 126 | + |
| 127 | + command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName) |
| 128 | + _, err = command.CombinedOutput() |
| 129 | + Expect(err).To(BeNil()) |
| 130 | + command = exec.Command("cf", "bind-service", app.Name, tagsServiceName) |
| 131 | + _, err = command.CombinedOutput() |
| 132 | + Expect(err).To(BeNil()) |
| 133 | + |
| 134 | + command = exec.Command("cf", "restage", app.Name) |
| 135 | + _, err = command.Output() |
| 136 | + Expect(err).To(BeNil()) |
| 137 | + |
| 138 | + Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed()) |
| 139 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent.")) |
| 140 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer")) |
| 141 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 142 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed.")) |
| 143 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up.")) |
| 144 | + }) |
| 145 | + }) |
| 146 | + |
| 147 | + Context("deploying a Python app with Dynatrace agent with single credentials service and without manifest.json", func() { |
| 148 | + It("checks if Dynatrace injection was successful", func() { |
| 149 | + serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 150 | + command := exec.Command("cf", "cups", serviceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas\",\"environmentid\":\"envid\"}'") |
| 151 | + _, err := command.CombinedOutput() |
| 152 | + Expect(err).To(BeNil()) |
| 153 | + createdServices = append(createdServices, serviceName) |
| 154 | + |
| 155 | + command = exec.Command("cf", "bind-service", app.Name, serviceName) |
| 156 | + _, err = command.CombinedOutput() |
| 157 | + Expect(err).To(BeNil()) |
| 158 | + command = exec.Command("cf", "restage", app.Name) |
| 159 | + _, err = command.Output() |
| 160 | + Expect(err).To(BeNil()) |
| 161 | + |
| 162 | + Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed()) |
| 163 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent.")) |
| 164 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer")) |
| 165 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 166 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed.")) |
| 167 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up.")) |
| 168 | + }) |
| 169 | + }) |
| 170 | + |
| 171 | + Context("deploying a Python app with Dynatrace agent with failing agent download and checking retry", func() { |
| 172 | + It("checks if retrying downloads works", func() { |
| 173 | + CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 174 | + command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paasFAILING/manifest\",\"environmentid\":\"envid\"}'") |
| 175 | + _, err := command.CombinedOutput() |
| 176 | + Expect(err).To(BeNil()) |
| 177 | + createdServices = append(createdServices, CredentialsServiceName) |
| 178 | + |
| 179 | + command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName) |
| 180 | + _, err = command.CombinedOutput() |
| 181 | + Expect(err).To(BeNil()) |
| 182 | + |
| 183 | + command = exec.Command("cf", "restage", app.Name) |
| 184 | + _, err = command.CombinedOutput() |
| 185 | + |
| 186 | + Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 4s")) |
| 187 | + Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 5s")) |
| 188 | + Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 7s")) |
| 189 | + Eventually(app.Stdout.String).Should(ContainSubstring("Download returned with status 404")) |
| 190 | + |
| 191 | + Eventually(app.Stdout.String).Should(ContainSubstring("Failed to compile droplet")) |
| 192 | + }) |
| 193 | + }) |
| 194 | + |
| 195 | + Context("deploying a Python app with Dynatrace agent with single credentials service and a redis service", func() { |
| 196 | + It("checks if Dynatrace injection was successful", func() { |
| 197 | + serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 198 | + command := exec.Command("cf", "cups", serviceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'") |
| 199 | + _, err := command.CombinedOutput() |
| 200 | + Expect(err).To(BeNil()) |
| 201 | + createdServices = append(createdServices, serviceName) |
| 202 | + command = exec.Command("cf", "bind-service", app.Name, serviceName) |
| 203 | + _, err = command.CombinedOutput() |
| 204 | + Expect(err).To(BeNil()) |
| 205 | + |
| 206 | + redisServiceName := "redis-" + cutlass.RandStringRunes(20) + "-service" |
| 207 | + command = exec.Command("cf", "cups", redisServiceName, "-p", "'{\"name\":\"redis\", \"credentials\":{\"db_type\":\"redis\", \"instance_administration_api\":{\"deployment_id\":\"12345asdf\", \"instance_id\":\"12345asdf\", \"root\":\"https://doesnotexi.st\"}}}'") |
| 208 | + _, err = command.CombinedOutput() |
| 209 | + Expect(err).To(BeNil()) |
| 210 | + createdServices = append(createdServices, redisServiceName) |
| 211 | + command = exec.Command("cf", "bind-service", app.Name, redisServiceName) |
| 212 | + _, err = command.CombinedOutput() |
| 213 | + Expect(err).To(BeNil()) |
| 214 | + |
| 215 | + command = exec.Command("cf", "restage", app.Name) |
| 216 | + _, err = command.Output() |
| 217 | + Expect(err).To(BeNil()) |
| 218 | + |
| 219 | + Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed()) |
| 220 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent.")) |
| 221 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer")) |
| 222 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 223 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed.")) |
| 224 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up.")) |
| 225 | + }) |
| 226 | + }) |
| 227 | +}) |
0 commit comments