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

openstack: added cinder volume tests #1943 #2330

Merged
merged 1 commit into from
Mar 12, 2021
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
9 changes: 9 additions & 0 deletions extensions-jvm/openstack/integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
Expand All @@ -51,6 +55,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-wiremock-support</artifactId>
<scope>test</scope>
</dependency>

<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
Expand Down
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class OpenstackResource {

private static final Logger LOG = Logger.getLogger(OpenstackResource.class);

private static final String COMPONENT_OPENSTACK_CINDER = "openstack-cinder";
private static final String COMPONENT_OPENSTACK_GLANCE = "openstack-glance";
private static final String COMPONENT_OPENSTACK_KEYSTONE = "openstack-keystone";
private static final String COMPONENT_OPENSTACK_NEUTRON = "openstack-neutron";
Expand All @@ -42,18 +41,6 @@ public class OpenstackResource {
@Inject
CamelContext context;

@Path("/load/component/openstack-cinder")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response loadComponentOpenstackCinder() throws Exception {
/* This is an autogenerated test */
if (context.getComponent(COMPONENT_OPENSTACK_CINDER) != null) {
return Response.ok().build();
}
LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_OPENSTACK_CINDER);
return Response.status(500, COMPONENT_OPENSTACK_CINDER + " could not be loaded from the Camel context").build();
}

@Path("/load/component/openstack-glance")
@GET
@Produces(MediaType.TEXT_PLAIN)
Expand Down
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));
}

}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
@QuarkusTest
class OpenstackTest {

@Test
public void loadComponentOpenstackCinder() {
/* A simple autogenerated test */
RestAssured.get("/openstack/load/component/openstack-cinder")
.then()
.statusCode(200);
}

@Test
public void loadComponentOpenstackGlance() {
/* A simple autogenerated test */
Expand Down

Large diffs are not rendered by default.

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
}
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
}
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
}