issue 830: fixing vAppTemplateApi*Test, vAppApiLiveTest and vmApiLiveTest

This commit is contained in:
Andrea Turli 2012-08-06 19:41:30 +02:00
parent d6aea87ab5
commit 9454aeb257
8 changed files with 52 additions and 341 deletions

View File

@ -222,8 +222,8 @@ public class NetworkConnection {
this.externalIpAddress = externalIpAddress;
this.isConnected = connected;
this.macAddress = macAddress;
this.ipAddressAllocationMode = ipAddressAllocationMode;
this.network = network;
this.ipAddressAllocationMode = checkNotNull(ipAddressAllocationMode, "ipAddressAllocationMode");
this.network = checkNotNull(network, "network");
this.needsCustomization = needsCustomization;
}

View File

@ -165,20 +165,6 @@ public interface VAppTemplateApi {
*/
CustomizationSection getCustomizationSection(URI templateUri);
/**
* Modifies the vApp template customization information.
*
* <pre>
* PUT /vAppTemplate/{id}/customizationSection
* </pre>
*
* @param templateUri the URI of the template
* @param section the new configuration to apply
* @return the task performing the action. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
*/
Task modifyCustomizationSection(URI templateUri, CustomizationSection section);
/**
* Retrieves the Guest Customization Section of a VM
*
@ -243,20 +229,6 @@ public interface VAppTemplateApi {
*/
NetworkConfigSection getNetworkConfigSection(URI templateUri);
/**
* Modifies the network config section of a vApp.
*
* <pre>
* PUT /vAppTemplate/{id}/networkConfigSection
* </pre>
*
* @param templateUri the URI of the template
* @param section the new configuration to apply
* @return the task performing the action. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
*/
Task modifyNetworkConfigSection(URI templateUri, NetworkConfigSection section);
/**
* Retrieves the network connection section of a VM
*
@ -269,20 +241,6 @@ public interface VAppTemplateApi {
*/
NetworkConnectionSection getNetworkConnectionSection(URI templateUri);
/**
* Modifies the network connection section of a VM.
*
* <pre>
* PUT /vAppTemplate/{id}/networkConnectionSection
* </pre>
*
* @param templateUri the URI of the template
* @param section the new configuration to apply
* @return the task performing the action. This operation is asynchronous and the user should monitor the returned
* task status in order to check when it is completed.
*/
Task modifyNetworkConnectionSection(URI templateUri, NetworkConnectionSection section);
/**
* Retrieves the network section of a vApp or vApp template.
*

View File

@ -147,17 +147,6 @@ public interface VAppTemplateAsyncApi {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<CustomizationSection> getCustomizationSection(@EndpointParam URI templateURI);
/**
* @see VAppTemplateApi#modifyCustomizationSection(URI, CustomizationSection)
*/
@PUT
@Produces(CUSTOMIZATION_SECTION)
@Consumes(TASK)
@Path("/customizationSection")
@JAXBResponseParser
ListenableFuture<Task> modifyCustomizationSection(@EndpointParam URI templateURI,
@BinderParam(BindToXMLPayload.class) CustomizationSection sectionType);
/**
* @see VAppTemplateApi#getGuestCustomizationSection(URI)
*/
@ -220,17 +209,6 @@ public interface VAppTemplateAsyncApi {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<NetworkConfigSection> getNetworkConfigSection(@EndpointParam URI templateURI);
/**
* @see VAppTemplateApi#modifyNetworkConfigSection(URI, NetworkConfigSection)
*/
@PUT
@Produces(NETWORK_CONFIG_SECTION)
@Consumes(TASK)
@Path("/networkConfigSection")
@JAXBResponseParser
ListenableFuture<Task> modifyNetworkConfigSection(@EndpointParam URI templateURI,
@BinderParam(BindToXMLPayload.class) NetworkConfigSection section);
/**
* @see VAppTemplateApi#getNetworkConnectionSection(URI)
*/
@ -241,17 +219,6 @@ public interface VAppTemplateAsyncApi {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<NetworkConnectionSection> getVAppTemplateNetworkConnectionSection(@EndpointParam URI templateURI);
/**
* @see VAppTemplateApi#modifyNetworkConnectionSection(URI, NetworkConnectionSection)
*/
@PUT
@Produces(NETWORK_CONNECTION_SECTION)
@Consumes(TASK)
@Path("/networkConnectionSection")
@JAXBResponseParser
ListenableFuture<Task> modifyNetworkConnectionSection(@EndpointParam URI templateURI,
@BinderParam(BindToXMLPayload.class) NetworkConnectionSection section);
/**
* @see VAppTemplateApi#getNetworkSection(URI)
*/

View File

@ -47,6 +47,7 @@ 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.Vm;
import org.jclouds.vcloud.director.v1_5.domain.dmtf.RasdItem;
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.section.GuestCustomizationSection;
import org.jclouds.vcloud.director.v1_5.domain.section.NetworkConnectionSection;
import org.jclouds.vcloud.director.v1_5.features.CatalogApi;
@ -112,7 +113,6 @@ public abstract class AbstractVAppApiLiveTest extends BaseVCloudDirectorApiLiveT
* @see BaseVCloudDirectorApiLiveTest#setupRequiredApis()
*/
@Override
@BeforeClass(alwaysRun = true, description = "Retrieves the required apis from the REST API context")
protected void setupRequiredApis() {
assertNotNull(context.getApi());
@ -122,14 +122,13 @@ public abstract class AbstractVAppApiLiveTest extends BaseVCloudDirectorApiLiveT
vAppTemplateApi = context.getApi().getVAppTemplateApi();
vdcApi = context.getApi().getVdcApi();
vmApi = context.getApi().getVmApi();
setupEnvironment();
}
/**
* Sets up the environment. Retrieves the test {@link Vdc} and {@link VAppTemplate} from their
* configured {@link URI}s. Instantiates a new test VApp.
*/
@BeforeClass(alwaysRun = true, description = "Retrieves the required apis from the REST API context")
protected void setupEnvironment() {
// Get the configured Vdc for the tests
vdc = vdcApi.getVdc(vdcURI);
@ -295,9 +294,10 @@ public abstract class AbstractVAppApiLiveTest extends BaseVCloudDirectorApiLiveT
protected Vm powerOffVm(final URI testVmURI) {
Vm test = vmApi.getVm(testVmURI);
Status status = test.getStatus();
if (status != Status.POWERED_OFF) {
Task powerOff = vmApi.powerOff(vm.getHref());
assertTaskSucceedsLong(powerOff);
if (status != Status.POWERED_OFF || test.isDeployed()) {
UndeployVAppParams undeployParams = UndeployVAppParams.builder().build();
Task shutdownVapp = vAppApi.undeploy(test.getHref(), undeployParams);
assertTaskSucceedsLong(shutdownVapp);
}
test = vmApi.getVm(testVmURI);
assertStatus(VM, test, Status.POWERED_OFF);

View File

@ -103,7 +103,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
private boolean mediaCreated = false;
private boolean testUserCreated = false;
@BeforeClass(alwaysRun = true, dependsOnMethods = { "setupRequiredApis" })
@BeforeClass(alwaysRun = true)
protected void setupRequiredEntities() {
Set<Link> links = vdcApi.getVdc(vdcURI).getLinks();

View File

@ -49,24 +49,10 @@ import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.network.FirewallRule;
import org.jclouds.vcloud.director.v1_5.domain.network.FirewallRuleProtocols;
import org.jclouds.vcloud.director.v1_5.domain.network.FirewallService;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRange;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRanges;
import org.jclouds.vcloud.director.v1_5.domain.network.IpScope;
import org.jclouds.vcloud.director.v1_5.domain.network.NatOneToOneVmRule;
import org.jclouds.vcloud.director.v1_5.domain.network.NatRule;
import org.jclouds.vcloud.director.v1_5.domain.network.NatService;
import org.jclouds.vcloud.director.v1_5.domain.network.Network.FenceMode;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkFeatures;
import org.jclouds.vcloud.director.v1_5.domain.network.VAppNetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.params.RelocateParams;
import org.jclouds.vcloud.director.v1_5.domain.section.CustomizationSection;
import org.jclouds.vcloud.director.v1_5.domain.section.GuestCustomizationSection;
import org.jclouds.vcloud.director.v1_5.domain.section.LeaseSettingsSection;
import org.jclouds.vcloud.director.v1_5.domain.section.NetworkConfigSection;
import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTest;
import org.testng.annotations.Test;
@ -256,27 +242,6 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
api.relocateVm(uri, params);
}
@Test
public void testCustomizationSection() {
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
URI uri = URI.create(endpoint + templateId);
VAppTemplateApi api = orderedRequestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/customizationSection").acceptMedia(CUSTOMIZATION_SECTION).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/customizationSection.xml", CUSTOMIZATION_SECTION).httpResponseBuilder().build(),
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/customizationSection").xmlFilePayload("/vapptemplate/customizationSection.xml", CUSTOMIZATION_SECTION).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/task/task.xml", TASK).httpResponseBuilder().build()
).getVAppTemplateApi();
assertNotNull(api);
CustomizationSection section = api.getCustomizationSection(uri);
assertEquals(section, exampleCustomizationSection());
Task task = api.modifyCustomizationSection(uri, exampleCustomizationSection());
assertNotNull(task);
}
public void testErrorGetCustomizationSection() {
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
URI uri = URI.create(endpoint + templateId);
@ -288,18 +253,6 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
assertNull(api.getCustomizationSection(uri));
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testErrorEditCustomizationSection() {
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
URI uri = URI.create(endpoint + templateId);
VAppTemplateApi api = orderedRequestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/customizationSection").xmlFilePayload("/vapptemplate/customizationSection.xml", CUSTOMIZATION_SECTION).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi();
api.modifyCustomizationSection(uri, exampleCustomizationSection());
}
public void testGuestCustomizationSection() {
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
URI uri = URI.create(endpoint + templateId);
@ -490,27 +443,6 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
api.getMetadataApi().deleteMetadataEntry(uri, "12345");
}
public void testNetworkConfigSection() throws ParseException {
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
URI uri = URI.create(endpoint + templateId);
VAppTemplateApi api = orderedRequestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/networkConfigSection").acceptMedia(NETWORK_CONFIG_SECTION).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/networkConfigSection.xml", NETWORK_CONFIG_SECTION).httpResponseBuilder().build(),
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/networkConfigSection").xmlFilePayload("/vapptemplate/networkConfigSection.xml", NETWORK_CONFIG_SECTION).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/task/task.xml", TASK).httpResponseBuilder().build()
).getVAppTemplateApi();
assertNotNull(api);
NetworkConfigSection section = api.getNetworkConfigSection(uri);
assertEquals(section, exampleNetworkConfigSection());
Task task = api.modifyNetworkConfigSection(uri, exampleNetworkConfigSection());
assertNotNull(task);
}
@Test(expectedExceptions = VCloudDirectorException.class)
public void testErrorGetNetworkConfigSection() {
@ -524,18 +456,6 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
api.getNetworkConfigSection(uri);
}
@Test(expectedExceptions = VCloudDirectorException.class)
public void testErrorEditNetworkConfigSection() throws ParseException {
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
URI uri = URI.create(endpoint + templateId);
VAppTemplateApi api = orderedRequestsSendResponses(loginRequest, sessionResponse,
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/networkConfigSection").xmlFilePayload("/vapptemplate/networkConfigSection.xml", NETWORK_CONFIG_SECTION).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.modifyNetworkConfigSection(uri, exampleNetworkConfigSection());
}
private VAppTemplate exampleTemplate() {
Link aLink = Link.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
.type("application/vnd.vmware.vcloud.vdc+xml").rel("up").build();
@ -575,20 +495,6 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
.build();
}
private CustomizationSection exampleCustomizationSection() {
return CustomizationSection.builder()
.links(ImmutableSet.of(
Link.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/customizationSection/"))
.type("application/vnd.vmware.vcloud.customizationSection+xml").rel("edit").build()
))
.type("application/vnd.vmware.vcloud.customizationSection+xml")
.info("VApp template customization section")
.customizeOnInstantiate(true)
.href(URI.create("https://vcloudbeta.bluelock.com/api/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9/customizationSection/"))
.required(false)
.build();
}
private GuestCustomizationSection exampleGuestCustomizationSection() {
return GuestCustomizationSection.builder()
.links(ImmutableSet.of(
@ -640,59 +546,4 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
return MetadataValue.builder().value("some value").build();
}
private NetworkConfigSection exampleNetworkConfigSection() throws ParseException {
FirewallService firewallService =
FirewallService.builder()
.enabled(true)
.firewallRules(
ImmutableSet.of(
FirewallRule.builder()
.isEnabled(true)
.description("FTP Rule")
.policy("allow")
.protocols(FirewallRuleProtocols.builder().tcp(true).build())
.port(21)
.destinationIp("10.147.115.1")
.build(),
FirewallRule.builder()
.isEnabled(true)
.description("SSH Rule")
.policy("allow")
.protocols(FirewallRuleProtocols.builder().tcp(true).build())
.port(22)
.destinationIp("10.147.115.1")
.build())).build();
NatService natService = NatService.builder().enabled(true).natType("ipTranslation").policy("allowTraffic")
.natRules(ImmutableSet.of(NatRule.builder().oneToOneVmRule(
NatOneToOneVmRule.builder().mappingMode("manual").externalIpAddress("64.100.10.1").vAppScopedVmId("20ea086f-1a6a-4fb2-8e2e-23372facf7de").vmNicId(0).build()).build()
)).build();
NetworkConfiguration networkConfiguration = NetworkConfiguration.builder().ipScope(
IpScope.builder()
.isInherited(false)
.gateway("10.147.56.253")
.netmask("255.255.255.0")
.dns1("10.147.115.1")
.dns2("10.147.115.2")
.dnsSuffix("example.com")
.ipRanges(IpRanges.builder().ipRange(IpRange.builder().startAddress("10.147.56.1").endAddress("10.147.56.1").build()).build())
.build())
.parentNetwork(Reference.builder().href(URI.create("http://vcloud.example.com/api/v1.0/network/54")).type("application/vnd.vmware.vcloud.network+xml").name("Internet").build())
.fenceMode(FenceMode.NAT_ROUTED)
.features(NetworkFeatures.builder().services(ImmutableSet.of(firewallService, natService)).build())
.build();
return NetworkConfigSection.builder()
.info("Configuration parameters for logical networks")
.networkConfigs(
ImmutableSet.of(
VAppNetworkConfiguration.builder()
.networkName("vAppNetwork")
.configuration(
networkConfiguration
).build()
)).build();
}
}

View File

@ -26,7 +26,6 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfEnvelope;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfNetworkSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOwner;
@ -60,8 +59,6 @@ import org.jclouds.vcloud.director.v1_5.domain.References;
import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
import org.jclouds.vcloud.director.v1_5.domain.dmtf.Envelope;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection.IpAddressAllocationMode;
import org.jclouds.vcloud.director.v1_5.domain.params.CloneVAppTemplateParams;
import org.jclouds.vcloud.director.v1_5.domain.params.RelocateParams;
import org.jclouds.vcloud.director.v1_5.domain.section.CustomizationSection;
@ -89,7 +86,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
private String key;
private String val;
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
protected void tidyUp() {
if (key != null) {
@ -101,11 +98,12 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
}
}
}
// FIXME cloneVAppTemplate is giving back 500 error
private VAppTemplate cloneVAppTemplate(boolean waitForTask) throws Exception {
CloneVAppTemplateParams cloneVAppTemplateParams = CloneVAppTemplateParams.builder()
.source(Reference.builder().href(vAppTemplateURI).build())
.isSourceDelete(false)
.name("clone")
.build();
VAppTemplate clonedVappTemplate = vdcApi.cloneVAppTemplate(vdcURI, cloneVAppTemplateParams);
@ -114,7 +112,6 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
assertNotNull(cloneTask, "vdcApi.cloneVAppTemplate returned VAppTemplate that did not contain any tasks");
assertTaskSucceeds(cloneTask);
}
return clonedVappTemplate;
}
@ -306,34 +303,15 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
assertEquals(modified.getComputerName(), computerName);
}
@Test(description = "PUT /vAppTemplate/{id}/customizationSection")
public void testEditCustomizationSection() {
boolean oldVal = vAppTemplateApi.getCustomizationSection(vAppTemplateURI).isCustomizeOnInstantiate();
boolean newVal = !oldVal;
CustomizationSection customizationSection = CustomizationSection.builder()
.info("")
.customizeOnInstantiate(newVal)
.build();
final Task task = vAppTemplateApi.modifyCustomizationSection(vAppTemplateURI, customizationSection);
assertTaskSucceeds(task);
CustomizationSection newCustomizationSection = vAppTemplateApi.getCustomizationSection(vAppTemplateURI);
assertEquals(newCustomizationSection.isCustomizeOnInstantiate(), newVal);
}
// FIXME deploymentLeaseInSeconds returned is null
// NOTE vAppTemplate supports only storageLease (deployment lease applies to vApp too)
@Test(description = "PUT /vAppTemplate/{id}/leaseSettingsSection")
public void testEditLeaseSettingsSection() throws Exception {
int deploymentLeaseInSeconds = random.nextInt(10000)+1;
// NOTE use smallish number for storageLeaseInSeconds; it seems to be capped at 5184000?
int storageLeaseInSeconds = random.nextInt(10000)+1;
LeaseSettingsSection leaseSettingSection = LeaseSettingsSection.builder()
.info("my info")
.storageLeaseInSeconds(storageLeaseInSeconds)
.deploymentLeaseInSeconds(deploymentLeaseInSeconds)
.build();
final Task task = vAppTemplateApi.modifyLeaseSettingsSection(vAppTemplateURI, leaseSettingSection);
@ -341,65 +319,8 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
LeaseSettingsSection newLeaseSettingsSection = vAppTemplateApi.getLeaseSettingsSection(vAppTemplateURI);
assertEquals(newLeaseSettingsSection.getStorageLeaseInSeconds(), (Integer) storageLeaseInSeconds);
assertEquals(newLeaseSettingsSection.getDeploymentLeaseInSeconds(), (Integer) deploymentLeaseInSeconds);
}
@Test(description = "PUT /vAppTemplate/{id}/networkConfigSection")
public void testEditNetworkConfigSection() {
// TODO What to modify?
NetworkConfigSection oldSection = vAppTemplateApi.getNetworkConfigSection(vApp.getHref());
NetworkConfigSection newSection = oldSection.toBuilder().build();
// String networkName = ""+random.nextInt();
// NetworkConfiguration networkConfiguration = NetworkConfiguration.builder()
// .fenceMode("isolated")
// .build();
// VAppNetworkConfiguration vappNetworkConfiguration = VAppNetworkConfiguration.builder()
// .networkName(networkName)
// .configuration(networkConfiguration)
// .build();
// Set<VAppNetworkConfiguration> vappNetworkConfigurations = ImmutableSet.of(vappNetworkConfiguration);
// NetworkConfigSection networkConfigSection = NetworkConfigSection.builder()
// .info("my info")
// .networkConfigs(vappNetworkConfigurations)
// .build();
final Task task = vAppTemplateApi.modifyNetworkConfigSection(vApp.getHref(), newSection);
assertTaskSucceeds(task);
NetworkConfigSection modified = vAppTemplateApi.getNetworkConfigSection(vAppTemplateURI);
checkNetworkConfigSection(modified);
// assertEquals(modified§.getNetworkConfigs().size(), 1);
//
// VAppNetworkConfiguration newVAppNetworkConfig = Iterables.get(modified§.getNetworkConfigs(), 0);
// assertEquals(newVAppNetworkConfig.getNetworkName(), networkName);
}
@Test(description = "PUT /vAppTemplate/{id}/networkConnectionSection")
public void testEditNetworkConnectionSection() {
// Look up a network in the Vdc
Set<Reference> networks = vdc.getAvailableNetworks();
Reference network = Iterables.getLast(networks);
// Copy existing section and update fields
NetworkConnectionSection oldSection = vAppTemplateApi.getNetworkConnectionSection(vm.getHref());
NetworkConnectionSection newSection = oldSection.toBuilder()
.networkConnection(NetworkConnection.builder()
.ipAddressAllocationMode(IpAddressAllocationMode.DHCP.toString())
.network(network.getName())
.build())
.build();
Task task = vAppTemplateApi.modifyNetworkConnectionSection(vm.getHref(), newSection);
assertTaskSucceeds(task);
NetworkConnectionSection modified = vAppTemplateApi.getNetworkConnectionSection(vm.getHref());
checkNetworkConnectionSection(modified);
}
// FIXME cloneVAppTemplate is giving back 500 error
@Test(description = "DELETE /vAppTemplate/{id}", dependsOnMethods = { "testGetVAppTemplate" })
public void testDeleteVAppTemplate() throws Exception {
VAppTemplate clonedVappTemplate = cloneVAppTemplate(true);

View File

@ -121,7 +121,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
private boolean mediaCreated = false;
private boolean testUserCreated = false;
@BeforeClass(alwaysRun = true, dependsOnMethods = { "setupRequiredApis" })
@BeforeClass(alwaysRun = true)
protected void setupRequiredEntities() {
Set<Link> links = vdcApi.getVdc(vdcURI).getLinks();
@ -280,23 +280,20 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
assertVmStatus(vmURI, Status.POWERED_OFF);
}
@Test(description = "POST /vApp/{id}/power/action/shutdown", dependsOnMethods = { "testDeployVm" })
@Test(description = "POST /vApp/{id}/power/action/shutdown", dependsOnMethods = { "testInstallVMwareTools" })
public void testShutdown() {
// Power on Vm
vm = powerOnVm(vm.getHref());
// The method under test
Task shutdown = vmApi.shutdown(vmURI);
Task shutdown = vmApi.shutdown(vm.getHref());
assertTaskSucceedsLong(shutdown);
// Get the updated Vm
vm = vmApi.getVm(vmURI);
vm = vmApi.getVm(vm.getHref());
// Check status
assertVmStatus(vmURI, Status.POWERED_OFF);
// Power on the Vm again
vm = powerOnVm(vm.getHref());
assertVmStatus(vm.getHref(), Status.POWERED_OFF);
}
@Test(description = "POST /vApp/{id}/power/action/suspend", dependsOnMethods = { "testDeployVm" })
@ -359,6 +356,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
vm = powerOnVm(vm.getHref());
// The method under test
// NB this will put the vm in partially powered off state
Task powerOffVm = vmApi.powerOff(vm.getHref());
assertTrue(retryTaskSuccess.apply(powerOffVm), String.format(TASK_COMPLETE_TIMELY, "powerOffVm"));
@ -391,8 +389,8 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "POST /vApp/{id}/action/installVMwareTools", dependsOnMethods = { "testDeployVm" })
public void testInstallVMwareTools() {
// First ensure the vApp is powered n
vm = powerOnVm(vm.getHref());
// First ensure the vApp is powered on
vm = powerOnVm(vm.getHref());
// The method under test
Task installVMwareTools = vmApi.installVMwareTools(vm.getHref());
@ -420,6 +418,9 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
// The method under test
Task upgradeHardwareVersion = vmApi.upgradeHardwareVersion(vm.getHref());
assertTrue(retryTaskSuccess.apply(upgradeHardwareVersion), String.format(TASK_COMPLETE_TIMELY, "upgradeHardwareVersion"));
// Power on the Vm again
vm = powerOnVm(vm.getHref());
}
@Test(description = "GET /vApp/{id}/guestCustomizationSection", dependsOnMethods = { "testGetVm" })
@ -438,7 +439,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
GuestCustomizationSection oldSection = vmApi.getGuestCustomizationSection(vm.getHref());
GuestCustomizationSection newSection = oldSection.toBuilder()
.computerName(name("n"))
.enabled(Boolean.FALSE)
.enabled(Boolean.TRUE)
.adminPassword(null) // Not allowed
.build();
@ -454,7 +455,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
// Check the modified section fields are set correctly
assertEquals(modified.getComputerName(), newSection.getComputerName());
assertFalse(modified.isEnabled());
assertTrue(modified.isEnabled());
// Reset the admin password in the retrieved GuestCustomizationSection for equality check
modified = modified.toBuilder().adminPassword(null).build();
@ -499,8 +500,9 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
}
// FIXME "Task error: Unable to perform this action. Contact your cloud administrator."
@Test(description = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testGetNetworkConnectionSection" })
@Test(description = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testModifyGuestCustomizationSection" })
public void testModifyNetworkConnectionSection() {
powerOffVm(vm.getHref());
// Look up a network in the Vdc
Set<Reference> networks = vdc.getAvailableNetworks();
Reference network = Iterables.getLast(networks);
@ -574,6 +576,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "PUT /vApp/{id}/productSections", dependsOnMethods = { "testGetProductSections" })
public void testModifyProductSections() {
powerOffVm(vm.getHref());
// Copy existing section and update fields
ProductSectionList oldSections = vmApi.getProductSections(vm.getHref());
ProductSectionList newSections = oldSections.toBuilder()
@ -600,7 +603,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
assertEquals(modified.getProductSections().size(), oldSections.getProductSections().size() + 1);
// Check the section was modified correctly
assertEquals(modified, newSections, String.format(ENTITY_EQUAL, "ProductSectionList"));
assertEquals(modified, newSections);
}
// FIXME How do we force it to ask a question?
@ -646,7 +649,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
}
// FIXME If still failing, consider escalating?
@Test(description = "GET /vApp/{id}/screen", dependsOnMethods = { "testDeployVm" })
@Test(description = "GET /vApp/{id}/screen", dependsOnMethods = { "testInstallVMwareTools" })
public void testGetScreenImage() {
// Power on Vm
vm = powerOnVm(vm.getHref());
@ -933,18 +936,23 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
checkMetadata(metadata);
// Check requirements for this test
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), String.format(NOT_EMPTY_OBJECT_FMT, "MetadataEntry", "vm"));
assertTrue(Iterables.isEmpty(metadata.getMetadataEntries()), String.format(NOT_EMPTY_OBJECT_FMT, "MetadataEntry", "vm"));
}
@Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetOrgMetadataValue() {
key = name("key-");
String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build();
vmApi.getMetadataApi().setMetadata(vm.getHref(), key, metadataValue);
// Call the method being tested
MetadataValue value = vmApi.getMetadataApi().getMetadataValue(vm.getHref(), key);
MetadataValue metadataValue = vmApi.getMetadataApi().getMetadataValue(vm.getHref(), key);
String expected = metadataValue.getValue();
checkMetadataValue(value);
assertEquals(value.getValue(), expected, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value.getValue()));
checkMetadataValue(metadataValue);
assertEquals(metadataValue.getValue(), expected, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, metadataValue.getValue()));
}
@Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
@ -1002,11 +1010,17 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
// Get the updated VApp and the Vm
delete = vAppApi.getVApp(delete.getHref());
Vm temp = Iterables.getOnlyElement(delete.getChildren().getVms());
// Power off the Vm
temp = powerOffVm(temp.getHref());
List<Vm> vms = delete.getChildren().getVms();
Vm temp = Iterables.get(vms, 0);
// otherwise it's impossible to stop a running vApp with no vms
if(vms.size() == 1) {
UndeployVAppParams undeployParams = UndeployVAppParams.builder().build();
Task shutdownVapp = vAppApi.undeploy(delete.getHref(), undeployParams);
assertTaskSucceedsLong(shutdownVapp);
} else {
powerOffVm(temp.getHref());
}
// The method under test
Task deleteVm = vmApi.deleteVm(temp.getHref());
assertTrue(retryTaskSuccess.apply(deleteVm), String.format(TASK_COMPLETE_TIMELY, "deleteVm"));