Strip hardcoded v2.0 in Neutron APIs. Prefer usage of ApiMetadata version string.

This commit is contained in:
Jeremy Daggett 2014-08-22 10:44:35 -07:00
parent 4f648567fa
commit b5b3a91fa3
13 changed files with 427 additions and 36 deletions

View File

@ -19,6 +19,9 @@ package org.jclouds.openstack.neutron.v2;
import java.io.Closeable;
import java.util.Set;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpoint;
import org.jclouds.openstack.neutron.v2.extensions.RouterApi;
@ -35,6 +38,7 @@ import com.google.inject.Provides;
/**
* Provides access to the OpenStack Networking (Neutron) v2 API.
*/
@Path("{" + Constants.PROPERTY_API_VERSION + "}")
public interface NeutronApi extends Closeable {
/**
* @return the Region codes configured

View File

@ -70,7 +70,7 @@ public class NeutronApiMetadata extends BaseHttpApiMetadata<NeutronApi> {
.credentialName("${password}")
.endpointName("Neutron base url ending in /v2.0/")
.documentation(URI.create("http://docs.openstack.org/api/openstack-network/2.0/content/"))
.version("2.0")
.version("v2.0")
.defaultEndpoint("http://localhost:5000/v2.0/")
.defaultProperties(NeutronApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()

View File

@ -61,7 +61,7 @@ import com.google.common.annotations.Beta;
* "http://docs.openstack.org/api/openstack-network/2.0/content/router_ext.html">api doc</a>
*/
@Beta
@Path("/v2.0/routers")
@Path("/routers")
@RequestFilters(AuthenticateRequest.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface RouterApi {

View File

@ -58,7 +58,7 @@ import javax.ws.rs.core.MediaType;
* "http://docs.openstack.org/api/openstack-network/2.0/content/Networks.html">api doc</a>
*/
@Beta
@Path("/v2.0/networks")
@Path("/networks")
@RequestFilters(AuthenticateRequest.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

View File

@ -57,7 +57,7 @@ import java.util.List;
* "http://docs.openstack.org/api/openstack-network/2.0/content/Ports.html">api doc</a>
*/
@Beta
@Path("/v2.0/ports")
@Path("/ports")
@RequestFilters(AuthenticateRequest.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface PortApi {

View File

@ -53,7 +53,7 @@ import java.util.List;
* @see <a href=
* "http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api doc</a>
*/
@Path("/v2.0/subnets")
@Path("/subnets")
@RequestFilters(AuthenticateRequest.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

View File

@ -15,7 +15,13 @@
* limitations under the License.
*/
package org.jclouds.openstack.neutron.v2.features;
package org.jclouds.openstack.neutron.v2.extensions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import org.jclouds.openstack.neutron.v2.domain.ExternalGatewayInfo;
import org.jclouds.openstack.neutron.v2.domain.Network;
@ -24,16 +30,12 @@ import org.jclouds.openstack.neutron.v2.domain.Port;
import org.jclouds.openstack.neutron.v2.domain.Router;
import org.jclouds.openstack.neutron.v2.domain.RouterInterface;
import org.jclouds.openstack.neutron.v2.domain.Subnet;
import org.jclouds.openstack.neutron.v2.extensions.RouterApi;
import org.jclouds.openstack.neutron.v2.features.NetworkApi;
import org.jclouds.openstack.neutron.v2.features.PortApi;
import org.jclouds.openstack.neutron.v2.features.SubnetApi;
import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiLiveTest;
import org.testng.annotations.Test;
import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
/**
* Tests parsing and Guice wiring of RouterApi
*/

View File

@ -14,25 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.openstack.neutron.v2.features;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import org.jclouds.openstack.neutron.v2.NeutronApi;
import org.jclouds.openstack.neutron.v2.domain.ExternalGatewayInfo;
import org.jclouds.openstack.neutron.v2.domain.NetworkStatus;
import org.jclouds.openstack.neutron.v2.domain.Router;
import org.jclouds.openstack.neutron.v2.domain.RouterInterface;
import org.jclouds.openstack.neutron.v2.domain.Routers;
import org.jclouds.openstack.neutron.v2.extensions.RouterApi;
import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiMockTest;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
package org.jclouds.openstack.neutron.v2.extensions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
@ -41,6 +23,24 @@ import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import org.jclouds.openstack.neutron.v2.NeutronApi;
import org.jclouds.openstack.neutron.v2.domain.ExternalGatewayInfo;
import org.jclouds.openstack.neutron.v2.domain.NetworkStatus;
import org.jclouds.openstack.neutron.v2.domain.Router;
import org.jclouds.openstack.neutron.v2.domain.RouterInterface;
import org.jclouds.openstack.neutron.v2.domain.Routers;
import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiMockTest;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
/**
* Tests NetworkApi Guice wiring and parsing
*

View File

@ -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.jclouds.openstack.neutron.v2.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import java.util.Set;
import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiLiveTest;
import org.jclouds.openstack.v2_0.domain.Extension;
import org.jclouds.openstack.v2_0.features.ExtensionApi;
import org.testng.annotations.Test;
/**
* Tests behavior of {@link ExtensionApi}
*/
@Test(groups = "live", testName = "ExtensionApiLiveTest")
public class ExtensionApiLiveTest extends BaseNeutronApiLiveTest {
/**
* Tests the listing of Neutron Extensions.
*
* @throws Exception
*/
public void testListExtensions() throws Exception {
for (String regionId : api.getConfiguredRegions()) {
ExtensionApi extensionApi = api.getExtensionApi(regionId);
Set<Extension> response = extensionApi.list();
assertNotNull(response);
assertFalse(response.isEmpty());
for (Extension extension : response) {
assertNotNull(extension.getId());
assertNotNull(extension.getName());
assertNotNull(extension.getDescription());
assertNotNull(extension.getNamespace());
assertNotNull(extension.getUpdated());
assertNotNull(extension.getLinks());
}
}
}
/**
* Tests retrieval of Neutron Extensions by their alias.
*
* @throws Exception
*/
public void testGetExtensionByAlias() throws Exception {
for (String regionId : api.getConfiguredRegions()) {
ExtensionApi extensionApi = api.getExtensionApi(regionId);
Set<Extension> response = extensionApi.list();
assertNotNull(response);
for (Extension extension : response) {
Extension details = extensionApi.get(extension.getId());
assertNotNull(details);
assertEquals(details.getId(), extension.getId());
assertEquals(details.getName(), extension.getName());
assertEquals(details.getDescription(), extension.getDescription());
assertEquals(details.getNamespace(), extension.getNamespace());
assertEquals(details.getUpdated(), extension.getUpdated());
assertEquals(details.getLinks(), extension.getLinks());
}
}
}
}

View File

@ -0,0 +1,152 @@
/*
* 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.jclouds.openstack.neutron.v2.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import org.jclouds.openstack.neutron.v2.NeutronApi;
import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiMockTest;
import org.jclouds.openstack.v2_0.domain.Extension;
import org.jclouds.openstack.v2_0.features.ExtensionApi;
import org.testng.annotations.Test;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
/**
* Tests annotation parsing of {@code ExtensionApi}
*/
@Test(groups = "unit", testName = "ExtensionApiMockTest")
public class ExtensionApiMockTest extends BaseNeutronApiMockTest {
public void testListExtensions() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
server.enqueue(addCommonHeaders(new MockResponse()
.setResponseCode(200).setBody(stringFromResource("/extension_list.json"))));
try {
NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides);
ExtensionApi api = neutronApi.getExtensionApi("RegionOne");
Set<Extension> extensions = api.list();
/*
* Check request
*/
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
/*
* Check response
*/
assertNotNull(extensions);
assertEquals(extensions.size(), 17);
} finally {
server.shutdown();
}
}
public void testListExtensionsIsEmpty() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
try {
NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides);
ExtensionApi api = neutronApi.getExtensionApi("RegionOne");
Set<Extension> extensions = api.list();
/*
* Check request
*/
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
assertRequest(server.takeRequest(), "GET", "/v2.0/extensions");
/*
* Check response
*/
assertTrue(extensions.isEmpty());
} finally {
server.shutdown();
}
}
public void testGetExtensionByAlias() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
server.enqueue(addCommonHeaders(new MockResponse()
.setResponseCode(200).setBody(stringFromResource("/extension_details.json"))));
try {
NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides);
Extension routerExtension = neutronApi.getExtensionApi("RegionOne").get("router");
/*
* Check request
*/
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
assertRequest(server.takeRequest(), "GET", "/v2.0/extensions/router");
/*
* Check response
*/
assertNotNull(routerExtension);
assertEquals(routerExtension.getName(), "Neutron L3 Router");
} finally {
server.shutdown();
}
}
public void testGetExtensionByAliasFail() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
try {
NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides);
Extension routerExtension = neutronApi.getExtensionApi("RegionOne").get("router");
/*
* Check request
*/
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
assertRequest(server.takeRequest(), "GET", "/v2.0/extensions/router");
/*
* Check response
*/
assertNull(routerExtension);
} finally {
server.shutdown();
}
}
}

