|
16 | 16 |
|
17 | 17 | package com.netflix.spinnaker.orca.clouddriver.tasks.monitoreddeploy
|
18 | 18 |
|
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper |
19 | 20 | import com.netflix.spectator.api.NoopRegistry
|
20 | 21 | import com.netflix.spinnaker.config.DeploymentMonitorDefinition
|
21 | 22 | import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus
|
22 | 23 | import com.netflix.spinnaker.orca.api.pipeline.TaskResult
|
| 24 | +import com.netflix.spinnaker.orca.clouddriver.MortServiceSpec |
23 | 25 | import com.netflix.spinnaker.orca.deploymentmonitor.DeploymentMonitorService
|
24 | 26 | import com.netflix.spinnaker.orca.deploymentmonitor.models.DeploymentMonitorStageConfig
|
25 | 27 | import com.netflix.spinnaker.orca.deploymentmonitor.models.DeploymentStep
|
26 | 28 | import com.netflix.spinnaker.orca.deploymentmonitor.models.EvaluateHealthResponse
|
27 | 29 | import com.netflix.spinnaker.orca.deploymentmonitor.models.MonitoredDeployInternalStageData
|
28 | 30 | import com.netflix.spinnaker.orca.pipeline.model.PipelineExecutionImpl
|
29 | 31 | import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl
|
| 32 | +import org.springframework.http.HttpStatus |
30 | 33 | import retrofit.RetrofitError
|
| 34 | +import retrofit.client.Response |
| 35 | +import retrofit.converter.JacksonConverter |
31 | 36 | import spock.lang.Specification
|
32 | 37 | import com.netflix.spinnaker.orca.deploymentmonitor.DeploymentMonitorServiceProvider
|
33 | 38 | import spock.lang.Unroll
|
@@ -198,6 +203,50 @@ class EvaluateDeploymentHealthTaskSpec extends Specification {
|
198 | 203 | false | null || ExecutionStatus.FAILED_CONTINUE
|
199 | 204 | }
|
200 | 205 |
|
| 206 | + def "should return status as RUNNING when Retrofit http error is thrown"() { |
| 207 | + |
| 208 | + def converter = new JacksonConverter(new ObjectMapper()) |
| 209 | + |
| 210 | + Response response = |
| 211 | + new Response( |
| 212 | + "/deployment/evaluateHealth", |
| 213 | + HttpStatus.BAD_REQUEST.value(), |
| 214 | + "bad-request", |
| 215 | + Collections.emptyList(), |
| 216 | + new MortServiceSpec.MockTypedInput(converter, [ |
| 217 | + accountName: "account", |
| 218 | + description: "simple description", |
| 219 | + name: "sg1", |
| 220 | + region: "region", |
| 221 | + type: "openstack" |
| 222 | + ])) |
| 223 | + |
| 224 | + given: |
| 225 | + def monitorServiceStub = Stub(DeploymentMonitorService) { |
| 226 | + evaluateHealth(_) >> { |
| 227 | + throw RetrofitError.httpError("https://foo.com/deployment/evaluateHealth", response, converter, null) |
| 228 | + } |
| 229 | + } |
| 230 | + |
| 231 | + def serviceProviderStub = getServiceProviderStub(monitorServiceStub) |
| 232 | + |
| 233 | + def task = new EvaluateDeploymentHealthTask(serviceProviderStub, new NoopRegistry()) |
| 234 | + |
| 235 | + MonitoredDeployInternalStageData stageData = new MonitoredDeployInternalStageData() |
| 236 | + stageData.deploymentMonitor = new DeploymentMonitorStageConfig() |
| 237 | + stageData.deploymentMonitor.id = "LogMonitorId" |
| 238 | + |
| 239 | + def stage = new StageExecutionImpl(pipe, "evaluateDeploymentHealth", stageData.toContextMap() + [application: pipe.application]) |
| 240 | + stage.startTime = Instant.now().toEpochMilli() |
| 241 | + |
| 242 | + when: 'we can still retry' |
| 243 | + TaskResult result = task.execute(stage) |
| 244 | + |
| 245 | + then: 'should retry' |
| 246 | + result.status == ExecutionStatus.RUNNING |
| 247 | + result.context.deployMonitorHttpRetryCount == 1 |
| 248 | + } |
| 249 | + |
201 | 250 | private getServiceProviderStub(monitorServiceStub) {
|
202 | 251 | return getServiceProviderStub(monitorServiceStub, {})
|
203 | 252 | }
|
|
0 commit comments