implemented optional extension lookup per region

This commit is contained in:
Adrian Cole 2012-03-16 02:33:09 -07:00
parent 3d0d0c6094
commit a845331eba
11 changed files with 244 additions and 59 deletions

View File

@ -94,13 +94,13 @@ public interface NovaAsyncClient {
* Provides asynchronous access to Security Group features.
*/
@Delegate
Optional<SecurityGroupAsyncClient> getSecurityGroupClientForRegion(
Optional<SecurityGroupAsyncClient> getSecurityGroupExtensionForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**
* Provides asynchronous access to Key Pair features.
*/
@Delegate
Optional<KeyPairAsyncClient> getKeyPairClientForRegion(
Optional<KeyPairAsyncClient> getKeyPairExtensionForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
}

View File

@ -96,14 +96,14 @@ public interface NovaClient {
* Provides synchronous access to Security Group features.
*/
@Delegate
SecurityGroupClient getSecurityGroupClientForRegion(
Optional<SecurityGroupClient> getSecurityGroupExtensionForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**
* Provides synchronous access to Key Pair features.
*/
@Delegate
KeyPairClient getKeyPairClientForRegion(
Optional<KeyPairClient> getKeyPairExtensionForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
}

View File

@ -18,7 +18,14 @@
*/
package org.jclouds.openstack.nova.v1_1.config;
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
@ -28,6 +35,7 @@ import org.jclouds.http.annotation.ServerError;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.domain.Extension;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairAsyncClient;
@ -42,11 +50,17 @@ import org.jclouds.openstack.nova.v1_1.features.ImageAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ImageClient;
import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ServerClient;
import org.jclouds.openstack.nova.v1_1.functions.PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet;
import org.jclouds.openstack.nova.v1_1.handlers.NovaErrorHandler;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.functions.ImplicitOptionalConverter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
/**
* Configures the Nova connection.
@ -57,13 +71,9 @@ import com.google.common.collect.ImmutableMap;
@ConfiguresRestClient
public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap
.<Class<?>, Class<?>> builder()
//
.put(ServerClient.class, ServerAsyncClient.class)
//
.put(FlavorClient.class, FlavorAsyncClient.class).put(ImageClient.class, ImageAsyncClient.class)
.put(ExtensionClient.class, ExtensionAsyncClient.class)
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(ServerClient.class, ServerAsyncClient.class).put(FlavorClient.class, FlavorAsyncClient.class)
.put(ImageClient.class, ImageAsyncClient.class).put(ExtensionClient.class, ExtensionAsyncClient.class)
.put(FloatingIPClient.class, FloatingIPAsyncClient.class)
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)
.put(KeyPairClient.class, KeyPairAsyncClient.class).build();
@ -75,6 +85,10 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
@Override
protected void configure() {
install(new NovaParserModule());
// ExtensionClient is used directly for determining which are installed
bindClientAndAsyncClient(binder(), ExtensionClient.class, ExtensionAsyncClient.class);
bind(ImplicitOptionalConverter.class).to(
PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
super.configure();
}
@ -89,6 +103,20 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
install(new KeystoneAuthenticationModule());
}
@Provides
@Singleton
public LoadingCache<String, Set<Extension>> provideExtensionsByRegion(final Provider<NovaClient> novaClient) {
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS)
.build(new CacheLoader<String, Set<Extension>>() {
@Override
public Set<Extension> load(String key) throws Exception {
return novaClient.get().getExtensionClientForRegion(key).listExtensions();
}
});
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(NovaErrorHandler.class);

View File

@ -0,0 +1,76 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.nova.v1_1.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.internal.ClassMethodArgsAndReturnVal;
import org.jclouds.openstack.nova.v1_1.domain.Extension;
import org.jclouds.openstack.nova.v1_1.predicates.ExtensionPredicates;
import org.jclouds.rest.functions.ImplicitOptionalConverter;
import com.google.common.base.Optional;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Iterables;
/**
* We use the annotation {@link org.jclouds.openstack.services.Extension} to
* bind a class that is an extension to an extension found in the
* {@link ExtensionsClient#listExtensions} call.
*
* @author Adrian Cole
*
*/
@Singleton
public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet implements
ImplicitOptionalConverter {
private final LoadingCache<String, Set<Extension>> extensions;
@Inject
public PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet(
LoadingCache<String, Set<Extension>> extensions) {
this.extensions = checkNotNull(extensions, "extensions");
}
@Override
public Optional<Object> apply(ClassMethodArgsAndReturnVal input) {
Optional<org.jclouds.openstack.services.Extension> ext = Optional.fromNullable(input.getClazz().getAnnotation(
org.jclouds.openstack.services.Extension.class));
if (ext.isPresent()) {
checkState(input.getArgs() != null && input.getArgs().length == 1, "expecting an arg %s", input);
URI namespace = URI.create(ext.get().namespace());
if (Iterables.any(extensions.getUnchecked(checkNotNull(input.getArgs()[0], "arg[0] in %s", input).toString()),
ExtensionPredicates.namespaceEquals(namespace)))
return Optional.of(input.getReturnVal());
}
return Optional.absent();
}
public String toString() {
return "presentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet()";
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
@ -43,6 +44,28 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit", testName = "FloatingIPAsyncClientExpectTest")
public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTest {
public void testWhenNamespaceInExtensionsListFloatingIpPresent() throws Exception {
NovaAsyncClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse);
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
assertTrue(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
}
public void testWhenNamespaceNotInExtensionsListFloatingIpNotPresent() throws Exception {
NovaAsyncClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse);
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
assertFalse(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
}
public void testListFloatingIPsWhenResponseIs2xx() throws Exception {
HttpRequest listFloatingIPs = HttpRequest
.builder()
@ -56,7 +79,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
.payload(payloadFromResource("/floatingip_list.json")).build();
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), ImmutableSet.of("North"));
@ -76,7 +99,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404).build();
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().get()
.isEmpty());
@ -95,7 +118,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1").get()
.toString(), new ParseFloatingIPTest().expected().toString());
@ -113,7 +136,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1").get());
}
@ -132,7 +155,8 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
allocateFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().allocate().get()
.toString(), new ParseFloatingIPTest().expected().toString());
@ -152,7 +176,8 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
allocateFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().allocate().get());
}

