From d1f4339c84ce4aa8f1bc4ad77a232c74d9e7bbf2 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 21 Dec 2011 22:10:25 -0800 Subject: [PATCH] fixed means by which tests get login credentials --- .../BaseCloudStackClientLiveTest.java | 4 +--- .../features/FirewallClientLiveTest.java | 4 ++-- .../features/ISOClientLiveTest.java | 10 ++++---- .../features/LoadBalancerClientLiveTest.java | 21 ++++++++-------- .../features/SecurityGroupClientLiveTest.java | 4 ++-- .../VirtualMachineClientLiveTest.java | 5 ++-- ...ticNATVirtualMachineInNetworkLiveTest.java | 18 +++----------- .../options/ListISOsOptionsTest.java | 24 +++++++++++++------ .../compute/BaseVersionedServiceLiveTest.java | 16 +++++++++++++ 9 files changed, 60 insertions(+), 46 deletions(-) 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 8637545271..f46a1923eb 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 @@ -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 virtualMachineDestroyed; protected RetryablePredicate 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"); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java index c1702a1b58..4ea03459df 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java @@ -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; } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOClientLiveTest.java index 2842f2ddef..2b3559e8cd 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOClientLiveTest.java @@ -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} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java index e9298e2f65..01931d7910 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java @@ -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 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 result = client.getAsyncJobClient().getAsyncJob(jobId); assertTrue(result.hasSucceed()); - Set machines = client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId()); + Set machines = client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule( + rule.getId()); assertEquals(machines.size(), 1); assertTrue(loadBalancerRuleActive.apply(rule), rule.toString()); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java index 563d614211..3f355d25d1 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java @@ -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 diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java index 95e14b3e4e..7558d13b3c 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java @@ -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()); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java index 00970fa02c..592b937de3 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java @@ -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") diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java index 530052749b..519cd0c06d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java @@ -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} diff --git a/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java index 309cc2bd4d..a01c05394c 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseVersionedServiceLiveTest.java @@ -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 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(); + } } }