mirror of https://github.com/apache/jclouds.git
Merge pull request #824 from andreaturli/vdir
issue 830: added systemadmin package; more tests fixed
This commit is contained in:
commit
b3907ebf77
|
@ -50,6 +50,7 @@ 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.dmtf.RasdItem;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection;
|
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.network.VAppNetworkConfiguration;
|
import org.jclouds.vcloud.director.v1_5.domain.network.VAppNetworkConfiguration;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection.IpAddressAllocationMode;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
|
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.GuestCustomizationSection;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.section.NetworkConnectionSection;
|
import org.jclouds.vcloud.director.v1_5.domain.section.NetworkConnectionSection;
|
||||||
|
@ -298,7 +299,7 @@ public abstract class AbstractVAppApiLiveTest extends BaseVCloudDirectorApiLiveT
|
||||||
Status status = test.getStatus();
|
Status status = test.getStatus();
|
||||||
if (status != Status.POWERED_OFF || test.isDeployed()) {
|
if (status != Status.POWERED_OFF || test.isDeployed()) {
|
||||||
UndeployVAppParams undeployParams = UndeployVAppParams.builder().build();
|
UndeployVAppParams undeployParams = UndeployVAppParams.builder().build();
|
||||||
Task shutdownVapp = vAppApi.undeploy(vmUrn, undeployParams);
|
Task shutdownVapp = vmApi.undeploy(vmUrn, undeployParams);
|
||||||
assertTaskSucceedsLong(shutdownVapp);
|
assertTaskSucceedsLong(shutdownVapp);
|
||||||
}
|
}
|
||||||
test = vmApi.get(vmUrn);
|
test = vmApi.get(vmUrn);
|
||||||
|
@ -396,4 +397,27 @@ public abstract class AbstractVAppApiLiveTest extends BaseVCloudDirectorApiLiveT
|
||||||
Set<VAppNetworkConfiguration> vAppNetworkConfigs = vAppApi.getNetworkConfigSection(vApp.getId()).getNetworkConfigs();
|
Set<VAppNetworkConfiguration> vAppNetworkConfigs = vAppApi.getNetworkConfigSection(vApp.getId()).getNetworkConfigs();
|
||||||
return vAppNetworkConfigs;
|
return vAppNetworkConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void attachVmToVAppNetwork(Vm vm, String vAppNetworkName) {
|
||||||
|
Set<NetworkConnection> networkConnections = vmApi.getNetworkConnectionSection(vm.getId())
|
||||||
|
.getNetworkConnections();
|
||||||
|
|
||||||
|
NetworkConnectionSection section = NetworkConnectionSection.builder()
|
||||||
|
.info("info")
|
||||||
|
.primaryNetworkConnectionIndex(0)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
for (NetworkConnection networkConnection : networkConnections) {
|
||||||
|
NetworkConnection newNetworkConnection = networkConnection.toBuilder()
|
||||||
|
.network(vAppNetworkName)
|
||||||
|
.isConnected(true)
|
||||||
|
.networkConnectionIndex(0)
|
||||||
|
.ipAddressAllocationMode(IpAddressAllocationMode.POOL)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
section = section.toBuilder().networkConnection(newNetworkConnection).build();
|
||||||
|
}
|
||||||
|
Task configureNetwork = vmApi.editNetworkConnectionSection(vm.getId(), section);
|
||||||
|
assertTaskSucceedsLong(configureNetwork);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,4 +214,4 @@ public class KeyPairsApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
assertTrue(retryTaskSuccess.apply(setKeyPair),
|
assertTrue(retryTaskSuccess.apply(setKeyPair),
|
||||||
String.format(TASK_COMPLETE_TIMELY, "setKeyPair"));
|
String.format(TASK_COMPLETE_TIMELY, "setKeyPair"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shared state between dependent tests.
|
* Shared state between dependent tests.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -26,7 +26,6 @@ import static org.testng.Assert.assertTrue;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -49,6 +48,7 @@ import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,6 +79,8 @@ public class QueryApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
public void setupRequiredApis() {
|
public void setupRequiredApis() {
|
||||||
queryApi = context.getApi().getQueryApi();
|
queryApi = context.getApi().getQueryApi();
|
||||||
vAppApi = context.getApi().getVAppApi();
|
vAppApi = context.getApi().getVAppApi();
|
||||||
|
|
||||||
|
cleanUpVAppTemplateInOrg();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "GET /query")
|
@Test(description = "GET /query")
|
||||||
|
@ -142,15 +144,21 @@ public class QueryApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
+ "; but only has " + hrefs);
|
+ "; but only has " + hrefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "GET /vApps/query?filter", dependsOnMethods = { "testQueryAllVApps" })
|
@Test(description = "GET /vApps/query?filter", dependsOnMethods = { "testQueryAllVApps" })
|
||||||
public void testQueryVAppsWithFilter() {
|
public void testQueryVAppsWithFilter() {
|
||||||
QueryResultRecords queryResult = queryApi.vAppsQuery(String.format("name==%s", vApp.getName()));
|
QueryResultRecords queryResult = queryApi.vAppsQuery(String.format(
|
||||||
Set<URI> hrefs = toHrefs(queryResult);
|
"name==%s", vApp.getName()));
|
||||||
|
Set<URI> hrefs = toHrefs(queryResult);
|
||||||
|
|
||||||
assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VAPP, null), QueryResultVAppRecord.class);
|
assertRecordTypes(queryResult,
|
||||||
assertEquals(hrefs, Collections.singleton(vApp.getHref()),
|
Arrays.asList(VCloudDirectorMediaType.VAPP, null),
|
||||||
"VApps query result should have found vApp " + vApp.getHref());
|
QueryResultVAppRecord.class);
|
||||||
}
|
String message = "VApps query result should have found vApp "
|
||||||
|
+ vApp.getHref();
|
||||||
|
assertTrue(
|
||||||
|
ImmutableSet.copyOf(hrefs).equals(
|
||||||
|
ImmutableSet.of(vApp.getHref())), message);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(description = "GET /vms/query", dependsOnMethods = { "testQueryAllVApps" })
|
@Test(description = "GET /vms/query", dependsOnMethods = { "testQueryAllVApps" })
|
||||||
public void testQueryAllVms() {
|
public void testQueryAllVms() {
|
||||||
|
@ -177,18 +185,24 @@ public class QueryApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
+ hrefs);
|
+ hrefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "GET /vms/query?filter", dependsOnMethods = { "testQueryAllVms" })
|
@Test(description = "GET /vms/query?filter", dependsOnMethods = { "testQueryAllVms" })
|
||||||
public void testQueryAllVmsWithFilter() {
|
public void testQueryAllVmsWithFilter() {
|
||||||
List<Vm> vms = vApp.getChildren().getVms();
|
List<Vm> vms = vApp.getChildren().getVms();
|
||||||
Set<URI> vmHrefs = toHrefs(vms);
|
Set<URI> vmHrefs = toHrefs(vms);
|
||||||
|
|
||||||
QueryResultRecords queryResult = queryApi.vmsQuery(String.format("containerName==%s", vApp.getName()));
|
QueryResultRecords queryResult = queryApi.vmsQuery(String.format(
|
||||||
Set<URI> hrefs = toHrefs(queryResult);
|
"containerName==%s", vApp.getName()));
|
||||||
|
Set<URI> hrefs = toHrefs(queryResult);
|
||||||
|
|
||||||
assertRecordTypes(queryResult, Arrays.asList(VCloudDirectorMediaType.VM, null), QueryResultVMRecord.class);
|
assertRecordTypes(queryResult,
|
||||||
assertEquals(hrefs, vmHrefs, "VMs query result should equal vms of vApp " + vApp.getName() + " (" + vmHrefs
|
Arrays.asList(VCloudDirectorMediaType.VM, null),
|
||||||
+ "); but only has " + hrefs);
|
QueryResultVMRecord.class);
|
||||||
}
|
String message = "VMs query result should equal vms of vApp "
|
||||||
|
+ vApp.getName() + " (" + vmHrefs + "); but only has " + hrefs;
|
||||||
|
assertTrue(
|
||||||
|
ImmutableSet.copyOf(hrefs).equals(ImmutableSet.copyOf(vmHrefs)),
|
||||||
|
message);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(description = "GET /mediaList/query")
|
@Test(description = "GET /mediaList/query")
|
||||||
public void testQueryAllMedia() {
|
public void testQueryAllMedia() {
|
||||||
|
@ -230,4 +244,5 @@ public class QueryApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
}
|
}
|
||||||
return hrefs;
|
return hrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,57 +432,6 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
String.format(TASK_COMPLETE_TIMELY, "discardSuspendedState"));
|
String.format(TASK_COMPLETE_TIMELY, "discardSuspendedState"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "POST /vApp/{id}/action/enterMaintenanceMode", groups = { "systemAdmin" })
|
|
||||||
public void testEnterMaintenanceMode() {
|
|
||||||
|
|
||||||
// Do this to a new vApp, so don't mess up subsequent tests by making the vApp read-only
|
|
||||||
VApp temp = instantiateVApp();
|
|
||||||
DeployVAppParams params = DeployVAppParams.builder()
|
|
||||||
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS)).notForceCustomization()
|
|
||||||
.notPowerOn().build();
|
|
||||||
Task deployVApp = vAppApi.deploy(temp.getId(), params);
|
|
||||||
assertTaskSucceedsLong(deployVApp);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Method under test
|
|
||||||
vAppApi.enterMaintenanceMode(temp.getId());
|
|
||||||
|
|
||||||
temp = vAppApi.get(temp.getId());
|
|
||||||
assertTrue(temp.isInMaintenanceMode(),
|
|
||||||
String.format(CONDITION_FMT, "InMaintenanceMode", "TRUE", temp.isInMaintenanceMode()));
|
|
||||||
|
|
||||||
// Exit maintenance mode
|
|
||||||
vAppApi.exitMaintenanceMode(temp.getId());
|
|
||||||
} finally {
|
|
||||||
cleanUpVApp(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(description = "POST /vApp/{id}/action/exitMaintenanceMode", dependsOnMethods = { "testEnterMaintenanceMode" }, groups = { "systemAdmin" })
|
|
||||||
public void testExitMaintenanceMode() {
|
|
||||||
// Do this to a new vApp, so don't mess up subsequent tests by making the vApp read-only
|
|
||||||
VApp temp = instantiateVApp();
|
|
||||||
DeployVAppParams params = DeployVAppParams.builder()
|
|
||||||
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS)).notForceCustomization()
|
|
||||||
.notPowerOn().build();
|
|
||||||
Task deployVApp = vAppApi.deploy(temp.getId(), params);
|
|
||||||
assertTaskSucceedsLong(deployVApp);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Enter maintenance mode
|
|
||||||
vAppApi.enterMaintenanceMode(temp.getId());
|
|
||||||
|
|
||||||
// Method under test
|
|
||||||
vAppApi.exitMaintenanceMode(temp.getId());
|
|
||||||
|
|
||||||
temp = vAppApi.get(temp.getId());
|
|
||||||
assertFalse(temp.isInMaintenanceMode(),
|
|
||||||
String.format(CONDITION_FMT, "InMaintenanceMode", "FALSE", temp.isInMaintenanceMode()));
|
|
||||||
} finally {
|
|
||||||
cleanUpVApp(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(groups = { "live", "user" }, description = "GET /vApp/{id}/controlAccess", dependsOnMethods = { "testGetVApp" })
|
@Test(groups = { "live", "user" }, description = "GET /vApp/{id}/controlAccess", dependsOnMethods = { "testGetVApp" })
|
||||||
public void testGetControlAccess() {
|
public void testGetControlAccess() {
|
||||||
// The method under test
|
// The method under test
|
||||||
|
|
|
@ -189,29 +189,6 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachVmToVAppNetwork(Vm vm, String vAppNetworkName) {
|
|
||||||
Set<NetworkConnection> networkConnections = vmApi.getNetworkConnectionSection(vm.getId())
|
|
||||||
.getNetworkConnections();
|
|
||||||
|
|
||||||
NetworkConnectionSection section = NetworkConnectionSection.builder()
|
|
||||||
.info("info")
|
|
||||||
.primaryNetworkConnectionIndex(0)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
for (NetworkConnection networkConnection : networkConnections) {
|
|
||||||
NetworkConnection newNetworkConnection = networkConnection.toBuilder()
|
|
||||||
.network(vAppNetworkName)
|
|
||||||
.isConnected(true)
|
|
||||||
.networkConnectionIndex(0)
|
|
||||||
.ipAddressAllocationMode(IpAddressAllocationMode.POOL)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
section = section.toBuilder().networkConnection(newNetworkConnection).build();
|
|
||||||
}
|
|
||||||
Task configureNetwork = vmApi.editNetworkConnectionSection(vm.getId(), section);
|
|
||||||
assertTaskSucceedsLong(configureNetwork);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IpScope addNewIpScope() {
|
private IpScope addNewIpScope() {
|
||||||
IpRange newIpRange = addIpRange();
|
IpRange newIpRange = addIpRange();
|
||||||
IpRanges newIpRanges = IpRanges.builder()
|
IpRanges newIpRanges = IpRanges.builder()
|
||||||
|
|
|
@ -31,6 +31,7 @@ import static org.testng.Assert.fail;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.dmtf.ovf.NetworkSection;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
|
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||||
|
@ -139,9 +140,12 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
|
|
||||||
@Test(description = "POST /vdc/{id}/action/captureVApp", dependsOnMethods = { "testInstantiateVAppTemplate" })
|
@Test(description = "POST /vdc/{id}/action/captureVApp", dependsOnMethods = { "testInstantiateVAppTemplate" })
|
||||||
public void testCaptureVApp() {
|
public void testCaptureVApp() {
|
||||||
|
VAppTemplate vAppTemplate = vappTemplateApi.get(vAppTemplateUrn);
|
||||||
String name = name("captured-");
|
String name = name("captured-");
|
||||||
|
|
||||||
CaptureVAppParams captureVappParams = CaptureVAppParams.builder().name(name).source(instantiatedVApp.getHref())
|
CaptureVAppParams captureVappParams = CaptureVAppParams.builder()
|
||||||
|
.name(name)
|
||||||
|
.source(instantiatedVApp.getHref())
|
||||||
// TODO: test optional params
|
// TODO: test optional params
|
||||||
// .description("")
|
// .description("")
|
||||||
// .sections(sections) // TODO: ovf sections
|
// .sections(sections) // TODO: ovf sections
|
||||||
|
@ -161,15 +165,16 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
@Test(description = "POST /vdc/{id}/action/cloneVApp", dependsOnMethods = { "testInstantiateVAppTemplate" })
|
@Test(description = "POST /vdc/{id}/action/cloneVApp", dependsOnMethods = { "testInstantiateVAppTemplate" })
|
||||||
public void testCloneVApp() {
|
public void testCloneVApp() {
|
||||||
CloneVAppParams cloneVappParams = CloneVAppParams.builder().source(instantiatedVApp.getHref())
|
CloneVAppParams cloneVappParams = CloneVAppParams.builder().source(instantiatedVApp.getHref())
|
||||||
// TODO: test optional params
|
.name(name("vappClone-"))
|
||||||
// .name("")
|
.deploy(true)
|
||||||
// .description("")
|
// TODO: test optional params
|
||||||
// .deploy(true)
|
// .description("")
|
||||||
// .isSourceDelete(true)
|
// .isSourceDelete(true)
|
||||||
// .powerOn(true)
|
// .powerOn(true)
|
||||||
// .instantiationParams(InstantiationParams.builder()
|
// .instantiationParams(InstantiationParams.builder()
|
||||||
// .sections(sections) // TODO: ovf sections? various tests?
|
// .sections(sections)
|
||||||
// .build())
|
// TODO: ovf sections? various tests?
|
||||||
|
// .build())
|
||||||
|
|
||||||
// Reserved. Unimplemented params; may test eventually when implemented
|
// Reserved. Unimplemented params; may test eventually when implemented
|
||||||
// .vAppParent(vAppParentRef)
|
// .vAppParent(vAppParentRef)
|
||||||
|
@ -189,6 +194,7 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
|
||||||
public void testCloneVAppTemplate() {
|
public void testCloneVAppTemplate() {
|
||||||
clonedVAppTemplate = vdcApi.cloneVAppTemplate(vdcUrn,
|
clonedVAppTemplate = vdcApi.cloneVAppTemplate(vdcUrn,
|
||||||
CloneVAppTemplateParams.builder()
|
CloneVAppTemplateParams.builder()
|
||||||
|
.name(name("vappTemplateClone-"))
|
||||||
.source(lazyGetVAppTemplate().getHref())
|
.source(lazyGetVAppTemplate().getHref())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.vcloud.director.v1_5.features;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_EQUAL;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_EQUAL;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
|
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
|
||||||
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.VCloudDirectorMediaType.MEDIA;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.MEDIA;
|
||||||
|
@ -69,14 +68,13 @@ 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.VmQuestionAnswer;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswerChoice;
|
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswerChoice;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.dmtf.RasdItem;
|
import org.jclouds.vcloud.director.v1_5.domain.dmtf.RasdItem;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection;
|
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.network.Network.FenceMode;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection.IpAddressAllocationMode;
|
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection.IpAddressAllocationMode;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.DeployVAppParams;
|
import org.jclouds.vcloud.director.v1_5.domain.params.DeployVAppParams;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.MediaInsertOrEjectParams;
|
import org.jclouds.vcloud.director.v1_5.domain.params.MediaInsertOrEjectParams;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.RelocateParams;
|
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
|
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
|
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
|
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.section.GuestCustomizationSection;
|
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.domain.section.NetworkConnectionSection;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.section.OperatingSystemSection;
|
import org.jclouds.vcloud.director.v1_5.domain.section.OperatingSystemSection;
|
||||||
|
@ -88,7 +86,9 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
@ -115,14 +115,6 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
|
|
||||||
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
|
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
if (adminContext != null && mediaUrn != null) {
|
|
||||||
try {
|
|
||||||
Task remove = context.getApi().getMediaApi().remove(mediaUrn);
|
|
||||||
taskDoneEventually(remove);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("Error when deleting media: %s", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (adminContext != null && testUserCreated && userUrn != null) {
|
if (adminContext != null && testUserCreated && userUrn != null) {
|
||||||
try {
|
try {
|
||||||
adminContext.getApi().getUserApi().remove(userUrn);
|
adminContext.getApi().getUserApi().remove(userUrn);
|
||||||
|
@ -146,6 +138,8 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
// Check the required fields are set
|
// Check the required fields are set
|
||||||
assertEquals(vm.isDeployed(), Boolean.FALSE,
|
assertEquals(vm.isDeployed(), Boolean.FALSE,
|
||||||
String.format(OBJ_FIELD_EQ, VM, "deployed", "FALSE", vm.isDeployed().toString()));
|
String.format(OBJ_FIELD_EQ, VM, "deployed", "FALSE", vm.isDeployed().toString()));
|
||||||
|
String vAppNetworkName = context.getApi().getNetworkApi().get(networkUrn).getName();
|
||||||
|
attachVmToVAppNetwork(vm, vAppNetworkName);
|
||||||
|
|
||||||
// Check status
|
// Check status
|
||||||
assertVmStatus(vmUrn, Status.POWERED_OFF);
|
assertVmStatus(vmUrn, Status.POWERED_OFF);
|
||||||
|
@ -215,7 +209,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
|
|
||||||
// The method under test
|
// The method under test
|
||||||
Task reboot = vmApi.reboot(vmUrn);
|
Task reboot = vmApi.reboot(vmUrn);
|
||||||
assertTaskSucceedsLong(reboot);
|
assertTaskSucceedsLong(reboot);
|
||||||
|
|
||||||
// Get the edited Vm
|
// Get the edited Vm
|
||||||
vm = vmApi.get(vmUrn);
|
vm = vmApi.get(vmUrn);
|
||||||
|
@ -228,7 +222,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
public void testShutdown() {
|
public void testShutdown() {
|
||||||
// Power on Vm
|
// Power on Vm
|
||||||
vm = powerOnVm(vmUrn);
|
vm = powerOnVm(vmUrn);
|
||||||
|
|
||||||
// The method under test
|
// The method under test
|
||||||
Task shutdown = vmApi.shutdown(vmUrn);
|
Task shutdown = vmApi.shutdown(vmUrn);
|
||||||
assertTaskSucceedsLong(shutdown);
|
assertTaskSucceedsLong(shutdown);
|
||||||
|
@ -298,7 +292,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
public void testPowerOffVm() {
|
public void testPowerOffVm() {
|
||||||
// Power on Vm
|
// Power on Vm
|
||||||
vm = powerOnVm(vmUrn);
|
vm = powerOnVm(vmUrn);
|
||||||
|
|
||||||
// The method under test
|
// The method under test
|
||||||
// NB this will put the vm in partially powered off state
|
// NB this will put the vm in partially powered off state
|
||||||
Task powerOffVm = vmApi.powerOff(vmUrn);
|
Task powerOffVm = vmApi.powerOff(vmUrn);
|
||||||
|
@ -311,16 +305,6 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
assertVmStatus(vmUrn, Status.POWERED_OFF);
|
assertVmStatus(vmUrn, Status.POWERED_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "POST /vApp/{id}/action/consolidate", dependsOnMethods = { "testDeployVm" })
|
|
||||||
public void testConsolidateVm() {
|
|
||||||
// Power on Vm
|
|
||||||
vm = powerOnVm(vmUrn);
|
|
||||||
|
|
||||||
// The method under test
|
|
||||||
Task consolidateVm = vmApi.consolidate(vmUrn);
|
|
||||||
assertTrue(retryTaskSuccess.apply(consolidateVm), String.format(TASK_COMPLETE_TIMELY, "consolidateVm"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(description = "POST /vApp/{id}/action/discardSuspendedState", dependsOnMethods = { "testDeployVm" })
|
@Test(description = "POST /vApp/{id}/action/discardSuspendedState", dependsOnMethods = { "testDeployVm" })
|
||||||
public void testDiscardSuspendedState() {
|
public void testDiscardSuspendedState() {
|
||||||
// Suspend the Vm
|
// Suspend the Vm
|
||||||
|
@ -342,20 +326,6 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
assertTrue(retryTaskSuccess.apply(installVMwareTools), String.format(TASK_COMPLETE_TIMELY, "installVMwareTools"));
|
assertTrue(retryTaskSuccess.apply(installVMwareTools), String.format(TASK_COMPLETE_TIMELY, "installVMwareTools"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE This test is disabled, as it is not possible to look up datastores using the User API
|
|
||||||
@Test(description = "POST /vApp/{id}/action/relocate", dependsOnMethods = { "testGetVm" })
|
|
||||||
public void testRelocate() {
|
|
||||||
// Relocate to the last of the available datastores
|
|
||||||
QueryResultRecords records = context.getApi().getQueryApi().queryAll("datastore");
|
|
||||||
QueryResultRecordType datastore = Iterables.getLast(records.getRecords());
|
|
||||||
RelocateParams params = RelocateParams.builder().datastore(Reference.builder().href(datastore.getHref()).build())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// The method under test
|
|
||||||
Task relocate = vmApi.relocate(vmUrn, params);
|
|
||||||
assertTrue(retryTaskSuccess.apply(relocate), String.format(TASK_COMPLETE_TIMELY, "relocate"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(description = "POST /vApp/{id}/action/upgradeHardwareVersion", dependsOnMethods = { "testGetVm" })
|
@Test(description = "POST /vApp/{id}/action/upgradeHardwareVersion", dependsOnMethods = { "testGetVm" })
|
||||||
public void testUpgradeHardwareVersion() {
|
public void testUpgradeHardwareVersion() {
|
||||||
// Power off Vm
|
// Power off Vm
|
||||||
|
@ -410,24 +380,27 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
assertEquals(modified, newSection, String.format(ENTITY_EQUAL, "GuestCustomizationSection"));
|
assertEquals(modified, newSection, String.format(ENTITY_EQUAL, "GuestCustomizationSection"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
@Test(description = "PUT /vApp/{id}/media/action/insertMedia", dependsOnMethods = { "testGetVm" })
|
||||||
// "Error: The requested operation on media "com.vmware.vcloud.entity.media:abfcb4b7-809f-4b50-a0aa-8c97bf09a5b0" is not supported in the current state."
|
public void testInsertMedia() {
|
||||||
@Test(description = "PUT /vApp/{id}/media/action/insertMedia", dependsOnMethods = { "testGetVm" })
|
// Setup media params from configured media id
|
||||||
public void testInsertMedia() {
|
MediaInsertOrEjectParams params = MediaInsertOrEjectParams
|
||||||
// Setup media params from configured media id
|
.builder()
|
||||||
MediaInsertOrEjectParams params = MediaInsertOrEjectParams.builder()
|
.media(Reference.builder().href(lazyGetMedia().getHref())
|
||||||
.media(Reference.builder().href(lazyGetMedia().getHref()).type(MEDIA).build()).build();
|
.type(MEDIA).build()).build();
|
||||||
|
|
||||||
// The method under test
|
// The method under test
|
||||||
Task insertMedia = vmApi.insertMedia(vmUrn, params);
|
Task insertMediaTask = vmApi.insertMedia(vmUrn, params);
|
||||||
assertTrue(retryTaskSuccess.apply(insertMedia), String.format(TASK_COMPLETE_TIMELY, "insertMedia"));
|
assertTrue(retryTaskSuccess.apply(insertMediaTask),
|
||||||
}
|
String.format(TASK_COMPLETE_TIMELY, "insertMedia"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test(description = "PUT /vApp/{id}/media/action/ejectMedia", dependsOnMethods = { "testInsertMedia" })
|
@Test(description = "PUT /vApp/{id}/media/action/ejectMedia", dependsOnMethods = { "testInsertMedia" })
|
||||||
public void testEjectMedia() {
|
public void testEjectMedia() {
|
||||||
|
|
||||||
// Setup media params from configured media id
|
// Setup media params from configured media id
|
||||||
MediaInsertOrEjectParams params = MediaInsertOrEjectParams.builder()
|
MediaInsertOrEjectParams params = MediaInsertOrEjectParams.builder()
|
||||||
.media(Reference.builder().href(lazyGetMedia().getHref()).type(MEDIA).build()).build();
|
.media(Reference.builder()
|
||||||
|
.href(lazyGetMedia().getHref()).type(MEDIA).build()).build();
|
||||||
|
|
||||||
// The method under test
|
// The method under test
|
||||||
Task ejectMedia = vmApi.ejectMedia(vmUrn, params);
|
Task ejectMedia = vmApi.ejectMedia(vmUrn, params);
|
||||||
|
@ -444,39 +417,47 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME "Task error: Unable to perform this action. Contact your cloud administrator."
|
|
||||||
@Test(description = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testEditGuestCustomizationSection" })
|
@Test(description = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testEditGuestCustomizationSection" })
|
||||||
public void testEditNetworkConnectionSection() {
|
public void testEditNetworkConnectionSection() {
|
||||||
powerOffVm(vmUrn);
|
|
||||||
// Look up a network in the Vdc
|
|
||||||
Set<Reference> networks = vdc.getAvailableNetworks();
|
|
||||||
Reference network = Iterables.getLast(networks);
|
|
||||||
|
|
||||||
// Copy existing section and edit fields
|
// Look up a network in the Vdc
|
||||||
NetworkConnectionSection oldSection = vmApi.getNetworkConnectionSection(vmUrn);
|
Set<Reference> networks = vdc.getAvailableNetworks();
|
||||||
NetworkConnectionSection newSection = oldSection
|
Reference network = Iterables.getLast(networks);
|
||||||
.toBuilder()
|
|
||||||
.networkConnection(
|
|
||||||
NetworkConnection.builder().ipAddressAllocationMode(IpAddressAllocationMode.DHCP.toString())
|
|
||||||
.network(network.getName()).build()).build();
|
|
||||||
|
|
||||||
// The method under test
|
// Copy existing section and edit fields
|
||||||
Task editNetworkConnectionSection = vmApi.editNetworkConnectionSection(vmUrn, newSection);
|
NetworkConnectionSection oldSection = vmApi
|
||||||
assertTrue(retryTaskSuccess.apply(editNetworkConnectionSection),
|
.getNetworkConnectionSection(vmUrn);
|
||||||
String.format(TASK_COMPLETE_TIMELY, "editNetworkConnectionSection"));
|
NetworkConnection newNetworkConnection = NetworkConnection.builder()
|
||||||
|
.network(network.getName()).networkConnectionIndex(1)
|
||||||
|
.ipAddressAllocationMode(IpAddressAllocationMode.DHCP).build();
|
||||||
|
NetworkConnectionSection newSection = oldSection.toBuilder()
|
||||||
|
.networkConnection(newNetworkConnection).build();
|
||||||
|
|
||||||
// Retrieve the modified section
|
// The method under test
|
||||||
NetworkConnectionSection modified = vmApi.getNetworkConnectionSection(vmUrn);
|
Task editNetworkConnectionSection = vmApi.editNetworkConnectionSection(
|
||||||
|
vmUrn, newSection);
|
||||||
|
assertTrue(retryTaskSuccess.apply(editNetworkConnectionSection),
|
||||||
|
String.format(TASK_COMPLETE_TIMELY,
|
||||||
|
"editNetworkConnectionSection"));
|
||||||
|
|
||||||
// Check the retrieved object is well formed
|
// Retrieve the modified section
|
||||||
checkNetworkConnectionSection(modified);
|
NetworkConnectionSection modified = vmApi
|
||||||
|
.getNetworkConnectionSection(vmUrn);
|
||||||
|
|
||||||
// Check the modified section has an extra network connection
|
// Check the retrieved object is well formed
|
||||||
assertEquals(modified.getNetworkConnections().size(), newSection.getNetworkConnections().size() + 1);
|
checkNetworkConnectionSection(modified);
|
||||||
|
|
||||||
// Check the section was modified correctly
|
// Check the section was modified correctly
|
||||||
assertEquals(modified, newSection, String.format(ENTITY_EQUAL, "NetworkConnectionSection"));
|
for (NetworkConnection connection : modified.getNetworkConnections()) {
|
||||||
}
|
if (connection.getNetwork().equals(
|
||||||
|
newNetworkConnection.getNetwork())) {
|
||||||
|
assertTrue(connection.getIpAddressAllocationMode().equals(
|
||||||
|
newNetworkConnection.getIpAddressAllocationMode()));
|
||||||
|
assertTrue(connection.getNetworkConnectionIndex() == newNetworkConnection
|
||||||
|
.getNetworkConnectionIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(description = "GET /vApp/{id}/operatingSystemSection", dependsOnMethods = { "testGetVm" })
|
@Test(description = "GET /vApp/{id}/operatingSystemSection", dependsOnMethods = { "testGetVm" })
|
||||||
public void testGetOperatingSystemSection() {
|
public void testGetOperatingSystemSection() {
|
||||||
|
@ -593,11 +574,10 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
checkRuntimeInfoSection(section);
|
checkRuntimeInfoSection(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME If still failing, consider escalating?
|
|
||||||
@Test(description = "GET /vApp/{id}/screen", dependsOnMethods = { "testInstallVMwareTools" })
|
@Test(description = "GET /vApp/{id}/screen", dependsOnMethods = { "testInstallVMwareTools" })
|
||||||
public void testGetScreenImage() {
|
public void testGetScreenImage() {
|
||||||
// Power on Vm
|
// Power on Vm
|
||||||
vm = powerOnVm(vmUrn);
|
vm = powerOnVm(vmUrn); // we need to have a way to wait for complete bootstrap
|
||||||
|
|
||||||
// The method under test
|
// The method under test
|
||||||
byte[] image = vmApi.getScreenImage(vmUrn);
|
byte[] image = vmApi.getScreenImage(vmUrn);
|
||||||
|
@ -880,17 +860,21 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", metadataValue, newMetadataValue));
|
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", metadataValue, newMetadataValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
|
@Test(description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
|
||||||
public void testGetMetadata() {
|
public void testGetMetadata() {
|
||||||
// Call the method being tested
|
|
||||||
Metadata metadata = vmApi.getMetadataApi(vmUrn).get();
|
|
||||||
|
|
||||||
checkMetadata(metadata);
|
key = name("key-");
|
||||||
|
metadataValue = name("value-");
|
||||||
|
|
||||||
// Check requirements for this test
|
vmApi.getMetadataApi(vmUrn).put(key, metadataValue);
|
||||||
assertTrue(Iterables.isEmpty(metadata.getMetadataEntries()),
|
// Call the method being tested
|
||||||
String.format(NOT_EMPTY_OBJECT_FMT, "MetadataEntry", "vm"));
|
Metadata metadata = vmApi.getMetadataApi(vmUrn).get();
|
||||||
}
|
|
||||||
|
checkMetadata(metadata);
|
||||||
|
|
||||||
|
// Check requirements for this test
|
||||||
|
assertTrue(metadata.containsValue(metadataValue), String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", metadata.get(key), metadataValue));
|
||||||
|
}
|
||||||
|
|
||||||
@Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
|
@Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
|
||||||
public void testGetOrgMetadataValue() {
|
public void testGetOrgMetadataValue() {
|
||||||
|
|
|
@ -0,0 +1,525 @@
|
||||||
|
/*
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
*(Link.builder().regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless(Link.builder().required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.vcloud.director.v1_5.features.systemadmin;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.dmtf.ovf.NetworkSection;
|
||||||
|
import org.jclouds.dmtf.ovf.StartupSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Owner;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.RasdItemsList;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||||
|
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.VApp;
|
||||||
|
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.dmtf.RasdItem;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
|
||||||
|
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.domain.section.NetworkConnectionSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.section.OperatingSystemSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.section.RuntimeInfoSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.section.VirtualHardwareSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.features.VAppApi;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTest;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.internal.annotations.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows us to test the {@link VAppApi} allowed to system administrators
|
||||||
|
*
|
||||||
|
* @author andrea turli
|
||||||
|
*/
|
||||||
|
@Test(groups = { "unit", "systemAdmin" }, singleThreaded = true, testName = "SystemAdminVAppApiExpectTest")
|
||||||
|
public class SystemAdminVAppApiExpectTest extends VCloudDirectorAdminApiExpectTest {
|
||||||
|
|
||||||
|
private String vAppId = "vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be";
|
||||||
|
private URI vAppURI = URI.create(endpoint + vAppId);
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void before() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false)
|
||||||
|
public void testEnterMaintenanceMode() {
|
||||||
|
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
new VcloudHttpRequestPrimer()
|
||||||
|
.apiCommand("POST", vAppId + "/action/enterMaintenanceMode")
|
||||||
|
.acceptAnyMedia()
|
||||||
|
.httpRequestBuilder().build(),
|
||||||
|
new VcloudHttpResponsePrimer()
|
||||||
|
.httpResponseBuilder().statusCode(204).build());
|
||||||
|
|
||||||
|
// TODO how to test?
|
||||||
|
api.getVAppApi().enterMaintenanceMode(vAppURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false)
|
||||||
|
public void testExitMaintenanceMode() {
|
||||||
|
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
new VcloudHttpRequestPrimer()
|
||||||
|
.apiCommand("POST", vAppId + "/action/exitMaintenanceMode")
|
||||||
|
.acceptAnyMedia()
|
||||||
|
.httpRequestBuilder().build(),
|
||||||
|
new VcloudHttpResponsePrimer()
|
||||||
|
.httpResponseBuilder().statusCode(204).build());
|
||||||
|
|
||||||
|
// TODO how to test?
|
||||||
|
api.getVAppApi().exitMaintenanceMode(vAppURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VApp getVApp() {
|
||||||
|
// FIXME Does not match XML
|
||||||
|
VApp vApp = VApp.builder()
|
||||||
|
.href(URI.create("https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be"))
|
||||||
|
// .link(Link.builder()
|
||||||
|
// .href(URI.create())
|
||||||
|
// .build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// <Link rel="power:powerOn" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/power/action/powerOn"/>
|
||||||
|
// <Link rel="deploy" type="application/vnd.vmware.vcloud.deployVAppParams+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/action/deploy"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.vAppNetwork+xml" name="orgNet-cloudsoft-External" href="https://mycloud.greenhousedata.com/api/network/2a2e2da4-446a-4ebc-a086-06df7c9570f0"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/controlAccess/"/>
|
||||||
|
// <Link rel="controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/action/controlAccess"/>
|
||||||
|
// <Link rel="recompose" type="application/vnd.vmware.vcloud.recomposeVAppParams+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/action/recomposeVApp"/>
|
||||||
|
// <Link rel="up" type="application/vnd.vmware.vcloud.vdc+xml" href="https://mycloud.greenhousedata.com/api/vdc/e9cd3387-ac57-4d27-a481-9bee75e0690f"/>
|
||||||
|
// <Link rel="edit" type="application/vnd.vmware.vcloud.vApp+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be"/>
|
||||||
|
// <Link rel="remove" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.owner+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/owner"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/metadata"/>
|
||||||
|
|
||||||
|
return vApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVAppTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task removeVAppTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task consolidateVAppTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ControlAccessParams controlAccessParams() {
|
||||||
|
ControlAccessParams params = ControlAccessParams.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task deployTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task discardSuspendedStateTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task installVMwareToolsTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task recomposeVAppTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task relocateTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task undeployTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task upgradeHardwareVersionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task powerOffTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task powerOnTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task rebootTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task resetTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task shutdownTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task suspendTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ControlAccessParams getAccessControlParams() {
|
||||||
|
ControlAccessParams params = ControlAccessParams.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GuestCustomizationSection getGuestCustomizationSection() {
|
||||||
|
GuestCustomizationSection section = GuestCustomizationSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editGuestCustomizationSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LeaseSettingsSection getLeaseSettingsSection() {
|
||||||
|
LeaseSettingsSection section = LeaseSettingsSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editLeaseSettingsSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task ejectMediaTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task insertMediaTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetworkConfigSection getNetworkConfigSection() {
|
||||||
|
NetworkConfigSection section = NetworkConfigSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editNetworkConfigSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetworkConnectionSection getNetworkConnectionSection() {
|
||||||
|
NetworkConnectionSection section = NetworkConnectionSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editNetworkConnectionSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetworkSection getNetworkSection() {
|
||||||
|
NetworkSection section = NetworkSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OperatingSystemSection getOperatingSystemSection() {
|
||||||
|
OperatingSystemSection section = OperatingSystemSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editOperatingSystemSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Owner getOwner() {
|
||||||
|
Owner owner = Owner.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editOwnerTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProductSectionList getProductSections() {
|
||||||
|
ProductSectionList sectionItems = ProductSectionList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return sectionItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editProductSectionsTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VmPendingQuestion getPendingQuestion() {
|
||||||
|
VmPendingQuestion question = VmPendingQuestion.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return question;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VmQuestionAnswer answerQuestion() {
|
||||||
|
VmQuestionAnswer answer = null; // = VmQuestionAnswer.builder()
|
||||||
|
// .build();
|
||||||
|
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RuntimeInfoSection getRuntimeInfoSection() {
|
||||||
|
RuntimeInfoSection section = RuntimeInfoSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getScreenImage() {
|
||||||
|
byte[] image = new byte[0];
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ScreenTicket getScreenTicket() {
|
||||||
|
ScreenTicket ticket = null; // = ScreenTicket.builder();
|
||||||
|
// .build();
|
||||||
|
|
||||||
|
return ticket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StartupSection getStartupSection() {
|
||||||
|
StartupSection section = null; // = StartupSection.builder();
|
||||||
|
// .build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editStartupSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VirtualHardwareSection getVirtualHardwareSection() {
|
||||||
|
VirtualHardwareSection section = VirtualHardwareSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItem getVirtualHardwareSectionCpu() {
|
||||||
|
RasdItem cpu = RasdItem.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionCpuTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionDisks() {
|
||||||
|
RasdItemsList disks = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return disks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionDisksTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionMedia() {
|
||||||
|
RasdItemsList media = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItem getVirtualHardwareSectionMemory() {
|
||||||
|
RasdItem memory = RasdItem.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionMemoryTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionNetworkCards() {
|
||||||
|
RasdItemsList networkCards = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return networkCards;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionNetworkCardsTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionSerialPorts() {
|
||||||
|
RasdItemsList serialPorts = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return serialPorts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionSerialPortsTask() {
|
||||||
|
return task("id", "name", "description", "status", "operation", "operationName", "startTime");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Used by other methods to add a custom {@link Task} object. */
|
||||||
|
private static Task task(String taskId, String name, String description, String status, String operation, String operationName, String startTime) {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.error(Error.builder().build())
|
||||||
|
.org(Reference.builder().build())
|
||||||
|
.owner(Reference.builder().build())
|
||||||
|
.user(Reference.builder().build())
|
||||||
|
.params(null)
|
||||||
|
.progress(0)
|
||||||
|
.status(status)
|
||||||
|
.operation(operation)
|
||||||
|
.operationName(operationName)
|
||||||
|
.startTime(dateService.iso8601DateParse(startTime))
|
||||||
|
.endTime(null)
|
||||||
|
.expiryTime(null)
|
||||||
|
.tasks(Sets.<Task>newLinkedHashSet())
|
||||||
|
.description(description)
|
||||||
|
.name(name)
|
||||||
|
.id("urn:vcloud:" + taskId)
|
||||||
|
.href(URI.create(endpoint + "/task/" + taskId))
|
||||||
|
.links(Sets.<Link>newLinkedHashSet())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
/*
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
*(Link.builder().regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless(Link.builder().required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.vcloud.director.v1_5.features.systemadmin;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.params.DeployVAppParams;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.features.VAppApi;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows us to test the {@link VAppApi} allowed to system administrators
|
||||||
|
*
|
||||||
|
* @author andrea turli
|
||||||
|
*/
|
||||||
|
@Test(singleThreaded = true, testName = "SystemAdminVAppApiLiveTest")
|
||||||
|
public class SystemAdminVAppApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
|
|
||||||
|
private boolean testUserCreated = false;
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true)
|
||||||
|
protected void setupRequiredEntities() {
|
||||||
|
|
||||||
|
if (adminContext != null) {
|
||||||
|
userUrn = adminContext.getApi().getUserApi().addUserToOrg(randomTestUser("VAppAccessTest"), org.getId())
|
||||||
|
.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
|
||||||
|
public void cleanUp() {
|
||||||
|
if (adminContext != null && testUserCreated && userUrn != null) {
|
||||||
|
try {
|
||||||
|
adminContext.getApi().getUserApi().remove(userUrn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn(e, "Error when deleting user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "POST /vApp/{id}/action/enterMaintenanceMode", groups = { "systemAdmin" })
|
||||||
|
public void testEnterMaintenanceMode() {
|
||||||
|
|
||||||
|
// Do this to a new vApp, so don't mess up subsequent tests by making the vApp read-only
|
||||||
|
VApp temp = instantiateVApp();
|
||||||
|
DeployVAppParams params = DeployVAppParams.builder()
|
||||||
|
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS)).notForceCustomization()
|
||||||
|
.notPowerOn().build();
|
||||||
|
Task deployVApp = vAppApi.deploy(temp.getId(), params);
|
||||||
|
assertTaskSucceedsLong(deployVApp);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Method under test
|
||||||
|
vAppApi.enterMaintenanceMode(temp.getId());
|
||||||
|
|
||||||
|
temp = vAppApi.get(temp.getId());
|
||||||
|
assertTrue(temp.isInMaintenanceMode(),
|
||||||
|
String.format(CONDITION_FMT, "InMaintenanceMode", "TRUE", temp.isInMaintenanceMode()));
|
||||||
|
|
||||||
|
// Exit maintenance mode
|
||||||
|
vAppApi.exitMaintenanceMode(temp.getId());
|
||||||
|
} finally {
|
||||||
|
cleanUpVApp(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "POST /vApp/{id}/action/exitMaintenanceMode", dependsOnMethods = { "testEnterMaintenanceMode" }, groups = { "systemAdmin" })
|
||||||
|
public void testExitMaintenanceMode() {
|
||||||
|
// Do this to a new vApp, so don't mess up subsequent tests by making the vApp read-only
|
||||||
|
VApp temp = instantiateVApp();
|
||||||
|
DeployVAppParams params = DeployVAppParams.builder()
|
||||||
|
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS)).notForceCustomization()
|
||||||
|
.notPowerOn().build();
|
||||||
|
Task deployVApp = vAppApi.deploy(temp.getId(), params);
|
||||||
|
assertTaskSucceedsLong(deployVApp);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Enter maintenance mode
|
||||||
|
vAppApi.enterMaintenanceMode(temp.getId());
|
||||||
|
|
||||||
|
// Method under test
|
||||||
|
vAppApi.exitMaintenanceMode(temp.getId());
|
||||||
|
|
||||||
|
temp = vAppApi.get(temp.getId());
|
||||||
|
assertFalse(temp.isInMaintenanceMode(),
|
||||||
|
String.format(CONDITION_FMT, "InMaintenanceMode", "FALSE", temp.isInMaintenanceMode()));
|
||||||
|
} finally {
|
||||||
|
cleanUpVApp(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,522 @@
|
||||||
|
/*
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
*(Link.builder().regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless(Link.builder().required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.vcloud.director.v1_5.features.systemadmin;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.dmtf.ovf.NetworkSection;
|
||||||
|
import org.jclouds.dmtf.ovf.StartupSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Owner;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.RasdItemsList;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||||
|
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.Vm;
|
||||||
|
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.dmtf.RasdItem;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.params.RelocateParams;
|
||||||
|
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.domain.section.NetworkConnectionSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.section.OperatingSystemSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.section.RuntimeInfoSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.section.VirtualHardwareSection;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.features.VmApi;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminApiExpectTest;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.internal.annotations.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows us to test the {@link VmApi} allowed to system administrators
|
||||||
|
*
|
||||||
|
* @author andrea turli
|
||||||
|
*/
|
||||||
|
@Test(groups = { "unit", "systemAdmin" }, singleThreaded = true, testName = "SystemAdminVmApiExpectTest")
|
||||||
|
public class SystemAdminVmApiExpectTest extends VCloudDirectorAdminApiExpectTest {
|
||||||
|
|
||||||
|
private String vmId = "vm-d0e2b6b9-4381-4ddc-9572-cdfae54059be";
|
||||||
|
private URI vmURI = URI.create(endpoint + vmId);
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void before() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false)
|
||||||
|
public void testRelocate() {
|
||||||
|
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
new VcloudHttpRequestPrimer()
|
||||||
|
.apiCommand("POST", vmId + "/action/relocate")
|
||||||
|
.xmlFilePayload("/vApp/relocateParams.xml", VCloudDirectorMediaType.RELOCATE_VM_PARAMS)
|
||||||
|
.acceptAnyMedia()
|
||||||
|
.httpRequestBuilder().build(),
|
||||||
|
new VcloudHttpResponsePrimer()
|
||||||
|
.xmlFilePayload("/vApp/relocateTask.xml", VCloudDirectorMediaType.TASK)
|
||||||
|
.httpResponseBuilder().build());
|
||||||
|
|
||||||
|
RelocateParams params = RelocateParams.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Task expected = relocateTask();
|
||||||
|
|
||||||
|
assertEquals(api.getVmApi().relocate(vmURI, params), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Vm getVm() {
|
||||||
|
// FIXME Does not match XML
|
||||||
|
Vm vm = Vm.builder()
|
||||||
|
.href(URI.create("https://mycloud.greenhousedata.com/api/vApp/vm-d0e2b6b9-4381-4ddc-9572-cdfae54059be"))
|
||||||
|
// .link(Link.builder()
|
||||||
|
// .href(URI.create())
|
||||||
|
// .build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// <Link rel="power:powerOn" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/power/action/powerOn"/>
|
||||||
|
// <Link rel="deploy" type="application/vnd.vmware.vcloud.deployVAppParams+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/action/deploy"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.vAppNetwork+xml" name="orgNet-cloudsoft-External" href="https://mycloud.greenhousedata.com/api/network/2a2e2da4-446a-4ebc-a086-06df7c9570f0"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/controlAccess/"/>
|
||||||
|
// <Link rel="controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/action/controlAccess"/>
|
||||||
|
// <Link rel="recompose" type="application/vnd.vmware.vcloud.recomposeVAppParams+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/action/recomposeVApp"/>
|
||||||
|
// <Link rel="up" type="application/vnd.vmware.vcloud.vdc+xml" href="https://mycloud.greenhousedata.com/api/vdc/e9cd3387-ac57-4d27-a481-9bee75e0690f"/>
|
||||||
|
// <Link rel="edit" type="application/vnd.vmware.vcloud.vApp+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be"/>
|
||||||
|
// <Link rel="remove" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.owner+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/owner"/>
|
||||||
|
// <Link rel="down" type="application/vnd.vmware.vcloud.metadata+xml" href="https://mycloud.greenhousedata.com/api/vApp/vapp-d0e2b6b9-4381-4ddc-9572-cdfae54059be/metadata"/>
|
||||||
|
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVmTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task removeVmTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task consolidateVmTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ControlAccessParams controlAccessParams() {
|
||||||
|
ControlAccessParams params = ControlAccessParams.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task deployTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task discardSuspendedStateTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task installVMwareToolsTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task recomposeVmTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task relocateTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task undeployTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task upgradeHardwareVersionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task powerOffTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task powerOnTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task rebootTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task resetTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task shutdownTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task suspendTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ControlAccessParams getAccessControlParams() {
|
||||||
|
ControlAccessParams params = ControlAccessParams.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GuestCustomizationSection getGuestCustomizationSection() {
|
||||||
|
GuestCustomizationSection section = GuestCustomizationSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editGuestCustomizationSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LeaseSettingsSection getLeaseSettingsSection() {
|
||||||
|
LeaseSettingsSection section = LeaseSettingsSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editLeaseSettingsSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task ejectMediaTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task insertMediaTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetworkConfigSection getNetworkConfigSection() {
|
||||||
|
NetworkConfigSection section = NetworkConfigSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editNetworkConfigSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetworkConnectionSection getNetworkConnectionSection() {
|
||||||
|
NetworkConnectionSection section = NetworkConnectionSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editNetworkConnectionSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetworkSection getNetworkSection() {
|
||||||
|
NetworkSection section = NetworkSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OperatingSystemSection getOperatingSystemSection() {
|
||||||
|
OperatingSystemSection section = OperatingSystemSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editOperatingSystemSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Owner getOwner() {
|
||||||
|
Owner owner = Owner.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editOwnerTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProductSectionList getProductSections() {
|
||||||
|
ProductSectionList sectionItems = ProductSectionList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return sectionItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editProductSectionsTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VmPendingQuestion getPendingQuestion() {
|
||||||
|
VmPendingQuestion question = VmPendingQuestion.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return question;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VmQuestionAnswer answerQuestion() {
|
||||||
|
VmQuestionAnswer answer = null; // = VmQuestionAnswer.builder()
|
||||||
|
// .build();
|
||||||
|
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RuntimeInfoSection getRuntimeInfoSection() {
|
||||||
|
RuntimeInfoSection section = RuntimeInfoSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getScreenImage() {
|
||||||
|
byte[] image = new byte[0];
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ScreenTicket getScreenTicket() {
|
||||||
|
ScreenTicket ticket = null; // = ScreenTicket.builder();
|
||||||
|
// .build();
|
||||||
|
|
||||||
|
return ticket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StartupSection getStartupSection() {
|
||||||
|
StartupSection section = null; // = StartupSection.builder();
|
||||||
|
// .build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editStartupSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VirtualHardwareSection getVirtualHardwareSection() {
|
||||||
|
VirtualHardwareSection section = VirtualHardwareSection.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItem getVirtualHardwareSectionCpu() {
|
||||||
|
RasdItem cpu = RasdItem.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionCpuTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionDisks() {
|
||||||
|
RasdItemsList disks = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return disks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionDisksTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionMedia() {
|
||||||
|
RasdItemsList media = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItem getVirtualHardwareSectionMemory() {
|
||||||
|
RasdItem memory = RasdItem.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionMemoryTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionNetworkCards() {
|
||||||
|
RasdItemsList networkCards = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return networkCards;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionNetworkCardsTask() {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RasdItemsList getVirtualHardwareSectionSerialPorts() {
|
||||||
|
RasdItemsList serialPorts = RasdItemsList.builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return serialPorts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task editVirtualHardwareSectionSerialPortsTask() {
|
||||||
|
return task("id", "name", "description", "status", "operation", "operationName", "startTime");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Used by other methods to add a custom {@link Task} object. */
|
||||||
|
private static Task task(String taskId, String name, String description, String status, String operation, String operationName, String startTime) {
|
||||||
|
Task task = Task.builder()
|
||||||
|
.error(Error.builder().build())
|
||||||
|
.org(Reference.builder().build())
|
||||||
|
.owner(Reference.builder().build())
|
||||||
|
.user(Reference.builder().build())
|
||||||
|
.params(null)
|
||||||
|
.progress(0)
|
||||||
|
.status(status)
|
||||||
|
.operation(operation)
|
||||||
|
.operationName(operationName)
|
||||||
|
.startTime(dateService.iso8601DateParse(startTime))
|
||||||
|
.endTime(null)
|
||||||
|
.expiryTime(null)
|
||||||
|
.tasks(Sets.<Task>newLinkedHashSet())
|
||||||
|
.description(description)
|
||||||
|
.name(name)
|
||||||
|
.id("urn:vcloud:" + taskId)
|
||||||
|
.href(URI.create(endpoint + "/task/" + taskId))
|
||||||
|
.links(Sets.<Link>newLinkedHashSet())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,136 @@
|
||||||
|
/*
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
*(Link.builder().regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless(Link.builder().required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.vcloud.director.v1_5.features.systemadmin;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVm;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.params.DeployVAppParams;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.params.RelocateParams;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.features.VmApi;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of the {@link VmApi}.
|
||||||
|
*
|
||||||
|
* @author andrea turli
|
||||||
|
*/
|
||||||
|
@Test(groups = { "live", "systemAdmin" }, singleThreaded = true, testName = "SystemAdminVmApiLiveTest")
|
||||||
|
public class SystemAdminVmApiLiveTest extends AbstractVAppApiLiveTest {
|
||||||
|
|
||||||
|
private boolean testUserCreated = false;
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true)
|
||||||
|
protected void setupRequiredEntities() {
|
||||||
|
|
||||||
|
if (adminContext != null) {
|
||||||
|
userUrn = adminContext.getApi().getUserApi().addUserToOrg(randomTestUser("VAppAccessTest"), org.getId())
|
||||||
|
.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
|
||||||
|
public void cleanUp() {
|
||||||
|
if (adminContext != null && testUserCreated && userUrn != null) {
|
||||||
|
try {
|
||||||
|
adminContext.getApi().getUserApi().remove(userUrn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("Error when deleting user: %s", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VmApi#get(String)
|
||||||
|
*/
|
||||||
|
@Test(description = "GET /vApp/{id}")
|
||||||
|
public void testGetVm() {
|
||||||
|
// The method under test
|
||||||
|
vm = vmApi.get(vmUrn);
|
||||||
|
|
||||||
|
// Check the retrieved object is well formed
|
||||||
|
checkVm(vm);
|
||||||
|
|
||||||
|
// Check the required fields are set
|
||||||
|
assertEquals(vm.isDeployed(), Boolean.FALSE,
|
||||||
|
String.format(OBJ_FIELD_EQ, VM, "deployed", "FALSE", vm.isDeployed().toString()));
|
||||||
|
|
||||||
|
// Check status
|
||||||
|
assertVmStatus(vmUrn, Status.POWERED_OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE This test is disabled, as it is not possible to look up datastores using the User API
|
||||||
|
@Test(description = "POST /vApp/{id}/action/relocate", dependsOnMethods = { "testGetVm" })
|
||||||
|
public void testRelocate() {
|
||||||
|
// Relocate to the last of the available datastores
|
||||||
|
QueryResultRecords records = adminContext.getApi().getQueryApi().queryAll("datastore");
|
||||||
|
QueryResultRecordType datastore = Iterables.getLast(records.getRecords());
|
||||||
|
RelocateParams params = RelocateParams.builder().datastore(Reference.builder().href(datastore.getHref()).build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// The method under test
|
||||||
|
Task relocate = vmApi.relocate(vmUrn, params);
|
||||||
|
assertTrue(retryTaskSuccess.apply(relocate), String.format(TASK_COMPLETE_TIMELY, "relocate"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "POST /vApp/{id}/action/deploy", dependsOnMethods = { "testGetVm" })
|
||||||
|
public void testDeployVm() {
|
||||||
|
DeployVAppParams params = DeployVAppParams.builder()
|
||||||
|
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS)).notForceCustomization()
|
||||||
|
.notPowerOn().build();
|
||||||
|
|
||||||
|
// The method under test
|
||||||
|
Task deployVm = vmApi.deploy(vmUrn, params);
|
||||||
|
assertTrue(retryTaskSuccessLong.apply(deployVm), String.format(TASK_COMPLETE_TIMELY, "deployVm"));
|
||||||
|
|
||||||
|
// Get the edited Vm
|
||||||
|
vm = vmApi.get(vmUrn);
|
||||||
|
|
||||||
|
// Check the required fields are set
|
||||||
|
assertTrue(vm.isDeployed(), String.format(OBJ_FIELD_EQ, VM, "deployed", "TRUE", vm.isDeployed().toString()));
|
||||||
|
|
||||||
|
// Check status
|
||||||
|
assertVmStatus(vmUrn, Status.POWERED_OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "POST /vApp/{id}/action/consolidate", dependsOnMethods = { "testDeployVm" })
|
||||||
|
public void testConsolidateVm() {
|
||||||
|
// Power on Vm
|
||||||
|
vm = powerOnVm(vmUrn);
|
||||||
|
|
||||||
|
// The method under test
|
||||||
|
Task consolidateVm = vmApi.consolidate(vmUrn);
|
||||||
|
assertTrue(retryTaskSuccess.apply(consolidateVm), String.format(TASK_COMPLETE_TIMELY, "consolidateVm"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.E
|
||||||
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.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.CATALOG;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.MEDIA;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NETWORK;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NETWORK;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG_NETWORK;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ORG_NETWORK;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.USER;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.USER;
|
||||||
|
@ -36,7 +37,6 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VAPP;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VAPP_TEMPLATE;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VAPP_TEMPLATE;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VDC;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VDC;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VM;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.VM;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.MEDIA;
|
|
||||||
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals;
|
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals;
|
||||||
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals;
|
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
@ -89,8 +89,6 @@ import org.jclouds.vcloud.director.v1_5.domain.org.Org;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiateVAppTemplateParams;
|
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiateVAppTemplateParams;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiationParams;
|
import org.jclouds.vcloud.director.v1_5.domain.params.InstantiationParams;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
|
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
|
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecords;
|
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.section.NetworkConfigSection;
|
import org.jclouds.vcloud.director.v1_5.domain.section.NetworkConfigSection;
|
||||||
import org.jclouds.vcloud.director.v1_5.features.TaskApi;
|
import org.jclouds.vcloud.director.v1_5.features.TaskApi;
|
||||||
import org.jclouds.vcloud.director.v1_5.features.VAppApi;
|
import org.jclouds.vcloud.director.v1_5.features.VAppApi;
|
||||||
|
@ -470,6 +468,30 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanUpVAppTemplateInOrg() {
|
||||||
|
FluentIterable<VAppTemplate> vAppTemplates = FluentIterable
|
||||||
|
.from(vdc.getResourceEntities())
|
||||||
|
.filter(ReferencePredicates
|
||||||
|
.<Reference> typeEquals(VAPP_TEMPLATE))
|
||||||
|
.transform(new Function<Reference, VAppTemplate>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VAppTemplate apply(Reference in) {
|
||||||
|
return context.getApi().getVAppTemplateApi()
|
||||||
|
.get(in.getHref());
|
||||||
|
}
|
||||||
|
}).filter(Predicates.notNull());
|
||||||
|
|
||||||
|
Iterables.removeIf(vAppTemplates, new Predicate<VAppTemplate>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(VAppTemplate input) {
|
||||||
|
if(input.getName().startsWith("captured-") || input.getName().startsWith("uploaded-") || input.getName().startsWith("vappTemplateClone-"))
|
||||||
|
context.getApi().getVAppTemplateApi().remove(input.getHref());
|
||||||
|
return false;
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
protected Vdc lazyGetVdc() {
|
protected Vdc lazyGetVdc() {
|
||||||
if (vdc == null) {
|
if (vdc == null) {
|
||||||
assertNotNull(vdcUrn, String.format(URN_REQ_LIVE, VDC));
|
assertNotNull(vdcUrn, String.format(URN_REQ_LIVE, VDC));
|
||||||
|
@ -530,9 +552,9 @@ public abstract class BaseVCloudDirectorApiLiveTest extends BaseContextLiveTest<
|
||||||
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
|
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
|
||||||
media = context.getApi().getMediaApi().get(media.getId());
|
media = context.getApi().getMediaApi().get(media.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaUrn = media.getId();
|
mediaUrn = media.getId();
|
||||||
}
|
} else
|
||||||
|
media = context.getApi().getMediaApi().get(mediaUrn);
|
||||||
}
|
}
|
||||||
return media;
|
return media;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue