Skip to content

Commit

Permalink
Prevent provisioning failure when VolumeSnapshot has no description.
Browse files Browse the repository at this point in the history
#220 reported
ClientResponseException{message=Invalid input for field/attribute
jenkins-boot-volumesnapshot-description. Value: None. None is not of
type 'string', status=400, status-code=BAD_REQUEST} when the
VolumeSnapshot has no description.
This code change now checks for null/empty and doesn't set the metadata
in such situations.
  • Loading branch information
pjdarton committed Sep 17, 2018
1 parent ff41fa9 commit 3a08f2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ public List<String> getFreeFipIds() {
*
* @param volumeSnapshotId
* The ID of the volume snapshot whose description is to be retrieved.
* @return The description string.
* @return The description string, or null if there isn't one.
*/
public String getVolumeSnapshotDescription(String volumeSnapshotId) {
public @CheckForNull String getVolumeSnapshotDescription(String volumeSnapshotId) {
return clientProvider.get().blockStorage().snapshots().get(volumeSnapshotId).getDescription();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public void setServerBootSource(@Nonnull ServerCreateBuilder builder, @Nonnull O
super.setServerBootSource(builder, os);
final List<String> matchingIds = getDescriptor().findMatchingIds(os, name);
final String id = selectIdFromListAndLogProblems(matchingIds, name, "VolumeSnapshots");
final String volumeSnapshotDescription = os.getVolumeSnapshotDescription(id);
final String volumeSnapshotDescriptionOrNull = os.getVolumeSnapshotDescription(id);
final BlockDeviceMappingBuilder volumeBuilder = Builders.blockDeviceMapping()
.sourceType(BDMSourceType.SNAPSHOT)
.destinationType(BDMDestType.VOLUME)
Expand All @@ -387,7 +387,9 @@ public void setServerBootSource(@Nonnull ServerCreateBuilder builder, @Nonnull O
.bootIndex(0);
builder.blockDevice(volumeBuilder.build());
builder.addMetadataItem(OPENSTACK_BOOTSOURCE_VOLUMESNAPSHOT_ID_KEY, id);
builder.addMetadataItem(OPENSTACK_BOOTSOURCE_VOLUMESNAPSHOT_DESC_KEY, volumeSnapshotDescription);
if (volumeSnapshotDescriptionOrNull != null && !volumeSnapshotDescriptionOrNull.isEmpty()) {
builder.addMetadataItem(OPENSTACK_BOOTSOURCE_VOLUMESNAPSHOT_DESC_KEY, volumeSnapshotDescriptionOrNull);
}
}

@Override
Expand Down

0 comments on commit 3a08f2e

Please sign in to comment.