Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to set name of Volume we booted from is no longer fatal #278

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,17 @@ public void afterProvisioning(@Nonnull Server server, @Nonnull Openstack opensta
+ name + (instanceVolumeSnapshotId == null ? "" : " (" + instanceVolumeSnapshotId + ")") + ".";
for (final String volumeId : volumeIds) {
final String newVolumeName = instanceName + '[' + (i++) + ']';
openstack.setVolumeNameAndDescription(volumeId, newVolumeName, newVolumeDescription);
try {
openstack.setVolumeNameAndDescription(volumeId, newVolumeName, newVolumeDescription);
} catch (Openstack.ActionFailed ex) {
/*
* Some versions of OpenStack work better than others. Not all will accept this
* operation. However, a failure to set the name and description is purely
* cosmetic and does not affect our ability to use the instance, so we log the
* problem and carry on.
*/
LOGGER.warning("Unable to set volume " + volumeId + " name and description: " + ex.getMessage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,32 @@ public void bootFromVolumeSnapshot() {
final JCloudsSlaveTemplate instance = j.dummySlaveTemplate(opts, "a");
final JCloudsCloud cloud = j.configureSlaveProvisioningWithFloatingIP(j.dummyCloud(instance));
final Openstack mockOs = cloud.getOpenstack();
testBootFromVolumeSnapshot(volumeSnapshotName, volumeSnapshotId, instance, mockOs);
}

@Test
public void bootFromVolumeSnapshotStillPossibleEvenIfCantSetVolumeNameAndDescription() {
/*
* openstack4j can throw fail with the error:
* "ActionResponse{success=false, fault=Invalid input for field/attribute volume.
* Value: {u'description': u'...', u'display_name': u'...', u'name': u'...',
* u'os-vol-mig-status-attr:migstat': u'none', u'display_description': u'...'}.
* Additional properties are not allowed (u'os-vol-mig-status-attr:migstat' was
* unexpected), code=400}".
* We need our code to survive this and not treat it as a fatal error.
*/
final String volumeSnapshotName = "MyOtherVolumeSnapshot";
final String volumeSnapshotId = "vs-345-id";
final SlaveOptions opts = dummySlaveOptions().getBuilder().bootSource(new VolumeSnapshot(volumeSnapshotName)).build();
final JCloudsSlaveTemplate instance = j.dummySlaveTemplate(opts, "b");
final JCloudsCloud cloud = j.configureSlaveProvisioningWithFloatingIP(j.dummyCloud(instance));
final Openstack mockOs = cloud.getOpenstack();
doThrow(new Openstack.ActionFailed("Mock OpenStack error setting volume name and description")).when(mockOs).setVolumeNameAndDescription(anyString(), anyString(), anyString());
testBootFromVolumeSnapshot(volumeSnapshotName, volumeSnapshotId, instance, mockOs);
}

private void testBootFromVolumeSnapshot(final String volumeSnapshotName, final String volumeSnapshotId,
final JCloudsSlaveTemplate instance, final Openstack mockOs) {
when(mockOs.getVolumeSnapshotIdsFor(volumeSnapshotName)).thenReturn(singletonList(volumeSnapshotId));

final ArgumentCaptor<ServerCreateBuilder> scbCaptor = ArgumentCaptor.forClass(ServerCreateBuilder.class);
Expand Down