View File

@ -16,13 +16,13 @@
*/
package org.jclouds.openstack.neutron.v2.internal;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.neutron.v2.NeutronApi;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
import java.util.Properties;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.neutron.v2.NeutronApi;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
/**
* Base class for writing Neutron Mock tests

View File

@ -0,0 +1,10 @@
{
"extension": {
"name": "Neutron L3 Router",
"namespace": "http://docs.openstack.org/ext/neutron/router/api/v1.0",
"alias": "router",
"updated": "2012-07-20T10:00:00-00:00",
"description": "Router abstraction for basic L3 forwarding between L2 Neutron networks and access to external networks via a NAT gateway.",
"links": []
}
}

View File

@ -0,0 +1,140 @@
{
"extensions": [
{
"updated": "2013-01-20T00:00:00-00:00",
"name": "Neutron Service Type Management",
"links": [],
"namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0",
"alias": "service-type",
"description": "API for retrieving service providers for Neutron advanced services"
},
{
"updated": "2012-10-05T10:00:00-00:00",
"name": "security-group",
"links": [],
"namespace": "http://docs.openstack.org/ext/securitygroups/api/v2.0",
"alias": "security-group",
"description": "The security groups extension."
},
{
"updated": "2013-02-07T10:00:00-00:00",
"name": "L3 Agent Scheduler",
"links": [],
"namespace": "http://docs.openstack.org/ext/l3_agent_scheduler/api/v1.0",
"alias": "l3_agent_scheduler",
"description": "Schedule routers among l3 agents"
},
{
"updated": "2013-02-07T10:00:00-00:00",
"name": "Loadbalancer Agent Scheduler",
"links": [],
"namespace": "http://docs.openstack.org/ext/lbaas_agent_scheduler/api/v1.0",
"alias": "lbaas_agent_scheduler",
"description": "Schedule pools among lbaas agents"
},
{
"updated": "2013-03-28T10:00:00-00:00",
"name": "Neutron L3 Configurable external gateway mode",
"links": [],
"namespace": "http://docs.openstack.org/ext/neutron/ext-gw-mode/api/v1.0",
"alias": "ext-gw-mode",
"description": "Extension of the router abstraction for specifying whether SNAT should occur on the external gateway"
},
{
"updated": "2014-02-03T10:00:00-00:00",
"name": "Port Binding",
"links": [],
"namespace": "http://docs.openstack.org/ext/binding/api/v1.0",
"alias": "binding",
"description": "Expose port bindings of a virtual port to external application"
},
{
"updated": "2012-09-07T10:00:00-00:00",
"name": "Provider Network",
"links": [],
"namespace": "http://docs.openstack.org/ext/provider/api/v1.0",
"alias": "provider",
"description": "Expose mapping of virtual networks to physical networks"
},
{
"updated": "2013-02-03T10:00:00-00:00",
"name": "agent",
"links": [],
"namespace": "http://docs.openstack.org/ext/agent/api/v2.0",
"alias": "agent",
"description": "The agent management extension."
},
{
"updated": "2012-07-29T10:00:00-00:00",
"name": "Quota management support",
"links": [],
"namespace": "http://docs.openstack.org/network/ext/quotas-sets/api/v2.0",
"alias": "quotas",
"description": "Expose functions for quotas management per tenant"
},
{
"updated": "2013-02-07T10:00:00-00:00",
"name": "DHCP Agent Scheduler",
"links": [],
"namespace": "http://docs.openstack.org/ext/dhcp_agent_scheduler/api/v1.0",
"alias": "dhcp_agent_scheduler",
"description": "Schedule networks among dhcp agents"
},
{
"updated": "2013-06-27T10:00:00-00:00",
"name": "Multi Provider Network",
"links": [],
"namespace": "http://docs.openstack.org/ext/multi-provider/api/v1.0",
"alias": "multi-provider",
"description": "Expose mapping of virtual networks to multiple physical networks"
},
{
"updated": "2013-01-14T10:00:00-00:00",
"name": "Neutron external network",
"links": [],
"namespace": "http://docs.openstack.org/ext/neutron/external_net/api/v1.0",
"alias": "external-net",
"description": "Adds external network attribute to network resource."
},
{
"updated": "2012-07-20T10:00:00-00:00",
"name": "Neutron L3 Router",
"links": [],
"namespace": "http://docs.openstack.org/ext/neutron/router/api/v1.0",
"alias": "router",
"description": "Router abstraction for basic L3 forwarding between L2 Neutron networks and access to external networks via a NAT gateway."
},
{
"updated": "2013-07-23T10:00:00-00:00",
"name": "Allowed Address Pairs",
"links": [],
"namespace": "http://docs.openstack.org/ext/allowedaddresspairs/api/v2.0",
"alias": "allowed-address-pairs",
"description": "Provides allowed address pairs"
},
{
"updated": "2013-03-17T12:00:00-00:00",
"name": "Neutron Extra DHCP opts",
"links": [],
"namespace": "http://docs.openstack.org/ext/neutron/extra_dhcp_opt/api/v1.0",
"alias": "extra_dhcp_opt",
"description": "Extra options configuration for DHCP. For example PXE boot options to DHCP clients can be specified (e.g. tftp-server, server-ip-address, bootfile-name)"
},
{
"updated": "2012-10-07T10:00:00-00:00",
"name": "LoadBalancing service",
"links": [],
"namespace": "http://wiki.openstack.org/neutron/LBaaS/API_1.0",
"alias": "lbaas",
"description": "Extension for LoadBalancing service"
},
{
"updated": "2013-02-01T10:00:00-00:00",
"name": "Neutron Extra Route",
"links": [],
"namespace": "http://docs.openstack.org/ext/neutron/extraroutes/api/v1.0",
"alias": "extraroute",
"description": "Extra routes configuration for L3 router"
}
]
}