// create volume only to make a snapshot
Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
// Sleep for 5 seconds to make sure the volume creation finishes.
Thread.sleep(5000);
Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());
template.getOptions().as(EC2TemplateOptions.class)//
// .unmapDeviceNamed("/dev/foo)
.mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
.mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
.mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);
try {
NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));
// TODO figure out how to validate the ephemeral drive. perhaps with df -k?
Map<String, BlockDevice> devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
.getParent().getId(), node.getProviderId());
BlockDevice device = devices.get("/dev/sdn");
// check delete on termination
assertTrue(device.isDeleteOnTermination());
volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
device.getVolumeId()));
// check volume size
assertEquals(volumeSize, volume.getSize());
device = devices.get("/dev/sdo");
// check delete on termination
assertTrue(device.isDeleteOnTermination());
volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
device.getVolumeId()));
// check volume size
assertEquals(volumeSize, volume.getSize());
// check volume's snapshot id
assertEquals(snapshot.getId(), volume.getSnapshotId());
} finally {
client.destroyNodesMatching(NodePredicates.inGroup(group));
ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
}
}