Skip to content

Commit

Permalink
openstack: added cinder snapshots and glance tests #1943
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger committed Mar 16, 2021
1 parent 6571331 commit a05fa67
Show file tree
Hide file tree
Showing 18 changed files with 412 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 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.model.storage.block.VolumeSnapshot;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Path("/openstack/cinder/snapshots/")
@ApplicationScoped
public class OpenstackCinderSnapshotResource {

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

private static final String URI_FORMAT = "openstack-cinder://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s&subsystem="
+ CinderConstants.SNAPSHOTS;

@Inject
ProducerTemplate template;

@Path("/getAllShouldSucceed")
@POST
public void getAllShouldSucceed() {
LOG.debug("Calling OpenstackCinderSnapshotResource.getAllShouldSucceed()");

String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL);
VolumeSnapshot[] volumeSnapshots = template.requestBody(uri, null, VolumeSnapshot[].class);

assertEquals(2, volumeSnapshots.length);
assertEquals("a06b0531-c14b-4a7b-8749-de1378dd1007", volumeSnapshots[0].getId());
assertEquals("b0e394e6-bb10-4bfe-960d-edf72100c810", volumeSnapshots[0].getVolumeId());
assertNotNull(volumeSnapshots[0].getMetaData());
assertTrue(volumeSnapshots[0].getMetaData().isEmpty());
assertEquals("6489c55f-b9f4-442e-8d0a-5a87349d2d07", volumeSnapshots[1].getId());
assertEquals("7f47ab73-303c-4a19-b311-6123bb115775", volumeSnapshots[1].getVolumeId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void createShouldSucceed() {
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);
assertEquals(10, out.getSize());
assertEquals(Boolean.TRUE, out.multiattach());
}

@Path("/getShouldSucceed")
Expand All @@ -72,30 +72,30 @@ public void getShouldSucceed() {
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");
assertEquals(id, out.getId());
assertEquals("test-volume", out.getName());
assertEquals("a description", out.getDescription());
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");
assertEquals("nova", out.getZone());
assertEquals(100, out.getSize());
assertEquals(Volume.Status.IN_USE, out.getStatus());
assertEquals("22222222-2222-2222-2222-222222222222", out.getSnapshotId());
assertEquals("11111111-1111-1111-1111-111111111111", out.getSourceVolid());
assertEquals("Gold", out.getVolumeType());

assertNotNull(out.getMetaData());
Map<String, String> metadata = out.getMetaData();
assertEquals(metadata.get("readonly"), "False");
assertEquals(metadata.get("attached_mode"), "rw");
assertEquals("False", metadata.get("readonly"));
assertEquals("rw", metadata.get("attached_mode"));

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");
assertEquals("/dev/vdd", attachments.get(0).getDevice());
assertEquals("myhost", attachments.get(0).getHostname());
assertEquals("8a9287b7-4f4d-4213-8d75-63470f19f27c", attachments.get(0).getId());
assertEquals("eaa6a54d-35c1-40ce-831d-bb61f991e1a9", attachments.get(0).getServerId());
assertEquals("8a9287b7-4f4d-4213-8d75-63470f19f27c", attachments.get(0).getVolumeId());
}

@Path("/getAllShouldSucceed")
Expand All @@ -106,8 +106,8 @@ public void 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");
assertEquals(3, volumes.length);
assertEquals("b0b5ed7ae06049688349fe43737796d4", volumes[0].getTenantId());
}

@Path("/getAllTypesShouldSucceed")
Expand All @@ -118,15 +118,15 @@ public void 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");
assertEquals(2, volumeTypes.length);
assertEquals("6a65bc1b-197b-45bf-8056-9695dc82191f", volumeTypes[0].getId());
assertEquals("testVolume1", volumeTypes[0].getName());
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");
assertEquals("gpu", volumeTypes[0].getExtraSpecs().get("capabilities"));
assertEquals("10f00bb7-46d8-4f3f-b89b-702693a3dcdc", volumeTypes[1].getId());
assertEquals("testVolume2", volumeTypes[1].getName());
assertNotNull(volumeTypes[1].getExtraSpecs());
assertEquals(volumeTypes[1].getExtraSpecs().get("capabilities"), "gpu");
assertEquals("gpu", volumeTypes[1].getExtraSpecs().get("capabilities"));
}

@Path("/updateShouldSucceed")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* 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.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
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.common.OpenstackConstants;
import org.apache.camel.component.openstack.glance.GlanceConstants;
import org.jboss.logging.Logger;
import org.openstack4j.model.common.Payload;
import org.openstack4j.model.common.Payloads;
import org.openstack4j.model.image.ContainerFormat;
import org.openstack4j.model.image.DiskFormat;
import org.openstack4j.model.image.Image;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@Path("/openstack/glance/")
@ApplicationScoped
public class OpenstackGlanceResource {

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

private static final String URI_FORMAT = "openstack-glance://{{camel.openstack.test.host-url}}?username=user&password=secret&project=project&operation=%s";

@Inject
ProducerTemplate template;

@Path("/createShouldSucceed")
@POST
public void createShouldSucceed() {
LOG.debug("Calling OpenstackGlanceResource.createShouldSucceed()");

Map<String, Object> headers = new HashMap<>();
headers.put(OpenstackConstants.NAME, "amphora-x64-haproxy");
headers.put(GlanceConstants.DISK_FORMAT, DiskFormat.QCOW2);
headers.put(GlanceConstants.CONTAINER_FORMAT, ContainerFormat.BARE);
headers.put(GlanceConstants.MIN_DISK, 0L);
headers.put(GlanceConstants.MIN_RAM, 0L);

Payload<InputStream> payload = Payloads.create(new ByteArrayInputStream(new byte[] { 10, 11, 12 }));
String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE);
Image out = template.requestBodyAndHeaders(uri, payload, headers, Image.class);

assertNotNull(out);
assertEquals("8a2ea42d-06b5-42c2-a54d-97105420f2bb", out.getId());
assertEquals("amphora-x64-haproxy", out.getName());
assertEquals(ContainerFormat.BARE, out.getContainerFormat());
assertEquals(DiskFormat.QCOW2, out.getDiskFormat());
assertEquals(0L, out.getMinDisk());
assertEquals(0L, out.getMinRam());
}

