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

Renamed CinderVolume properties to be compatible with block storage API v2, fixed broken VolumeTests #1046

Merged
merged 3 commits into from
Jun 27, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ pom-shade.xml
*.versionsBackup
*/bin/*
*.iml
*.ipr
*.iws
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void getVolumeV1() throws Exception {
assertTrue(getRequest.getPath().matches("/v[12]/\\p{XDigit}*/volumes/8a9287b7-4f4d-4213-8d75-63470f19f27c"));

assertEquals(volume.getId(), "8a9287b7-4f4d-4213-8d75-63470f19f27c");
assertEquals(volume.getName(), "vol-test");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you have to remove these, the methods are the same i guess

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vinodborole!

As mentioned above - for block storage API v1, volume.getName() and volume.getDescription() now return null values (due to json property change display_name->name and display_description->description) and these assertions would fail.

Similar change was applied to CinderVolumeSnapshot.java in #1031. Nevertheless, json property change fixes the response for API v2/v3. Removed the skip from getVolumeV2() which does assert for name and description.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@auhlig What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While thinking about it: How about keeping both properties display_name and name? Maybe we should have done the same in the other class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Fixed both classes, added display_name and display_description to maintain backwards compatibility with deprecated cinder v1 API.

assertEquals(volume.getDescription(), "a description");
assertEquals(volume.getDisplayName(), "vol-test");
assertEquals(volume.getDisplayDescription(), "a description");
assertNotNull(volume.getCreated());
assertEquals(volume.getZone(), "nova");
assertEquals(volume.getSize(), 100);
Expand All @@ -91,7 +91,6 @@ public void getVolumeV1() throws Exception {

@SuppressWarnings("unchecked")
@Test
@SkipTest(connector = ".*", issue = 395, description = "Volume attribute not recognized when using cinder v2 api")
public void getVolumeV2() throws Exception {
// Check get volume
respondWith("/storage/v2/volume.json");
Expand All @@ -101,7 +100,7 @@ public void getVolumeV2() throws Exception {
assertTrue(getRequest.getPath().matches("/v[12]/\\p{XDigit}*/volumes/8a9287b7-4f4d-4213-8d75-63470f19f27c"));

assertEquals(volume.getId(), "8a9287b7-4f4d-4213-8d75-63470f19f27c");
assertEquals(volume.getName(), "vol-test");
assertEquals(volume.getName(), "test-volume");
assertEquals(volume.getDescription(), "a description");
assertNotNull(volume.getCreated());
assertEquals(volume.getZone(), "nova");
Expand Down
2 changes: 1 addition & 1 deletion core-test/src/main/resources/storage/v2/volume.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"status": "in-use",
"user_id": "92ac3530a6cb4d47aa406f1c2c90fca4",
"attachments": [{
"host_name": null,
"host_name": "myhost",
"device": "/dev/vdd",
"server_id": "eaa6a54d-35c1-40ce-831d-bb61f991e1a9",
"id": "8a9287b7-4f4d-4213-8d75-63470f19f27c",
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/org/openstack4j/model/storage/block/Volume.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,23 @@ public static MigrationStatus fromValue(String migrationStatus) {
*/
String getName();

/**
* @return the display name of the volume
*/
@Deprecated
String getDisplayName();

/**
* @return the description of the volume
*/
String getDescription();

/**
* @return the display description of the volume
*/
@Deprecated
String getDisplayDescription();

/**
* @return the status of the volume
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ public interface VolumeSnapshot extends ModelEntity, Buildable<VolumeSnapshotBui
*/
String getName();

/**
* @return the display name of the snapshot
*/
@Deprecated
String getDisplayName();

/**
* @return the description of the snapshot
*/
String getDescription();

/**
* @return the display description of the snapshot
*/
@Deprecated
String getDisplayDescription();

/**
* The volume identifier of an existing volume
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ public class CinderVolume implements Volume {
private static final long serialVersionUID = 1L;

private String id;
@JsonProperty("display_name")
@JsonProperty("name")
private String name;
@JsonProperty("display_description")
@JsonProperty("display_name")
private String displayName;
@JsonProperty("description")
private String description;
@JsonProperty("display_description")
private String displayDescription;
private Status status;
@JsonInclude(Include.NON_DEFAULT)
@JsonProperty("size")
Expand Down Expand Up @@ -96,6 +100,14 @@ public String getName() {
return name;
}

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return displayName;
}

/**
* {@inheritDoc}
*/
Expand All @@ -104,6 +116,14 @@ public String getDescription() {
return description;
}

/**
* {@inheritDoc}
*/
@Override
public String getDisplayDescription() {
return displayDescription;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ public class CinderVolumeSnapshot implements VolumeSnapshot {
private String id;
@JsonProperty("name")
private String name;
@JsonProperty("display_name")
private String displayName;
@JsonProperty("description")
private String description;
@JsonProperty("display_description")
private String displayDescription;
@JsonProperty("volume_id")
private String volumeId;
private Status status;
Expand Down Expand Up @@ -73,6 +77,14 @@ public String getName() {
return name;
}

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return displayName;
}

/**
* {@inheritDoc}
*/
Expand All @@ -81,6 +93,14 @@ public String getDescription() {
return description;
}

/**
* {@inheritDoc}
*/
@Override
public String getDisplayDescription() {
return displayDescription;
}

/**
* {@inheritDoc}
*/
Expand Down