Skip to content

Commit

Permalink
Issue 541: corrected add/remove disk functionality per trmk spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed May 30, 2011
1 parent 1f5155c commit be2009b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
Expand Up @@ -137,12 +137,13 @@ private void addMemoryItem(XMLBuilder sectionBuilder, VCloudExpressVApp vApp, VA
private void addDiskItems(XMLBuilder sectionBuilder, VCloudExpressVApp vApp, VAppConfiguration configuration) {
for (ResourceAllocationSettingData disk : filter(vApp.getResourceAllocations(), CIMPredicates
.resourceTypeIn(ResourceType.DISK_DRIVE))) {
if (!configuration.getDisksToDelete().contains(disk.getAddressOnParent()))
if (!configuration.getDisksToDelete().contains(new Integer(disk.getAddressOnParent()))) {
addDiskWithQuantity(sectionBuilder, disk);
}
}
for (Long quantity : configuration.getDisks()) {
ResourceAllocationSettingData disk = ResourceAllocationSettingData.builder().instanceID("9")
.elementName("n/a").resourceType(ResourceType.DISK_DRIVE).virtualQuantity(quantity).build();
ResourceAllocationSettingData disk = ResourceAllocationSettingData.builder().instanceID("9").addressOnParent(
"-1").elementName("").resourceType(ResourceType.DISK_DRIVE).virtualQuantity(quantity).build();
addDiskWithQuantity(sectionBuilder, disk);
}
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.vcloud.terremark.domain.VAppConfiguration.Builder.changeNameTo;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -96,6 +97,42 @@ ImmutableListMultimap.<String, String> of(), null, null, null, ImmutableSet.of(
}

public void testRemoveDisk() throws IOException {
VCloudExpressVAppImpl vApp = new VCloudExpressVAppImpl("MyAppServer6", URI
.create("https://services.vcloudexpress/terremark.com/api/v0.8/vapp/4213"), Status.OFF, 4194304l, null,
ImmutableListMultimap.<String, String> of(), null, null, null, ImmutableSet.of(
ResourceAllocationSettingData.builder().instanceID("1").elementName("foo").resourceType(
ResourceType.PROCESSOR).virtualQuantity(2l).build(),//
ResourceAllocationSettingData.builder().instanceID("2").elementName("foo").resourceType(
ResourceType.MEMORY).virtualQuantity(1024l).build(), //
ResourceAllocationSettingData.builder().instanceID("9").elementName("foo").addressOnParent("0")
.hostResource("1048576").resourceType(ResourceType.DISK_DRIVE)
.virtualQuantity(209152l).build(),//
ResourceAllocationSettingData.builder().instanceID("9").elementName("foo").addressOnParent("1")
.hostResource("1048576").resourceType(ResourceType.DISK_DRIVE)
.virtualQuantity(209152l).build()//
)

);

String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/configureVApp.xml"))
.replace("eduardo", "MyAppServer6");

VAppConfiguration config = new VAppConfiguration().deleteDiskWithAddressOnParent(1);

GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(vApp, config)).atLeastOnce();
request.setPayload(expected);
replay(request);

BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);

Map<String, String> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);
}

public void testChangeAll() throws IOException {
VCloudExpressVAppImpl vApp = new VCloudExpressVAppImpl("MyAppServer6", URI
.create("https://services.vcloudexpress/terremark.com/api/v0.8/vapp/4213"), Status.OFF, 4194304l, null,
ImmutableListMultimap.<String, String> of(), null, null, null, ImmutableSet.of(
Expand All @@ -106,10 +143,10 @@ ImmutableListMultimap.<String, String> of(), null, null, null, ImmutableSet.of(
"9").elementName("foo").addressOnParent("0").hostResource("1048576").resourceType(
ResourceType.DISK_DRIVE).virtualQuantity(209152l).build()));

String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/configureVApp.xml"))
.replace("eduardo", "MyAppServer6");
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/configureVAppAll.xml"));

VAppConfiguration config = new VAppConfiguration().deleteDiskWithAddressOnParent(1);
VAppConfiguration config = changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1).addDisk(
25 * 1048576).addDisk(25 * 1048576);

GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
Expand Down
@@ -0,0 +1 @@
<VApp xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="eduardo" size="4194304" status="2" type="application/vnd.vmware.vcloud.vApp+xml" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Section xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:q2="http://www.vmware.com/vcloud/v1" xsi:type="VirtualHardwareSection_Type"><Info>Virtual Hardware</Info><Item><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity></Item><Item><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1536</VirtualQuantity></Item><Item><AddressOnParent xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">0</AddressOnParent><HostResource xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1048576</HostResource><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">9</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">17</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">209152</VirtualQuantity></Item><Item><AddressOnParent xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">-1</AddressOnParent><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">9</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">17</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">26214400</VirtualQuantity></Item><Item><AddressOnParent xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">-1</AddressOnParent><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">9</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">17</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">26214400</VirtualQuantity></Item></Section></VApp>
Expand Up @@ -39,8 +39,8 @@
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "TerremarkECloudClientLiveTestDisabled")
public class TerremarkECloudClientLiveTestDisabled extends TerremarkClientLiveTest {
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "TerremarkECloudClientLiveTest")
public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest {
@BeforeClass
void setProvider() {
this.provider = "trmk-ecloud";
Expand Down
Expand Up @@ -100,7 +100,7 @@
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", sequential = true, testName = "TerremarkVCloudExpressAsyncClientTest")
@Test(groups = "unit", singleThreaded = true, testName = "TerremarkVCloudExpressAsyncClientTest")
public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<TerremarkVCloudExpressAsyncClient> {

public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Expand Down

0 comments on commit be2009b

Please sign in to comment.