View File

@ -19,6 +19,7 @@
package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
@ -42,6 +43,27 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(groups = "unit", testName = "FloatingIPClientExpectTest")
public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
public void testWhenNamespaceInExtensionsListFloatingIpPresent() throws Exception {
NovaClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse);
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
assertTrue(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
}
public void testWhenNamespaceNotInExtensionsListFloatingIpNotPresent() throws Exception {
NovaClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse);
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
assertFalse(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
}
public void testListFloatingIPsWhenResponseIs2xx() throws Exception {
HttpRequest listFloatingIPs = HttpRequest
@ -56,7 +78,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/floatingip_list.json")).build();
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), ImmutableSet.of("North"));
@ -76,7 +98,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404).build();
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().isEmpty());
}
@ -94,7 +116,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1")
.toString(), new ParseFloatingIPTest().expected().toString());
@ -112,7 +134,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1"));
}
@ -131,7 +153,8 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
allocateFloatingIPResponse);
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().allocate().toString(),
new ParseFloatingIPTest().expected().toString());
@ -151,7 +174,8 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
allocateFloatingIPResponse);
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().allocate());
}

View File

@ -55,11 +55,11 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/keypair_list.json")).build();
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listKeyPairs, listKeyPairsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listKeyPairs, listKeyPairsResponse);
assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North"));
assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North").listKeyPairs().toString(),
assertEquals(clientWhenServersExist.getKeyPairExtensionForRegion("North").get().listKeyPairs().toString(),
new ParseKeyPairListTest().expected().toString());
}
@ -75,9 +75,9 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(404).build();
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listKeyPairs, listKeyPairsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listKeyPairs, listKeyPairsResponse);
assertTrue(clientWhenNoServersExist.getKeyPairClientForRegion("North").listKeyPairs().isEmpty());
assertTrue(clientWhenNoServersExist.getKeyPairExtensionForRegion("North").get().listKeyPairs().isEmpty());
}
@ -96,10 +96,10 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/keypair_created.json")).build();
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, createKeyPair, createKeyPairResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createKeyPair, createKeyPairResponse);
assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North").createKeyPair("testkeypair").toString(),
new ParseKeyPairTest().expected().toString());
assertEquals(clientWhenServersExist.getKeyPairExtensionForRegion("North").get().createKeyPair("testkeypair")
.toString(), new ParseKeyPairTest().expected().toString());
}
@ -120,11 +120,12 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/keypair_created.json")).build();
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, createKeyPair, createKeyPairResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createKeyPair, createKeyPairResponse);
assertEquals(
clientWhenServersExist
.getKeyPairClientForRegion("North")
.getKeyPairExtensionForRegion("North")
.get()
.createKeyPairWithPublicKey(
"testkeypair",
"ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n")
@ -143,8 +144,8 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse deleteKeyPairResponse = HttpResponse.builder().statusCode(202).build();
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, deleteKeyPair, deleteKeyPairResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteKeyPair, deleteKeyPairResponse);
assertTrue(clientWhenServersExist.getKeyPairClientForRegion("North").deleteKeyPair("testkeypair"));
assertTrue(clientWhenServersExist.getKeyPairExtensionForRegion("North").get().deleteKeyPair("testkeypair"));
}
}

