From 906b3bbea0d0bfd0b6d85da3a16acf2b33c82d0b Mon Sep 17 00:00:00 2001 From: Aled Sage Date: Thu, 21 Jun 2012 14:49:24 +0100 Subject: [PATCH] Issue 995: handle illegal argument in vcloud images --- .../strategy/VCloudComputeServiceAdapter.java | 9 + .../BaseVCloudComputeServiceExpectTest.java | 8 + .../VCloudComputeServiceAdapterTest.java | 74 +++++ .../src/test/resources/ovf-multi-vm.xml | 285 ++++++++++++++++++ .../resources/template1.0-vcd15-multi-vm.xml | 68 +++++ 5 files changed, 444 insertions(+) create mode 100644 apis/vcloud/src/test/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapterTest.java create mode 100644 apis/vcloud/src/test/resources/ovf-multi-vm.xml create mode 100644 apis/vcloud/src/test/resources/template1.0-vcd15-multi-vm.xml diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapter.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapter.java index d46fce7787..c315162c13 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapter.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapter.java @@ -36,6 +36,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; import org.jclouds.ovf.Envelope; +import org.jclouds.util.Throwables2; import org.jclouds.vcloud.TaskInErrorStateException; import org.jclouds.vcloud.TaskStillRunningException; import org.jclouds.vcloud.VCloudClient; @@ -109,6 +110,14 @@ public class VCloudComputeServiceAdapter implements ComputeServiceAdapter builder() @@ -142,6 +146,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE .message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/ovf-ubuntu64.xml", MediaType.TEXT_XML +";version=1.0")) .build(); + protected HttpResponse successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithMultipleVMs = HttpResponse.builder().statusCode(200) + .message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/ovf-multi-vm.xml", MediaType.TEXT_XML +";version=1.0")) + .build(); + public BaseVCloudComputeServiceExpectTest() { provider = "vcloud"; } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapterTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapterTest.java new file mode 100644 index 0000000000..8bf2bc9fdb --- /dev/null +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/strategy/VCloudComputeServiceAdapterTest.java @@ -0,0 +1,74 @@ +package org.jclouds.vcloud.compute.strategy; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Collections; + +import org.jclouds.compute.ComputeService; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.vcloud.compute.BaseVCloudComputeServiceExpectTest; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +public class VCloudComputeServiceAdapterTest extends BaseVCloudComputeServiceExpectTest { + + @Test + public void testListHardwareProfiles() throws Exception { + ComputeService compute = requestsSendResponses(ImmutableMap. builder() + .put(versionsRequest, versionsResponseFromVCD1_5) + .put(version1_0LoginRequest, successfulVersion1_0LoginResponseFromVCD1_5WithSingleOrg) + .put(version1_0GetOrgRequest, successfulVersion1_0GetOrgResponseFromVCD1_5WithSingleTasksListVDCAndNetwork) + .put(version1_0GetCatalogRequest, successfulVersion1_0GetCatalogResponseFromVCD1_5WithSingleTemplate) + .put(version1_0GetCatalogItemRequest, successfulVersion1_0GetCatalogItemResponseFromVCD1_5ForTemplate) + .put(version1_0GetVDCRequest, successfulVersion1_0GetVDCResponseFromVCD1_5WithSingleTemplateAndNetwork) + .put(version1_0GetVAppTemplateRequest, successfulVersion1_0GetVAppTemplateResponseFromVCD1_5WithSingleVMAndVDCParent) + .put(version1_0GetOVFForVAppTemplateRequest, successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithSingleVM) + .build()); + + VCloudComputeServiceAdapter adapter = compute.getContext() + .utils().injector().getInstance(VCloudComputeServiceAdapter.class); + + Iterable hardwareProfiles = adapter.listHardwareProfiles(); + + Iterable hardwareProfileRefs = Iterables.transform(ImmutableList.copyOf(hardwareProfiles), new Function() { + @Override public URI apply(VAppTemplate input) { + return input.getHref(); + } + }); + assertEquals(ImmutableSet.copyOf(hardwareProfileRefs), ImmutableSet.of(URI.create("https://zone.myvcloud.com/api/v1.0/vAppTemplate/vappTemplate-51891b97-c5dd-47dc-a687-aabae354f728"))); + } + + /** + * For issue 994. In BaseEnvelopeHandler when it encounters VirtualSystemCollection, it throws IllegalArgumentException + * (cannot currently create envelopes with multiple virtual systems). + * Thus we do not include the VM in the supported set, but we do return without propagating the exception. + */ + @Test + public void testListHardwareProfilesWithUnsupportedTemplate() throws Exception { + ComputeService compute = requestsSendResponses(ImmutableMap. builder() + .put(versionsRequest, versionsResponseFromVCD1_5) + .put(version1_0LoginRequest, successfulVersion1_0LoginResponseFromVCD1_5WithSingleOrg) + .put(version1_0GetOrgRequest, successfulVersion1_0GetOrgResponseFromVCD1_5WithSingleTasksListVDCAndNetwork) + .put(version1_0GetCatalogRequest, successfulVersion1_0GetCatalogResponseFromVCD1_5WithSingleTemplate) + .put(version1_0GetCatalogItemRequest, successfulVersion1_0GetCatalogItemResponseFromVCD1_5ForTemplate) + .put(version1_0GetVDCRequest, successfulVersion1_0GetVDCResponseFromVCD1_5WithSingleTemplateAndNetwork) + .put(version1_0GetVAppTemplateRequest, successfulVersion1_0GetVAppTemplateResponseFromVCD1_5WithMultipleVMsAndVDCParent) + .put(version1_0GetOVFForVAppTemplateRequest, successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithMultipleVMs) + .build()); + + VCloudComputeServiceAdapter adapter = compute.getContext() + .utils().injector().getInstance(VCloudComputeServiceAdapter.class); + + Iterable hardwareProfiles = adapter.listHardwareProfiles(); + + assertEquals(ImmutableSet.copyOf(hardwareProfiles), Collections.emptySet()); + } +} diff --git a/apis/vcloud/src/test/resources/ovf-multi-vm.xml b/apis/vcloud/src/test/resources/ovf-multi-vm.xml new file mode 100644 index 0000000000..fa4bb37236 --- /dev/null +++ b/apis/vcloud/src/test/resources/ovf-multi-vm.xml @@ -0,0 +1,285 @@ + + + + + The list of logical networks + + + + + + The configuration parameters for logical networks + + + + + false + 192.168.2.1 + 255.255.255.0 + 195.225.219.131 + + + 192.168.2.100 + 192.168.2.199 + + + + isolated + + + false + 7200 + 7200 + + + + + false + + + + Lease settings section + 0 + 0 + + + VApp template customization section + true + + + A collection of virtual machines: + centos-web/db-5.5 + + VApp startup section + + + + + A virtual machine: + centos-db + + Specifies the operating system installed + Other 2.6x Linux (64-bit) + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + centos-db + vmx-07 + + + 00:50:56:01:06:81 + 0 + true + vapp net + + PCNet32 ethernet adapter + Network adapter 0 + 1 + PCNet32 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 2 + lsilogic + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 2 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 3 + 5 + + + 0 + false + CD/DVD Drive + CD/DVD Drive 1 + + 3000 + 3 + 15 + + + 0 + false + Floppy Drive + Floppy Drive 1 + + 8000 + 14 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 4 + 0 + 3 + 1 + 0 + + + byte * 2^20 + Memory Size + 2048 MB of memory + 5 + 0 + 4 + 2048 + 0 + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.2.100 + true + 00:50:56:01:06:81 + POOL + + + + Specifies Guest OS Customization Settings + true + false + false + false + false + true + false + centos-db + + + + A virtual machine: + centos-web + + Specifies the operating system installed + Other 2.6x Linux (64-bit) + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + centos-web + vmx-07 + + + 00:50:56:01:06:82 0 + true + vapp net + + PCNet32 ethernet adapter + Network adapter 0 + 1 + PCNet32 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 2 + lsilogic + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 2 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 3 + 5 + + + 0 + false + CD/DVD Drive + CD/DVD Drive 1 + + 3000 + 3 + 15 + + + 0 + false + Floppy Drive + Floppy Drive 1 + + 8000 + 14 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 4 + 0 + 3 + 1 + 0 + + + byte * 2^20 + Memory Size + 2048 MB of memory + 5 + 0 + 4 + 2048 + 0 + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.2.101 + true + 00:50:56:01:06:82 + POOL + + + + Specifies Guest OS Customization Settings + true + false + false + false + false + true + false + centos-web + + + + diff --git a/apis/vcloud/src/test/resources/template1.0-vcd15-multi-vm.xml b/apis/vcloud/src/test/resources/template1.0-vcd15-multi-vm.xml new file mode 100644 index 0000000000..46b3c83011 --- /dev/null +++ b/apis/vcloud/src/test/resources/template1.0-vcd15-multi-vm.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + Specifies the available VM network connections + 0 + + 0 + false + 00:50:56:b5:09:dc + NONE + + + + Specifies Guest OS Customization Settings + true + false + false + false + true + true + true WindowsServ-001 + + Windows Server 2008 R2 + + + The list of logical networks + + This is a special place-holder used for disconnected network interfaces. + + + The configuration parameters for logical networks + + This is a special place-holder used for disconnected network interfaces. + + + false + 196.254.254.254 + 255.255.0.0 + 196.254.254.254 + + isolated + + false + + + + Lease settings section + 0 + + + VApp template customization section + true + + +