Updated Branches: refs/heads/opendaylight 30d46fd2f -> b7d7342cd
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronPortsNorthboundAction.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronPortsNorthboundAction.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronPortsNorthboundAction.java new file mode 100644 index 0000000..6ff1691 --- /dev/null +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronPortsNorthboundAction.java @@ -0,0 +1,111 @@ +// +// 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.cloudstack.network.opendaylight.api.resources; + +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Type; +import java.net.URL; +import java.text.MessageFormat; +import java.util.Collections; + +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; +import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronPortsList; +import org.apache.commons.httpclient.methods.StringRequestEntity; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +public class NeutronPortsNorthboundAction extends Action { + + private final Gson gsonNeutronPort; + + public NeutronPortsNorthboundAction(final URL url, final String username, final String password) { + super(url, username, password); + gsonNeutronPort = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); + } + + @SuppressWarnings("unchecked") + public <T> T listAllPorts() throws NeutronRestApiException { + String uri = NeutronNorthboundEnum.PORTS_URI.getUri(); + String bodystring = executeGet(uri, Collections.<String, String> emptyMap()); + + Type returnType = new TypeToken<NeutronPortsList<NeutronPortWrapper>>() { + }.getType(); + + T returnValue = (T) gsonNeutronPort.fromJson(bodystring, returnType); + + return returnValue; + } + + @SuppressWarnings("unchecked") + public <T> T findPortById(final String portId) throws NeutronRestApiException { + String uri = NeutronNorthboundEnum.PORTS_PARAM_URI.getUri(); + uri = MessageFormat.format(uri, portId); + + String bodystring = executeGet(uri, Collections.<String, String> emptyMap()); + + Type returnType = new TypeToken<NeutronPortWrapper>() { + }.getType(); + + T returnValue = (T) gsonNeutronPort.fromJson(bodystring, returnType); + + return returnValue; + } + + @SuppressWarnings("unchecked") + public <T> T createNeutronPort(final NeutronPortWrapper newPortWrapper) throws NeutronRestApiException { + try { + String uri = NeutronNorthboundEnum.PORTS_URI.getUri(); + StringRequestEntity entity = new StringRequestEntity(gsonNeutronPort.toJson(newPortWrapper), JSON_CONTENT_TYPE, null); + + String bodystring = executePost(uri, entity); + + T result = (T) gsonNeutronPort.fromJson(bodystring, TypeToken.get(NeutronPortWrapper.class).getType()); + + return result; + } catch (UnsupportedEncodingException e) { + throw new NeutronRestApiException("Failed to encode json request body", e); + } + } + + public <T> void updateNeutronPort(final String portId, final NeutronPortWrapper newPortWrapper) throws NeutronRestApiException { + try { + String uri = NeutronNorthboundEnum.PORTS_PARAM_URI.getUri(); + uri = MessageFormat.format(uri, portId); + + StringRequestEntity entity = new StringRequestEntity(gsonNeutronPort.toJson(newPortWrapper), JSON_CONTENT_TYPE, null); + + executePut(uri, entity); + } catch (UnsupportedEncodingException e) { + throw new NeutronRestApiException("Failed to encode json request body", e); + } + } + + public <T> void deleteNeutronPort(final String portId) throws NeutronRestApiException { + String uri = NeutronNorthboundEnum.PORTS_PARAM_URI.getUri(); + uri = MessageFormat.format(uri, portId); + + executeDelete(uri); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/responses/OpenDaylightControllerResponse.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/responses/OpenDaylightControllerResponse.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/responses/OpenDaylightControllerResponse.java new file mode 100644 index 0000000..98c644a --- /dev/null +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/responses/OpenDaylightControllerResponse.java @@ -0,0 +1,26 @@ +// +// 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.cloudstack.network.opendaylight.api.responses; + +import org.apache.cloudstack.api.BaseResponse; + +public class OpenDaylightControllerResponse extends BaseResponse { + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronEnumsTest.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronEnumsTest.java b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronEnumsTest.java new file mode 100644 index 0000000..1edf93b --- /dev/null +++ b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronEnumsTest.java @@ -0,0 +1,85 @@ +// +// 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.cloudstack.network.opendaylight.api.test; + +import java.text.MessageFormat; + +import junit.framework.Assert; + +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; +import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum; +import org.junit.Test; + +public class NeutronEnumsTest { + + @Test + public <T> void enumsUrlFormatTest1() throws NeutronRestApiException { + String netUrl = NeutronNorthboundEnum.NETWORK_PARAM_URI.getUri(); + netUrl = MessageFormat.format(netUrl, netId); + + Assert.assertEquals(NETWORK_PARAM_URI, netUrl); + } + + @Test + public <T> void enumsUrlFormatTest2() throws NeutronRestApiException { + String portUrl = NeutronNorthboundEnum.PORTS_PARAM_URI.getUri(); + portUrl = MessageFormat.format(portUrl, portId); + + Assert.assertEquals(PORTS_PARAM_URI, portUrl); + } + + @Test + public <T> void enumsUrlFormatTest3() throws NeutronRestApiException { + String nodedelUrl = NeutronNorthboundEnum.NODE_PARAM_URI.getUri(); + nodedelUrl = MessageFormat.format(nodedelUrl, "test", nodeId); + + Assert.assertEquals(NODE_PARAM_URI, nodedelUrl); + } + + @Test + public <T> void enumsUrlFormatTest4() throws NeutronRestApiException { + String nodeV1Url = NeutronNorthboundEnum.NODE_PORT_PER_NODE_URI.getUri(); + nodeV1Url = MessageFormat.format(nodeV1Url, nodeId, ip, String.valueOf(port)); + + Assert.assertEquals(NODE_PORT_PER_NODE_URI, nodeV1Url); + } + + @Test + public <T> void enumsUrlFormatTest5() throws NeutronRestApiException { + String nodeV2Url = NeutronNorthboundEnum.NODE_PORT_PER_TYPE_URI.getUri(); + nodeV2Url = MessageFormat.format(nodeV2Url, "test", nodeId, ip, String.valueOf(port)); + + Assert.assertEquals(NODE_PORT_PER_TYPE_URI, nodeV2Url); + } + + static String NETWORK_PARAM_URI = "/controller/nb/v2/neutron/networks/0AACEED5-A688-429A-92FC-E1C9E4EEEE98"; + + static String PORTS_PARAM_URI = "/controller/nb/v2/neutron/ports/F4267875-0C85-4829-8434-901A08691C6E"; + + static String NODE_PARAM_URI = "/controller/nb/v2/connectionmanager/node/test/ca31aa7f-84c7-416d-bc00-1f84927367e0"; + static String NODE_PORT_PER_NODE_URI = "/controller/nb/v2/connectionmanager/node/ca31aa7f-84c7-416d-bc00-1f84927367e0/address/1.1.1.1/port/6400"; + static String NODE_PORT_PER_TYPE_URI = "/controller/nb/v2/connectionmanager/node/test/ca31aa7f-84c7-416d-bc00-1f84927367e0/address/1.1.1.1/port/6400"; + + static String netId = "0AACEED5-A688-429A-92FC-E1C9E4EEEE98"; + static String portId = "F4267875-0C85-4829-8434-901A08691C6E"; + static String nodeId = "ca31aa7f-84c7-416d-bc00-1f84927367e0"; + static String ip = "1.1.1.1"; + static int port = 6400; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNetworkAdapterTest.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNetworkAdapterTest.java b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNetworkAdapterTest.java new file mode 100644 index 0000000..9d0adad --- /dev/null +++ b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNetworkAdapterTest.java @@ -0,0 +1,88 @@ +// +// 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.cloudstack.network.opendaylight.api.test; + +import java.io.UnsupportedEncodingException; +import java.util.UUID; + +import junit.framework.Assert; + +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.junit.Test; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper; + +public class NeutronNetworkAdapterTest { + + private final Gson gsonNeutronNetwork = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); + + @Test + public void gsonNeutronNetworkMarshalingTest() throws NeutronRestApiException { + NeutronNetwork network = new NeutronNetwork(); + network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + network.setName("test_gre"); + network.setNetworkType("test"); + network.setSegmentationId(1001); + network.setShared(true); + network.setTenantId("wilder"); + + NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper(); + networkWrapper.setNetwork(network); + + StringRequestEntity entity; + try { + entity = new StringRequestEntity(gsonNeutronNetwork.toJson(networkWrapper), "application/json", null); + + String actual = entity.getContent(); + Assert.assertEquals(jsonString, actual); + } catch (UnsupportedEncodingException e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public <T> void gsonNeutronNetworkUnmarshalingTest() throws NeutronRestApiException { + NeutronNetwork network = new NeutronNetwork(); + network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + network.setName("test_gre"); + network.setNetworkType("test"); + network.setSegmentationId(1001); + network.setShared(true); + network.setTenantId("wilder"); + + NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper(); + networkWrapper.setNetwork(network); + + NeutronNetworkWrapper returnValue = (NeutronNetworkWrapper) gsonNeutronNetwork.fromJson(jsonString, TypeToken.get(networkWrapper.getClass()).getType()); + + Assert.assertNotNull(returnValue); + Assert.assertEquals("test_gre", returnValue.getNetwork().getName()); + } + + static String jsonString = "{\"network\":{\"id\":\"ca31aa7f-84c7-416d-bc00-1f84927367e0\",\"name\":" + + "\"test_gre\",\"shared\":true,\"tenant_id\":\"wilder\",\"provider:network_type\":\"test\",\"provider:segmentation_id\":1001}}"; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNodeAdapterTest.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNodeAdapterTest.java b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNodeAdapterTest.java new file mode 100644 index 0000000..d7437fe --- /dev/null +++ b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronNodeAdapterTest.java @@ -0,0 +1,74 @@ +// +// 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.cloudstack.network.opendaylight.api.test; + +import java.io.UnsupportedEncodingException; + +import junit.framework.Assert; + +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNode; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.junit.Test; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +public class NeutronNodeAdapterTest { + + private final Gson gsonNeutronNode = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); + + @Test + public void gsonNeutronPortMarshalingTest() throws NeutronRestApiException { + NeutronNode node = new NeutronNode("node-test", "test"); + NeutronNodeWrapper nodeWrapper = new NeutronNodeWrapper(node); + + StringRequestEntity entity; + try { + entity = new StringRequestEntity(gsonNeutronNode.toJson(nodeWrapper), "application/json", null); + + String actual = entity.getContent(); + Assert.assertEquals(jsonString, actual); + } catch (UnsupportedEncodingException e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public <T> void gsonNeutronPortUnmarshalingTest() throws NeutronRestApiException { + NeutronNodeWrapper returnValue = (NeutronNodeWrapper) gsonNeutronNode.fromJson(jsonString, TypeToken.get(NeutronNodeWrapper.class).getType()); + + Assert.assertNotNull(returnValue); + Assert.assertEquals("node-test", returnValue.getNode().getId().toString()); + } + + @Test + public <T> void gsonNeutronPortUnmarshalingNullTest() throws NeutronRestApiException { + String json = null; + NeutronNodeWrapper returnValue = (NeutronNodeWrapper) gsonNeutronNode.fromJson(json, TypeToken.get(NeutronNodeWrapper.class).getType()); + + Assert.assertNull(returnValue); + } + + static String jsonString = "{\"node\":{\"id\":\"node-test\",\"type\":\"test\"}}"; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronPortAdapterTest.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronPortAdapterTest.java b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronPortAdapterTest.java new file mode 100644 index 0000000..4d88344 --- /dev/null +++ b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronPortAdapterTest.java @@ -0,0 +1,95 @@ +// +// 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.cloudstack.network.opendaylight.api.test; + +import java.io.UnsupportedEncodingException; +import java.util.UUID; + +import junit.framework.Assert; + +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronPort; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.junit.Test; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +public class NeutronPortAdapterTest { + + private final Gson gsonNeutronPort = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); + + @Test + public void gsonNeutronPortMarshalingTest() throws NeutronRestApiException { + NeutronPort port = new NeutronPort(); + + port.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + port.setName("test_gre"); + port.setAdminStateUp(true); + port.setDeviceId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + port.setMacAddress("ca31aa7f-84c7-416d-bc00-1f84927367e0"); + port.setNetworkId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + port.setStatus("ACTIVE"); + port.setTenantId("wilder"); + + NeutronPortWrapper portWrapper = new NeutronPortWrapper(); + portWrapper.setPort(port); + + StringRequestEntity entity; + try { + entity = new StringRequestEntity(gsonNeutronPort.toJson(portWrapper), "application/json", null); + + String actual = entity.getContent(); + + Assert.assertEquals(jsonString, actual); + } catch (UnsupportedEncodingException e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public <T> void gsonNeutronPortUnmarshalingTest() throws NeutronRestApiException { + NeutronPort port = new NeutronPort(); + + port.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + port.setName("test_gre"); + port.setAdminStateUp(true); + port.setDeviceId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + port.setMacAddress("ca31aa7f-84c7-416d-bc00-1f84927367e0"); + port.setNetworkId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + port.setStatus("ACTIVE"); + port.setTenantId("wilder"); + + NeutronPortWrapper portWrapper = new NeutronPortWrapper(); + portWrapper.setPort(port); + + NeutronPortWrapper returnValue = (NeutronPortWrapper) gsonNeutronPort.fromJson(jsonString, TypeToken.get(portWrapper.getClass()).getType()); + + Assert.assertNotNull(returnValue); + Assert.assertEquals("ca31aa7f-84c7-416d-bc00-1f84927367e0", returnValue.getPort().getMacAddress()); + } + + static String jsonString = "{\"port\":{\"id\":\"ca31aa7f-84c7-416d-bc00-1f84927367e0\",\"name\":\"test_gre\",\"tenant_id\":\"wilder\",\"network_id\":" + + "\"ca31aa7f-84c7-416d-bc00-1f84927367e0\",\"mac_address\":\"ca31aa7f-84c7-416d-bc00-1f84927367e0\",\"device_id\":\"ca31aa7f-84c7-416d-bc00-1f84927367e0\"," + + "\"admin_state_up\":true,\"status\":\"ACTIVE\"}}"; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiIT.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiIT.java b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiIT.java new file mode 100644 index 0000000..89f4b41 --- /dev/null +++ b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiIT.java @@ -0,0 +1,95 @@ +// +// 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.cloudstack.network.opendaylight.api.test; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import junit.framework.Assert; + +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodesList; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronPortWrapper; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronPortsList; +import org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction; +import org.apache.cloudstack.network.opendaylight.api.resources.NeutronNodesNorthboundAction; +import org.apache.cloudstack.network.opendaylight.api.resources.NeutronPortsNorthboundAction; +import org.junit.Test; + +public class NeutronRestApiIT { + + @Test + public void neutronListAllNodes() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://178.237.34.233:8080"); + + NeutronNodesNorthboundAction neutron = new NeutronNodesNorthboundAction(url, "admin", "admin"); + NeutronNodesList<NeutronNodeWrapper> results = neutron.listAllNodes(); + + Assert.assertNotNull(results); + + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + @Test + public void neutronListAllNetworks() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://178.237.34.233:8080"); + + NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin"); + NeutronNetworksList<NeutronNetworkWrapper> results = neutron.listAllNetworks(); + + Assert.assertNotNull(results); + + List<NeutronNetworkWrapper> networks = results.getNetworks(); + Assert.assertNotNull(networks); + + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + @Test + public void neutronListAllPorts() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://178.237.34.233:8080"); + + NeutronPortsNorthboundAction neutron = new NeutronPortsNorthboundAction(url, "admin", "admin"); + NeutronPortsList<NeutronPortWrapper> results = neutron.listAllPorts(); + + Assert.assertNotNull(results); + + List<NeutronPortWrapper> networks = results.getPorts(); + Assert.assertNotNull(networks); + + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7d7342c/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiTest.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiTest.java b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiTest.java new file mode 100644 index 0000000..aee15b3 --- /dev/null +++ b/plugins/network-elements/opendaylight/src/test/java/org/apache/cloudstack/network/opendaylight/api/test/NeutronRestApiTest.java @@ -0,0 +1,254 @@ +// +// 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.cloudstack.network.opendaylight.api.test; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.UUID; + +import junit.framework.Assert; + +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApi; +import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; +import org.apache.cloudstack.network.opendaylight.api.NeutronRestFactory; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork; +import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper; +import org.apache.cloudstack.network.opendaylight.api.resources.NeutronNetworksNorthboundAction; +import org.apache.cloudstack.network.opendaylight.api.resources.NeutronNodesNorthboundAction; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.junit.Test; + +public class NeutronRestApiTest { + + NeutronRestFactory factory = NeutronRestFactory.getInstance(); + + NeutronRestApi httpGet = factory.getNeutronApi(GetMethod.class); + NeutronRestApi httpPost = factory.getNeutronApi(PostMethod.class); + NeutronRestApi httpPut = factory.getNeutronApi(PutMethod.class); + NeutronRestApi httpDelete = factory.getNeutronApi(DeleteMethod.class); + + @Test + public void resourceHttpGetInstances() throws NeutronRestApiException { + NeutronRestApi newHttpGet = factory.getNeutronApi(GetMethod.class); + assertTrue(httpGet == newHttpGet); + } + + @Test + public void resourceHttpPostInstances() throws NeutronRestApiException { + NeutronRestApi newHttpPost = factory.getNeutronApi(PostMethod.class); + assertTrue(httpPost == newHttpPost); + } + + @Test + public void resourceHttpPutInstances() throws NeutronRestApiException { + NeutronRestApi newHttpPut = factory.getNeutronApi(PutMethod.class); + assertTrue(httpPut == newHttpPut); + } + + @Test + public void resourceHttpDeleteInstances() throws NeutronRestApiException { + NeutronRestApi newHttpDelete = factory.getNeutronApi(DeleteMethod.class); + assertTrue(httpDelete == newHttpDelete); + } + + @Test(expected = NeutronRestApiException.class) + public void neutronNetworksFail() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://localhost:8080"); + + NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin"); + neutron.listAllNetworks(); + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + @Test(expected = NeutronRestApiException.class) + public void neutronFindNetworkByIdFail() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://localhost:8080"); + + NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin"); + neutron.findNetworkById("0AACEED5-A688-429A-92FC-E1C9E4EEEE98"); + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + @Test(expected = NeutronRestApiException.class) + public void neutronNodesFail() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://localhost:8080"); + + NeutronNodesNorthboundAction neutron = new NeutronNodesNorthboundAction(url, "admin", "admin"); + neutron.listAllNodes(); + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + /* + * Test fails because there is no controller. It's used only to test that + * the HTTP methods are correct. + */ + @Test(expected = NeutronRestApiException.class) + public void neutronHTTPDeleteMethod() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://127.0.0.1:8080"); + + NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin"); + neutron.deleteNeutronNetwork("0AACEED5-A688-429A-92FC-E1C9E4EEEE98"); + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + /* + * Test fails because there is no controller. It's used only to test that + * the HTTP methods are correct. + */ + @Test(expected = NeutronRestApiException.class) + public void neutronHTTPGetMethod() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://localhost:8080"); + + NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin"); + neutron.listAllNetworks(); + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + /* + * Test fails because there is no controller. It's used only to test that + * the HTTP methods are correct. + */ + @Test(expected = NeutronRestApiException.class) + public void neutronHTTPPostMethod() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://localhost:8080"); + + NeutronNetwork network = new NeutronNetwork(); + network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + network.setName("test_gre"); + network.setNetworkType("test"); + network.setSegmentationId(1001); + network.setShared(true); + network.setTenantId("wilder"); + + NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper(); + networkWrapper.setNetwork(network); + + NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin"); + neutron.createNeutronNetwork(networkWrapper); + + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + /* + * Test fails because there is no controller. It's used only to test that + * the HTTP methods are correct. + */ + @Test(expected = NeutronRestApiException.class) + public void neutronHTTPPutMethod() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://localhost:8080"); + + NeutronNetwork network = new NeutronNetwork(); + network.setId(UUID.fromString("ca31aa7f-84c7-416d-bc00-1f84927367e0")); + network.setName("test_gre"); + network.setNetworkType("test"); + network.setSegmentationId(1001); + network.setShared(true); + network.setTenantId("wilder"); + + NeutronNetworkWrapper networkWrapper = new NeutronNetworkWrapper(); + networkWrapper.setNetwork(network); + + NeutronNetworksNorthboundAction neutron = new NeutronNetworksNorthboundAction(url, "admin", "admin"); + neutron.updateNeutronNetwork("ca31aa7f-84c7-416d-bc00-1f84927367e0", networkWrapper); + + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + /* + * Test fails because there is no controller. It's used only to test that + * the HTTP methods are correct. + */ + @Test(expected = NeutronRestApiException.class) + public void neutronHTTPPutUriMethod() throws NeutronRestApiException { + URL url; + try { + url = new URL("http://localhost:8080"); + + NeutronNodesNorthboundAction neutron = new NeutronNodesNorthboundAction(url, "admin", "admin"); + neutron.updateNeutronNodeV1("ca31aa7f-84c7-416d-bc00-1f84927367e0", "1.1.1.1.", 6400); + + } catch (MalformedURLException e) { + Assert.fail("Should not fail here."); + } + } + + static String networkJSON = "{" + "\"networks\": [" + "{" + "\"network\": {" + "\"segmentation_id\": 100," + "\"shared\": false," + "\"name\": \"net_test\"," + + "\"network_type\": \"test\"," + "\"tenant_id\": \"t\"," + "\"id\": \"0AACEED5-A688-429A-92FC-E1C9E4EEEE98\"," + "\"status\": \"ACTIVE\"" + "}" + "}" + "]" + "}"; +} + +class NeutronRestApiMock extends NeutronRestApi { + + HttpClient client = mock(HttpClient.class); + + NeutronRestApiMock(final Class<? extends HttpMethodBase> httpClazz) { + super(httpClazz); + } + + @Override + public void executeMethod(final HttpMethodBase method) throws NeutronRestApiException { + try { + client.executeMethod(method); + } catch (HttpException e) { + method.releaseConnection(); + throw new NeutronRestApiException("API call to Neutron NVP Controller Failed", e); + } catch (IOException e) { + method.releaseConnection(); + throw new NeutronRestApiException("API call to Neutron NVP Controller Failed", e); + } + } +} \ No newline at end of file
