Skip to content

Commit

Permalink
fix(cf): fail destoryService stage if service not found (#3779)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy Louie authored and Jon Schneider committed Jun 12, 2019
1 parent dc3b881 commit 5dfcbcb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public ServiceInstanceResponse operate(List priorOutputs) {
+ description.getSpace().getName());
LastOperation.State state = response.getState();
if (state == NOT_FOUND) {
task.updateStatus(
PHASE,
"Finished removing service instance '" + description.getServiceInstanceName() + "'");
throw new RuntimeException(
"Service instance "
+ description.getServiceInstanceName()
+ " not found, in "
+ description.getSpace().getRegion());
}
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import static com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v2.LastOperation.State.IN_PROGRESS;
import static com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v2.LastOperation.State.NOT_FOUND;
import static com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v2.LastOperation.Type.DELETE;
import static com.netflix.spinnaker.clouddriver.cloudfoundry.utils.TestUtils.assertThrows;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.atIndex;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;

import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.ServiceInstanceResponse;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.DestroyCloudFoundryServiceDescription;
import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundryOrganization;
import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundrySpace;
import com.netflix.spinnaker.clouddriver.data.task.Task;
import java.util.List;
Expand All @@ -35,12 +37,18 @@ class DestroyCloudFoundryServiceAtomicOperationTest
extends AbstractCloudFoundryAtomicOperationTest {
private DestroyCloudFoundryServiceDescription desc = new DestroyCloudFoundryServiceDescription();

@Test
void destroyCloudFoundryService() {
{
desc.setServiceInstanceName("service-instance-name");
desc.setSpace(CloudFoundrySpace.builder().name("space-name").build());
desc.setSpace(
CloudFoundrySpace.builder()
.name("space-name")
.organization(CloudFoundryOrganization.builder().name("org-name").build())
.build());
desc.setClient(client);
}

@Test
void destroyCloudFoundryService() {
ServiceInstanceResponse serviceInstanceResponse =
new ServiceInstanceResponse()
.setServiceInstanceName("service-instance-name")
Expand All @@ -67,17 +75,37 @@ void destroyCloudFoundryService() {
atIndex(1));
}

@Test
void destroyCloudFoundryServiceFailsWhenInstanceNotFound() {
ServiceInstanceResponse serviceInstanceResponse =
new ServiceInstanceResponse()
.setServiceInstanceName("service-instance-name")
.setType(DELETE)
.setState(NOT_FOUND);

when(client.getServiceInstances().destroyServiceInstance(any(), any()))
.thenReturn(serviceInstanceResponse);

DestroyCloudFoundryServiceAtomicOperation op =
new DestroyCloudFoundryServiceAtomicOperation(desc);

assertThrows(
() -> runOperation(op),
RuntimeException.class,
"Service instance "
+ desc.getServiceInstanceName()
+ " not found, in "
+ desc.getSpace().getRegion());
}

@Test
void destroyUserProvidedService() {
desc.setServiceInstanceName("up-service-instance-name");
desc.setSpace(CloudFoundrySpace.builder().name("space-name").build());
desc.setClient(client);

ServiceInstanceResponse serviceInstanceResponse =
new ServiceInstanceResponse()
.setServiceInstanceName("up-service-instance-name")
.setType(DELETE)
.setState(NOT_FOUND);
.setState(IN_PROGRESS);

when(client.getServiceInstances().destroyServiceInstance(any(), any()))
.thenReturn(serviceInstanceResponse);
Expand All @@ -96,7 +124,6 @@ void destroyUserProvidedService() {
.has(
status(
"Started removing service instance 'up-service-instance-name' from space space-name"),
atIndex(1))
.has(status("Finished removing service instance 'up-service-instance-name'"), atIndex(2));
atIndex(1));
}
}

0 comments on commit 5dfcbcb

Please sign in to comment.