View File

@ -37,7 +37,7 @@ public class KeyPairClientLiveTest extends BaseNovaClientLiveTest {
public void testListKeyPairs() throws Exception {
for (String regionId : context.getApi().getConfiguredRegions()) {
KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId);
KeyPairClient client = context.getApi().getKeyPairExtensionForRegion(regionId).get();
Set<Map<String, KeyPair>> keyPairsList = client.listKeyPairs();
assertNotNull(keyPairsList);
}
@ -46,7 +46,7 @@ public class KeyPairClientLiveTest extends BaseNovaClientLiveTest {
public void testCreateAndDeleteKeyPair() throws Exception {
final String KEYPAIR_NAME = "testkp";
for (String regionId : context.getApi().getConfiguredRegions()) {
KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId);
KeyPairClient client = context.getApi().getKeyPairExtensionForRegion(regionId).get();
KeyPair keyPair = null;
try {
keyPair = client.createKeyPair(KEYPAIR_NAME);
@ -64,7 +64,7 @@ public class KeyPairClientLiveTest extends BaseNovaClientLiveTest {
final String PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCrrBREFxz3002l1HuXz0+UOdJQ/mOYD5DiJwwB/TOybwIKQJPOxJWA9gBoo4k9dthTKBTaEYbzrll7iZcp59E80S6mNiAr3mUgi+x5Y8uyXeJ2Ws+h6peVyFVUu9epkwpcTd1GVfdcVWsTajwDz9+lxCDhl0RZKDFoT0scTxbj/w== nova@nv-aw2az2-api0002";
for (String regionId : context.getApi().getConfiguredRegions()) {
KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId);
KeyPairClient client = context.getApi().getKeyPairExtensionForRegion(regionId).get();
KeyPair keyPair = null;
try {
keyPair = client.createKeyPairWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY);

View File

@ -58,11 +58,12 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/securitygroup_list.json")).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listSecurityGroups, listSecurityGroupsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listSecurityGroups,
listSecurityGroupsResponse);
assertEquals(clientWhenSecurityGroupsExist.getConfiguredRegions(), ImmutableSet.of("North"));
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North").listSecurityGroups()
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get().listSecurityGroups()
.toString(), new ParseSecurityGroupListTest().expected().toString());
}
@ -78,9 +79,10 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse listListSecurityGroupsResponse = HttpResponse.builder().statusCode(404).build();
NovaClient clientWhenNoSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, listListSecurityGroups, listListSecurityGroupsResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listListSecurityGroups,
listListSecurityGroupsResponse);
assertTrue(clientWhenNoSecurityGroupsExist.getSecurityGroupClientForRegion("North").listSecurityGroups()
assertTrue(clientWhenNoSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get().listSecurityGroups()
.isEmpty());
}
@ -98,10 +100,11 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/securitygroup_details.json")).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getSecurityGroup, getSecurityGroupResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getSecurityGroup,
getSecurityGroupResponse);
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North").getSecurityGroup("0")
.toString(), new ParseSecurityGroupTest().expected().toString());
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
.getSecurityGroup("0").toString(), new ParseSecurityGroupTest().expected().toString());
}
public void testGetSecurityGroupWhenResponseIs404() throws Exception {
@ -116,9 +119,11 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse getSecurityGroupResponse = HttpResponse.builder().statusCode(404).build();
NovaClient clientWhenNoSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, getSecurityGroup, getSecurityGroupResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getSecurityGroup,
getSecurityGroupResponse);
assertNull(clientWhenNoSecurityGroupsExist.getSecurityGroupClientForRegion("North").getSecurityGroup("0"));
assertNull(clientWhenNoSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
.getSecurityGroup("0"));
}
@ -139,10 +144,11 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/securitygroup_created.json")).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, createSecurityGroup, createSecurityGroupResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createSecurityGroup,
createSecurityGroupResponse);
assertEquals(
clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North")
clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
.createSecurityGroup("name", "description").toString(), createSecurityGroupExpected().toString());
}
@ -158,9 +164,10 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse deleteSecurityGroupResponse = HttpResponse.builder().statusCode(202).build();
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, deleteSecurityGroup, deleteSecurityGroupResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteSecurityGroup,
deleteSecurityGroupResponse);
assertTrue(clientWhenServersExist.getSecurityGroupClientForRegion("North").deleteSecurityGroup("160"));
assertTrue(clientWhenServersExist.getSecurityGroupExtensionForRegion("North").get().deleteSecurityGroup("160"));
}
@ -181,11 +188,11 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
.payload(payloadFromResource("/securitygrouprule_created.json")).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, createSecurityGroupRule, createSecurityGroupRuleResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createSecurityGroupRule,
createSecurityGroupRuleResponse);
assertEquals(
clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North")
.createSecurityGroupRule("tcp", "80", "8080", "0.0.0.0/0", "", "161").toString(),
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
.createSecurityGroupRule("tcp", "80", "8080", "0.0.0.0/0", "", "161").toString(),
createSecurityGroupRuleExpected().toString());
}
@ -201,9 +208,11 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
HttpResponse deleteSecurityGroupRuleResponse = HttpResponse.builder().statusCode(202).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
responseWithKeystoneAccess, deleteSecurityGroupRule, deleteSecurityGroupRuleResponse);
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteSecurityGroupRule,
deleteSecurityGroupRuleResponse);
assertTrue(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North").deleteSecurityGroupRule("161"));
assertTrue(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
.deleteSecurityGroupRule("161"));
}

