Set<? extends VolumeAttachment> attachments = volumeOption.get().listAttachmentsOnServer(serverId).toSet();
assertNotNull(attachments);
final int before = attachments.size();
VolumeAttachment testAttachment = volumeOption.get().attachVolumeToServerAsDevice(testVolume.getId(),
serverId, "/dev/vdf");
assertNotNull(testAttachment.getId());
assertEquals(testAttachment.getVolumeId(), testVolume.getId());
assertTrue(retry(new Predicate<VolumeApi>() {
public boolean apply(VolumeApi volumeApi) {
return volumeOption.get().listAttachmentsOnServer(serverId).size() > before;
}
}, 60 * 1000L).apply(volumeOption.get()));
attachments = volumeOption.get().listAttachmentsOnServer(serverId).toSet();
assertNotNull(attachments);
assertEquals(attachments.size(), before + 1);
assertTrue(retry(new Predicate<VolumeApi>() {
public boolean apply(VolumeApi volumeApi) {
return volumeApi.get(testVolume.getId()).getStatus() == Volume.Status.IN_USE;
}
}, 30 * 1000L).apply(volumeOption.get()), "Volume status did not show in-use after 30 seconds");
boolean foundIt = false;
for (VolumeAttachment att : attachments) {
VolumeAttachment details = volumeOption.get()
.getAttachmentForVolumeOnServer(att.getVolumeId(), serverId);
assertNotNull(details);
assertNotNull(details.getId());
assertNotNull(details.getServerId());
assertNotNull(details.getVolumeId());
if (Objects.equal(details.getVolumeId(), testVolume.getId())) {
foundIt = true;
assertEquals(details.getDevice(), "/dev/vdf");
assertEquals(details.getServerId(), serverId);
}
}
assertTrue(foundIt, "Failed to find the attachment we created in listAttachments() response");