Issue 830: More power related test ordering and dependency

Includes changes from patch submitted by <aled.sage@gmail.com>
This commit is contained in:
Andrew Donald Kennedy 2012-03-21 12:14:25 +00:00 committed by Andrew Donald Kennedy
parent e31eecb4a6
commit 4706ea4057
3 changed files with 286 additions and 207 deletions

View File

@ -23,6 +23,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkGuestCustomizationSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkGuestCustomizationSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
@ -45,6 +46,7 @@ import org.jclouds.vcloud.director.v1_5.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.Vdc;
import org.jclouds.vcloud.director.v1_5.domain.Vm; import org.jclouds.vcloud.director.v1_5.domain.Vm;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntityType.Status;
import org.jclouds.vcloud.director.v1_5.domain.cim.CimBoolean; import org.jclouds.vcloud.director.v1_5.domain.cim.CimBoolean;
import org.jclouds.vcloud.director.v1_5.domain.cim.CimString; import org.jclouds.vcloud.director.v1_5.domain.cim.CimString;
import org.jclouds.vcloud.director.v1_5.domain.cim.CimUnsignedInt; import org.jclouds.vcloud.director.v1_5.domain.cim.CimUnsignedInt;
@ -146,7 +148,7 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
// Get the Vm // Get the Vm
List<Vm> vms = vApp.getChildren().getVms(); List<Vm> vms = vApp.getChildren().getVms();
vm = Iterables.getOnlyElement(vms); vm = Iterables.getOnlyElement(vms);
assertFalse(vms.isEmpty(), "The VApp must have at least one Vm"); assertFalse(vms.isEmpty(), "The VApp must have a Vm");
} }
protected void getGuestCustomizationSection(Function<URI, GuestCustomizationSection> getGuestCustomizationSection) { protected void getGuestCustomizationSection(Function<URI, GuestCustomizationSection> getGuestCustomizationSection) {
@ -238,6 +240,87 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
assertTrue(found.isPresent(), "no " + context + " item found with id " + instanceId + "; only found " + items); assertTrue(found.isPresent(), "no " + context + " item found with id " + instanceId + "; only found " + items);
} }
/**
* Power on a {@link VApp}s {@link Vm}s.
*
* @see #powerOn(URI)
*/
protected VApp powerOn(VApp testVApp) {
return powerOn(testVApp.getHref());
}
/**
* Power on a VApp.
*/
protected VApp powerOn(URI testVAppURI) {
VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
Status status = Status.fromValue(vm.getStatus());
if (status != Status.POWERED_ON) {
Task powerOn = vAppClient.powerOn(vm.getHref());
assertTaskSucceedsLong(powerOn);
}
assertVAppStatus(testVAppURI, Status.POWERED_ON);
return testVApp;
}
/**
* Power off a {@link VApp}s {@link Vm}s.
*
* @see #powerOff(URI)
*/
protected VApp powerOff(VApp testVApp) {
return powerOff(testVApp.getHref());
}
/**
* Power off a {@link VApp}s {@link Vm}s.
*/
protected VApp powerOff(URI testVAppURI) {
VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
Status status = Status.fromValue(vm.getStatus());
if (status != Status.POWERED_OFF) {
Task powerOff = vAppClient.powerOff(vm.getHref());
assertTaskSucceedsLong(powerOff);
}
assertVAppStatus(testVAppURI, Status.POWERED_OFF);
return testVApp;
}
/**
* Suspend a {@link VApp}s {@link Vm}s.
*
* @see #suspend(URI)
*/
protected VApp suspend(VApp testVApp) {
return powerOff(testVApp.getHref());
}
/**
* Suspend a {@link VApp}s {@link Vm}s.
*/
protected VApp suspend(URI testVAppURI) {
VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
Status status = Status.fromValue(vm.getStatus());
if (status != Status.SUSPENDED) {
Task suspend = vAppClient.suspend(vm.getHref());
assertTaskSucceedsLong(suspend);
}
assertVAppStatus(testVAppURI, Status.SUSPENDED);
return testVApp;
}
/**
* Check the {@link VApp}s {@link Vm}s current status.
*/
protected void assertVAppStatus(URI testVAppURI, Status status) {
VApp testVApp = vAppClient.getVApp(testVAppURI);
Vm vm = Iterables.getOnlyElement(testVApp.getChildren().getVms());
assertEquals(vm.getStatus(), status.getValue(),String.format(OBJ_FIELD_EQ, VAPP, "status", status.toString(), Status.fromValue(vm.getStatus()).toString()));
}
/** /**
* Marshals a JAXB annotated object into XML. The XML is output on {@link System#err}. * Marshals a JAXB annotated object into XML. The XML is output on {@link System#err}.
*/ */

View File

