From 8921dfcdc2be3634181f352afc604b23edbe73ce Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 10 Mar 2010 11:03:32 -0800 Subject: [PATCH] corrected Ip address handling in default vcloud impl --- .../org/jclouds/vcloud/xml/VAppHandler.java | 4 +- .../jclouds/vcloud/xml/VAppHandlerTest.java | 137 +++++++++++------- 2 files changed, 85 insertions(+), 56 deletions(-) diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java index 0c3ab027be..3ff536a1c7 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java @@ -96,7 +96,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { } } else if (qName.equals("OperatingSystemSection")) { inOs = true; - } else if (qName.equals("NetworkConnection")) { + } else if (qName.endsWith("NetworkConnection")) { networkName = attributes.getValue(attributes.getIndex("Network")); } else { systemHandler.startElement(uri, localName, qName, attributes); @@ -111,7 +111,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { inOs = false; } else if (inOs && qName.equals("Description")) { operatingSystemDescription = currentText.toString().trim(); - } else if (qName.equals("IpAddress")) { + } else if (qName.endsWith("IpAddress")) { networkToAddresses.put(networkName, parseInetAddress(currentText.toString().trim())); } else if (qName.equals("System")) { systemHandler.endElement(uri, localName, qName); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java index 0e9a66b7ff..d153e8e4cc 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java @@ -52,33 +52,40 @@ public class VAppHandlerTest extends BaseHandlerTest { public void testHosting() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/vapp-hosting.xml"); - VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is); + VApp result = factory.create(injector.getInstance(VAppHandler.class)) + .parse(is); ListMultimap networkToAddresses = ImmutableListMultimap - . of("Network 1", InetAddress.getByName("204.12.11.167")); + . of("Network 1", InetAddress + .getByName("204.12.11.167")); - VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "SimpleVM", "vmx-07"); + VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", + "SimpleVM", "vmx-07"); SortedSet resourceAllocations = ImmutableSortedSet - . naturalOrder().add( - new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", - ResourceType.PROCESSOR, null, null, null, null, null, null, 1, - "hertz * 10^6"), - new ResourceAllocation(2, "512MB of memory", "Memory Size", - ResourceType.MEMORY, null, null, null, null, null, null, 512, - "byte * 2^20")).add( + . naturalOrder().add( + new ResourceAllocation(1, "1 virtual CPU(s)", + "Number of Virtual CPUs", ResourceType.PROCESSOR, null, + null, null, null, null, null, 1, "hertz * 10^6"), + new ResourceAllocation(2, "512MB of memory", "Memory Size", + ResourceType.MEMORY, null, null, null, null, null, + null, 512, "byte * 2^20")).add( - new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller", - ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null, - null, 1, null)).add( + new ResourceAllocation(3, "SCSI Controller 0", + "SCSI Controller", ResourceType.SCSI_CONTROLLER, + "lsilogic", null, 0, null, null, null, 1, null)).add( - new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, - null, "20971520", null, 0, 3, null, 20971520, "byte * 2^20")) - .build(); + new ResourceAllocation(9, "Hard Disk 1", null, + ResourceType.DISK_DRIVE, null, "20971520", null, 0, 3, + null, 20971520, "byte * 2^20")).build(); - VApp expects = new VAppImpl("188849-96", "188849-96", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96"), VAppStatus.OFF, - new Long(20971520), null, networkToAddresses, null, system, resourceAllocations); + VApp expects = new VAppImpl( + "188849-96", + "188849-96", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96"), + VAppStatus.OFF, new Long(20971520), null, networkToAddresses, null, + system, resourceAllocations); assertEquals(result, expects); } @@ -86,55 +93,77 @@ public class VAppHandlerTest extends BaseHandlerTest { public void testInstantiated() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/instantiatedvapp.xml"); - VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is); + VApp result = factory.create(injector.getInstance(VAppHandler.class)) + .parse(is); VApp expects = new VAppImpl("10", "centos53", URI - .create("http://10.150.4.49/api/v0.8/vApp/10"), VAppStatus.RESOLVED, 123456789l, - new NamedResourceImpl("4", null, "application/vnd.vmware.vcloud.vdc+xml", URI - .create("http://10.150.4.49/api/v0.8/vdc/4")), ImmutableListMultimap - . of(), null, null, ImmutableSet - . of()); + .create("http://10.150.4.49/api/v0.8/vApp/10"), + VAppStatus.RESOLVED, 123456789l, new NamedResourceImpl("4", null, + "application/vnd.vmware.vcloud.vdc+xml", URI + .create("http://10.150.4.49/api/v0.8/vdc/4")), + ImmutableListMultimap. of(), null, null, + ImmutableSet. of()); assertEquals(result, expects); } // TODO why does this fail? - @Test(enabled = false) public void testDefault() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/vapp.xml"); - VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is); + VApp result = factory.create(injector.getInstance(VAppHandler.class)) + .parse(is); ListMultimap networkToAddresses = ImmutableListMultimap - . of(); - - VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "Oracle", "vmx-07"); + . of("Public Network", InetAddress + .getByName("10.150.4.93")); + VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", + "centos53", "vmx-07"); SortedSet resourceAllocations = ImmutableSortedSet - . naturalOrder().add( - new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", - ResourceType.PROCESSOR, null, null, null, null, null, null, 1, - "hertz * 10^6"), - new ResourceAllocation(2, "16MB of memory", "Memory Size", - ResourceType.MEMORY, null, null, null, null, null, null, 16, - "byte * 2^20")).add( - new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller", - ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null, - null, 1, null)).add( - new ResourceAllocation(8, "Network Adapter 1", - "PCNet32 ethernet adapter on \"Internal\" network", - ResourceType.ETHERNET_ADAPTER, "PCNet32", null, null, 7, null, - true, 1, null)).add( - new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, - null, "104857", null, 0, 3, null, 104857, "byte * 2^20")).build(); - - VApp expects = new VAppImpl("4", "Oracle", URI.create("http://10.150.4.49/api/v0.8/vApp/4"), - VAppStatus.ON, new Long(104857), - new NamedResourceImpl("32", null, "application/vnd.vmware.vcloud.vdc+xml", URI - .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")), - networkToAddresses, "Other Linux (32-bit)", system, resourceAllocations); - - assertEquals(result, expects); + . naturalOrder().add( + new ResourceAllocation(1, "1 virtual CPU(s)", + "Number of Virtual CPUs", ResourceType.PROCESSOR, null, + null, null, null, null, null, 1, "hertz * 10^6"), + new ResourceAllocation(2, "16MB of memory", "Memory Size", + ResourceType.MEMORY, null, null, null, null, null, + null, 16, "byte * 2^20")).add( + new ResourceAllocation(3, "SCSI Controller 0", + "SCSI Controller", ResourceType.SCSI_CONTROLLER, + "lsilogic", null, 0, null, null, null, 1, null)).add( + new ResourceAllocation(8, "Network Adapter 1", + "PCNet32 ethernet adapter on \"Internal\" network", + ResourceType.ETHERNET_ADAPTER, "PCNet32", null, null, + 7, null, true, 1, null)).add( + new ResourceAllocation(9, "Hard Disk 1", null, + ResourceType.DISK_DRIVE, null, "104857", null, 0, 3, + null, 104857, "byte * 2^20")).build(); + VApp expects = new VAppImpl( + "10", + "centos53", + URI.create("http://10.150.4.49/api/v0.8/vApp/10"), + VAppStatus.ON, + new Long(104857), + new NamedResourceImpl( + "4", + null, + "application/vnd.vmware.vcloud.vdc+xml", + URI + .create("http://10.150.4.49/api/v0.8/vdc/4")), + networkToAddresses, "Other Linux (32-bit)", system, + resourceAllocations); + assertEquals(result.getId(), expects.getId()); + assertEquals(result.getLocation(), expects.getLocation()); + assertEquals(result.getName(), expects.getName()); + assertEquals(result.getNetworkToAddresses(), expects.getNetworkToAddresses()); + assertEquals(result.getOperatingSystemDescription(), expects.getOperatingSystemDescription()); + assertEquals(result.getResourceAllocationByType(), expects.getResourceAllocationByType()); + assertEquals(result.getResourceAllocations(), expects.getResourceAllocations()); + assertEquals(result.getSize(), expects.getSize()); + assertEquals(result.getStatus(), expects.getStatus()); + assertEquals(result.getSystem(), expects.getSystem()); + assertEquals(result.getType(), expects.getType()); + assertEquals(result.getVDC(), expects.getVDC()); } }