Skip to content

Commit

Permalink
openstack: added neutron network tests #1943
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger committed Mar 22, 2021
1 parent 504a427 commit 397d6dc
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* 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.Network;
import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.State;

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

private static final Logger LOG = Logger.getLogger(OpenstackNeutronNetworkResource.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_NETWORK_SUBSYSTEM;

private static final String NETWORK_NAME = "net1";
private static final String NETWORK_ID = "4e8e5957-649f-477b-9e5b-f1f75b21c03c";

@Inject
ProducerTemplate template;

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

Network in = Builders.network().name(NETWORK_NAME).isRouterExternal(true).adminStateUp(true).build();

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

assertEquals(NETWORK_NAME, out.getName());
assertEquals(State.ACTIVE, out.getStatus());
assertTrue(out.isRouterExternal());
}

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

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

assertNotNull(out);
assertEquals(NETWORK_NAME, out.getName());
assertEquals(State.ACTIVE, out.getStatus());
assertFalse(out.isRouterExternal());
}

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

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

assertNotNull(networks);
assertEquals(1, networks.length);

assertEquals(NETWORK_NAME, networks[0].getName());
assertNotNull(networks[0].getSubnets());
assertEquals(1, networks[0].getSubnets().size());
assertEquals("0c4faf33-8c23-4dc9-8bf5-30dd1ab452f9", networks[0].getSubnets().get(0));
assertEquals("73f6f1ac-5e58-4801-88c3-7e12c6ddfb39", networks[0].getId());
assertEquals(NetworkType.VXLAN, networks[0].getNetworkType());
}

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

String uri = String.format(URI_FORMAT, OpenstackConstants.DELETE);
template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, NETWORK_ID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 OpenstackNeutronNetworkTest {

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

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

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

@Test
public void deleteShouldSucceed() {
post("/openstack/neutron/networks/deleteShouldSucceed").then().statusCode(204);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id" : "c9cd2086-3aed-4e30-a774-74bf0ab45483",
"name" : "network.json",
"request" : {
"url" : "/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c",
"method" : "GET"
},
"response" : {
"body" : "{\"network\":{\"status\":\"ACTIVE\",\"subnets\":[],\"name\":\"net1\",\"admin_state_up\":true,\"tenant_id\":\"9bacb3c5d39d41a79512987f338cf177\",\"segments\":[{\"provider:segmentation_id\":2,\"provider:physical_network\":\"8bab8453-1bc9-45af-8c70-f83aa9b50453\",\"provider:network_type\":\"vlan\"},{\"provider:segmentation_id\":null,\"provider:physical_network\":\"8bab8453-1bc9-45af-8c70-f83aa9b50453\",\"provider:network_type\":\"stt\"}],\"shared\":false,\"port_security_enabled\":true,\"id\":\"4e8e5957-649f-477b-9e5b-f1f75b21c03c\",\"created_at\":\"2020-10-30T22:16:01Z\",\"updated_at\":\"2020-10-30T22:16:01Z\"}}",
"headers" : {
"Content-Type" : "application/json; charset=UTF-8"
},
"status" : 200
},
"uuid" : "c9cd2086-3aed-4e30-a774-74bf0ab45483",
"persistent" : true,
"insertionIndex" : 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"id" : "2dafd863-ec9e-40aa-8e38-002006b6fc2c",
"name" : "network_delete.json",
"request" : {
"url" : "/v2.0/networks/4e8e5957-649f-477b-9e5b-f1f75b21c03c",
"method" : "DELETE"
},
"response" : {
"status" : 204,
"headers" : {
"Date": "Wed, 16 Mar 2016 15:01:58 GMT",
"Server": "Apache/2.4.7 (Ubuntu)",
"Vary": "X-Auth-Token",
"x-openstack-request-id": "req-e4b30959-e338-4c4a-be4b-180b5edb03d3"
}
},
"uuid" : "2dafd863-ec9e-40aa-8e38-002006b6fc2c",
"persistent" : true,
"insertionIndex" : 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id" : "d8c54bc8-ddc6-4c93-80ee-f474581a62ac",
"name" : "network_external.json",
"request" : {
"url" : "/v2.0/networks",
"method" : "POST"
},
"response" : {
"body" : "{\"network\":{\"status\":\"ACTIVE\",\"subnets\":[],\"name\":\"net1\",\"admin_state_up\":true,\"tenant_id\":\"9bacb3c5d39d41a79512987f338cf177\",\"segments\":[{\"provider:segmentation_id\":2,\"provider:physical_network\":\"8bab8453-1bc9-45af-8c70-f83aa9b50453\",\"provider:network_type\":\"vlan\"},{\"provider:segmentation_id\":null,\"provider:physical_network\":\"8bab8453-1bc9-45af-8c70-f83aa9b50453\",\"provider:network_type\":\"stt\"}],\"router:external\":true,\"shared\":false,\"port_security_enabled\":true,\"id\":\"4e8e5957-649f-477b-9e5b-f1f75b21c03c\",\"created_at\":\"2016-03-08T20:19:41\",\"updated_at\":\"2016-03-08T20:19:41\"}}",
"headers" : {
"Content-Type" : "application/json; charset=UTF-8"
},
"status" : 201
},
"uuid" : "d8c54bc8-ddc6-4c93-80ee-f474581a62ac",
"persistent" : true,
"insertionIndex" : 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id" : "4385766e-5070-403d-9e7f-cf43ccb8f26e",
"name" : "networks_filtered.json",
"request" : {
"url" : "/v2.0/networks",
"method" : "GET"
},
"response" : {
"body" : "{\"networks\":[{\"status\":\"ACTIVE\",\"subnets\":[\"0c4faf33-8c23-4dc9-8bf5-30dd1ab452f9\"],\"name\":\"net1\",\"provider:physical_network\":null,\"admin_state_up\":true,\"tenant_id\":\"9712d107d5f9445a9fc5b4108502e312\",\"mtu\":0,\"router:external\":true,\"shared\":true,\"provider:network_type\":\"vxlan\",\"id\":\"73f6f1ac-5e58-4801-88c3-7e12c6ddfb39\",\"provider:segmentation_id\":101101,\"created_at\":\"2020-10-30T22:16:01Z\",\"updated_at\":\"2020-10-30T22:16:01Z\"}]}",
"headers" : {
"Content-Type": "application/json",
"Date": "Wed, 16 Mar 2016 15:01:58 GMT",
"Server": "Apache/2.4.7 (Ubuntu)",
"Vary": "X-Auth-Token",
"x-openstack-request-id": "req-6e244e09-3016-4a19-8b6d-f9872f5ac66e"
},
"status" : 200
},
"uuid" : "4385766e-5070-403d-9e7f-cf43ccb8f26e",
"persistent" : true,
"insertionIndex" : 1
}

0 comments on commit 397d6dc

Please sign in to comment.