View File

@ -39,7 +39,7 @@ public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest {
public void listSecurityGroups() throws Exception {
for (String regionId : context.getApi().getConfiguredRegions()) {
SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId);
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForRegion(regionId).get();
Set<SecurityGroup> securityGroupsList = client.listSecurityGroups();
assertNotNull(securityGroupsList);
}
@ -47,7 +47,7 @@ public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest {
public void createGetAndDeleteSecurityGroup() throws Exception {
for (String regionId : context.getApi().getConfiguredRegions()) {
SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId);
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForRegion(regionId).get();
SecurityGroup securityGroup = null;
String id;
try {
@ -66,7 +66,7 @@ public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest {
public void createAndDeleteSecurityGroupRule() throws Exception {
for (String regionId : context.getApi().getConfiguredRegions()) {
SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId);
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForRegion(regionId).get();
SecurityGroup securityGroup = null;
try {

View File

@ -18,11 +18,15 @@
*/
package org.jclouds.openstack.nova.v1_1.internal;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture;
import org.jclouds.rest.BaseRestClientExpectTest;
import com.google.common.collect.ImmutableMultimap;
/**
* Base class for writing Nova Expect tests
*
@ -33,6 +37,9 @@ public class BaseNovaExpectTest<T> extends BaseRestClientExpectTest<T> {
protected HttpRequest keystoneAuthWithAccessKeyAndSecretKey;
protected String authToken;
protected HttpResponse responseWithKeystoneAccess;
protected HttpRequest extensionsOfNovaRequest;
protected HttpResponse extensionsOfNovaResponse;
protected HttpResponse unmatchedExtensionsOfNovaResponse;
public BaseNovaExpectTest() {
provider = "openstack-nova";
@ -44,5 +51,20 @@ public class BaseNovaExpectTest<T> extends BaseRestClientExpectTest<T> {
responseWithKeystoneAccess = KeystoneFixture.INSTANCE.responseWithAccess();
// now, createContext arg will need tenant prefix
identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity;
extensionsOfNovaRequest = HttpRequest
.builder()
.method("GET")
// NOTE THIS IS NOVA, NOT KEYSTONE
.endpoint(URI.create("https://compute.north.host/v1.1/3456/extensions"))
.headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()).build();
extensionsOfNovaResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/extension_list_normal.json")).build();
unmatchedExtensionsOfNovaResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/extension_list.json")).build();
}
}