@Path("/uploadShouldSucceed")
@POST
public void uploadShouldSucceed() {
LOG.debug("Calling OpenstackGlanceResource.uploadShouldSucceed()");

Map<String, Object> headers = new HashMap<>();
headers.put(OpenstackConstants.NAME, "amphora-x64-haproxy");
headers.put(OpenstackConstants.ID, "4b434528-032b-4467-946c-b5880ce15c06");
headers.put(GlanceConstants.DISK_FORMAT, DiskFormat.QCOW2);
headers.put(GlanceConstants.CONTAINER_FORMAT, ContainerFormat.BARE);
headers.put(GlanceConstants.MIN_DISK, 0L);
headers.put(GlanceConstants.MIN_RAM, 0L);

Payload<InputStream> payload = Payloads.create(new ByteArrayInputStream(new byte[] { 10, 11, 12 }));
String uri = String.format(URI_FORMAT, GlanceConstants.UPLOAD);
Image out = template.requestBodyAndHeaders(uri, payload, headers, Image.class);

assertNotNull(out);
assertEquals("4b434528-032b-4467-946c-b5880ce15c06", out.getId());
}

@Path("/getShouldSucceed")
@POST
public void getShouldSucceed() {
LOG.debug("Calling OpenstackGlanceResource.getShouldSucceed()");

String uri = String.format(URI_FORMAT, OpenstackConstants.GET);
String id = "8a2ea42d-06b5-42c2-a54d-97105420f2bb";
Image out = template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, id, Image.class);

assertEquals(id, out.getId());
}

@Path("/getAllShouldSucceed")
@POST
public void getAllShouldSucceed() {
LOG.debug("Calling OpenstackGlanceResource.getAllShouldSucceed()");

String uri = String.format(URI_FORMAT, OpenstackConstants.GET_ALL);
Image[] images = template.requestBody(uri, null, Image[].class);

assertEquals(2, images.length);
assertEquals("7541b8be-c62b-46c3-b5a5-5bb5ce43ce01", images[0].getId());
}

@Path("/deleteShouldSucceed")
@POST
public void deleteShouldSucceed() {
LOG.debug("Calling OpenstackGlanceResource.deleteShouldSucceed()");

String uri = String.format(URI_FORMAT, OpenstackConstants.DELETE);
template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, "8a2ea42d-06b5-42c2-a54d-97105420f2bb");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 OpenstackCinderSnapshotTest {

@Test
public void getAllShouldSucceed() {
post("/openstack/cinder/snapshots/getAllShouldSucceed").then().statusCode(204);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 OpenstackGlanceTest {

@Test
public void createShouldSucceed() {
post("/openstack/glance/createShouldSucceed").then().statusCode(204);
}

@Test
public void uploadShouldSucceed() {
post("/openstack/glance/uploadShouldSucceed").then().statusCode(204);
}

@Test
public void getShouldSucceed() {
post("/openstack/glance/getShouldSucceed").then().statusCode(204);
}

@Test
public void getAllShouldSucceed() {
post("/openstack/glance/getAllShouldSucceed").then().statusCode(204);
}

@Test
public void deleteShouldSucceed() {
post("/openstack/glance/deleteShouldSucceed").then().statusCode(204);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id" : "abd83ce9-92e5-41dd-8bad-b5ce5408c775",
"name" : "volume_snapshots.json",
"request" : {
"url" : "/v2/123ac695d4db400a9001b91bb3b8aa46/snapshots",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"snapshots\":[{\"status\":\"available\",\"display_name\":\"snap-vol-test-1\",\"created_at\":\"2015-04-23T11:32:28.364877\",\"display_description\":\"\",\"volume_id\":\"b0e394e6-bb10-4bfe-960d-edf72100c810\",\"metadata\":{},\"id\":\"a06b0531-c14b-4a7b-8749-de1378dd1007\",\"size\":1},{\"status\":\"available\",\"display_name\":\"snap-vol-test-2\",\"created_at\":\"2015-04-23T11:32:14.620321\",\"display_description\":\"\",\"volume_id\":\"7f47ab73-303c-4a19-b311-6123bb115775\",\"metadata\":{},\"id\":\"6489c55f-b9f4-442e-8d0a-5a87349d2d07\",\"size\":1}]}",
"headers" : {
"Content-Type" : "application/json; charset=UTF-8"
}
},
"uuid" : "abd83ce9-92e5-41dd-8bad-b5ce5408c775",
"persistent" : true,
"insertionIndex" : 1
}

0 comments on commit a05fa67

Please sign in to comment.