@ -53,6 +53,7 @@ import static org.testng.Assert.fail;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -85,7 +86,10 @@ import org.jclouds.vcloud.director.v1_5.domain.ScreenTicket;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.UndeployVAppParams; import org.jclouds.vcloud.director.v1_5.domain.UndeployVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.VApp; import org.jclouds.vcloud.director.v1_5.domain.VApp;
import org.jclouds.vcloud.director.v1_5.domain.Vm;
import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion; import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion;
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswer;
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswerChoice;
import org.jclouds.vcloud.director.v1_5.domain.cim.OSType; import org.jclouds.vcloud.director.v1_5.domain.cim.OSType;
import org.jclouds.vcloud.director.v1_5.domain.cim.ResourceAllocationSettingData; import org.jclouds.vcloud.director.v1_5.domain.cim.ResourceAllocationSettingData;
import org.jclouds.vcloud.director.v1_5.domain.ovf.MsgType; import org.jclouds.vcloud.director.v1_5.domain.ovf.MsgType;
@ -132,8 +136,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
// TODO source.href vAppTemplateURI // TODO source.href vAppTemplateURI
// Check status // Check status
Status poweredOffStatus = Status.POWERED_OFF; assertVAppStatus(vAppURI, Status.POWERED_OFF);
assertEquals(vApp.getStatus(), poweredOffStatus.getValue(),String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
} }
/** /**
@ -178,12 +181,14 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
assertTrue(vApp.isDeployed(), String.format(OBJ_FIELD_EQ, VAPP, "deployed", "TRUE", vApp.isDeployed().toString())); assertTrue(vApp.isDeployed(), String.format(OBJ_FIELD_EQ, VAPP, "deployed", "TRUE", vApp.isDeployed().toString()));
// Check status // Check status
Status deployedStatus = Status.POWERED_OFF; assertVAppStatus(vAppURI, Status.POWERED_OFF);
assertEquals(vApp.getStatus(), deployedStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", deployedStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
} }
@Test(testName = "POST /vApp/{id}/power/action/powerOn", dependsOnMethods = { "testDeployVApp" }) @Test(testName = "POST /vApp/{id}/power/action/powerOn", dependsOnMethods = { "testDeployVApp" })
public void testPowerOnVApp() { public void testPowerOnVApp() {
// Power off VApp
vApp = powerOff(vApp);
// The method under test // The method under test
Task powerOnVApp = vAppClient.powerOn(vApp.getHref()); Task powerOnVApp = vAppClient.powerOn(vApp.getHref());
assertTaskSucceedsLong(powerOnVApp); assertTaskSucceedsLong(powerOnVApp);
@ -192,12 +197,14 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
vApp = vAppClient.getVApp(vApp.getHref()); vApp = vAppClient.getVApp(vApp.getHref());
// Check status // Check status
Status poweredOnStatus = Status.POWERED_ON; assertVAppStatus(vAppURI, Status.POWERED_ON);
assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
} }
@Test(testName = "POST /vApp/{id}/power/action/reboot", dependsOnMethods = { "testPowerOnVApp" }) @Test(testName = "POST /vApp/{id}/power/action/reboot", dependsOnMethods = { "testDeployVApp" })
public void testReboot() { public void testReboot() {
// Power on VApp
vApp = powerOn(vApp);
// The method under test // The method under test
Task reboot = vAppClient.reboot(vApp.getHref()); Task reboot = vAppClient.reboot(vApp.getHref());
assertTaskSucceedsLong(reboot); assertTaskSucceedsLong(reboot);
@ -206,14 +213,13 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
vApp = vAppClient.getVApp(vApp.getHref()); vApp = vAppClient.getVApp(vApp.getHref());
// Check status // Check status
Status poweredOffStatus = Status.POWERED_OFF; assertVAppStatus(vAppURI, Status.POWERED_OFF);
assertEquals(vApp.getStatus(), poweredOffStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
} }
@Test(testName = "POST /vApp/{id}/power/action/shutdown", dependsOnMethods = { "testPowerOnVApp" }) @Test(testName = "POST /vApp/{id}/power/action/shutdown", dependsOnMethods = { "testDeployVApp" })
public void testShutdown() { public void testShutdown() {
// Power on VApp // Power on VApp
powerOn(); vApp = powerOn(vApp);
// The method under test // The method under test
Task shutdown = vAppClient.shutdown(vAppURI); Task shutdown = vAppClient.shutdown(vAppURI);
@ -223,17 +229,16 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
vApp = vAppClient.getVApp(vAppURI); vApp = vAppClient.getVApp(vAppURI);
// Check status // Check status
Status poweredOffStatus = Status.POWERED_OFF; assertVAppStatus(vAppURI, Status.POWERED_OFF);
assertEquals(vApp.getStatus(), poweredOffStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
// Power on the VApp again // Power on the VApp again
powerOn(); vApp = powerOn(vApp);
} }
@Test(testName = "POST /vApp/{id}/power/action/suspend", dependsOnMethods = { "testPowerOnVApp" }) @Test(testName = "POST /vApp/{id}/power/action/suspend", dependsOnMethods = { "testDeployVApp" })
public void testSuspend() { public void testSuspend() {
// Power on VApp // Power on VApp
powerOn(); vApp = powerOn(vApp);
// The method under test // The method under test
Task suspend = vAppClient.suspend(vAppURI); Task suspend = vAppClient.suspend(vAppURI);
@ -243,32 +248,33 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
vApp = vAppClient.getVApp(vApp.getHref()); vApp = vAppClient.getVApp(vApp.getHref());
// Check status // Check status
Status suspendedStatus = Status.SUSPENDED; assertVAppStatus(vAppURI, Status.SUSPENDED);
assertEquals(vApp.getStatus(), suspendedStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", suspendedStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
// Power on the VApp again // Power on the VApp again
powerOn(); vApp = powerOn(vApp);
} }
@Test(testName = "POST /vApp/{id}/power/action/reset", dependsOnMethods = { "testPowerOnVApp" }) @Test(testName = "POST /vApp/{id}/power/action/reset", dependsOnMethods = { "testDeployVApp" })
public void testReset() { public void testReset() {
// Power on VApp // Power on VApp
powerOn(); vApp = powerOn(vApp);
// The method under test // The method under test
Task reset = vAppClient.reset(vApp.getHref()); Task reset = vAppClient.reset(vAppURI);
assertTaskSucceedsLong(reset); assertTaskSucceedsLong(reset);
// Get the updated VApp // Get the updated VApp
vApp = vAppClient.getVApp(vApp.getHref()); vApp = vAppClient.getVApp(vAppURI);
// Check status // Check status
Status poweredOnStatus = Status.POWERED_ON; assertVAppStatus(vAppURI, Status.POWERED_ON);
assertEquals(vApp.getStatus(), poweredOnStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOnStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
} }
@Test(testName = "POST /vApp/{id}/action/undeploy", dependsOnMethods = { "testReset" }) @Test(testName = "POST /vApp/{id}/action/undeploy", dependsOnMethods = { "testDeployVApp" })
public void testUndeployVApp() { public void testUndeployVApp() {
// Power on VApp
vApp = powerOn(vApp);
UndeployVAppParams params = UndeployVAppParams.builder().build(); UndeployVAppParams params = UndeployVAppParams.builder().build();
// The method under test // The method under test
@ -276,31 +282,34 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
assertTrue(retryTaskSuccess.apply(undeploy), String.format(TASK_COMPLETE_TIMELY, "undeploy")); assertTrue(retryTaskSuccess.apply(undeploy), String.format(TASK_COMPLETE_TIMELY, "undeploy"));
// Get the updated VApp // Get the updated VApp
vApp = vAppClient.getVApp(vApp.getHref()); vApp = vAppClient.getVApp(vAppURI);
// Check status // Check status
assertFalse(vApp.isDeployed(), String.format(OBJ_FIELD_EQ, VAPP, "deployed", "FALSE", vApp.isDeployed().toString())); assertFalse(vApp.isDeployed(), String.format(OBJ_FIELD_EQ, VAPP, "deployed", "FALSE", vApp.isDeployed().toString()));
assertVAppStatus(vAppURI, Status.POWERED_OFF);
Status poweredOffStatus = Status.POWERED_OFF;
assertEquals(vApp.getStatus(), poweredOffStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
} }
@Test(testName = "POST /vApp/{id}/power/action/powerOff", dependsOnMethods = { "testUndeployVApp" }) @Test(testName = "POST /vApp/{id}/power/action/powerOff", dependsOnMethods = { "testUndeployVApp" })
public void testPowerOffVApp() { public void testPowerOffVApp() {
// Power on VApp
vApp = powerOn(vApp);
// The method under test // The method under test
Task powerOffVApp = vAppClient.powerOff(vApp.getHref()); Task powerOffVApp = vAppClient.powerOff(vApp.getHref());
assertTrue(retryTaskSuccess.apply(powerOffVApp), String.format(TASK_COMPLETE_TIMELY, "powerOffVApp")); assertTrue(retryTaskSuccess.apply(powerOffVApp), String.format(TASK_COMPLETE_TIMELY, "powerOffVApp"));
// Get the updated VApp // Get the updated VApp
vApp = vAppClient.getVApp(vApp.getHref()); vApp = vAppClient.getVApp(vAppURI);
// Check status // Check status
Status poweredOffStatus = Status.POWERED_OFF; assertVAppStatus(vAppURI, Status.POWERED_OFF);
assertEquals(vApp.getStatus(), poweredOffStatus.getValue(), String.format(OBJ_FIELD_EQ, VAPP, "status", poweredOffStatus.toString(), Status.fromValue(vApp.getStatus()).toString()));
} }
@Test(testName = "POST /vApp/{id}/action/consolidate", dependsOnMethods = { "testPowerOnVApp" }) @Test(testName = "POST /vApp/{id}/action/consolidate", dependsOnMethods = { "testDeployVApp" })
public void testConsolidateVApp() { public void testConsolidateVApp() {
// Power on VApp
vApp = powerOn(vApp);
// The method under test // The method under test
Task consolidateVApp = vAppClient.consolidateVApp(vApp.getHref()); Task consolidateVApp = vAppClient.consolidateVApp(vApp.getHref());
assertTrue(retryTaskSuccess.apply(consolidateVApp), String.format(TASK_COMPLETE_TIMELY, "consolidateVApp")); assertTrue(retryTaskSuccess.apply(consolidateVApp), String.format(TASK_COMPLETE_TIMELY, "consolidateVApp"));
@ -344,35 +353,75 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
assertEquals(modified, params, String.format(ENTITY_EQUAL, "ControlAccessParams")); assertEquals(modified, params, String.format(ENTITY_EQUAL, "ControlAccessParams"));
} }
@Test(testName = "POST /vApp/{id}/action/discardSuspendedState", dependsOnMethods = { "testSuspend" }) @Test(testName = "POST /vApp/{id}/action/discardSuspendedState", dependsOnMethods = { "testDeployVApp" })
public void testDiscardSuspendedState() { public void testDiscardSuspendedState() {
// Suspend the VApp
vApp = suspend(vAppURI);
// The method under test // The method under test
Task discardSuspendedState = vAppClient.discardSuspendedState(vApp.getHref()); Task discardSuspendedState = vAppClient.discardSuspendedState(vApp.getHref());
assertTrue(retryTaskSuccess.apply(discardSuspendedState), String.format(TASK_COMPLETE_TIMELY, "discardSuspendedState")); assertTrue(retryTaskSuccess.apply(discardSuspendedState), String.format(TASK_COMPLETE_TIMELY, "discardSuspendedState"));
} }
@Test(testName = "POST /vApp/{id}/action/enterMaintenanceMode", dependsOnMethods = { "testPowerOnVApp" }) @Test(testName = "POST /vApp/{id}/action/enterMaintenanceMode")
public void testEnterMaintenanceMode() { public void testEnterMaintenanceMode() {
// The method under test // Do this to a new vApp, so don't mess up subsequent tests by making the vApp read-only
vAppClient.enterMaintenanceMode(vApp.getHref()); VApp temp = instantiateVApp();
DeployVAppParams params = DeployVAppParams.builder()
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS))
.notForceCustomization()
.notPowerOn()
.build();
Task deployVApp = vAppClient.deploy(temp.getHref(), params);
assertTaskSucceedsLong(deployVApp);
vApp = vAppClient.getVApp(vApp.getHref()); try {
assertTrue(vApp.isInMaintenanceMode(), String.format(CONDITION_FMT, "InMaintenanceMode", "TRUE", vApp.isInMaintenanceMode())); // Method under test
vAppClient.enterMaintenanceMode(temp.getHref());
temp = vAppClient.getVApp(temp.getHref());
assertTrue(temp.isInMaintenanceMode(), String.format(CONDITION_FMT, "InMaintenanceMode", "TRUE", temp.isInMaintenanceMode()));
// Exit maintenance mode
vAppClient.exitMaintenanceMode(temp.getHref());
} finally {
cleanUpVApp(temp);
}
} }
@Test(testName = "POST /vApp/{id}/action/exitMaintenanceMode", dependsOnMethods = { "testEnterMaintenanceMode" }) @Test(testName = "POST /vApp/{id}/action/exitMaintenanceMode", dependsOnMethods = { "testEnterMaintenanceMode" })
public void testExitMaintenanceMode() { public void testExitMaintenanceMode() {
// The method under test // Do this to a new vApp, so don't mess up subsequent tests by making the vApp read-only
vAppClient.exitMaintenanceMode(vApp.getHref()); VApp temp = instantiateVApp();
DeployVAppParams params = DeployVAppParams.builder()
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS))
.notForceCustomization()
.notPowerOn()
.build();
Task deployVApp = vAppClient.deploy(temp.getHref(), params);
assertTaskSucceedsLong(deployVApp);
vApp = vAppClient.getVApp(vApp.getHref()); try {
assertFalse(vApp.isInMaintenanceMode(), String.format(CONDITION_FMT, "InMaintenanceMode", "FALSE", vApp.isInMaintenanceMode())); // Enter maintenance mode
vAppClient.enterMaintenanceMode(temp.getHref());
// Method under test
vAppClient.exitMaintenanceMode(temp.getHref());
temp = vAppClient.getVApp(temp.getHref());
assertFalse(temp.isInMaintenanceMode(), String.format(CONDITION_FMT, "InMaintenanceMode", "FALSE", temp.isInMaintenanceMode()));
} finally {
cleanUpVApp(temp);
}
} }
@Test(testName = "POST /vApp/{id}/action/installVMwareTools", dependsOnMethods = { "testPowerOnVApp" }) @Test(testName = "POST /vApp/{id}/action/installVMwareTools", dependsOnMethods = { "testDeployVApp" })
public void testInstallVMwareTools() { public void testInstallVMwareTools() {
// First ensure the vApp is powered n
vApp = powerOn(vApp);
// The method under test // The method under test
Task installVMwareTools = vAppClient.installVMwareTools(vApp.getHref()); Task installVMwareTools = vAppClient.installVMwareTools(vm.getHref());
assertTrue(retryTaskSuccess.apply(installVMwareTools), String.format(TASK_COMPLETE_TIMELY, "installVMwareTools")); assertTrue(retryTaskSuccess.apply(installVMwareTools), String.format(TASK_COMPLETE_TIMELY, "installVMwareTools"));
} }
@ -403,8 +452,11 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "POST /vApp/{id}/action/upgradeHardwareVersion", dependsOnMethods = { "testGetVApp" }) @Test(testName = "POST /vApp/{id}/action/upgradeHardwareVersion", dependsOnMethods = { "testGetVApp" })
public void testUpgradeHardwareVersion() { public void testUpgradeHardwareVersion() {
// Power off VApp
vApp = powerOff(vApp);
// The method under test // The method under test
Task upgradeHardwareVersion = vAppClient.upgradeHardwareVersion(vApp.getHref()); Task upgradeHardwareVersion = vAppClient.upgradeHardwareVersion(vm.getHref());
assertTrue(retryTaskSuccess.apply(upgradeHardwareVersion), String.format(TASK_COMPLETE_TIMELY, "upgradeHardwareVersion")); assertTrue(retryTaskSuccess.apply(upgradeHardwareVersion), String.format(TASK_COMPLETE_TIMELY, "upgradeHardwareVersion"));
} }
@ -429,11 +481,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/guestCustomizationSection", dependsOnMethods = { "testGetGuestCustomizationSection" }) @Test(testName = "PUT /vApp/{id}/guestCustomizationSection", dependsOnMethods = { "testGetGuestCustomizationSection" })
public void testModifyGuestCustomizationSection() { public void testModifyGuestCustomizationSection() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Copy existing section and update fields // Copy existing section and update fields
GuestCustomizationSection oldSection = vAppClient.getGuestCustomizationSection(vmURI); GuestCustomizationSection oldSection = vAppClient.getGuestCustomizationSection(vm.getHref());
GuestCustomizationSection newSection = oldSection.toBuilder() GuestCustomizationSection newSection = oldSection.toBuilder()
.computerName("newComputerName") .computerName("newComputerName")
.enabled(Boolean.FALSE) .enabled(Boolean.FALSE)
@ -441,11 +490,11 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
.build(); .build();
// The method under test // The method under test
Task modifyGuestCustomizationSection = vAppClient.modifyGuestCustomizationSection(vmURI, newSection); Task modifyGuestCustomizationSection = vAppClient.modifyGuestCustomizationSection(vm.getHref(), newSection);
assertTrue(retryTaskSuccess.apply(modifyGuestCustomizationSection), String.format(TASK_COMPLETE_TIMELY, "modifyGuestCustomizationSection")); assertTrue(retryTaskSuccess.apply(modifyGuestCustomizationSection), String.format(TASK_COMPLETE_TIMELY, "modifyGuestCustomizationSection"));
// Retrieve the modified section // Retrieve the modified section
GuestCustomizationSection modified = vAppClient.getGuestCustomizationSection(vmURI); GuestCustomizationSection modified = vAppClient.getGuestCustomizationSection(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkGuestCustomizationSection(modified); checkGuestCustomizationSection(modified);
@ -522,11 +571,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
.media(Reference.builder().href(mediaURI).type(MEDIA).build()) .media(Reference.builder().href(mediaURI).type(MEDIA).build())
.build(); .build();
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// The method under test // The method under test
Task insertMedia = vAppClient.insertMedia(vmURI, params); Task insertMedia = vAppClient.insertMedia(vm.getHref(), params);
assertTrue(retryTaskSuccess.apply(insertMedia), String.format(TASK_COMPLETE_TIMELY, "insertMedia")); assertTrue(retryTaskSuccess.apply(insertMedia), String.format(TASK_COMPLETE_TIMELY, "insertMedia"));
} }
@ -537,11 +583,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
.media(Reference.builder().href(mediaURI).type(MEDIA).build()) .media(Reference.builder().href(mediaURI).type(MEDIA).build())
.build(); .build();
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// The method under test // The method under test
Task ejectMedia = vAppClient.ejectMedia(vmURI, params); Task ejectMedia = vAppClient.ejectMedia(vm.getHref(), params);
assertTrue(retryTaskSuccess.apply(ejectMedia), String.format(TASK_COMPLETE_TIMELY, "ejectMedia")); assertTrue(retryTaskSuccess.apply(ejectMedia), String.format(TASK_COMPLETE_TIMELY, "ejectMedia"));
} }
@ -559,7 +602,6 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
// Copy existing section and update fields // Copy existing section and update fields
NetworkConfigSection oldSection = vAppClient.getNetworkConfigSection(vApp.getHref()); NetworkConfigSection oldSection = vAppClient.getNetworkConfigSection(vApp.getHref());
NetworkConfigSection newSection = oldSection.toBuilder() NetworkConfigSection newSection = oldSection.toBuilder()
// .info("New NetworkConfigSection Info")
.build(); .build();
// The method under test // The method under test
@ -592,15 +634,12 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
// FIXME "Task error: Unable to perform this action. Contact your cloud administrator." // FIXME "Task error: Unable to perform this action. Contact your cloud administrator."
@Test(testName = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testGetNetworkConnectionSection" }) @Test(testName = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testGetNetworkConnectionSection" })
public void testModifyNetworkConnectionSection() { public void testModifyNetworkConnectionSection() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Look up a network in the Vdc // Look up a network in the Vdc
Set<Reference> networks = vdc.getAvailableNetworks().getNetworks(); Set<Reference> networks = vdc.getAvailableNetworks().getNetworks();
Reference network = Iterables.getLast(networks); Reference network = Iterables.getLast(networks);
// Copy existing section and update fields // Copy existing section and update fields
NetworkConnectionSection oldSection = vAppClient.getNetworkConnectionSection(vmURI); NetworkConnectionSection oldSection = vAppClient.getNetworkConnectionSection(vm.getHref());
NetworkConnectionSection newSection = oldSection.toBuilder() NetworkConnectionSection newSection = oldSection.toBuilder()
.networkConnection(NetworkConnection.builder() .networkConnection(NetworkConnection.builder()
.ipAddressAllocationMode(IpAddressAllocationMode.DHCP.toString()) .ipAddressAllocationMode(IpAddressAllocationMode.DHCP.toString())
@ -609,11 +648,11 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
.build(); .build();
// The method under test // The method under test
Task modifyNetworkConnectionSection = vAppClient.modifyNetworkConnectionSection(vmURI, newSection); Task modifyNetworkConnectionSection = vAppClient.modifyNetworkConnectionSection(vm.getHref(), newSection);
assertTrue(retryTaskSuccess.apply(modifyNetworkConnectionSection), String.format(TASK_COMPLETE_TIMELY, "modifyNetworkConnectionSection")); assertTrue(retryTaskSuccess.apply(modifyNetworkConnectionSection), String.format(TASK_COMPLETE_TIMELY, "modifyNetworkConnectionSection"));
// Retrieve the modified section // Retrieve the modified section
NetworkConnectionSection modified = vAppClient.getNetworkConnectionSection(vmURI); NetworkConnectionSection modified = vAppClient.getNetworkConnectionSection(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkNetworkConnectionSection(modified); checkNetworkConnectionSection(modified);
@ -636,21 +675,15 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "GET /vApp/{id}/operatingSystemSection", dependsOnMethods = { "testGetVApp" }) @Test(testName = "GET /vApp/{id}/operatingSystemSection", dependsOnMethods = { "testGetVApp" })
public void testGetOperatingSystemSection() { public void testGetOperatingSystemSection() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// The method under test // The method under test
OperatingSystemSection section = vAppClient.getOperatingSystemSection(vmURI); OperatingSystemSection section = vAppClient.getOperatingSystemSection(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkOperatingSystemSection(section); checkOperatingSystemSection(section);
} }
@Test(testName = "PUT /vApp/{id}/operatingSystemSection", dependsOnMethods = { "testGetOperatingSystemSection" }) @Test(testName = "PUT /vApp/{id}/operatingSystemSection", dependsOnMethods = { "testGetOperatingSystemSection", "testModifyVirtualHardwareSection" })
public void testModifyOperatingSystemSection() { public void testModifyOperatingSystemSection() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Create new OperatingSystemSection // Create new OperatingSystemSection
OperatingSystemSection newSection = OperatingSystemSection.builder() OperatingSystemSection newSection = OperatingSystemSection.builder()
.info("") // NOTE Required OVF field, ignored .info("") // NOTE Required OVF field, ignored
@ -659,11 +692,11 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
.build(); .build();
// The method under test // The method under test
Task modifyOperatingSystemSection = vAppClient.modifyOperatingSystemSection(vmURI, newSection); Task modifyOperatingSystemSection = vAppClient.modifyOperatingSystemSection(vm.getHref(), newSection);
assertTrue(retryTaskSuccess.apply(modifyOperatingSystemSection), String.format(TASK_COMPLETE_TIMELY, "modifyOperatingSystemSection")); assertTrue(retryTaskSuccess.apply(modifyOperatingSystemSection), String.format(TASK_COMPLETE_TIMELY, "modifyOperatingSystemSection"));
// Retrieve the modified section // Retrieve the modified section
OperatingSystemSection modified = vAppClient.getOperatingSystemSection(vmURI); OperatingSystemSection modified = vAppClient.getOperatingSystemSection(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkOperatingSystemSection(modified); checkOperatingSystemSection(modified);
@ -738,11 +771,16 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
assertEquals(modified, newSections, String.format(ENTITY_EQUAL, "ProductSectionList")); assertEquals(modified, newSections, String.format(ENTITY_EQUAL, "ProductSectionList"));
} }
@Test(testName = "GET /vApp/{id}/question", dependsOnMethods = { "testPowerOnVApp" }) // FIXME How do we force it to ask a question?
@Test(testName = "GET /vApp/{id}/question", dependsOnMethods = { "testDeployVApp" })
public void testGetPendingQuestion() { public void testGetPendingQuestion() {
// Power on VApp
vApp = powerOn(vAppURI);
// TODO how to test? // TODO how to test?
// The method under test // The method under test
VmPendingQuestion question = vAppClient.getPendingQuestion(vApp.getHref()); VmPendingQuestion question = vAppClient.getPendingQuestion(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkVmPendingQuestion(question); checkVmPendingQuestion(question);
@ -750,34 +788,39 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/question/action/answer", dependsOnMethods = { "testGetPendingQuestion" }) @Test(testName = "PUT /vApp/{id}/question/action/answer", dependsOnMethods = { "testGetPendingQuestion" })
public void testAnswerQuestion() { public void testAnswerQuestion() {
// TODO add builder // TODO check that the question has been answered (e.g. asking for getPendingQuestion does not
// VmQuestionAnswer answer = VmQuestionAnswer.builer() // include our answered question).
// .build();
// The method under test VmPendingQuestion question = vAppClient.getPendingQuestion(vm.getHref());
// vAppClient.answerQuestion(vApp.getHref(), answer); List<VmQuestionAnswerChoice> answerChoices = question.getChoices();
// TODO how to test? VmQuestionAnswerChoice answerChoice = Iterables.getFirst(answerChoices, null);
assertNotNull(answerChoice, "Question "+question+" must have at least once answer-choice");
VmQuestionAnswer answer = VmQuestionAnswer.builder()
.choiceId(answerChoice.getId())
.questionId(question.getQuestionId())
.build();
vAppClient.answerQuestion(vm.getHref(), answer);
} }
@Test(testName = "GET /vApp/{id}/runtimeInfoSection", dependsOnMethods = { "testGetVApp" }) @Test(testName = "GET /vApp/{id}/runtimeInfoSection", dependsOnMethods = { "testGetVApp" })
public void testGetRuntimeInfoSection() { public void testGetRuntimeInfoSection() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// The method under test // The method under test
RuntimeInfoSection section = vAppClient.getRuntimeInfoSection(vmURI); RuntimeInfoSection section = vAppClient.getRuntimeInfoSection(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRuntimeInfoSection(section); checkRuntimeInfoSection(section);
} }
@Test(testName = "GET /vApp/{id}/screen", dependsOnMethods = { "testPowerOnVApp" }) // FIXME If still failing, consider escalating?
@Test(testName = "GET /vApp/{id}/screen", dependsOnMethods = { "testDeployVApp" })
public void testGetScreenImage() { public void testGetScreenImage() {
// Get URI for child VM // Power on VApp
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref(); vApp = powerOn(vApp);
// The method under test // The method under test
byte[] image = vAppClient.getScreenImage(vmURI); byte[] image = vAppClient.getScreenImage(vm.getHref());
// Check returned bytes against PNG header magic number // Check returned bytes against PNG header magic number
byte[] pngHeaderBytes = new byte[] { (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }; byte[] pngHeaderBytes = new byte[] { (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
@ -788,13 +831,13 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
} }
} }
@Test(testName = "GET /vApp/{id}/screen/action/acquireTicket", dependsOnMethods = { "testGetVApp" }) @Test(testName = "GET /vApp/{id}/screen/action/acquireTicket", dependsOnMethods = { "testDeployVApp" })
public void testGetScreenTicket() { public void testGetScreenTicket() {
// Get URI for child VM // Power on VApp
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref(); vApp = powerOn(vApp);
// The method under test // The method under test
ScreenTicket ticket = vAppClient.getScreenTicket(vmURI); ScreenTicket ticket = vAppClient.getScreenTicket(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkScreenTicket(ticket); checkScreenTicket(ticket);
@ -832,11 +875,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "GET /vApp/{id}/virtualHardwareSection", dependsOnMethods = { "testGetVApp" }) @Test(testName = "GET /vApp/{id}/virtualHardwareSection", dependsOnMethods = { "testGetVApp" })
public void testGetVirtualHardwareSection() { public void testGetVirtualHardwareSection() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Method under test // Method under test
VirtualHardwareSection hardware = vAppClient.getVirtualHardwareSection(vmURI); VirtualHardwareSection hardware = vAppClient.getVirtualHardwareSection(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkVirtualHardwareSection(hardware); checkVirtualHardwareSection(hardware);
@ -844,12 +884,13 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/virtualHardwareSection", dependsOnMethods = { "testGetVirtualHardwareSection" }) @Test(testName = "PUT /vApp/{id}/virtualHardwareSection", dependsOnMethods = { "testGetVirtualHardwareSection" })
public void testModifyVirtualHardwareSection() { public void testModifyVirtualHardwareSection() {
// Get URI for child VM // Power off VApp
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref(); vApp = powerOff(vApp);
// Copy existing section and update fields // Copy existing section and update fields
VirtualHardwareSection oldSection = vAppClient.getVirtualHardwareSection(vmURI); VirtualHardwareSection oldSection = vAppClient.getVirtualHardwareSection(vm.getHref());
Set<ResourceAllocationSettingData> oldItems = oldSection.getItems(); Set<ResourceAllocationSettingData> oldItems = oldSection.getItems();
Set<ResourceAllocationSettingData> newItems = Sets.newLinkedHashSet(oldItems);
ResourceAllocationSettingData oldMemory = Iterables.find(oldItems, new Predicate<ResourceAllocationSettingData>() { ResourceAllocationSettingData oldMemory = Iterables.find(oldItems, new Predicate<ResourceAllocationSettingData>() {
@Override @Override
public boolean apply(ResourceAllocationSettingData rasd) { public boolean apply(ResourceAllocationSettingData rasd) {
@ -858,9 +899,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
}); });
ResourceAllocationSettingData newMemory = oldMemory.toBuilder() ResourceAllocationSettingData newMemory = oldMemory.toBuilder()
.elementName("1024 MB of memory") .elementName("1024 MB of memory")
.virtualQuantity(BigInteger.valueOf(1024L)) .virtualQuantity(new BigInteger("1024"))
.build(); .build();
Set<ResourceAllocationSettingData> newItems = Sets.newLinkedHashSet(oldItems);
newItems.remove(oldMemory); newItems.remove(oldMemory);
newItems.add(newMemory); newItems.add(newMemory);
VirtualHardwareSection newSection = oldSection.toBuilder() VirtualHardwareSection newSection = oldSection.toBuilder()
@ -868,34 +908,32 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
.build(); .build();
// The method under test // The method under test
Task modifyVirtualHardwareSection = vAppClient.modifyVirtualHardwareSection(vmURI, newSection); Task modifyVirtualHardwareSection = vAppClient.modifyVirtualHardwareSection(vm.getHref(), newSection);
assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSection), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSection")); assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSection), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSection"));
// Retrieve the modified section // Retrieve the modified section
VirtualHardwareSection modifiedSection = vAppClient.getVirtualHardwareSection(vmURI); VirtualHardwareSection modifiedSection = vAppClient.getVirtualHardwareSection(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkVirtualHardwareSection(modifiedSection); checkVirtualHardwareSection(modifiedSection);
// Check the modified section fields are set correctly // Check the modified section fields are set correctly
ResourceAllocationSettingData modifiedMemory = Iterables.find(modifiedSection.getItems(), new Predicate<ResourceAllocationSettingData>() { ResourceAllocationSettingData modifiedMemory = Iterables.find(modifiedSection.getItems(),
new Predicate<ResourceAllocationSettingData>() {
@Override @Override
public boolean apply(ResourceAllocationSettingData rasd) { public boolean apply(ResourceAllocationSettingData rasd) {
return rasd.getResourceType() == ResourceAllocationSettingData.ResourceType.MEMORY; return rasd.getResourceType() == ResourceAllocationSettingData.ResourceType.MEMORY;
} }
}); });
assertEquals(modifiedMemory.getVirtualQuantity(), BigInteger.valueOf(1024L)); assertEquals(modifiedMemory.getVirtualQuantity(), new BigInteger("1024"));
assertEquals(modifiedMemory, newMemory); assertEquals(modifiedMemory, newMemory);
assertEquals(modifiedSection, newSection); assertEquals(modifiedSection, newSection);
} }
@Test(testName = "GET /vApp/{id}/virtualHardwareSection/cpu", dependsOnMethods = { "testGetVirtualHardwareSection" }) @Test(testName = "GET /vApp/{id}/virtualHardwareSection/cpu", dependsOnMethods = { "testGetVirtualHardwareSection" })
public void testGetVirtualHardwareSectionCpu() { public void testGetVirtualHardwareSectionCpu() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Method under test // Method under test
ResourceAllocationSettingData rasd = vAppClient.getVirtualHardwareSectionCpu(vmURI); ResourceAllocationSettingData rasd = vAppClient.getVirtualHardwareSectionCpu(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkResourceAllocationSettingData(rasd); checkResourceAllocationSettingData(rasd);
@ -903,42 +941,33 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/virtualHardwareSection/cpu", dependsOnMethods = { "testGetVirtualHardwareSectionCpu" }) @Test(testName = "PUT /vApp/{id}/virtualHardwareSection/cpu", dependsOnMethods = { "testGetVirtualHardwareSectionCpu" })
public void testModifyVirtualHardwareSectionCpu() { public void testModifyVirtualHardwareSectionCpu() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Copy existing section and update fields // Copy existing section and update fields
ResourceAllocationSettingData oldItem = vAppClient.getVirtualHardwareSectionCpu(vmURI); ResourceAllocationSettingData oldItem = vAppClient.getVirtualHardwareSectionCpu(vm.getHref());
ResourceAllocationSettingData newItem = oldItem.toBuilder() ResourceAllocationSettingData newItem = oldItem.toBuilder()
.elementName("2 virtual CPU(s)")
.virtualQuantity(new BigInteger("2"))
.build(); .build();
// Method under test // Method under test
Task modifyVirtualHardwareSectionCpu = vAppClient.modifyVirtualHardwareSectionCpu(vmURI, newItem); Task modifyVirtualHardwareSectionCpu = vAppClient.modifyVirtualHardwareSectionCpu(vm.getHref(), newItem);
assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionCpu), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionCpu")); assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionCpu), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionCpu"));
// Retrieve the modified section // Retrieve the modified section
ResourceAllocationSettingData modified = vAppClient.getVirtualHardwareSectionCpu(vmURI); ResourceAllocationSettingData modified = vAppClient.getVirtualHardwareSectionCpu(vm.getHref());
// Check the retrieved object // Check the retrieved object
checkResourceAllocationSettingData(modified); checkResourceAllocationSettingData(modified);
// TODO What is modifiable? What can we change, so we can assert the change took effect? // Check modified item
// I tried changing "weight", but it continued to have the value zero when looked up post-modify. assertEquals(modified.getVirtualQuantity(), new BigInteger("2"),
// String.format(OBJ_FIELD_EQ, "ResourceAllocationSettingData", "VirtualQuantity", "2", modified.getVirtualQuantity().toString()));
// long weight = random.nextInt(Integer.MAX_VALUE); assertEquals(modified, newItem);
// ResourceAllocationSettingData newSection = origSection.toBuilder()
// .weight(newCimUnsignedInt(weight))
// .build();
// ...
// assertEquals(modified.getWeight().getValue(), weight, String.format(OBJ_FIELD_EQ, VAPP, "virtualHardwareSection/cpu/weight", weight, ""+modified.getWeight()));
} }
@Test(testName = "GET /vApp/{id}/virtualHardwareSection/disks", dependsOnMethods = { "testGetVirtualHardwareSection" }) @Test(testName = "GET /vApp/{id}/virtualHardwareSection/disks", dependsOnMethods = { "testGetVirtualHardwareSection" })
public void testGetVirtualHardwareSectionDisks() { public void testGetVirtualHardwareSectionDisks() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Method under test // Method under test
RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionDisks(vmURI); RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionDisks(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRasdItemsList(rasdItems); checkRasdItemsList(rasdItems);
@ -946,19 +975,16 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/virtualHardwareSection/disks", dependsOnMethods = { "testGetVirtualHardwareSectionDisks" }) @Test(testName = "PUT /vApp/{id}/virtualHardwareSection/disks", dependsOnMethods = { "testGetVirtualHardwareSectionDisks" })
public void testModifyVirtualHardwareSectionDisks() { public void testModifyVirtualHardwareSectionDisks() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Copy the existing items list and modify the name of an item // Copy the existing items list and modify the name of an item
RasdItemsList oldSection = vAppClient.getVirtualHardwareSectionDisks(vmURI); RasdItemsList oldSection = vAppClient.getVirtualHardwareSectionDisks(vm.getHref());
RasdItemsList newSection = oldSection.toBuilder().build(); RasdItemsList newSection = oldSection.toBuilder().build();
// Method under test // Method under test
Task modifyVirtualHardwareSectionDisks = vAppClient.modifyVirtualHardwareSectionDisks(vmURI, newSection); Task modifyVirtualHardwareSectionDisks = vAppClient.modifyVirtualHardwareSectionDisks(vm.getHref(), newSection);
assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionDisks), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionDisks")); assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionDisks), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionDisks"));
// Retrieve the modified section // Retrieve the modified section
RasdItemsList modified = vAppClient.getVirtualHardwareSectionDisks(vmURI); RasdItemsList modified = vAppClient.getVirtualHardwareSectionDisks(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRasdItemsList(modified); checkRasdItemsList(modified);
@ -985,11 +1011,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "GET /vApp/{id}/virtualHardwareSection/media", dependsOnMethods = { "testGetVirtualHardwareSection" }) @Test(testName = "GET /vApp/{id}/virtualHardwareSection/media", dependsOnMethods = { "testGetVirtualHardwareSection" })
public void testGetVirtualHardwareSectionMedia() { public void testGetVirtualHardwareSectionMedia() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Method under test // Method under test
RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionMedia(vmURI); RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionMedia(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRasdItemsList(rasdItems); checkRasdItemsList(rasdItems);
@ -997,11 +1020,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "GET /vApp/{id}/virtualHardwareSection/memory", dependsOnMethods = { "testGetVirtualHardwareSection" }) @Test(testName = "GET /vApp/{id}/virtualHardwareSection/memory", dependsOnMethods = { "testGetVirtualHardwareSection" })
public void testGetVirtualHardwareSectionMemory() { public void testGetVirtualHardwareSectionMemory() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Method under test // Method under test
ResourceAllocationSettingData rasd = vAppClient.getVirtualHardwareSectionCpu(vmURI); ResourceAllocationSettingData rasd = vAppClient.getVirtualHardwareSectionCpu(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkResourceAllocationSettingData(rasd); checkResourceAllocationSettingData(rasd);
@ -1009,34 +1029,32 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/virtualHardwareSection/memory", dependsOnMethods = { "testGetVirtualHardwareSectionMemory" }) @Test(testName = "PUT /vApp/{id}/virtualHardwareSection/memory", dependsOnMethods = { "testGetVirtualHardwareSectionMemory" })
public void testModifyVirtualHardwareSectionMemory() { public void testModifyVirtualHardwareSectionMemory() {
// Get URI for child VM ResourceAllocationSettingData origItem = vAppClient.getVirtualHardwareSectionMemory(vm.getHref());
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref(); ResourceAllocationSettingData newItem = origItem.toBuilder()
.elementName("1024 MB of memory")
ResourceAllocationSettingData origSection = vAppClient.getVirtualHardwareSectionMemory(vmURI); .virtualQuantity(new BigInteger("1024"))
ResourceAllocationSettingData newSection = origSection.toBuilder().build(); .build();
// Method under test // Method under test
Task modifyVirtualHardwareSectionMemory = vAppClient.modifyVirtualHardwareSectionMemory(vmURI, newSection); Task modifyVirtualHardwareSectionMemory = vAppClient.modifyVirtualHardwareSectionMemory(vm.getHref(), newItem);
assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionMemory), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionMemory")); assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionMemory), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionMemory"));
// Retrieve the modified section // Retrieve the modified section
ResourceAllocationSettingData modified = vAppClient.getVirtualHardwareSectionMemory(vmURI); ResourceAllocationSettingData modified = vAppClient.getVirtualHardwareSectionMemory(vm.getHref());
// Check the retrieved object // Check the retrieved object
checkResourceAllocationSettingData(modified); checkResourceAllocationSettingData(modified);
// TODO What is modifiable? What can we change, so we can assert the change took effect? // Check modified item
// I tried changing "weight", but it continued to have the value zero when looked up post-modify. assertEquals(modified.getVirtualQuantity(), new BigInteger("1024"),
// See description under testModifyVirtualHardwareSectionMemoryCpu String.format(OBJ_FIELD_EQ, "ResourceAllocationSettingData", "VirtualQuantity", "1024", modified.getVirtualQuantity().toString()));
assertEquals(modified, newItem);
} }
@Test(testName = "GET /vApp/{id}/virtualHardwareSection/networkCards", dependsOnMethods = { "testGetVirtualHardwareSection" }) @Test(testName = "GET /vApp/{id}/virtualHardwareSection/networkCards", dependsOnMethods = { "testGetVirtualHardwareSection" })
public void testGetVirtualHardwareSectionNetworkCards() { public void testGetVirtualHardwareSectionNetworkCards() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Method under test // Method under test
RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionNetworkCards(vmURI); RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionNetworkCards(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRasdItemsList(rasdItems); checkRasdItemsList(rasdItems);
@ -1044,18 +1062,15 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/virtualHardwareSection/networkCards", dependsOnMethods = { "testGetVirtualHardwareSectionNetworkCards" }) @Test(testName = "PUT /vApp/{id}/virtualHardwareSection/networkCards", dependsOnMethods = { "testGetVirtualHardwareSectionNetworkCards" })
public void testModifyVirtualHardwareSectionNetworkCards() { public void testModifyVirtualHardwareSectionNetworkCards() {
// Get URI for child VM RasdItemsList oldSection = vAppClient.getVirtualHardwareSectionNetworkCards(vm.getHref());
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
RasdItemsList oldSection = vAppClient.getVirtualHardwareSectionNetworkCards(vmURI);
RasdItemsList newSection = oldSection.toBuilder().build(); RasdItemsList newSection = oldSection.toBuilder().build();
// Method under test // Method under test
Task modifyVirtualHardwareSectionNetworkCards = vAppClient.modifyVirtualHardwareSectionNetworkCards(vmURI, newSection); Task modifyVirtualHardwareSectionNetworkCards = vAppClient.modifyVirtualHardwareSectionNetworkCards(vm.getHref(), newSection);
assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionNetworkCards), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionNetworkCards")); assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionNetworkCards), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionNetworkCards"));
// Retrieve the modified section // Retrieve the modified section
RasdItemsList modified = vAppClient.getVirtualHardwareSectionNetworkCards(vmURI); RasdItemsList modified = vAppClient.getVirtualHardwareSectionNetworkCards(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRasdItemsList(modified); checkRasdItemsList(modified);
@ -1067,11 +1082,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "GET /vApp/{id}/virtualHardwareSection/serialPorts", dependsOnMethods = { "testGetVirtualHardwareSection" }) @Test(testName = "GET /vApp/{id}/virtualHardwareSection/serialPorts", dependsOnMethods = { "testGetVirtualHardwareSection" })
public void testGetVirtualHardwareSectionSerialPorts() { public void testGetVirtualHardwareSectionSerialPorts() {
// Get URI for child VM
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
// Method under test // Method under test
RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionSerialPorts(vmURI); RasdItemsList rasdItems = vAppClient.getVirtualHardwareSectionSerialPorts(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRasdItemsList(rasdItems); checkRasdItemsList(rasdItems);
@ -1079,18 +1091,15 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
@Test(testName = "PUT /vApp/{id}/virtualHardwareSection/serialPorts", dependsOnMethods = { "testGetVirtualHardwareSectionSerialPorts" }) @Test(testName = "PUT /vApp/{id}/virtualHardwareSection/serialPorts", dependsOnMethods = { "testGetVirtualHardwareSectionSerialPorts" })
public void testModifyVirtualHardwareSectionSerialPorts() { public void testModifyVirtualHardwareSectionSerialPorts() {
// Get URI for child VM RasdItemsList oldSection = vAppClient.getVirtualHardwareSectionSerialPorts(vm.getHref());
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
RasdItemsList oldSection = vAppClient.getVirtualHardwareSectionSerialPorts(vmURI);
RasdItemsList newSection = oldSection.toBuilder().build(); RasdItemsList newSection = oldSection.toBuilder().build();
// Method under test // Method under test
Task modifyVirtualHardwareSectionSerialPorts = vAppClient.modifyVirtualHardwareSectionSerialPorts(vmURI, newSection); Task modifyVirtualHardwareSectionSerialPorts = vAppClient.modifyVirtualHardwareSectionSerialPorts(vm.getHref(), newSection);
assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionSerialPorts), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionSerialPorts")); assertTrue(retryTaskSuccess.apply(modifyVirtualHardwareSectionSerialPorts), String.format(TASK_COMPLETE_TIMELY, "modifyVirtualHardwareSectionSerialPorts"));
// Retrieve the modified section // Retrieve the modified section
RasdItemsList modified = vAppClient.getVirtualHardwareSectionSerialPorts(vmURI); RasdItemsList modified = vAppClient.getVirtualHardwareSectionSerialPorts(vm.getHref());
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkRasdItemsList(modified); checkRasdItemsList(modified);
@ -1108,8 +1117,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
checkMetadataFor(VAPP, metadata); checkMetadataFor(VAPP, metadata);
} }
@Test(testName = "PUT & GET /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" }) @Test(testName = "PUT /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" })
public void testSetAndGetMetadataValue() { public void testSetMetadataValue() {
// Store a value // Store a value
String key = name("key-"); String key = name("key-");
String value = name("value-"); String value = name("value-");
@ -1123,7 +1132,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
checkMetadataValueFor(VAPP, newMetadataValue, value); checkMetadataValueFor(VAPP, newMetadataValue, value);
} }
@Test(testName = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetAndGetMetadataValue" }) @Test(testName = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testDeleteMetadataEntry() { public void testDeleteMetadataEntry() {
// Store a value, to be deleted // Store a value, to be deleted
String key = name("key-"); String key = name("key-");
@ -1173,13 +1182,6 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
public void testDeleteVApp() { public void testDeleteVApp() {
// Create a temporary VApp to delete // Create a temporary VApp to delete
VApp temp = instantiateVApp(); VApp temp = instantiateVApp();
DeployVAppParams params = DeployVAppParams.builder()
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS))
.notForceCustomization()
.notPowerOn()
.build();
Task deployVApp = vAppClient.deploy(temp.getHref(), params);
assertTrue(retryTaskSuccessLong.apply(deployVApp), String.format(TASK_COMPLETE_TIMELY, "deployVApp"));
// The method under test // The method under test
Task deleteVApp = vAppClient.deleteVApp(temp.getHref()); Task deleteVApp = vAppClient.deleteVApp(temp.getHref());
@ -1187,18 +1189,9 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
try { try {
vAppClient.getVApp(temp.getHref()); vAppClient.getVApp(temp.getHref());
fail("The VApp should have been deleted"); fail("The VApp "+temp+" should have been deleted");
} catch (VCloudDirectorException vcde) { } catch (VCloudDirectorException vcde) {
assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The error code should have been 'Forbidden' (403)"); assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The error code for deleted vApp should have been 'Forbidden' (403)");
}
}
private void powerOn() {
vApp = vAppClient.getVApp(vAppURI); // Refresh
Status status = Status.fromValue(vApp.getStatus());
if (status != Status.POWERED_ON) {
Task powerOn = vAppClient.powerOn(vAppURI);
assertTaskSucceedsLong(powerOn);
} }
} }
} }

View File

@ -270,6 +270,9 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
VApp vAppInstantiated = vdcClient.instantiateVApp(vdcURI, instantiate); VApp vAppInstantiated = vdcClient.instantiateVApp(vdcURI, instantiate);
assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP)); assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP));
Task instantiationTask = Iterables.getFirst(vAppInstantiated.getTasks(), null);
if (instantiationTask != null) assertTaskSucceedsLong(instantiationTask);
// Save VApp name for cleanUp // Save VApp name for cleanUp
vAppNames.add(name); vAppNames.add(name);