mirror of https://github.com/apache/jclouds.git
Added root volume deletion after the test ends
This commit is contained in:
parent
6786db2738
commit
cec1a92bb4
|
@ -29,6 +29,7 @@ import org.jclouds.aws.domain.Region;
|
||||||
import org.jclouds.aws.ec2.domain.*;
|
import org.jclouds.aws.ec2.domain.*;
|
||||||
import org.jclouds.aws.ec2.domain.Volume;
|
import org.jclouds.aws.ec2.domain.Volume;
|
||||||
import org.jclouds.aws.ec2.predicates.InstanceStateRunning;
|
import org.jclouds.aws.ec2.predicates.InstanceStateRunning;
|
||||||
|
import org.jclouds.aws.ec2.predicates.InstanceStateTerminated;
|
||||||
import org.jclouds.aws.ec2.reference.EC2Constants;
|
import org.jclouds.aws.ec2.reference.EC2Constants;
|
||||||
import org.jclouds.compute.ComputeService;
|
import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.domain.*;
|
import org.jclouds.compute.domain.*;
|
||||||
|
@ -64,7 +65,9 @@ public class InstanceVolumeManagerLiveTest {
|
||||||
private ComputeService client;
|
private ComputeService client;
|
||||||
private Template template;
|
private Template template;
|
||||||
private Predicate<RunningInstance> instanceRunning;
|
private Predicate<RunningInstance> instanceRunning;
|
||||||
|
private Predicate<RunningInstance> instanceTerminated;
|
||||||
private RunningInstance instanceCreated;
|
private RunningInstance instanceCreated;
|
||||||
|
private Volume volumeAttached;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
public void setupClient() throws IOException {
|
public void setupClient() throws IOException {
|
||||||
|
@ -98,6 +101,10 @@ public class InstanceVolumeManagerLiveTest {
|
||||||
new RetryablePredicate<RunningInstance>(new InstanceStateRunning(manager.getApi().
|
new RetryablePredicate<RunningInstance>(new InstanceStateRunning(manager.getApi().
|
||||||
getInstanceServices()),
|
getInstanceServices()),
|
||||||
600, 10, TimeUnit.SECONDS);
|
600, 10, TimeUnit.SECONDS);
|
||||||
|
instanceTerminated =
|
||||||
|
new RetryablePredicate<RunningInstance>(new InstanceStateTerminated(manager.getApi().
|
||||||
|
getInstanceServices()),
|
||||||
|
600, 10, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -123,16 +130,22 @@ public class InstanceVolumeManagerLiveTest {
|
||||||
// NOTE: this step is essential
|
// NOTE: this step is essential
|
||||||
instanceCreated = getOnlyInstance(launchedNode.getId(), region);
|
instanceCreated = getOnlyInstance(launchedNode.getId(), region);
|
||||||
|
|
||||||
Volume volumeAttached = manager.getEbsApi().getRootVolumeForInstance(instanceCreated);
|
volumeAttached = manager.getEbsApi().getRootVolumeForInstance(instanceCreated);
|
||||||
checkState(volumeAttached.getSize() == NEW_SIZE,
|
checkState(volumeAttached.getSize() == NEW_SIZE,
|
||||||
String.format("The size of the new volume expected: " +
|
String.format("The size of the new volume expected: " +
|
||||||
"%d. Found: %d", NEW_SIZE, volumeAttached.getSize()));
|
"%d. Found: %d", NEW_SIZE, volumeAttached.getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTest
|
@AfterTest
|
||||||
public void close() {
|
public void close() {
|
||||||
manager.getApi().getInstanceServices().terminateInstancesInRegion
|
manager.getApi().getInstanceServices().terminateInstancesInRegion
|
||||||
(instanceCreated.getRegion(), instanceCreated.getId());
|
(instanceCreated.getRegion(), instanceCreated.getId());
|
||||||
|
checkState(instanceTerminated.apply(instanceCreated), "" +
|
||||||
|
/*or throw*/ "Couldn't terminate the instance");
|
||||||
|
if(volumeAttached != null) {
|
||||||
|
manager.getApi().getElasticBlockStoreServices().deleteVolumeInRegion
|
||||||
|
(volumeAttached.getRegion(), volumeAttached.getId());
|
||||||
|
}
|
||||||
manager.closeContext();
|
manager.closeContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,13 +195,13 @@ public class InstanceVolumeManagerLiveTest {
|
||||||
*/
|
*/
|
||||||
private RunningInstance getOnlyInstance(String instanceId, Region region) {
|
private RunningInstance getOnlyInstance(String instanceId, Region region) {
|
||||||
return Iterables.getOnlyElement(
|
return Iterables.getOnlyElement(
|
||||||
Iterables.getOnlyElement(
|
Iterables.getOnlyElement(
|
||||||
manager.getApi().
|
manager.getApi().
|
||||||
getInstanceServices().
|
getInstanceServices().
|
||||||
describeInstancesInRegion(region, instanceId
|
describeInstancesInRegion(region, instanceId
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue