From 85fad8e3f7bcb9b1a0b4ff5687b510d16dfcd8d4 Mon Sep 17 00:00:00 2001 From: Kedar Dave Date: Thu, 2 Jun 2011 13:36:23 -0500 Subject: [PATCH 1/2] fixed tests for savvis --- providers/savvis-symphonyvpdc/pom.xml | 1 + .../vpdc/features/FirewallAsyncClient.java | 4 +- .../vpdc/features/BaseVPDCClientLiveTest.java | 4 + .../vpdc/features/BrowsingClientLiveTest.java | 6 +- .../vpdc/features/FirewallClientLiveTest.java | 22 ++- .../vpdc/features/VMClientLiveTest.java | 167 ++++++------------ 6 files changed, 83 insertions(+), 121 deletions(-) diff --git a/providers/savvis-symphonyvpdc/pom.xml b/providers/savvis-symphonyvpdc/pom.xml index 0c19c904d2..529e9e254f 100644 --- a/providers/savvis-symphonyvpdc/pom.xml +++ b/providers/savvis-symphonyvpdc/pom.xml @@ -126,6 +126,7 @@ test + 1 test.savvis-symphonyvpdc.endpoint diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java index ee44b53e55..076b1a1c22 100644 --- a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java @@ -55,7 +55,7 @@ public interface FirewallAsyncClient { */ @PUT @XMLResponseParser(TaskHandler.class) - @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/FirewallService/") + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/FirewallService") @MapBinder(BindFirewallRuleToXmlPayload.class) ListenableFuture addFirewallRule( @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, @@ -66,7 +66,7 @@ public interface FirewallAsyncClient { */ @DELETE @XMLResponseParser(TaskHandler.class) - @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/FirewallService/") + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/FirewallService") @MapBinder(BindFirewallRuleToXmlPayload.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture deleteFirewallRule( diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java index 0080de9373..12e30f4951 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Properties; import java.util.concurrent.TimeUnit; +import org.jclouds.Constants; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; @@ -79,6 +80,9 @@ public class BaseVPDCClientLiveTest { overrides.setProperty(provider + ".endpoint", endpoint); if (apiversion != null) overrides.setProperty(provider + ".apiversion", apiversion); + // TODO savvis uses untrusted certificates, remove these once savvis fixes the issue + overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); + overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); return overrides; } diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java index 473f6e6380..738400a5cb 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java @@ -151,9 +151,13 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { String ip = Iterables.get(response.getNetworkConnectionSections(), 0).getIpAddress(); assert HostSpecifier.isValid(ip) : response; if (InetAddresses2.isPrivateIPAddress(ip)) { + // get public ip ip = Iterables.get(response.getNetworkConfigSections(), 0).getInternalToExternalNATRules().get(ip); + // could be null + if(ip != null){ + assert HostSpecifier.isValid(ip) : response; + } } - assert HostSpecifier.isValid(ip) : response; } } diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java index 14bb39307e..3cf78c641a 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java @@ -52,9 +52,14 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { // the jclouds-wire.log @Override public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + if(restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + arg0.getId()).getName().equals("Oracle")){ + return true; + } + return false; + /*String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, arg0.getId()).getDescription(); - return description.indexOf(email) != -1; + return description.indexOf(email) != -1;*/ } }).getId(); @@ -66,7 +71,7 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { FirewallRule firewallRule = FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet") .destination(networkTierName).port("10000").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build(); - System.out.printf("adding firewall rule:%s %n", firewallRule.toString()); + System.out.printf("adding firewall rule:%s in vpdc %s %n", firewallRule.toString(), vpdcId); Task task = client.addFirewallRule(billingSiteId, vpdcId, firewallRule); @@ -87,9 +92,14 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { // the jclouds-wire.log @Override public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + if(restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + arg0.getId()).getName().equals("Oracle")){ + return true; + } + return false; + /*String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, arg0.getId()).getDescription(); - return description.indexOf(email) != -1; + return description.indexOf(email) != -1;*/ } }).getId(); @@ -101,7 +111,7 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { FirewallRule firewallRule = FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet") .destination(networkTierName).port("10000").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build(); - System.out.printf("deleting firewall rule:%s %n", firewallRule.toString()); + System.out.printf("deleting firewall rule:%s in vpdc %s %n", firewallRule.toString(), vpdcId); Task task = client.deleteFirewallRule(billingSiteId, vpdcId, firewallRule); diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java index 1a6bc1eb18..ecbf493449 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java @@ -21,10 +21,11 @@ package org.jclouds.savvis.vpdc.features; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; -import java.net.URI; +import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.Constants; import org.jclouds.cim.OSType; import org.jclouds.compute.domain.CIMOperatingSystem; import org.jclouds.compute.domain.ExecResponse; @@ -38,7 +39,6 @@ import org.jclouds.savvis.vpdc.domain.Task; import org.jclouds.savvis.vpdc.domain.VDC; import org.jclouds.savvis.vpdc.domain.VM; import org.jclouds.savvis.vpdc.domain.VMSpec; -import org.jclouds.savvis.vpdc.domain.VM.Status; import org.jclouds.savvis.vpdc.options.GetVMOptions; import org.jclouds.savvis.vpdc.reference.VCloudMediaType; import org.jclouds.ssh.SshClient; @@ -49,8 +49,8 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.collect.ImmutableSet.Builder; +import com.google.common.collect.Iterables; import com.google.common.net.HostSpecifier; @Test(groups = "live") @@ -98,13 +98,8 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { .getName(); String name = prefix; - // delete any old VM VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - for (Resource resource : vpdc.getResourceEntities()) { - if (resource.getName().equals(prefix)) { - taskTester.apply(client.removeVMFromVDC(billingSiteId, vpdcId, resource.getId()).getId()); - } - } + CIMOperatingSystem os = Iterables.find(restContext.getApi().listPredefinedOperatingSystems(), new Predicate() { @@ -114,22 +109,30 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { } }); - System.out.printf("vpdcId %s, networkName %s, name %s, os %s%n", vpdcId, networkTierName, name, os); + System.out.printf("Creating vm - vpdcId %s, vpdcName %s, networkName %s, name %s, os %s%n", vpdcId, vpdc.getName(), networkTierName, name, os); // TODO: determine the sizes available in the VDC, for example there's // a minimum size of boot disk, and also a preset combination of cpu count vs ram Task task = client.addVMIntoVDC(billingSiteId, vpdcId, VMSpec.builder().name(name).networkTierName( networkTierName).operatingSystem(os).memoryInGig(2).addDataDrive("/data01", 25).build()); - + // make sure there's no error assert task.getId() != null && task.getError() == null : task; assert this.taskTester.apply(task.getId()); - vm = restContext.getApi().getBrowsingClient().getVMInVDC(billingSiteId, vpdcId, task.getOwner().getId()); - conditionallyCheckSSH(); + + // fetch the task again, in savvis, task.getOwner is populated with vApp after task has finished + task = restContext.getApi().getBrowsingClient().getTask(task.getId()); + + vm = restContext.getApi().getBrowsingClient().getVM(task.getOwner().getHref(), GetVMOptions.NONE); + assert vm.getHref() != null : vm; + + // cannot ssh in savvis, as no public ip is assigned by default +// conditionallyCheckSSH(); } - public void testCreateMultipleVMs() throws Exception { + @Test + public void testZCreateMultipleVMs() throws Exception { billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), new Predicate() { @@ -168,7 +171,7 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { // TODO: Savvis returns network names with a - instead of space on getNetworkInVDC call, // fix this once savvis api starts returning correctly - System.out.printf("vpdcId %s, vpdcName %s, networkName %s, name %s, os %s%n", vpdcId, vpdc.getName(), networkTier + System.out.printf("Creating vm's - vpdcId %s, vpdcName %s, networkName %s, name %s, os %s%n", vpdcId, vpdc.getName(), networkTier .getName().replace("-", " "), name, os); Builder vmSpecs = ImmutableSet. builder(); @@ -186,11 +189,21 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { for (Task task : tasks) { // make sure there's no error assert task.getId() != null && task.getError() == null : task; - assert this.taskTester.apply(task.getId()); + + // fetch the task again, in savvis, task.getOwner is populated with vApp after task has finished + task = restContext.getApi().getBrowsingClient().getTask(task.getId()); + + vm = restContext.getApi().getBrowsingClient().getVM(task.getOwner().getHref(), GetVMOptions.NONE); + assert vm.getHref() != null : vm; } } - + + /** + * disabled because it not currently supported by savvis. Planned for august release by savvis. + * @throws Exception + */ + @Test(enabled=false) public void testCaptureVAppTemplate() throws Exception { billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), @@ -229,9 +242,10 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { } } + @Test(dependsOnMethods="testPowerOnVM") public void testCloneVApp() throws Exception { - billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default - vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), + billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default + vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), new Predicate() { // try to find the first VDC owned by the current user @@ -245,29 +259,22 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { } }).getId(); - - VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - - String networkTierName = Iterables.get(vpdc.getAvailableNetworks(), 0).getId(); - - for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate() { - - @Override - public boolean apply(Resource arg0) { - return VCloudMediaType.VAPP_XML.equals(arg0.getType()); - } - - })) { - - System.out.printf("Cloning VApp - %s%n", vApp.getName()); - - Task task = client.cloneVApp(vApp.getHref(), "clonedvm", networkTierName); - - // make sure there's no error - assert task.getId() != null && task.getError() == null : task; - - assert this.taskTester.apply(task.getId()); - } + + String networkTierName = Iterables.get( + restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0) + .getId(); + + Task task = client.cloneVApp(vm.getHref(), "clonedvm", networkTierName); + + // make sure there's no error + assert task.getId() != null && task.getError() == null : task; + assert this.taskTester.apply(task.getId()); + + // fetch the task again, in savvis, task.getOwner is populated with vApp after task has finished + task = restContext.getApi().getBrowsingClient().getTask(task.getId()); + + vm = restContext.getApi().getBrowsingClient().getVM(task.getOwner().getHref(), GetVMOptions.NONE); + assert vm.getHref() != null : vm; } private void conditionallyCheckSSH() { @@ -297,84 +304,20 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { } } - @Test(enabled = false) + @Test(dependsOnMethods="testCreateVirtualMachine") public void testPowerOffVM() throws Exception { - billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default - vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), - new Predicate() { - - // try to find the first VDC owned by the current user - // check here for what the email property might be, or in - // the jclouds-wire.log - @Override - public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getDescription(); - return description.indexOf(email) != -1; - } - - }).getId(); - - VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - URI vmURI = Iterables.find(vpdc.getResourceEntities(), new Predicate() { - @Override - public boolean apply(Resource arg0) { - if (VCloudMediaType.VAPP_XML.equals(arg0.getType())) { - VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null); - System.out.printf("powering off vm - %s%n", response1.getName()); - if (response1.getStatus().equals(Status.ON)) { - return true; - } - } - return false; - } - - }).getHref(); - - Task task = client.powerOffVM(vmURI); - + Task task = client.powerOffVM(vm.getHref()); + // make sure there's no error assert task.getId() != null && task.getError() == null : task; assert this.taskTester.apply(task.getId()); } - @Test(enabled = false) + @Test(dependsOnMethods="testPowerOffVM") public void testPowerOnVM() throws Exception { - billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default - vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), - new Predicate() { - - // try to find the first VDC owned by the current user - // check here for what the email property might be, or in - // the jclouds-wire.log - @Override - public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getDescription(); - return description.indexOf(email) != -1; - } - - }).getId(); - - VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - URI vmURI = Iterables.find(vpdc.getResourceEntities(), new Predicate() { - @Override - public boolean apply(Resource arg0) { - if (VCloudMediaType.VAPP_XML.equals(arg0.getType())) { - VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null); - System.out.printf("powering on vm - %s%n", response1.getName()); - if (response1.getStatus().equals(Status.OFF)) { - return true; - } - } - return false; - } - - }).getHref(); - - Task task = client.powerOnVM(vmURI); - + Task task = client.powerOnVM(vm.getHref()); + // make sure there's no error assert task.getId() != null && task.getError() == null : task; From 607051a0ca3b1d2fcb18c6bc2fbed9ad6212a349 Mon Sep 17 00:00:00 2001 From: Kedar Dave Date: Thu, 2 Jun 2011 13:41:50 -0500 Subject: [PATCH 2/2] cleanup --- .../vpdc/features/FirewallClientLiveTest.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java index 3cf78c641a..6d04042f26 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java @@ -52,14 +52,9 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { // the jclouds-wire.log @Override public boolean apply(Resource arg0) { - if(restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getName().equals("Oracle")){ - return true; - } - return false; - /*String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, arg0.getId()).getDescription(); - return description.indexOf(email) != -1;*/ + return description.indexOf(email) != -1; } }).getId(); @@ -92,14 +87,9 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { // the jclouds-wire.log @Override public boolean apply(Resource arg0) { - if(restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getName().equals("Oracle")){ - return true; - } - return false; - /*String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, arg0.getId()).getDescription(); - return description.indexOf(email) != -1;*/ + return description.indexOf(email) != -1; } }).getId();