-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openstack: added cinder volume tests #1943
- Loading branch information
1 parent
325a781
commit 64758e9
Showing
14 changed files
with
406 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...n/java/org/apache/camel/quarkus/component/openstack/it/OpenstackCinderVolumeResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.openstack.it; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
|
||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.component.openstack.cinder.CinderConstants; | ||
import org.apache.camel.component.openstack.common.OpenstackConstants; | ||
import org.jboss.logging.Logger; | ||
import org.openstack4j.api.Builders; | ||
import org.openstack4j.model.storage.block.Volume; | ||
import org.openstack4j.model.storage.block.VolumeAttachment; | ||
import org.openstack4j.model.storage.block.VolumeType; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@Path("/openstack/cinder/volumes/") | ||
@ApplicationScoped | ||
public class OpenstackCinderVolumeResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(OpenstackCinderVolumeResource.class); | ||
|
||
private static final String URI_FORMAT = "openstack-cinder://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem=" | ||
+ CinderConstants.VOLUMES; | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/createShouldSucceed") | ||
@POST | ||
public void createShouldSucceed() { | ||
LOG.debug("Calling OpenstackCinderVolumeResource.createShouldSucceed()"); | ||
|
||
Volume in = Builders.volume().size(10).name("test_openstack4j").description("test").multiattach(true).build(); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE); | ||
Volume out = template.requestBody(uri, in, Volume.class); | ||
|
||
assertEquals(out.getSize(), 10); | ||
assertEquals(out.multiattach(), Boolean.TRUE); | ||
} | ||
|
||
@Path("/getShouldSucceed") | ||
@POST | ||
public void getShouldSucceed() { | ||
LOG.debug("Calling OpenstackCinderVolumeResource.getShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET); | ||
String id = "8a9287b7-4f4d-4213-8d75-63470f19f27c"; | ||
Volume out = template.requestBodyAndHeader(uri, null, CinderConstants.VOLUME_ID, id, Volume.class); | ||
|
||
assertEquals(out.getId(), id); | ||
assertEquals(out.getName(), "test-volume"); | ||
assertEquals(out.getDescription(), "a description"); | ||
assertNotNull(out.getCreated()); | ||
assertEquals(out.getZone(), "nova"); | ||
assertEquals(out.getSize(), 100); | ||
assertEquals(out.getStatus(), Volume.Status.IN_USE); | ||
assertEquals(out.getSnapshotId(), "22222222-2222-2222-2222-222222222222"); | ||
assertEquals(out.getSourceVolid(), "11111111-1111-1111-1111-111111111111"); | ||
assertEquals(out.getVolumeType(), "Gold"); | ||
|
||
assertNotNull(out.getMetaData()); | ||
Map<String, String> metadata = out.getMetaData(); | ||
assertEquals(metadata.get("readonly"), "False"); | ||
assertEquals(metadata.get("attached_mode"), "rw"); | ||
|
||
assertNotNull(out.getAttachments()); | ||
List<? extends VolumeAttachment> attachments = out.getAttachments(); | ||
assertEquals(1, attachments.size()); | ||
assertEquals(attachments.get(0).getDevice(), "/dev/vdd"); | ||
assertEquals(attachments.get(0).getHostname(), "myhost"); | ||
assertEquals(attachments.get(0).getId(), "8a9287b7-4f4d-4213-8d75-63470f19f27c"); | ||
assertEquals(attachments.get(0).getServerId(), "eaa6a54d-35c1-40ce-831d-bb61f991e1a9"); | ||
assertEquals(attachments.get(0).getVolumeId(), "8a9287b7-4f4d-4213-8d75-63470f19f27c"); | ||
} | ||
|
||
@Path("/getAllShouldSucceed") | ||
@POST | ||
public void getAllShouldSucceed() { | ||
LOG.debug("Calling OpenstackCinderVolumeResource.getAllShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL); | ||
Volume[] volumes = template.requestBody(uri, null, Volume[].class); | ||
|
||
assertEquals(volumes.length, 3); | ||
assertEquals(volumes[0].getTenantId(), "b0b5ed7ae06049688349fe43737796d4"); | ||
} | ||
|
||
@Path("/getAllTypesShouldSucceed") | ||
@POST | ||
public void getAllTypesShouldSucceed() { | ||
LOG.debug("Calling OpenstackCinderVolumeResource.getAllTypesShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, CinderConstants.GET_ALL_TYPES); | ||
VolumeType[] volumeTypes = template.requestBody(uri, null, VolumeType[].class); | ||
|
||
assertEquals(volumeTypes.length, 2); | ||
assertEquals(volumeTypes[0].getId(), "6a65bc1b-197b-45bf-8056-9695dc82191f"); | ||
assertEquals(volumeTypes[0].getName(), "testVolume1"); | ||
assertNotNull(volumeTypes[0].getExtraSpecs()); | ||
assertEquals(volumeTypes[0].getExtraSpecs().get("capabilities"), "gpu"); | ||
assertEquals(volumeTypes[1].getId(), "10f00bb7-46d8-4f3f-b89b-702693a3dcdc"); | ||
assertEquals(volumeTypes[1].getName(), "testVolume2"); | ||
assertNotNull(volumeTypes[1].getExtraSpecs()); | ||
assertEquals(volumeTypes[1].getExtraSpecs().get("capabilities"), "gpu"); | ||
} | ||
|
||
@Path("/updateShouldSucceed") | ||
@POST | ||
public void updateShouldSucceed() { | ||
LOG.debug("Calling OpenstackCinderVolumeResource.updateShouldSucceed()"); | ||
|
||
Map<String, Object> headers = new HashMap<>(); | ||
headers.put(CinderConstants.VOLUME_ID, "fffab33e-38e8-4626-9fee-fe90f240ff0f"); | ||
headers.put(OpenstackConstants.NAME, "name"); | ||
headers.put(OpenstackConstants.DESCRIPTION, "description"); | ||
headers.put(CinderConstants.DESCRIPTION, 1024); | ||
headers.put(CinderConstants.VOLUME_TYPE, "volume-type"); | ||
headers.put(CinderConstants.IMAGE_REF, "image-ref"); | ||
headers.put(CinderConstants.SNAPSHOT_ID, "snaphot-id"); | ||
headers.put(CinderConstants.IS_BOOTABLE, false); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.UPDATE); | ||
template.requestBodyAndHeaders(uri, null, headers); | ||
} | ||
|
||
@Path("/deleteShouldSucceed") | ||
@POST | ||
public void deleteShouldSucceed() { | ||
LOG.debug("Calling OpenstackCinderVolumeResource.deleteShouldSucceed()"); | ||
|
||
String uri = String.format(URI_FORMAT, OpenstackConstants.DELETE); | ||
template.requestBodyAndHeader(uri, null, CinderConstants.VOLUME_ID, "fffab33e-38e8-4626-9fee-fe90f240ff0f"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
.../src/test/java/org/apache/camel/quarkus/component/openstack/it/OpenStackTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.openstack.it; | ||
|
||
import java.util.Map; | ||
|
||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; | ||
import org.apache.camel.quarkus.test.wiremock.WireMockTestResourceLifecycleManager; | ||
|
||
public class OpenStackTestResource extends WireMockTestResourceLifecycleManager { | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
Map<String, String> properties = super.start(); | ||
String wiremockUrl = properties.get("wiremock.url"); | ||
properties.put("camel.openstack.test.host-url", wiremockUrl); | ||
return properties; | ||
} | ||
|
||
@Override | ||
protected String getRecordTargetBaseUrl() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected boolean isMockingEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void customizeWiremockConfiguration(WireMockConfiguration config) { | ||
config.extensions(new ResponseTemplateTransformer(false)); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
.../test/java/org/apache/camel/quarkus/component/openstack/it/OpenstackCinderVolumeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.openstack.it; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.post; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(OpenStackTestResource.class) | ||
class OpenstackCinderVolumeTest { | ||
|
||
@Test | ||
public void createShouldSucceed() { | ||
post("/openstack/cinder/volumes/createShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void getShouldSucceed() { | ||
post("/openstack/cinder/volumes/getShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void getAllShouldSucceed() { | ||
post("/openstack/cinder/volumes/getAllShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void getAllTypesShouldSucceed() { | ||
post("/openstack/cinder/volumes/getAllTypesShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void updateShouldSucceed() { | ||
post("/openstack/cinder/volumes/updateShouldSucceed").then().statusCode(204); | ||
} | ||
|
||
@Test | ||
public void deleteShouldSucceed() { | ||
post("/openstack/cinder/volumes/deleteShouldSucceed").then().statusCode(204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
extensions-jvm/openstack/integration-test/src/test/resources/mappings/authv3_project.json
Large diffs are not rendered by default.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...-jvm/openstack/integration-test/src/test/resources/mappings/createVolume_multiattach.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id" : "64cb434b-c6fa-4e5b-b330-863738c56727", | ||
"name" : "createVolume_multiattach.json", | ||
"request" : { | ||
"url" : "/v2/123ac695d4db400a9001b91bb3b8aa46/volumes", | ||
"method" : "POST" | ||
}, | ||
"response" : { | ||
"status" : 201, | ||
"body" : "{\"volume\":{\"id\":\"ac9ae248-cf21-4301-87b1-568ff20a0a02\",\"status\":\"creating\",\"size\":10,\"zone\":\"nova\",\"created\":\"Wed Aug 16 13:27:14 KST 2017\",\"multiattach\":true,\"metadata\":{},\"bootable\":false}}", | ||
"headers" : { | ||
"Content-Type" : "application/json; charset=UTF-8" | ||
} | ||
}, | ||
"uuid" : "64cb434b-c6fa-4e5b-b330-863738c56727", | ||
"persistent" : true, | ||
"insertionIndex" : 1 | ||
} |
18 changes: 18 additions & 0 deletions
18
extensions-jvm/openstack/integration-test/src/test/resources/mappings/volume.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id" : "cae93cbc-a4a5-4fd8-b1a8-e66fbee24b0c", | ||
"name" : "volume.json", | ||
"request" : { | ||
"url" : "/v2/123ac695d4db400a9001b91bb3b8aa46/volumes/8a9287b7-4f4d-4213-8d75-63470f19f27c", | ||
"method" : "GET" | ||
}, | ||
"response" : { | ||
"status" : 200, | ||
"body" : "{\"volume\":{\"status\":\"in-use\",\"user_id\":\"92ac3530a6cb4d47aa406f1c2c90fca4\",\"attachments\":[{\"host_name\":\"myhost\",\"device\":\"\/dev\/vdd\",\"server_id\":\"eaa6a54d-35c1-40ce-831d-bb61f991e1a9\",\"id\":\"8a9287b7-4f4d-4213-8d75-63470f19f27c\",\"volume_id\":\"8a9287b7-4f4d-4213-8d75-63470f19f27c\"}],\"links\":[{\"href\":\"http:\/\/example.com.com:8776\/v2\/b0b5ed7ae06049688349fe43737796d4\/volumes\/8a9287b7-4f4d-4213-8d75-63470f19f27c\",\"rel\":\"self\"},{\"href\":\"http:\/\/example.com:8776\/b0b5ed7ae06049688349fe43737796d4\/volumes\/8a9287b7-4f4d-4213-8d75-63470f19f27c\",\"rel\":\"bookmark\"}],\"availability_zone\":\"nova\",\"bootable\":\"false\",\"encrypted\":false,\"created_at\":\"2015-05-25T15:03:43.104260\",\"description\":\"a description\",\"os-vol-tenant-attr:tenant_id\":\"b0b5ed7ae06049688349fe43737796d4\",\"os-volume-replication:driver_data\":null,\"volume_type\":\"Gold\",\"name\":\"test-volume\",\"replication_status\":\"disabled\",\"consistencygroup_id\":null,\"source_volid\":\"11111111-1111-1111-1111-111111111111\",\"snapshot_id\":\"22222222-2222-2222-2222-222222222222\",\"os-volume-replication:extended_status\":null,\"metadata\":{\"readonly\":\"False\",\"attached_mode\":\"rw\"},\"id\":\"8a9287b7-4f4d-4213-8d75-63470f19f27c\",\"size\":100}}", | ||
"headers" : { | ||
"Content-Type" : "application/json; charset=UTF-8" | ||
} | ||
}, | ||
"uuid" : "cae93cbc-a4a5-4fd8-b1a8-e66fbee24b0c", | ||
"persistent" : true, | ||
"insertionIndex" : 1 | ||
} |
14 changes: 14 additions & 0 deletions
14
extensions-jvm/openstack/integration-test/src/test/resources/mappings/volume_delete.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"id" : "543610ac-12c1-4b4e-9038-6287e97e3290", | ||
"name" : "volume_delete.json", | ||
"request" : { | ||
"url" : "/v2/123ac695d4db400a9001b91bb3b8aa46/volumes/fffab33e-38e8-4626-9fee-fe90f240ff0f", | ||
"method" : "DELETE" | ||
}, | ||
"response" : { | ||
"status" : 200 | ||
}, | ||
"uuid" : "543610ac-12c1-4b4e-9038-6287e97e3290", | ||
"persistent" : true, | ||
"insertionIndex" : 1 | ||
} |
Oops, something went wrong.