Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;

import okio.Buffer;
import org.openstack4j.api.AbstractTest;
import org.openstack4j.api.Builders;
import org.openstack4j.model.common.ActionResponse;
Expand Down Expand Up @@ -41,11 +42,38 @@ public void createVolumeBackupV1() throws Exception {
assertNotNull(request.getHeader("X-Auth-Token"));
assertTrue(request.getPath().matches("/v[123]/\\p{XDigit}*/backups" ));
assertEquals( request.getMethod(), "POST");


String requestBody = request.getBody().readUtf8();
assertTrue(requestBody.contains("\"volume_id\" : \"999b49ff-a813-45cc-aef3-3ec82f089490\""));

assertEquals(backup.getName(), name);
assertNotNull(backup.getId());
assertEquals(backup.getId(), "7069c687-c85c-45ca-befa-aa78a971fdfe");
}

@Test
public void createVolumeBackupFromSnapshotV1() throws Exception {
respondWith("/storage/v1/volumebackup_create_response.json");
final String name = "backup1122";

VolumeBackupCreate create = Builders.volumeBackupCreate().volumeId("999b49ff-a813-45cc-aef3-3ec82f089490").container("container123")
.description("description123").name(name).incremental(false).snapshotId("b4b3258d-555a-4fce-8f53-69cc2ae96d3c").build();
VolumeBackup backup = osv3().blockStorage().backups().create(create);

RecordedRequest request = server.takeRequest();
assertNotNull(request.getHeader("X-Auth-Token"));
assertTrue(request.getPath().matches("/v[123]/\\p{XDigit}*/backups" ));
assertEquals( request.getMethod(), "POST");

String requestBody = request.getBody().readUtf8();
assertTrue(requestBody.contains("\"volume_id\" : \"999b49ff-a813-45cc-aef3-3ec82f089490\""));
assertTrue(requestBody.contains("\"snapshot_id\" : \"b4b3258d-555a-4fce-8f53-69cc2ae96d3c\""));

assertEquals(backup.getName(), name);
assertNotNull(backup.getId());
assertEquals(backup.getId(), "7069c687-c85c-45ca-befa-aa78a971fdfe");
}


@Test
public void deleteVolumeBackupV1() throws Exception {
Expand Down Expand Up @@ -146,4 +174,32 @@ public void getVolumeBackupV1() throws Exception {

}


@Test
public void getVolumeBackupFromSnapshotV1() throws Exception {
// Check get volume
respondWith("/storage/v1/volumebackup_from_snapshot.json");
String id="735359d5-9584-4046-94d3-5ffc47be84f5";
VolumeBackup backup = osv3().blockStorage().backups().get(id);

RecordedRequest getRequest = server.takeRequest();
assertNotNull(getRequest.getHeader("X-Auth-Token"));
assertTrue(getRequest.getPath().matches("/v[123]/\\p{XDigit}*/backups/"+id));

assertEquals(backup.getId(), "735359d5-9584-4046-94d3-5ffc47be84f5");
assertEquals(backup.getContainer(), "test999b49ff-a813-45cc-aef3-3ec82f089490");
assertEquals(backup.getVolumeId(), "999b49ff-a813-45cc-aef3-3ec82f089490");
assertEquals(backup.getName(), "backup999b49ff-a813-45cc-aef3-3ec82f089490");
assertEquals(backup.getSnapshotId(), "b4b3258d-555a-4fce-8f53-69cc2ae96d3c");
assertEquals(backup.getStatus(), VolumeBackup.Status.AVAILABLE);
assertEquals(backup.getSize(), 1);
assertEquals(backup.getObjectCount(), 22);
assertEquals(backup.getZone(), "nova");
assertNotNull(backup.getCreated());
assertEquals(backup.getDescription(), "by API999b49ff-a813-45cc-aef3-3ec82f089490");
assertFalse(backup.hasDependent());
assertFalse(backup.isIncremental());

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"backup": {
"status": "available",
"description": "by API999b49ff-a813-45cc-aef3-3ec82f089490",
"links": [{
"href": "https://192.168.100.3:8776/v1/aec84f30304745c1b568593eee763eb4/backups/735359d5-9584-4046-94d3-5ffc47be84f5",
"rel": "self"
}, {
"href": "https://192.168.100.3:8776/aec84f30304745c1b568593eee763eb4/backups/735359d5-9584-4046-94d3-5ffc47be84f5",
"rel": "bookmark"
}],
"availability_zone": "nova",
"has_dependent_backups": false,
"volume_id": "999b49ff-a813-45cc-aef3-3ec82f089490",
"fail_reason": null,
"id": "735359d5-9584-4046-94d3-5ffc47be84f5",
"size": 1,
"object_count": 22,
"container": "test999b49ff-a813-45cc-aef3-3ec82f089490",
"name": "backup999b49ff-a813-45cc-aef3-3ec82f089490",
"created_at": "2016-11-22T06:23:33.000000",
"is_incremental": false,
"snapshot_id": "b4b3258d-555a-4fce-8f53-69cc2ae96d3c"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ public static Status fromValue(String status) {
*/
Boolean hasDependent();

/**
* @return If the backup was created from snapshot, the snapshot id. Otherwise, null.
*/
String getSnapshotId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ public interface VolumeBackupCreate extends ModelEntity, Buildable<VolumeBackupC
*/
boolean isIncremental();

/**
* @return Force mode. True to do backup while a volume is attached. Default is false.
*/
boolean isForce();

/**
* @return Force mode. True to do backup while a volume is attached. Default is false.
*/
String getSnapshotId();


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public interface VolumeBackupCreateBuilder extends Builder<VolumeBackupCreateBu

VolumeBackupCreateBuilder incremental(boolean incremental);

VolumeBackupCreateBuilder force(boolean force);

VolumeBackupCreateBuilder snapshotId(String snapshotId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class CinderVolumeBackup implements VolumeBackup{
@JsonProperty("is_incremental")
@Nullable
private Boolean incremental;

@JsonProperty("snapshot_id")
@Nullable
private String snapshotId;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -143,12 +147,23 @@ public int getObjectCount() {
return objectCount;
}

/**
* {@inheritDoc}
*/
@Override
public Boolean hasDependent() {
return hasDependent;
}



/**
* {@inheritDoc}
*/
@Override
public String getSnapshotId() {
return snapshotId;
}


public static class VolumeBackups extends ListResult<CinderVolumeBackup> {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class CinderVolumeBackupCreate implements VolumeBackupCreate {
private String volumeId;
@JsonProperty("incremental")
private boolean incremental;
@JsonProperty("force")
private boolean force;
@JsonProperty("snapshot_id")
private String snapshotId;


/**
* {@inheritDoc}
Expand Down Expand Up @@ -50,6 +55,22 @@ public boolean isIncremental() {
return incremental;
}

/**
* {@inheritDoc}
*/
@Override
public boolean isForce() {
return force;
}

/**
* {@inheritDoc}
*/
@Override
public String getSnapshotId() {
return snapshotId;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -119,6 +140,18 @@ public VolumeBackupCreateBuilder incremental(boolean incremental) {
model.incremental = incremental;
return this;
}

@Override
public VolumeBackupCreateBuilder force(boolean force) {
model.force = force;
return this;
}

@Override
public VolumeBackupCreateBuilder snapshotId(String snapshotId) {
model.snapshotId = snapshotId;
return this;
}
}

}