Addressed some of the offline comments made by Adrian

This commit is contained in:
andreisavu 2011-11-16 14:40:32 +02:00
parent dc5c04951b
commit f4c1e5b882
3 changed files with 15 additions and 17 deletions

View File

@ -21,14 +21,15 @@ package org.jclouds.cloudstack.suppliers;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.cloudstack.CloudStackClient; import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.domain.User; import org.jclouds.cloudstack.domain.User;
import org.jclouds.cloudstack.predicates.UserPredicates; import org.jclouds.cloudstack.predicates.UserPredicates;
import org.jclouds.logging.Logger;
import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.annotations.Identity;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -40,6 +41,10 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class GetCurrentUser implements Supplier<User> { public class GetCurrentUser implements Supplier<User> {
@Resource
protected Logger logger = Logger.NULL;
private final CloudStackClient client; private final CloudStackClient client;
private final String identity; private final String identity;
@ -62,11 +67,7 @@ public class GetCurrentUser implements Supplier<User> {
} }
if (currentUser.getAccountType() != Account.Type.USER) { if (currentUser.getAccountType() != Account.Type.USER) {
Logger.getAnonymousLogger().warning("You are using an administrative account to start a machine"); logger.warn("Expecting an user account: {}", currentUser);
/* 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; return currentUser;
} }

View File

@ -33,7 +33,6 @@ import java.util.logging.Logger;
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions; import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkType;
import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.cloudstack.features.BaseCloudStackClientLiveTest; import org.jclouds.cloudstack.features.BaseCloudStackClientLiveTest;
import org.jclouds.cloudstack.options.ListNetworksOptions; import org.jclouds.cloudstack.options.ListNetworksOptions;
@ -54,7 +53,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
provider = "cloudstack"; provider = "cloudstack";
} }
protected void deleteNetworkByVLAN(String vlan, long zoneId) throws URISyntaxException { protected void deleteNetworksInZoneWithVlanId(long zoneId, String vlanId) {
Set<Network> networks = domainAdminContext.getApi().getNetworkClient().listNetworks( Set<Network> networks = domainAdminContext.getApi().getNetworkClient().listNetworks(
ListNetworksOptions.Builder ListNetworksOptions.Builder
.isDefault(false) .isDefault(false)
@ -64,7 +63,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
); );
// Warning: the vlan id is not set in the response - using an workaround // Warning: the vlan id is not set in the response - using an workaround
URI broadcastUri = new URI("vlan://" + vlan); URI broadcastUri = URI.create("vlan://" + vlanId);
for(Network net : networks) { for(Network net : networks) {
if (broadcastUri.equals(net.getBroadcastURI())) { if (broadcastUri.equals(net.getBroadcastURI())) {
long jobId = domainAdminContext.getApi().getNetworkClient().deleteNetwork(net.getId()); long jobId = domainAdminContext.getApi().getNetworkClient().deleteNetwork(net.getId());
@ -74,13 +73,14 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
} }
@Test @Test
public void testAndExperiment() throws URISyntaxException { public void testAndExperiment() {
if (!domainAdminEnabled) { if (!domainAdminEnabled) {
Logger.getAnonymousLogger().log(Level.SEVERE, "domainAdmin credentials not present, skipping test"); Logger.getAnonymousLogger().log(Level.SEVERE, "domainAdmin credentials not present, skipping test");
return; return;
} }
String group = prefix + "-vlan"; String group = prefix + "-vlan";
String vlanId = "2";
Network network = null; Network network = null;
Set<? extends NodeMetadata> nodes = null; Set<? extends NodeMetadata> nodes = null;
try { try {
@ -92,7 +92,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
long zoneId = Long.parseLong(template.getLocation().getId()); long zoneId = Long.parseLong(template.getLocation().getId());
// cleanup before running the test // cleanup before running the test
deleteNetworkByVLAN("2", zoneId); deleteNetworksInZoneWithVlanId(zoneId, vlanId);
// find a network offering that supports vlans in our zone // find a network offering that supports vlans in our zone
long offeringId = get( long offeringId = get(
@ -103,7 +103,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
.getNetworkClient() .getNetworkClient()
// startIP/endIP/netmask/gateway must be specified together // startIP/endIP/netmask/gateway must be specified together
.createNetworkInZone(zoneId, offeringId, group, group, .createNetworkInZone(zoneId, offeringId, group, group,
vlan("2").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1")); vlan(vlanId).startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
// set options to specify this network id // set options to specify this network id
template.getOptions().as(CloudStackTemplateOptions.class).networkId(network.getId()); template.getOptions().as(CloudStackTemplateOptions.class).networkId(network.getId());

View File

@ -216,11 +216,8 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
} }
if (currentUser.getAccountType() != type) { if (currentUser.getAccountType() != type) {
Logger.getAnonymousLogger().warning("You are using an administrative account for testing"); Logger.getAnonymousLogger().warning(
/* throw new IllegalArgumentException(String.format( String.format("Expecting an user with type %s. Got: %s", type.toString(), currentUser.toString()));
"invalid account type: %s, please specify an apiKey of %s, for example: %s",
currentUser.getAccountType(), type, Iterables.filter(users, UserPredicates.accountTypeEquals(type))));
*/
} }
return currentUser; return currentUser;
} }