From 5413e12fcce7539eae39d09e2375c497976747e7 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 19 Aug 2010 01:43:26 -0700 Subject: [PATCH] Issue 296 make terremark ecloud and vcloudexpress work from mvn -Plive install --- .../test/resources/ec2/describe_images_cc.xml | 31 ++++++ .../compute/BaseComputeServiceLiveTest.java | 25 +++-- .../CloudServersComputeServiceLiveTest.java | 2 - .../functions/VCloudGetNodeMetadata.java | 7 +- .../compute/VCloudComputeServiceLiveTest.java | 2 - vcloud/terremark/pom.xml | 78 +++++++++++++- ...markVCloudComputeServiceContextModule.java | 2 +- .../functions/CreateUniqueKeyPair.java | 6 +- .../compute/strategy/DeleteKeyPair.java | 5 +- ...eTerremarkVCloudErrorFromHttpResponse.java | 40 ++++--- .../terremark/InternetServiceLiveTest.java | 20 ++-- .../terremark/TerremarkClientLiveTest.java | 40 ++++--- .../TerremarkECloudClientLiveTest.java | 7 ++ ...TerremarkVCloudExpressClientLiveTest.java} | 10 +- ...TerremarkECloudComputeServiceLiveTest.java | 100 ++++++++++++++++++ ...kVCloudExpressComputeServiceLiveTest.java} | 16 +-- .../compute/strategy/DeleteKeyPairTest.java | 2 +- .../VAppTemplatesInOrgsLiveTest.java | 12 +-- ...remarkVCloudErrorFromHttpResponseTest.java | 50 +++++---- 19 files changed, 325 insertions(+), 130 deletions(-) create mode 100644 aws/core/src/test/resources/ec2/describe_images_cc.xml rename vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/{TerremarkVCloudClientLiveTest.java => TerremarkVCloudExpressClientLiveTest.java} (88%) create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java rename vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/{TerremarkVCloudComputeServiceLiveTest.java => TerremarkVCloudExpressComputeServiceLiveTest.java} (88%) diff --git a/aws/core/src/test/resources/ec2/describe_images_cc.xml b/aws/core/src/test/resources/ec2/describe_images_cc.xml new file mode 100644 index 0000000000..3484748352 --- /dev/null +++ b/aws/core/src/test/resources/ec2/describe_images_cc.xml @@ -0,0 +1,31 @@ + + + 31e35e56-dd3e-43d3-9c3b-656cb202d6e7 + + + ami-7ea24a17 + amazon/EC2 CentOS 5.4 HVM AMI + available + 206029621532 + true + x86_64 + machine + amazon + EC2 CentOS 5.4 HVM AMI + EC2 CentOS 5.4 HVM AMI + ebs + /dev/sda1 + + + /dev/sda1 + + snap-1099e578 + 20 + true + + + + hvm + + + diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 6b72297bf1..4500537cae 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -75,7 +75,6 @@ import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; import org.jclouds.util.Utils; import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -121,7 +120,6 @@ public abstract class BaseComputeServiceLiveTest { .append("sudo zypper install java-1.6.0-openjdk-devl\n")// .toString(); - @BeforeClass abstract public void setServiceDefaults(); protected String provider; @@ -139,6 +137,7 @@ public abstract class BaseComputeServiceLiveTest { @BeforeGroups(groups = { "integration", "live" }) public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { + setServiceDefaults(); if (tag == null) tag = checkNotNull(provider, "provider"); setupCredentials(); @@ -272,11 +271,7 @@ public abstract class BaseComputeServiceLiveTest { } catch (NoSuchElementException e) { } - template = buildTemplate(client.templateBuilder()); - - template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( - newStringPayload(keyPair.get("public"))).runScript( - newStringPayload(buildScript(template.getImage().getOperatingSystem()))); + refreshTemplate(); try { nodes = newTreeSet(client.runNodesWithTag(tag, 2, template)); } catch (RunNodesException e) { @@ -298,6 +293,14 @@ public abstract class BaseComputeServiceLiveTest { checkOsMatchesTemplate(node2); } + private void refreshTemplate() { + template = buildTemplate(client.templateBuilder()); + + template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( + newStringPayload(keyPair.get("public"))).runScript( + newStringPayload(buildScript(template.getImage().getOperatingSystem()))); + } + protected void checkImageIdMatchesTemplate(NodeMetadata node) { if (node.getImageId() != null) assertEquals(node.getImageId(), template.getImage().getId()); @@ -319,13 +322,14 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript") public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { initializeContextAndClient(); + refreshTemplate(); TreeSet nodes = newTreeSet(client.runNodesWithTag(tag, 1, template)); checkNodes(nodes, tag); NodeMetadata node = nodes.first(); this.nodes.add(node); assertEquals(nodes.size(), 1); assertLocationSameOrChild(node.getLocation(), template.getLocation()); - assertEquals(node.getOperatingSystem().getFamily(), template.getImage().getOperatingSystem().getFamily()); + checkOsMatchesTemplate(node); } protected Map runScriptWithCreds(final String tag, OperatingSystem os, @@ -334,11 +338,6 @@ public abstract class BaseComputeServiceLiveTest { return client.runScriptOnNodesMatching(runningWithTag(tag), newStringPayload(buildScript(os)), overrideCredentialsWith(creds)); } catch (SshException e) { - if (getRootCause(e).getMessage().contains("Auth fail")) { - // System.err.printf("bad credentials: %s:%s for %s%n", - // creds.identity, creds.key, client - // .listNodesDetailsMatching(tag)); - } throw e; } } diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java index a689605c0c..aa5d3ec3ee 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -33,7 +33,6 @@ import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient; import org.jclouds.rackspace.cloudservers.CloudServersClient; import org.jclouds.rest.RestContext; import org.jclouds.ssh.jsch.config.JschSshClientModule; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -45,7 +44,6 @@ import org.testng.annotations.Test; @Test(groups = "live", enabled = true, sequential = true, testName = "cloudservers.CloudServersComputeServiceLiveTest") public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTest { - @BeforeClass @Override public void setServiceDefaults() { provider = "cloudservers"; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java index 65a6df7e3f..131698ec59 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java @@ -87,9 +87,10 @@ public class VCloudGetNodeMetadata { String tag = parseTagFromName(from.getName()); Location location = findLocationForResourceInVDC.apply(from.getVDC()); return new NodeMetadataImpl(in, from.getName(), in, location, from.getId(), ImmutableMap. of(), - tag, null, new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(from.getOsType()), null, null, - from.getOperatingSystemDescription()), vAppStatusToNodeState.get(from.getStatus()), - computeClient.getPublicAddresses(id), computeClient.getPrivateAddresses(id), getExtra.apply(from), null); + tag, null, from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(from + .getOsType()), null, null, from.getOperatingSystemDescription()) : null, vAppStatusToNodeState + .get(from.getStatus()), computeClient.getPublicAddresses(id), computeClient + .getPrivateAddresses(id), getExtra.apply(from), null); } } \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java index 7ca465c903..3aaa7c0482 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java @@ -31,7 +31,6 @@ import org.jclouds.rest.RestContext; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -42,7 +41,6 @@ import org.testng.annotations.Test; @Test(groups = "live", enabled = true, sequential = true, testName = "vcloud.VCloudComputeServiceLiveTest") public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { - @BeforeClass @Override public void setServiceDefaults() { System.setProperty("vcloud.endpoint", checkNotNull(System.getProperty("jclouds.test.endpoint"), diff --git a/vcloud/terremark/pom.xml b/vcloud/terremark/pom.xml index 5dcf4aeefb..17783c4c13 100644 --- a/vcloud/terremark/pom.xml +++ b/vcloud/terremark/pom.xml @@ -31,10 +31,16 @@ jclouds terremark Components Core jclouds Core components to access terremark - - ${jclouds.terremark.user} - ${jclouds.terremark.password} - ${jclouds.terremark.password} + + trmkrun-ccc,trmk-924 + https://services.vcloudexpress.terremark.com/api + 0.8a-ext1.6 + FIXME + FIXME + https://services.enterprisecloud.terremark.com/api + 0.8b-ext2.3 + FIXME + FIXME @@ -58,4 +64,68 @@ + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + + trmk-vcloudexpress.endpoint + ${trmk-vcloudexpress.endpoint} + + + trmk-vcloudexpress.apiversion + ${trmk-vcloudexpress.apiversion} + + + trmk-vcloudexpress.identity + ${trmk-vcloudexpress.identity} + + + trmk-vcloudexpress.credential + ${trmk-vcloudexpress.credential} + + + trmk-ecloud.endpoint + ${trmk-ecloud.endpoint} + + + trmk-ecloud.apiversion + ${trmk-ecloud.apiversion} + + + trmk-ecloud.identity + ${trmk-ecloud.identity} + + + trmk-ecloud.credential + ${trmk-ecloud.credential} + + + jclouds.compute.blacklist.nodes + ${jclouds.compute.blacklist.nodes} + + + + + + + + + + + + diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java index 8c9348d874..fd29ab55fc 100755 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -82,7 +82,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer return new Supplier() { @Override public String get() { - return random.nextInt(100) + ""; + return random.nextInt(4096) + ""; } }; diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/CreateUniqueKeyPair.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/CreateUniqueKeyPair.java index 9ef89de84b..291f5350e8 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/CreateUniqueKeyPair.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/CreateUniqueKeyPair.java @@ -59,10 +59,10 @@ public class CreateUniqueKeyPair implements Function { @Override public KeyPair apply(OrgAndName from) { - return createNewKeyPairInRegion(from.getOrg(), from.getName()); + return createNewKeyPairInOrg(from.getOrg(), from.getName()); } - private KeyPair createNewKeyPairInRegion(URI org, String keyPairName) { + private KeyPair createNewKeyPairInOrg(URI org, String keyPairName) { checkNotNull(org, "org"); checkNotNull(keyPairName, "keyPairName"); logger.debug(">> creating keyPair org(%s) name(%s)", org, keyPairName); @@ -82,6 +82,6 @@ public class CreateUniqueKeyPair implements Function { } private String getNextName(String keyPairName) { - return "jclouds#" + keyPairName + "-" + randomSuffix.get(); + return "jclouds#" + keyPairName + "#" + randomSuffix.get(); } } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPair.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPair.java index 01b456ed8b..34b28f2c84 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPair.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPair.java @@ -48,14 +48,15 @@ public class DeleteKeyPair { final ConcurrentMap credentialsMap; @Inject - DeleteKeyPair(TerremarkVCloudExpressClient terremarkClient, ConcurrentMap credentialsMap) { + DeleteKeyPair(TerremarkVCloudExpressClient terremarkClient, + ConcurrentMap credentialsMap) { this.terremarkClient = terremarkClient; this.credentialsMap = credentialsMap; } public void execute(OrgAndName orgTag) { for (KeyPair keyPair : terremarkClient.listKeyPairsInOrg(orgTag.getOrg())) { - if (keyPair.getName().matches("jclouds#" + orgTag.getName() + "-[0-9a-f]+")) { + if (keyPair.getName().matches("jclouds#" + orgTag.getName() + "#[0-9a-f]+")) { logger.debug(">> deleting keyPair(%s)", keyPair.getName()); terremarkClient.deleteKeyPair(keyPair.getId()); // TODO: test this clear happens diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java index 44b07aaa1d..c0b452782b 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponse.java @@ -55,16 +55,15 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl try { String content = parseErrorFromContentOrNull(command, response); switch (response.getStatusCode()) { - case 400: - exception = new IllegalArgumentException(response.getMessage(), exception); - break; - case 401: - exception = new AuthorizationException(command.getRequest(), content); - break; - case 403: // TODO temporary as terremark mistakenly uses this for vApp - // not found. - case 404: - if (!command.getRequest().getMethod().equals("DELETE")) { + case 400: + exception = new IllegalArgumentException(response.getMessage(), exception); + break; + case 401: + exception = new AuthorizationException(command.getRequest(), content); + break; + case 403: // TODO temporary as terremark mistakenly uses this for vApp + // not found. + case 404: String path = command.getRequest().getEndpoint().getPath(); Matcher matcher = RESOURCE_PATTERN.matcher(path); String message; @@ -74,17 +73,16 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl message = path; } exception = new ResourceNotFoundException(message, exception); - } - break; - case 500: - if ((response.getMessage().indexOf("because there is a pending task running") != -1) - || (response.getMessage().indexOf("because it is already powered off") != -1) - || (response.getMessage().indexOf("already exists") != -1) - || (response.getMessage().indexOf("same name exists") != -1)) - exception = new IllegalStateException(response.getMessage(), exception); - break; - default: - exception = new HttpResponseException(command, response, content); + break; + case 500: + if ((response.getMessage().indexOf("because there is a pending task running") != -1) + || (response.getMessage().indexOf("because it is already powered off") != -1) + || (response.getMessage().indexOf("already exists") != -1) + || (response.getMessage().indexOf("same name exists") != -1)) + exception = new IllegalStateException(response.getMessage(), exception); + break; + default: + exception = new HttpResponseException(command, response, content); } } finally { releasePayload(response); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java index ce8d9b3857..c458e154c9 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java @@ -22,14 +22,13 @@ package org.jclouds.vcloud.terremark; import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; -import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; @@ -78,8 +77,7 @@ public class InternetServiceLiveTest { @Test public void testGetAllPublicIps() throws Exception { - for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null) - .getId())) { + for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getId())) { tmClient.getInternetServicesOnPublicIp(ip.getId()); } } @@ -91,15 +89,11 @@ public class InternetServiceLiveTest { @BeforeGroups(groups = { "live" }) public void setupClient() { - String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); - String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); + String identity = checkNotNull(System.getProperty("trmk-vcloudexpress.identity"), "trmk-vcloudexpress.identity"); + String credential = checkNotNull(System.getProperty("trmk-vcloudexpress.credential"), "trmk-vcloudexpress.credential"); - String endpoint = System.getProperty("jclouds.test.endpoint"); - Properties props = new Properties(); - if (endpoint != null && !"".equals(endpoint)) - props.setProperty("terremark.endpoint", endpoint); - context = new RestContextFactory().createContext("trmk-vcloudexpress", identity, credential, ImmutableSet - . of(new Log4JLoggingModule(), new JschSshClientModule()), props); + context = new ComputeServiceContextFactory().createContext("trmk-vcloudexpress", identity, credential, ImmutableSet + . of(new Log4JLoggingModule(), new JschSshClientModule())).getProviderSpecificContext(); tmClient = context.getApi(); @@ -108,7 +102,7 @@ public class InternetServiceLiveTest { void print(Set set) { for (InternetService service : set) { System.out.printf("%d (%s:%d%n)", service.getName(), service.getPublicIpAddress().getAddress(), service - .getPort()); + .getPort()); for (Node node : tmClient.getNodes(service.getId())) { System.out.printf(" %d (%s:%d%n)", node.getName(), node.getIpAddress(), node.getPort()); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java index 2408700b12..55d49e2e46 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java @@ -19,7 +19,6 @@ package org.jclouds.vcloud.terremark; -import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.size; @@ -34,7 +33,6 @@ import java.io.IOException; import java.net.URI; import java.util.List; import java.util.NoSuchElementException; -import java.util.Properties; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -103,12 +101,13 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { private RetryablePredicate successTester; private VApp clone; private VDC vdc; + protected String credential; public static final String PREFIX = System.getProperty("user.name") + "-terremark"; @Test public void testGetAllInternetServices() throws Exception { for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null) - .getId())) { + .getId())) { assertNotNull(tmClient.getNodes(service.getId())); } } @@ -144,7 +143,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { @Test(enabled = true) public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException, - IOException { + IOException { prepare(); StringBuffer name = new StringBuffer(); for (int i = 0; i < 15; i++) @@ -168,7 +167,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { // if this template supports setting the root password, let's add it to // our options CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions() - .getId()); + .getId()); if (customizationOptions.canCustomizePassword()) instantiateOptions.withPassword("robotsarefun"); @@ -229,11 +228,11 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { PublicIpAddress ip; if (tmClient instanceof TerremarkVCloudExpressClient) { is = TerremarkVCloudExpressClient.class.cast(tmClient).addInternetServiceToVDC( - tmClient.findVDCInOrgNamed(null, null).getId(), "SSH", Protocol.TCP, 22); + tmClient.findVDCInOrgNamed(null, null).getId(), "SSH", Protocol.TCP, 22); ip = is.getPublicIpAddress(); } else { ip = TerremarkECloudClient.class.cast(tmClient).activatePublicIpInVDC( - tmClient.findVDCInOrgNamed(null, null).getId()); + tmClient.findVDCInOrgNamed(null, null).getId()); is = tmClient.addInternetServiceToExistingIp(ip.getId(), "SSH", Protocol.TCP, 22); } publicIp = ip.getAddress(); @@ -274,7 +273,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { @Test(enabled = true, dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" }) public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException, IOException { node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName() - + "-SSH", 22); + + "-SSH", 22); loopAndCheckPass(); } @@ -337,7 +336,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { vApp = tmClient.getVApp(vApp.getId()); Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1) - .addDisk(25 * 1048576).addDisk(25 * 1048576)); + .addDisk(25 * 1048576).addDisk(25 * 1048576)); assert successTester.apply(task.getLocation()); @@ -355,7 +354,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { // extract the disks on the vApp sorted by addressOnParent List disks = Lists.newArrayList(filter(vApp.getResourceAllocations(), - resourceType(ResourceType.DISK_DRIVE))); + resourceType(ResourceType.DISK_DRIVE))); // delete the second disk task = tmClient.configureVApp(vApp, deleteDiskWithAddressOnParent(disks.get(1).getAddressOnParent())); @@ -367,18 +366,18 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { } private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, int processorCount, - long memory, long hardDisk) { + long memory, long hardDisk) { assertEquals(vApp.getName(), serverName); assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(), - processorCount); + processorCount); assertEquals( - find(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER)).getVirtualQuantity(), 1); + find(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER)).getVirtualQuantity(), 1); assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(), memory); assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity(), - hardDisk); + hardDisk); assertEquals(vApp.getSize().longValue(), find(vApp.getResourceAllocations(), - resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity()); + resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity()); } private void doCheckPass(String address) throws IOException { @@ -431,15 +430,10 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { @BeforeGroups(groups = { "live" }) @Override public void setupClient() { - String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); - String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); + setupCredentials(); - String endpoint = System.getProperty("jclouds.test.endpoint"); - Properties props = new Properties(); - if (endpoint != null && !"".equals(endpoint)) - props.setProperty("terremark.endpoint", endpoint); Injector injector = new RestContextFactory().createContextBuilder(provider, identity, credential, - ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), props).buildInjector(); + ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule())).buildInjector(); connection = tmClient = injector.getInstance(TerremarkVCloudClient.class); @@ -453,4 +447,6 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { successTester = new RetryablePredicate(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS); } + protected abstract void setupCredentials(); + } \ No newline at end of file diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudClientLiveTest.java index 8295706906..febd054011 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudClientLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.terremark; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount; import org.jclouds.net.IPSocket; @@ -45,6 +46,12 @@ public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest { return processorCount(1).memory(512); } + @Override + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("trmk-ecloud.identity"), "trmk-ecloud.identity"); + credential = checkNotNull(System.getProperty("trmk-ecloud.credential"), "trmk-ecloud.credential"); + } + @Override protected SshClient getConnectionFor(IPSocket socket) { return sshFactory.create(socket, "ecloud", "$Ep455l0ud!2"); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressClientLiveTest.java similarity index 88% rename from vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java rename to vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressClientLiveTest.java index fb376a9796..a96ed92429 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressClientLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.terremark; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -41,7 +42,12 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest") -public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest { +public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTest { + @Override + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("trmk-vcloudexpress.identity"), "trmk-vcloudexpress.identity"); + credential = checkNotNull(System.getProperty("trmk-vcloudexpress.credential"), "trmk-vcloudexpress.credential"); + } KeyPair key; @@ -74,7 +80,7 @@ public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest { assertNotNull(key.getFingerPrint()); assertEquals(key.isDefault(), false); assertEquals(key.getFingerPrint(), vCloudExpressClient.findKeyPairInOrg(org.getId(), key.getName()) - .getFingerPrint()); + .getFingerPrint()); } @AfterTest diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java new file mode 100644 index 0000000000..2ec2128ec0 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudComputeServiceLiveTest.java @@ -0,0 +1,100 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.terremark.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.domain.ComputeType; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.rest.RestContext; +import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest; +import org.jclouds.vcloud.terremark.TerremarkECloudAsyncClient; +import org.jclouds.vcloud.terremark.TerremarkECloudClient; +import org.testng.annotations.Test; + +/** + * + * + * @author Adrian Cole + */ +@Test(groups = "live", enabled = true, sequential = true, testName = "terremark.TerremarkVCloudComputeServiceLiveTest") +public class TerremarkECloudComputeServiceLiveTest extends VCloudComputeServiceLiveTest { + + @Override + public void setServiceDefaults() { + provider = "trmk-ecloud"; + } + + @Override + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("trmk-ecloud.identity"), "trmk-ecloud.identity"); + credential = checkNotNull(System.getProperty("trmk-ecloud.credential"), "trmk-ecloud.credential"); + } + + @Test + public void testTemplateBuilder() { + Template defaultTemplate = client.templateBuilder().build(); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); + assertEquals(defaultTemplate.getLocation().getDescription(), "Miami Environment 1"); + assertEquals(defaultTemplate.getSize().getCores(), 1.0d); + } + + public void testAssignability() throws Exception { + @SuppressWarnings("unused") + RestContext tmContext = new ComputeServiceContextFactory() + .createContext(provider, identity, credential).getProviderSpecificContext(); + } + + @Override + protected Template buildTemplate(TemplateBuilder templateBuilder) { + Template template = super.buildTemplate(templateBuilder); + Image image = template.getImage(); + assert image.getDefaultCredentials().identity != null : image; + assert image.getDefaultCredentials().credential != null : image; + return template; + } + + // currently, the wrong CIM OSType data is coming back. + @Override + protected void checkOsMatchesTemplate(NodeMetadata node) { + if (node.getOperatingSystem() != null) + assertEquals(node.getOperatingSystem().getFamily(), OsFamily.UNKNOWN); + } + + @Override + public void testListImages() throws Exception { + for (Image image : client.listImages()) { + assert image.getProviderId() != null : image; + // image.getLocationId() can be null, if it is a location-free image + assertEquals(image.getType(), ComputeType.IMAGE); + assert image.getDefaultCredentials().identity != null : image; + if (image.getOperatingSystem().getFamily() != OsFamily.WINDOWS) + assert image.getDefaultCredentials().credential != null : image; + } + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressComputeServiceLiveTest.java similarity index 88% rename from vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java rename to vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressComputeServiceLiveTest.java index d1c580faf4..9ba882d5be 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressComputeServiceLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.terremark.compute; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import org.jclouds.compute.ComputeServiceContextFactory; @@ -32,7 +33,6 @@ import org.jclouds.rest.RestContext; import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -41,16 +41,18 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", enabled = true, sequential = true, testName = "terremark.TerremarkVCloudComputeServiceLiveTest") -public class TerremarkVCloudComputeServiceLiveTest extends VCloudComputeServiceLiveTest { +public class TerremarkVCloudExpressComputeServiceLiveTest extends VCloudComputeServiceLiveTest { - @BeforeClass @Override public void setServiceDefaults() { - String endpoint = System.getProperty("jclouds.test.endpoint"); - if (endpoint != null && !"".equals(endpoint)) - System.setProperty("terremark.endpoint", endpoint); provider = "trmk-vcloudexpress"; - tag = "trmk"; + tag = "trmk-vcx"; + } + + @Override + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("trmk-vcloudexpress.identity"), "trmk-vcloudexpress.identity"); + credential = checkNotNull(System.getProperty("trmk-vcloudexpress.credential"), "trmk-vcloudexpress.credential"); } @Test diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPairTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPairTest.java index a335d95015..3318de4deb 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPairTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/strategy/DeleteKeyPairTest.java @@ -75,7 +75,7 @@ public class DeleteKeyPairTest { // setup expectations expect(strategy.terremarkClient.listKeyPairsInOrg(orgTag.getOrg())).andReturn(ImmutableSet. of(keyPair)); - expect(keyPair.getName()).andReturn("jclouds#" + orgTag.getName() + "-123").atLeastOnce(); + expect(keyPair.getName()).andReturn("jclouds#" + orgTag.getName() + "#123").atLeastOnce(); expect(keyPair.getId()).andReturn(URI.create("1245")); strategy.terremarkClient.deleteKeyPair(URI.create("1245")); expect(strategy.credentialsMap.remove(orgTag)).andReturn(null); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgsLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgsLiveTest.java index 2e986f9ccd..89f3856ec8 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgsLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgsLiveTest.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; -import java.util.Properties; import java.util.Set; import org.jclouds.compute.domain.Image; @@ -57,15 +56,12 @@ public class VAppTemplatesInOrgsLiveTest { @BeforeGroups(groups = { "live" }) public void setupClient() { - String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); - String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); + String identity = checkNotNull(System.getProperty("trmk-vcloudexpress.identity"), "trmk-vcloudexpress.identity"); + String credential = checkNotNull(System.getProperty("trmk-vcloudexpress.credential"), + "trmk-vcloudexpress.credential"); - String endpoint = System.getProperty("jclouds.test.endpoint"); - Properties props = new Properties(); - if (endpoint != null && !"".equals(endpoint)) - props.setProperty("terremark.endpoint", endpoint); Injector injector = new RestContextFactory().createContextBuilder("trmk-vcloudexpress", identity, credential, - ImmutableSet. of(new Log4JLoggingModule()), props).buildInjector(); + ImmutableSet. of(new Log4JLoggingModule())).buildInjector(); tmClient = injector.getInstance(TerremarkVCloudClient.class); allCatalogItemsInOrganization = injector.getInstance(AllCatalogItemsInOrganization.class); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java index 2e4c0b6c76..907349299e 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/handlers/ParseTerremarkVCloudErrorFromHttpResponseTest.java @@ -23,7 +23,6 @@ import java.net.URI; import org.jclouds.http.BaseHttpErrorHandlerTest; import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.HttpResponseException; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; @@ -36,13 +35,10 @@ import org.testng.annotations.Test; public class ParseTerremarkVCloudErrorFromHttpResponseTest extends BaseHttpErrorHandlerTest { @Test public void testGet400SetsIllegalArgumentException() { - assertCodeMakes( - "GET", - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), - 400, - "HTTP/1.1 400 Service name is required.", - "", IllegalArgumentException.class); + assertCodeMakes("GET", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), 400, + "HTTP/1.1 400 Service name is required.", "", IllegalArgumentException.class); } + @Test public void testGet403SetsResourceNotFoundException() { assertCodeMakes( @@ -54,33 +50,35 @@ public class ParseTerremarkVCloudErrorFromHttpResponseTest extends BaseHttpError } @Test - public void testGet404SetsResourceNotFoundException() { - assertCodeMakes("GET", URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), - 404, "", "", ResourceNotFoundException.class); + public void testDelete403SetsResourceNotFoundException() { + assertCodeMakes( + "DELETE", + URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vapp/361849"), + 403, + "HTTP/1.1 403 Server does not exist in the system. Server was probably deleted by another user. Please refresh and retry the operation", + "", ResourceNotFoundException.class); } @Test - public void testDelete404SetsHttpResponseException() { - assertCodeMakes("DELETE", URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), - 404, "", "", HttpResponseException.class); + public void testGet404SetsResourceNotFoundException() { + assertCodeMakes("GET", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), 404, + "", "", ResourceNotFoundException.class); } @Test public void test401SetsAuthorizationException() { - assertCodeMakes("GET", URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), - 401, "", "", AuthorizationException.class); + assertCodeMakes("GET", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), 401, + "", "", AuthorizationException.class); } -// -// @Test -// public void testbecause_there_is_a_pending_task_runningSetsIllegalStateException() { -// assertCodeMakes("GET", URI -// .create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), -// 500, "because there is a pending task running", -// "because there is a pending task running", IllegalStateException.class); -// } + + // + // @Test + // public void testbecause_there_is_a_pending_task_runningSetsIllegalStateException() { + // assertCodeMakes("GET", URI + // .create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), + // 500, "because there is a pending task running", + // "because there is a pending task running", IllegalStateException.class); + // } // case 401: // exception = new AuthorizationException(command.getRequest(), content);