Skip to content

Commit

Permalink
openstack: added neutron port, subnet and nova flavor tests #1943
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger authored and ppalaga committed Mar 24, 2021
1 parent 2937812 commit b90b5f8
Show file tree
Hide file tree
Showing 14 changed files with 487 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.common.OpenstackConstants;
import org.apache.camel.component.openstack.neutron.NeutronConstants;
import org.jboss.logging.Logger;
import org.openstack4j.api.Builders;
import org.openstack4j.model.network.AllowedAddressPair;
import org.openstack4j.model.network.Port;

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

@Path("/openstack/neutron/ports/")
@ApplicationScoped
public class OpenstackNeutronPortResource {

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

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

private static final String NETWORK_ID = "a87cc70a-3e15-4acf-8205-9b711a3531b7";

@Inject
ProducerTemplate template;

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

Port in = Builders.port().networkId(NETWORK_ID).build();

String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE);
Port out = template.requestBody(uri, in, Port.class);

assertNotNull(out);
assertEquals(NETWORK_ID, out.getNetworkId());
assertNotNull(out.getAllowedAddressPairs());
assertEquals(1, out.getAllowedAddressPairs().size());
AllowedAddressPair allowedAddressPair = out.getAllowedAddressPairs().iterator().next();
assertNotNull(allowedAddressPair.getIpAddress());
assertNotNull(allowedAddressPair.getMacAddress());
}

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

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

assertNotNull(ports);
assertEquals(2, ports.length);
assertEquals(NETWORK_ID, ports[0].getNetworkId());
assertEquals("94225baa-9d3f-4b93-bf12-b41e7ce49cdb", ports[0].getId());
assertEquals(NETWORK_ID, ports[1].getNetworkId());
assertEquals("235b09e0-63c4-47f1-b221-66ba54c21760", ports[1].getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.common.OpenstackConstants;
import org.apache.camel.component.openstack.neutron.NeutronConstants;
import org.jboss.logging.Logger;
import org.openstack4j.model.network.Ipv6AddressMode;
import org.openstack4j.model.network.Ipv6RaMode;
import org.openstack4j.model.network.Subnet;

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/neutron/subnets/")
@ApplicationScoped
public class OpenstackNeutronSubnetResource {

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

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

private static final String SUBNET_NAME = "sub1";
private static final String SUBNET_ID = "3b80198d-4f7b-4f77-9ef5-774d54e17126";

@Inject
ProducerTemplate template;

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

String uri = String.format(URI_FORMAT, OpenstackConstants.GET);
Subnet out = template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, SUBNET_ID, Subnet.class);

assertNotNull(out);
assertEquals(SUBNET_NAME, out.getName());
assertEquals(Ipv6AddressMode.DHCPV6_STATEFUL, out.getIpv6AddressMode());
assertEquals(Ipv6RaMode.DHCPV6_STATEFUL, out.getIpv6RaMode());
assertNotNull(out.getDnsNames());
assertTrue(out.getDnsNames().isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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.common.OpenstackConstants;
import org.apache.camel.component.openstack.nova.NovaConstants;
import org.jboss.logging.Logger;
import org.openstack4j.api.Builders;
import org.openstack4j.model.compute.Flavor;

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

@Path("/openstack/nova/flavors/")
@ApplicationScoped
public class OpenstackNovaFlavorResource {

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

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

private static final String FLAVOR_ID = "1";
private static final String FLAVOR_NAME = "m1.tiny";

@Inject
ProducerTemplate template;

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

Flavor in = Builders.flavor().name("safe_to_delete_flavor").vcpus(1).disk(2).isPublic(true).rxtxFactor(2.0f)
.ephemeral(1)
.ram(128).id("delete_1").swap(1).build();

String uri = String.format(URI_FORMAT, OpenstackConstants.CREATE);
Flavor out = template.requestBody(uri, in, Flavor.class);

assertNotNull(out);
assertEquals(1, out.getVcpus());
assertEquals(2, out.getDisk());
assertEquals(FLAVOR_NAME, out.getName());
assertTrue(out.isPublic());
assertEquals(2.0f, out.getRxtxFactor());
assertEquals(1, out.getEphemeral());
assertEquals(128, out.getRam());
assertEquals(FLAVOR_ID, out.getId());
assertEquals(1, out.getSwap());
}

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

String uri = String.format(URI_FORMAT, OpenstackConstants.GET);
Flavor out = template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, FLAVOR_ID, Flavor.class);

assertNotNull(out);
assertEquals(1, out.getDisk());
assertEquals(FLAVOR_NAME, out.getName());
assertEquals(512, out.getRam());
assertTrue(out.isPublic());
assertEquals(0, out.getEphemeral());
assertFalse(out.isDisabled());
assertEquals(2.0f, out.getRxtxFactor());
assertEquals(1, out.getVcpus());
}

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

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

assertNotNull(flavors);
assertEquals(2, flavors.length);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,12 @@ public class OpenstackResource {

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

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";
private static final String COMPONENT_OPENSTACK_NOVA = "openstack-nova";
private static final String COMPONENT_OPENSTACK_SWIFT = "openstack-swift";

@Inject
CamelContext context;

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

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

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

@Path("/load/component/openstack-nova")
@GET
@Produces(MediaType.TEXT_PLAIN)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 OpenstackNeutronPortTest {

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

@Test
public void getAllShouldSucceed() {
post("/openstack/neutron/ports/getAllShouldSucceed").then().statusCode(204);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 OpenstackNeutronSubnetTest {

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

0 comments on commit b90b5f8

Please sign in to comment.