fixed means by which tests get login credentials

This commit is contained in:
Adrian Cole 2011-12-21 22:10:25 -08:00
parent 6a1f9e3fbe
commit d1f4339c84
9 changed files with 60 additions and 46 deletions

View File

@ -54,7 +54,6 @@ import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
@ -162,7 +161,6 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
protected RetryablePredicate<VirtualMachine> virtualMachineDestroyed;
protected RetryablePredicate<VirtualMachine> adminVirtualMachineDestroyed;
protected SshClient.Factory sshFactory;
protected String password = "password";
protected Injector injector;
@ -182,7 +180,7 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
protected void checkSSH(IPSocket socket) {
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(password).build());
SshClient client = sshFactory.create(socket, loginCredentials);
try {
client.connect();
ExecResponse exec = client.exec("echo hello");

View File

@ -61,8 +61,8 @@ public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest {
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
virtualMachineRunning);
if (vm.getPassword() != null)
password = vm.getPassword();
if (vm.getPassword() != null && !loginCredentials.hasPasswordOption())
loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build();
} catch (NoSuchElementException e) {
networksDisabled = true;
}

View File

@ -18,14 +18,14 @@
*/
package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.domain.Zone;
import org.jclouds.cloudstack.options.ListISOsOptions;
import org.testng.annotations.Test;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import java.util.Set;
import static org.testng.Assert.*;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.options.ListISOsOptions;
import org.testng.annotations.Test;
/**
* Tests behavior of {@link ISOClient} and {@link ISOAsyncClient}

View File

@ -28,7 +28,6 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Predicates;
import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.JobResult;
import org.jclouds.cloudstack.domain.LoadBalancerRule;
@ -47,6 +46,7 @@ import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
/**
* Tests behavior of {@code LoadBalancerClientLiveTest}
@ -70,7 +70,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
TimeUnit.SECONDS);
prefix += "rule";
try {
network = find(client.getNetworkClient().listNetworks(), Predicates.and(NetworkPredicates.hasLoadBalancerService(), NetworkPredicates.isVirtualNetwork()));
network = find(client.getNetworkClient().listNetworks(),
Predicates.and(NetworkPredicates.hasLoadBalancerService(), NetworkPredicates.isVirtualNetwork()));
} catch (NoSuchElementException e) {
networksDisabled = true;
}
@ -83,8 +84,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
virtualMachineRunning);
if (vm.getPassword() != null)
password = vm.getPassword();
if (vm.getPassword() != null && !loginCredentials.hasPasswordOption())
loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build();
}
@Test(dependsOnMethods = "testCreateVm")
@ -95,8 +96,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
while (rule == null && attempts < 10) {
ip = reuseOrAssociate.apply(network);
try {
Long jobId = client.getLoadBalancerClient().createLoadBalancerRuleForPublicIP(ip.getId(), Algorithm.LEASTCONN,
prefix, 22, 22);
Long jobId = client.getLoadBalancerClient().createLoadBalancerRuleForPublicIP(ip.getId(),
Algorithm.LEASTCONN, prefix, 22, 22);
assertTrue(jobComplete.apply(jobId));
AsyncJob<LoadBalancerRule> asyncJob = client.getAsyncJobClient().getAsyncJob(jobId);
LoadBalancerRule result = asyncJob.getResult();
@ -106,7 +107,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
attempts++;
}
}
assertNotNull(rule, "Failed to get a load balancer rule after "+attempts+" attempts");
assertNotNull(rule, "Failed to get a load balancer rule after " + attempts + " attempts");
assert (rule.getPublicIPId() == ip.getId()) : rule;
assertEquals(rule.getPublicPort(), 22);
assertEquals(rule.getPrivatePort(), 22);
@ -122,12 +123,12 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
public void testAssignToLoadBalancerRule() throws Exception {
if (networksDisabled)
return;
long jobId = client.getLoadBalancerClient().assignVirtualMachinesToLoadBalancerRule(rule.getId(),
vm.getId());
long jobId = client.getLoadBalancerClient().assignVirtualMachinesToLoadBalancerRule(rule.getId(), vm.getId());
assertTrue(jobComplete.apply(jobId));
AsyncJob<JobResult> result = client.getAsyncJobClient().getAsyncJob(jobId);
assertTrue(result.hasSucceed());
Set<VirtualMachine> machines = client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId());
Set<VirtualMachine> machines = client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule(
rule.getId());
assertEquals(machines.size(), 1);
assertTrue(loadBalancerRuleActive.apply(rule), rule.toString());
}

View File

@ -174,8 +174,8 @@ public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest {
vm = VirtualMachineClientLiveTest.createVirtualMachineWithSecurityGroupInZone(zone.getId(),
defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), group.getId(), client,
jobComplete, virtualMachineRunning);
if (vm.getPassword() != null)
password = vm.getPassword();
if (vm.getPassword() != null && !loginCredentials.hasPasswordOption())
loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build();
// ingress port 22
checkSSH(new IPSocket(vm.getIPAddress(), 22));
// ingress icmp disabled as this is platform dependent and may actually

View File

@ -278,14 +278,15 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
}
private void conditionallyCheckSSH() {
password = vm.getPassword();
if (vm.getPassword() != null && !loginCredentials.hasPasswordOption())
loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build();
assert HostSpecifier.isValid(vm.getIPAddress());
if (!InetAddresses2.isPrivateIPAddress(vm.getIPAddress())) {
// not sure if the network is public or not, so we have to test
IPSocket socket = new IPSocket(vm.getIPAddress(), 22);
System.err.printf("testing socket %s%n", socket);
System.err.printf("testing ssh %s%n", socket);
this.checkSSH(socket);
checkSSH(socket);
} else {
System.err.printf("skipping ssh %s, as private%n", vm.getIPAddress());
}

View File

@ -37,10 +37,7 @@ import org.jclouds.cloudstack.features.NATClientLiveTest;
import org.jclouds.cloudstack.features.VirtualMachineClientLiveTest;
import org.jclouds.cloudstack.predicates.NetworkPredicates;
import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -72,8 +69,8 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATClientLiveTest
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
virtualMachineRunning);
if (vm.getPassword() != null)
password = vm.getPassword();
if (vm.getPassword() != null && !loginCredentials.hasPasswordOption())
loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build();
} catch (NoSuchElementException e) {
networksDisabled = true;
}
@ -110,16 +107,7 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATClientLiveTest
assertEquals(rule.getProtocol(), "tcp");
checkRule(rule);
IPSocket socket = new IPSocket(ip.getIPAddress(), 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(password).build());
try {
client.connect();
ExecResponse exec = client.exec("echo hello");
assertEquals(exec.getOutput().trim(), "hello");
} finally {
if (client != null)
client.disconnect();
}
checkSSH(socket);
}
@AfterGroups(groups = "live")

View File

@ -18,16 +18,26 @@
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.domain.TemplateFilter;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.bootable;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.hypervisor;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.id;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.isNotReady;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.isPrivate;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.isPublic;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.isReady;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.isoFilter;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.keyword;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.name;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.notBootable;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.zoneId;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.*;
import static org.testng.Assert.assertEquals;
import org.jclouds.cloudstack.domain.ISO;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@link ListISOsOptions}

View File

@ -24,9 +24,14 @@ import static com.google.common.base.Strings.emptyToNull;
import java.util.Properties;
import org.jclouds.Constants;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.domain.LoginCredentials.Builder;
import org.jclouds.rest.RestContextFactory;
import org.testng.annotations.BeforeClass;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
/**
*
* @author Jason King
@ -42,6 +47,7 @@ public abstract class BaseVersionedServiceLiveTest {
protected String imageId;
protected String loginUser;
protected String authenticateSudo;
protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build();
protected Properties setupRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
@ -85,6 +91,16 @@ public abstract class BaseVersionedServiceLiveTest {
imageId = System.getProperty("test." + provider + ".image-id");
loginUser = System.getProperty("test." + provider + ".image.login-user");
authenticateSudo = System.getProperty("test." + provider + ".image.authenticate-sudo");
if (loginUser != null){
Iterable<String> userPass = Splitter.on(':').split(loginUser);
Builder loginCredentialsBuilder = LoginCredentials.builder();
loginCredentialsBuilder.user(Iterables.get(userPass, 0));
if (Iterables.size(userPass) == 2)
loginCredentialsBuilder.password(Iterables.get(userPass, 1));
if (authenticateSudo != null)
loginCredentialsBuilder.authenticateSudo(Boolean.valueOf(authenticateSudo));
loginCredentials = loginCredentialsBuilder.build();
}
}
}