|
| 1 | +package integration_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os/exec" |
| 6 | + "path/filepath" |
| 7 | + "testing" |
| 8 | + "time" |
| 9 | + |
| 10 | + "github.com/cloudfoundry/libbuildpack/cutlass" |
| 11 | + "github.com/sclevine/spec" |
| 12 | + |
| 13 | + . "github.com/onsi/gomega" |
| 14 | +) |
| 15 | + |
| 16 | +func testDynatrace(t *testing.T, context spec.G, it spec.S) { |
| 17 | + var ( |
| 18 | + Expect = NewWithT(t).Expect |
| 19 | + Eventually = NewWithT(t).Eventually |
| 20 | + |
| 21 | + app *cutlass.App |
| 22 | + services []string |
| 23 | + ) |
| 24 | + |
| 25 | + it.Before(func() { |
| 26 | + app = cutlass.New(filepath.Join(settings.FixturesPath, "source_apps", "simple")) |
| 27 | + app.SetEnv("BP_DEBUG", "true") |
| 28 | + PushAppAndConfirm(t, app) |
| 29 | + }) |
| 30 | + |
| 31 | + it.After(func() { |
| 32 | + app = DestroyApp(t, app) |
| 33 | + |
| 34 | + for _, service := range services { |
| 35 | + command := exec.Command("cf", "delete-service", "-f", service) |
| 36 | + _, err := command.Output() |
| 37 | + Expect(err).NotTo(HaveOccurred()) |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + context("deploying a .NET Core app with Dynatrace agent with single credentials service", func() { |
| 42 | + it("checks if Dynatrace injection was successful", func() { |
| 43 | + service := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 44 | + command := exec.Command("cf", "cups", service, "-p", fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI)) |
| 45 | + output, err := command.CombinedOutput() |
| 46 | + Expect(err).NotTo(HaveOccurred(), string(output)) |
| 47 | + services = append(services, service) |
| 48 | + |
| 49 | + command = exec.Command("cf", "bind-service", app.Name, service) |
| 50 | + output, err = command.CombinedOutput() |
| 51 | + Expect(err).NotTo(HaveOccurred(), string(output)) |
| 52 | + |
| 53 | + command = exec.Command("cf", "restage", app.Name) |
| 54 | + output, err = command.CombinedOutput() |
| 55 | + Expect(err).NotTo(HaveOccurred(), string(output)) |
| 56 | + |
| 57 | + Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed()) |
| 58 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent")) |
| 59 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer")) |
| 60 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 61 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed.")) |
| 62 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up.")) |
| 63 | + }) |
| 64 | + }) |
| 65 | + |
| 66 | + context("deploying a .Net Core app with Dynatrace agent with configured network zone", func() { |
| 67 | + it("checks if Dynatrace injection was successful", func() { |
| 68 | + serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 69 | + command := exec.Command("cf", "cups", serviceName, "-p", fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\", \"networkzone\":\"testzone\"}'", settings.Dynatrace.URI)) |
| 70 | + _, err := command.CombinedOutput() |
| 71 | + Expect(err).To(BeNil()) |
| 72 | + services = append(services, serviceName) |
| 73 | + |
| 74 | + command = exec.Command("cf", "bind-service", app.Name, serviceName) |
| 75 | + _, err = command.CombinedOutput() |
| 76 | + Expect(err).To(BeNil()) |
| 77 | + command = exec.Command("cf", "restage", app.Name) |
| 78 | + _, err = command.Output() |
| 79 | + Expect(err).To(BeNil()) |
| 80 | + |
| 81 | + Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed()) |
| 82 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent")) |
| 83 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer")) |
| 84 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 85 | + Expect(app.Stdout.String()).To(ContainSubstring("Setting DT_NETWORK_ZONE...")) |
| 86 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed.")) |
| 87 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up.")) |
| 88 | + }) |
| 89 | + }) |
| 90 | + |
| 91 | + context("deploying a .NET Core app with Dynatrace agent with two credentials services", func() { |
| 92 | + it("checks if detection of second service with credentials works", func() { |
| 93 | + credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 94 | + command := exec.Command("cf", "cups", credentialsServiceName, "-p", |
| 95 | + fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI)) |
| 96 | + _, err := command.CombinedOutput() |
| 97 | + Expect(err).To(BeNil()) |
| 98 | + services = append(services, credentialsServiceName) |
| 99 | + |
| 100 | + duplicateCredentialsServiceName := "dynatrace-dupe-" + cutlass.RandStringRunes(20) + "-service" |
| 101 | + command = exec.Command("cf", "cups", duplicateCredentialsServiceName, "-p", |
| 102 | + fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI)) |
| 103 | + _, err = command.CombinedOutput() |
| 104 | + Expect(err).To(BeNil()) |
| 105 | + services = append(services, duplicateCredentialsServiceName) |
| 106 | + |
| 107 | + command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName) |
| 108 | + _, err = command.CombinedOutput() |
| 109 | + Expect(err).To(BeNil()) |
| 110 | + command = exec.Command("cf", "bind-service", app.Name, duplicateCredentialsServiceName) |
| 111 | + _, err = command.CombinedOutput() |
| 112 | + Expect(err).To(BeNil()) |
| 113 | + |
| 114 | + command = exec.Command("cf", "restage", app.Name) |
| 115 | + _, err = command.Output() |
| 116 | + Expect(err).To(BeNil()) |
| 117 | + |
| 118 | + Expect(app.Stdout.String()).To(ContainSubstring("More than one matching service found!")) |
| 119 | + }) |
| 120 | + }) |
| 121 | + |
| 122 | + context("deploying a .NET Core app with Dynatrace agent with failing agent download and ignoring errors", func() { |
| 123 | + it("checks if skipping download errors works", func() { |
| 124 | + credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 125 | + command := exec.Command("cf", "cups", credentialsServiceName, "-p", |
| 126 | + fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s/no-such-endpoint\",\"environmentid\":\"envid\",\"skiperrors\":\"true\"}'", settings.Dynatrace.URI)) |
| 127 | + _, err := command.CombinedOutput() |
| 128 | + Expect(err).To(BeNil()) |
| 129 | + services = append(services, credentialsServiceName) |
| 130 | + |
| 131 | + command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName) |
| 132 | + _, err = command.CombinedOutput() |
| 133 | + Expect(err).To(BeNil()) |
| 134 | + |
| 135 | + command = exec.Command("cf", "restage", app.Name) |
| 136 | + _, err = command.Output() |
| 137 | + Expect(err).To(BeNil()) |
| 138 | + |
| 139 | + Expect(app.Stdout.String()).To(ContainSubstring("Download returned with status 404")) |
| 140 | + Expect(app.Stdout.String()).To(ContainSubstring("Error during installer download, skipping installation")) |
| 141 | + }) |
| 142 | + }) |
| 143 | + |
| 144 | + context("deploying a .NET Core app with Dynatrace agent with two dynatrace services", func() { |
| 145 | + it("check if service detection isn't disturbed by a service with tags", func() { |
| 146 | + credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 147 | + command := exec.Command("cf", "cups", credentialsServiceName, "-p", |
| 148 | + fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI)) |
| 149 | + _, err := command.CombinedOutput() |
| 150 | + Expect(err).To(BeNil()) |
| 151 | + services = append(services, credentialsServiceName) |
| 152 | + |
| 153 | + tagsServiceName := "dynatrace-tags-" + cutlass.RandStringRunes(20) + "-service" |
| 154 | + command = exec.Command("cf", "cups", tagsServiceName, "-p", "'{\"tag:dttest\":\"dynatrace_test\"}'") |
| 155 | + _, err = command.CombinedOutput() |
| 156 | + Expect(err).To(BeNil()) |
| 157 | + services = append(services, tagsServiceName) |
| 158 | + |
| 159 | + command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName) |
| 160 | + _, err = command.CombinedOutput() |
| 161 | + Expect(err).To(BeNil()) |
| 162 | + command = exec.Command("cf", "bind-service", app.Name, tagsServiceName) |
| 163 | + _, err = command.CombinedOutput() |
| 164 | + Expect(err).To(BeNil()) |
| 165 | + |
| 166 | + command = exec.Command("cf", "restage", app.Name) |
| 167 | + _, err = command.Output() |
| 168 | + Expect(err).To(BeNil()) |
| 169 | + |
| 170 | + Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed()) |
| 171 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent.")) |
| 172 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer")) |
| 173 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 174 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed.")) |
| 175 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up.")) |
| 176 | + }) |
| 177 | + }) |
| 178 | + |
| 179 | + context("deploying a .NET Core app with Dynatrace agent with single credentials service and without manifest.json", func() { |
| 180 | + it("checks if Dynatrace injection was successful", func() { |
| 181 | + serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 182 | + command := exec.Command("cf", "cups", serviceName, "-p", |
| 183 | + fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI)) |
| 184 | + _, err := command.CombinedOutput() |
| 185 | + Expect(err).To(BeNil()) |
| 186 | + services = append(services, serviceName) |
| 187 | + |
| 188 | + command = exec.Command("cf", "bind-service", app.Name, serviceName) |
| 189 | + _, err = command.CombinedOutput() |
| 190 | + Expect(err).To(BeNil()) |
| 191 | + command = exec.Command("cf", "restage", app.Name) |
| 192 | + _, err = command.Output() |
| 193 | + Expect(err).To(BeNil()) |
| 194 | + |
| 195 | + Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed()) |
| 196 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent.")) |
| 197 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer")) |
| 198 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 199 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed.")) |
| 200 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up.")) |
| 201 | + }) |
| 202 | + }) |
| 203 | + |
| 204 | + context("deploying a .NET Core app with Dynatrace agent with failing agent download and checking retry", func() { |
| 205 | + it.Before(func() { |
| 206 | + SetDefaultEventuallyTimeout(5 * time.Second) |
| 207 | + }) |
| 208 | + |
| 209 | + it("checks if retrying downloads works", func() { |
| 210 | + credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 211 | + command := exec.Command("cf", "cups", credentialsServiceName, "-p", |
| 212 | + fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s/no-such-endpoint\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI)) |
| 213 | + _, err := command.CombinedOutput() |
| 214 | + Expect(err).To(BeNil()) |
| 215 | + services = append(services, credentialsServiceName) |
| 216 | + |
| 217 | + command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName) |
| 218 | + _, err = command.CombinedOutput() |
| 219 | + Expect(err).To(BeNil()) |
| 220 | + |
| 221 | + command = exec.Command("cf", "restage", app.Name) |
| 222 | + _, err = command.CombinedOutput() |
| 223 | + |
| 224 | + Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 4s")) |
| 225 | + Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 5s")) |
| 226 | + Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 7s")) |
| 227 | + Eventually(app.Stdout.String).Should(ContainSubstring("Download returned with status 404")) |
| 228 | + |
| 229 | + Eventually(app.Stdout.String).Should(ContainSubstring("Failed to compile droplet")) |
| 230 | + }) |
| 231 | + }) |
| 232 | + |
| 233 | + context("deploying a .NET Core app with Dynatrace agent with single credentials service and a redis service", func() { |
| 234 | + it("checks if Dynatrace injection was successful", func() { |
| 235 | + serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service" |
| 236 | + command := exec.Command("cf", "cups", serviceName, "-p", |
| 237 | + fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI)) |
| 238 | + _, err := command.CombinedOutput() |
| 239 | + Expect(err).To(BeNil()) |
| 240 | + services = append(services, serviceName) |
| 241 | + command = exec.Command("cf", "bind-service", app.Name, serviceName) |
| 242 | + _, err = command.CombinedOutput() |
| 243 | + Expect(err).To(BeNil()) |
| 244 | + |
| 245 | + redisServiceName := "redis-" + cutlass.RandStringRunes(20) + "-service" |
| 246 | + 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\"}}}'") |
| 247 | + _, err = command.CombinedOutput() |
| 248 | + Expect(err).To(BeNil()) |
| 249 | + services = append(services, redisServiceName) |
| 250 | + command = exec.Command("cf", "bind-service", app.Name, redisServiceName) |
| 251 | + _, err = command.CombinedOutput() |
| 252 | + Expect(err).To(BeNil()) |
| 253 | + |
| 254 | + command = exec.Command("cf", "restage", app.Name) |
| 255 | + _, err = command.Output() |
| 256 | + Expect(err).To(BeNil()) |
| 257 | + |
| 258 | + Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed()) |
| 259 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent.")) |
| 260 | + Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer")) |
| 261 | + Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh")) |
| 262 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed.")) |
| 263 | + Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up.")) |
| 264 | + }) |
| 265 | + }) |
| 266 | +} |
0 commit comments