diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/suppliers/GetCurrentUser.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/suppliers/GetCurrentUser.java index b05efafa3a..0eb9af3592 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/suppliers/GetCurrentUser.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/suppliers/GetCurrentUser.java @@ -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 { 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; } } \ No newline at end of file diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java index b41bf6f9ce..f2074adff0 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java @@ -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 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())); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java index bc34626651..7ab180a198 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java @@ -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 context; protected CloudStackClient client; + protected CloudStackClient adminClient; protected User user; protected Predicate socketTester; protected RetryablePredicate jobComplete; + protected RetryablePredicate adminJobComplete; protected RetryablePredicate virtualMachineRunning; protected RetryablePredicate 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(new JobComplete(client), 1200, 1, 5, TimeUnit.SECONDS); injector.injectMembers(jobComplete); + adminJobComplete = new RetryablePredicate(new JobComplete(adminClient), 1200, 1, 5, TimeUnit.SECONDS); + injector.injectMembers(adminJobComplete); virtualMachineRunning = new RetryablePredicate(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; }