Improved the experimental test to be able to cleanup existing networks

This commit is contained in:
andreisavu 2011-11-16 11:37:27 +02:00
parent 85a0cdfa9c
commit dc5c04951b
3 changed files with 49 additions and 5 deletions

View File

@ -21,6 +21,7 @@ package org.jclouds.cloudstack.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.NoSuchElementException;
import java.util.logging.Logger;
import javax.inject.Inject;
@ -60,10 +61,13 @@ public class GetCurrentUser implements Supplier<User> {
users));
}
if (currentUser.getAccountType() != Account.Type.USER)
throw new IllegalArgumentException(String.format(
if (currentUser.getAccountType() != Account.Type.USER) {
Logger.getAnonymousLogger().warning("You are using an administrative account to start a machine");
/* throw new IllegalArgumentException(String.format(
"invalid account type: %s, please specify an apiKey of a USER, for example: %s",
currentUser.getAccountType(), Iterables.filter(users, UserPredicates.isUserAccount())));
*/
}
return currentUser;
}
}

View File

@ -19,18 +19,24 @@
package org.jclouds.cloudstack.compute;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Sets.newTreeSet;
import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.vlan;
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.specifyVLAN;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkType;
import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.cloudstack.features.BaseCloudStackClientLiveTest;
import org.jclouds.cloudstack.options.ListNetworksOptions;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
@ -43,12 +49,32 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live", testName = "CloudStackExperimentLiveTest")
public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
public CloudStackExperimentLiveTest() {
provider = "cloudstack";
}
protected void deleteNetworkByVLAN(String vlan, long zoneId) throws URISyntaxException {
Set<Network> networks = domainAdminContext.getApi().getNetworkClient().listNetworks(
ListNetworksOptions.Builder
.isDefault(false)
.isSystem(false)
.zoneId(zoneId)
.trafficType(TrafficType.GUEST)
);
// Warning: the vlan id is not set in the response - using an workaround
URI broadcastUri = new URI("vlan://" + vlan);
for(Network net : networks) {
if (broadcastUri.equals(net.getBroadcastURI())) {
long jobId = domainAdminContext.getApi().getNetworkClient().deleteNetwork(net.getId());
adminJobComplete.apply(jobId);
}
}
}
@Test
public void testAndExperiment() {
public void testAndExperiment() throws URISyntaxException {
if (!domainAdminEnabled) {
Logger.getAnonymousLogger().log(Level.SEVERE, "domainAdmin credentials not present, skipping test");
return;
@ -65,6 +91,9 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
// get the zone we are launching into
long zoneId = Long.parseLong(template.getLocation().getId());
// cleanup before running the test
deleteNetworkByVLAN("2", zoneId);
// find a network offering that supports vlans in our zone
long offeringId = get(
context.getApi().getOfferingClient().listNetworkOfferings(specifyVLAN(true).zoneId(zoneId)), 0).getId();
@ -82,6 +111,8 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
// launch the VM
nodes = computeContext.getComputeService().createNodesInGroup(group, 1, template);
assert nodes.size() > 0;
} catch (RunNodesException e) {
Logger.getAnonymousLogger().log(Level.SEVERE, "error creating nodes", e);
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));

View File

@ -27,6 +27,7 @@ import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.jclouds.cloudstack.CloudStackAsyncClient;
import org.jclouds.cloudstack.CloudStackClient;
@ -128,10 +129,12 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
protected ComputeServiceContext computeContext;
protected RestContext<CloudStackClient, CloudStackAsyncClient> context;
protected CloudStackClient client;
protected CloudStackClient adminClient;
protected User user;
protected Predicate<IPSocket> socketTester;
protected RetryablePredicate<Long> jobComplete;
protected RetryablePredicate<Long> adminJobComplete;
protected RetryablePredicate<VirtualMachine> virtualMachineRunning;
protected RetryablePredicate<VirtualMachine> virtualMachineDestroyed;
protected SshClient.Factory sshFactory;
@ -179,6 +182,7 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
domainAdminContext = domainAdminComputeContext.getProviderSpecificContext();
domainAdminClient = domainAdminContext.getApi();
domainAdminUser = verifyCurrentUserIsOfType(domainAdminContext, Account.Type.DOMAIN_ADMIN);
adminClient = domainAdminContext.getApi();
}
injector = Guice.createInjector(new SshjSshClientModule(), new Log4JLoggingModule());
@ -187,6 +191,8 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
injector.injectMembers(socketTester);
jobComplete = new RetryablePredicate<Long>(new JobComplete(client), 1200, 1, 5, TimeUnit.SECONDS);
injector.injectMembers(jobComplete);
adminJobComplete = new RetryablePredicate<Long>(new JobComplete(adminClient), 1200, 1, 5, TimeUnit.SECONDS);
injector.injectMembers(adminJobComplete);
virtualMachineRunning = new RetryablePredicate<VirtualMachine>(new VirtualMachineRunning(client), 600, 5, 5,
TimeUnit.SECONDS);
injector.injectMembers(virtualMachineRunning);
@ -209,10 +215,13 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
users));
}
if (currentUser.getAccountType() != type)
throw new IllegalArgumentException(String.format(
if (currentUser.getAccountType() != type) {
Logger.getAnonymousLogger().warning("You are using an administrative account for testing");
/* throw new IllegalArgumentException(String.format(
"invalid account type: %s, please specify an apiKey of %s, for example: %s",
currentUser.getAccountType(), type, Iterables.filter(users, UserPredicates.accountTypeEquals(type))));
*/
}
return currentUser;
}