mirror of https://github.com/apache/jclouds.git
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
3b561fc399
|
@ -212,7 +212,7 @@ public class CloudStackComputeServiceContextModule
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
Map<NetworkType, ? extends OptionsConverter> optionsConverters(){
|
||||
public Map<NetworkType, ? extends OptionsConverter> optionsConverters(){
|
||||
return ImmutableMap.of(
|
||||
NetworkType.ADVANCED, new AdvancedNetworkOptionsConverter(),
|
||||
NetworkType.BASIC, new BasicNetworkOptionsConverter());
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.cloudstack.domain.Account;
|
|||
import org.jclouds.cloudstack.domain.AsyncJob;
|
||||
import org.jclouds.cloudstack.domain.AsyncJob.Builder;
|
||||
import org.jclouds.cloudstack.domain.AsyncJobError;
|
||||
import org.jclouds.cloudstack.domain.FirewallRule;
|
||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
||||
import org.jclouds.cloudstack.domain.LoadBalancerRule;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
|
@ -72,6 +73,7 @@ public class ParseTypedAsyncJob implements Function<AsyncJob<Map<String, JsonBal
|
|||
.put("securitygroup", SecurityGroup.class)
|
||||
.put("portforwardingrule", PortForwardingRule.class)
|
||||
.put("ipforwardingrule", IPForwardingRule.class)
|
||||
.put("firewallrule", FirewallRule.class)
|
||||
.put("network", Network.class)
|
||||
.put("ipaddress", PublicIPAddress.class)
|
||||
.put("virtualmachine", VirtualMachine.class)
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.cloudstack.compute;
|
|||
|
||||
import static com.google.common.collect.Iterables.getFirst;
|
||||
import static com.google.inject.name.Names.bindProperties;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.fail;
|
||||
|
@ -33,20 +34,26 @@ import java.util.concurrent.TimeUnit;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule;
|
||||
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRulesByVirtualMachine;
|
||||
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
|
||||
import org.jclouds.cloudstack.compute.strategy.CloudStackComputeServiceAdapter;
|
||||
import org.jclouds.cloudstack.compute.strategy.OptionsConverter;
|
||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.domain.NetworkType;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.features.BaseCloudStackClientLiveTest;
|
||||
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork;
|
||||
import org.jclouds.cloudstack.functions.ZoneIdToZone;
|
||||
import org.jclouds.cloudstack.predicates.JobComplete;
|
||||
import org.jclouds.cloudstack.predicates.TemplatePredicates;
|
||||
import org.jclouds.cloudstack.suppliers.GetCurrentUser;
|
||||
import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser;
|
||||
import org.jclouds.cloudstack.suppliers.ZoneIdToZoneSupplier;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||
import org.jclouds.compute.ComputeTestUtils;
|
||||
|
@ -65,6 +72,7 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -76,6 +84,7 @@ import com.google.inject.Provides;
|
|||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
@Test(groups = "live", singleThreaded = true, testName = "CloudStackComputeServiceAdapterLiveTest")
|
||||
public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
@ -103,6 +112,13 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
|||
bind(new TypeLiteral<Map<String, Credentials>>() {
|
||||
}).toInstance(credentialStore);
|
||||
bind(CloudStackClient.class).toInstance(context.getApi());
|
||||
bind(new TypeLiteral<Map<NetworkType, ? extends OptionsConverter>>() {}).
|
||||
toInstance(new CloudStackComputeServiceContextModule().optionsConverters());
|
||||
bind(Long.class).annotatedWith(Names.named(PROPERTY_SESSION_INTERVAL)).toInstance(60L);
|
||||
bind(new TypeLiteral<CacheLoader<Long, Zone>>() {}).
|
||||
to(ZoneIdToZone.class);
|
||||
bind(new TypeLiteral<Supplier<LoadingCache<Long, Zone>>>() {}).
|
||||
to(ZoneIdToZoneSupplier.class);
|
||||
install(new FactoryModuleBuilder().build(StaticNATVirtualMachineInNetwork.Factory.class));
|
||||
}
|
||||
|
||||
|
@ -127,6 +143,10 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
|||
keyPairName = prefix + "-adapter-test-keypair";
|
||||
try {
|
||||
keyPair = ComputeTestUtils.setupKeyPair();
|
||||
|
||||
client.getSSHKeyPairClient().deleteSSHKeyPair(keyPairName);
|
||||
client.getSSHKeyPairClient().registerSSHKeyPair(keyPairName, keyPair.get("public"));
|
||||
|
||||
} catch (IOException e) {
|
||||
fail("Unable to create keypair", e);
|
||||
}
|
||||
|
|
|
@ -18,22 +18,30 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.domain.NetworkOffering;
|
||||
import org.jclouds.cloudstack.domain.TrafficType;
|
||||
import org.jclouds.cloudstack.domain.VlanIPRange;
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions;
|
||||
import org.jclouds.cloudstack.options.ListNetworksOptions;
|
||||
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
|
||||
import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
|
||||
import org.jclouds.cloudstack.predicates.ZonePredicates;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.getFirst;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.zoneId;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +53,8 @@ import static org.testng.Assert.*;
|
|||
public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
private Network network;
|
||||
private boolean usingExistingNetwork;
|
||||
|
||||
private VlanIPRange range;
|
||||
|
||||
public void testListVlanIPRanges() throws Exception {
|
||||
|
@ -72,10 +82,28 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
}
|
||||
|
||||
public void testCreateVlanIPRange() {
|
||||
Zone zone = Iterables.find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
|
||||
NetworkOffering offering = find(client.getOfferingClient().listNetworkOfferings(), NetworkOfferingPredicates.supportsGuestVirtualNetworks());
|
||||
final Zone zone = Iterables.find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
|
||||
final NetworkOffering offering = find(client.getOfferingClient().listNetworkOfferings(),
|
||||
NetworkOfferingPredicates.supportsGuestVirtualNetworks());
|
||||
|
||||
Set<Network> suitableNetworks = Sets.filter(client.getNetworkClient().listNetworks(
|
||||
zoneId(zone.getId()).isSystem(false).trafficType(TrafficType.GUEST)),
|
||||
new Predicate<Network>() {
|
||||
@Override
|
||||
public boolean apply(Network network) {
|
||||
return network.getNetworkOfferingId() == offering.getId();
|
||||
}
|
||||
});
|
||||
|
||||
network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), "net-"+prefix, "jclouds test "+prefix);
|
||||
if (suitableNetworks.size() > 0) {
|
||||
network = Iterables.get(suitableNetworks, 0);
|
||||
usingExistingNetwork = true;
|
||||
|
||||
} else if (network == null) {
|
||||
network = client.getNetworkClient().createNetworkInZone(zone.getId(),
|
||||
offering.getId(), "net-" + prefix, "jclouds test " + prefix);
|
||||
usingExistingNetwork = false;
|
||||
}
|
||||
|
||||
range = globalAdminClient.getVlanClient().createVlanIPRange("172.19.1.1", "172.19.1.199", CreateVlanIPRangeOptions.Builder
|
||||
.accountInDomain(user.getAccount(), user.getDomainId())
|
||||
|
@ -91,7 +119,7 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
globalAdminClient.getVlanClient().deleteVlanIPRange(range.getId());
|
||||
range = null;
|
||||
}
|
||||
if (network != null) {
|
||||
if (network != null && !usingExistingNetwork) {
|
||||
client.getNetworkClient().deleteNetwork(network.getId());
|
||||
network = null;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import static com.google.common.collect.Iterables.get;
|
|||
import static com.google.common.collect.Iterables.getFirst;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Sets.filter;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.isDefault;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
@ -88,7 +89,7 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
public static VirtualMachine createVirtualMachine(CloudStackClient client, Long defaultTemplate,
|
||||
RetryablePredicate<Long> jobComplete, RetryablePredicate<VirtualMachine> virtualMachineRunning) {
|
||||
Set<Network> networks = client.getNetworkClient().listNetworks();
|
||||
Set<Network> networks = client.getNetworkClient().listNetworks(isDefault(true));
|
||||
if (networks.size() > 0) {
|
||||
Network network = get(networks, 0);
|
||||
return createVirtualMachineInNetwork(network,
|
||||
|
@ -231,9 +232,7 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
@Override
|
||||
public boolean apply(@Nullable Network network) {
|
||||
return network.isDefault() &&
|
||||
network.getGuestIPType() == GuestIPType.VIRTUAL &&
|
||||
network.getNetworkOfferingId() == 6 &&
|
||||
network.getId() == 204;
|
||||
network.getGuestIPType() == GuestIPType.VIRTUAL;
|
||||
}
|
||||
}));
|
||||
logger.info("Required network: " + requiredNetwork);
|
||||
|
|
|
@ -170,7 +170,7 @@ public class ModifyRequest {
|
|||
int indexOfFirstEquals = stringToParse.indexOf('=');
|
||||
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(0, indexOfFirstEquals);
|
||||
String value = indexOfFirstEquals == -1 ? null : stringToParse.substring(indexOfFirstEquals + 1);
|
||||
map.put(key, Strings2.urlDecode(value));
|
||||
map.put(Strings2.urlDecode(key), Strings2.urlDecode(value));
|
||||
}
|
||||
|
||||
public static String makeQueryLine(Multimap<String, String> params,
|
||||
|
|
|
@ -147,4 +147,12 @@ public class ModifyRequestTest {
|
|||
assertEquals(parsedMap.get("publickey"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseQueryWithKeysThatRequireDecoding() {
|
||||
Multimap<String, String> parsedMap = parseQueryToMap("network%5B0%5D.id=23&network%5B0%5D.address=192.168.0.1");
|
||||
|
||||
assertEquals(parsedMap.get("network[0].id"), ImmutableSet.of("23"));
|
||||
assertEquals(parsedMap.get("network[0].address"), ImmutableSet.of("192.168.0.1"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue