mirror of https://github.com/apache/jclouds.git
Issue 830: Create shared parent class for VApp and VAppTemplate tests
This commit is contained in:
parent
d7bbfe9cd8
commit
86f249d0d8
|
@ -32,7 +32,7 @@ import com.google.common.base.Predicate;
|
|||
public class ReferenceTypePredicates {
|
||||
|
||||
/**
|
||||
* Matches {@link Reference}s of the given name.
|
||||
* Matches {@link Reference}s with the given name.
|
||||
*
|
||||
* @param T type of the reference, for example {@link Link}
|
||||
* @param name value of the name attribute of the referenced object
|
||||
|
@ -54,6 +54,30 @@ public class ReferenceTypePredicates {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches {@link Reference}s with names starting with the given prefix.
|
||||
*
|
||||
* @param T type of the reference, for example {@link Link}
|
||||
* @param name prefix of the name attribute of the referenced object
|
||||
* @return predicate that will match references with names starting with the given prefix
|
||||
*/
|
||||
public static <T extends Reference> Predicate<T> nameStartsWith(final String prefix) {
|
||||
checkNotNull(prefix, "prefix must be defined");
|
||||
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean apply(T reference) {
|
||||
String name = reference.getName();
|
||||
return name != null && name.startsWith(prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "nameStartsWith(" + prefix + ")";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches {@link Reference}s of the given type.
|
||||
*
|
||||
|
|
|
@ -483,7 +483,7 @@ public class Checks {
|
|||
public static void checkMacAddress(String macAddress) {
|
||||
// Check the string is a valid MAC address
|
||||
assertNotNull(macAddress, String.format(NOT_EMPTY_STRING_FMT, "macAddress"));
|
||||
assertTrue(macAddress.toUpperCase().matches(MAC_ADDRESS_PATTERN), String.format(MATCHES_STRING_FMT, "macAddress", MAC_ADDRESS_PATTERN, macAddress));
|
||||
assertTrue(macAddress.matches(MAC_ADDRESS_PATTERN), String.format(MATCHES_STRING_FMT, "macAddress", MAC_ADDRESS_PATTERN, macAddress));
|
||||
}
|
||||
|
||||
public static void checkComputeCapacity(ComputeCapacity computeCapacity) {
|
||||
|
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_NON_NULL;
|
||||
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.checkGuestCustomizationSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.NetworkConnectionSection;
|
||||
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.ResourceEntityType.Status;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.UndeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.cim.CimString;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.cim.CimUnsignedInt;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.RASD;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
|
||||
import org.jclouds.xml.internal.JAXBParser;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Shared code to test the behaviour of {@link VAppClient} and {@link VAppTemplateClient}.
|
||||
*
|
||||
* @author grkvlt@apache.org
|
||||
*/
|
||||
public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||
|
||||
public static final String VAPP = "vApp";
|
||||
public static final String VAPP_TEMPLATE = "vAppTemplate";
|
||||
public static final String VDC = "vdc";
|
||||
|
||||
/*
|
||||
* Convenience reference to API clients.
|
||||
*/
|
||||
|
||||
protected CatalogClient catalogClient;
|
||||
protected QueryClient queryClient;
|
||||
protected VAppClient vAppClient;
|
||||
protected VAppTemplateClient vAppTemplateClient;
|
||||
protected VdcClient vdcClient;
|
||||
protected MetadataClient.Writeable metadataClient;
|
||||
|
||||
/*
|
||||
* Objects shared between tests.
|
||||
*/
|
||||
|
||||
protected Vdc vdc;
|
||||
protected Vm vm;
|
||||
protected URI vAppURI;
|
||||
protected VApp vApp;
|
||||
protected VAppTemplate vAppTemplate;
|
||||
|
||||
protected final Random random = new Random();
|
||||
|
||||
/**
|
||||
* Retrieves the required clients from the REST API context
|
||||
*
|
||||
* @see BaseVCloudDirectorClientLiveTest#setupRequiredClients()
|
||||
*/
|
||||
@BeforeClass(inheritGroups = true, description = "Retrieves the required clients from the REST API context")
|
||||
@Override
|
||||
protected void setupRequiredClients() {
|
||||
assertNotNull(context.getApi());
|
||||
|
||||
catalogClient = context.getApi().getCatalogClient();
|
||||
queryClient = context.getApi().getQueryClient();
|
||||
vAppClient = context.getApi().getVAppClient();
|
||||
vAppTemplateClient = context.getApi().getVAppTemplateClient();
|
||||
vdcClient = context.getApi().getVdcClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the environment.
|
||||
*
|
||||
* Retrieves the test {@link Vdc} and {@link VAppTemplate} from their configured {@link URI}s. Cleans up
|
||||
* existing {@link VApp}s and instantiates a new test VApp.
|
||||
*
|
||||
* @see #cleanUp()
|
||||
*/
|
||||
@BeforeClass(inheritGroups = true, description = "Cleans up the environment")
|
||||
protected void setupEnvironment() {
|
||||
// Get the configured Vdc for the tests
|
||||
vdc = vdcClient.getVdc(vdcURI);
|
||||
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
|
||||
|
||||
// Get the configured VAppTemplate for the tests
|
||||
vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
assertNotNull(vAppTemplate, String.format(ENTITY_NON_NULL, VAPP_TEMPLATE));
|
||||
|
||||
// Clean up after previous test runs
|
||||
cleanUp();
|
||||
|
||||
// Instantiate a new VApp
|
||||
VApp vAppInstantiated = instantiateVApp();
|
||||
assertNotNull(vAppInstantiated, String.format(ENTITY_NON_NULL, VAPP));
|
||||
vAppURI = vAppInstantiated.getHref();
|
||||
|
||||
// Wait for the task to complete
|
||||
Task instantiateTask = Iterables.getOnlyElement(vAppInstantiated.getTasks());
|
||||
assertTrue(retryTaskSuccessLong.apply(instantiateTask), String.format(TASK_COMPLETE_TIMELY, "instantiateTask"));
|
||||
|
||||
// Get the instantiated VApp
|
||||
vApp = vAppClient.getVApp(vAppURI);
|
||||
|
||||
// Get the Vm
|
||||
List<Vm> vms = vApp.getChildren().getVms();
|
||||
vm = Iterables.getOnlyElement(vms);
|
||||
assertFalse(vms.isEmpty(), "The VApp must have at least one Vm");
|
||||
}
|
||||
|
||||
protected void getGuestCustomizationSection(Function<URI, GuestCustomizationSection> getGuestCustomizationSection) {
|
||||
// Get URI for child VM
|
||||
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
|
||||
|
||||
// The method under test
|
||||
try {
|
||||
GuestCustomizationSection section = getGuestCustomizationSection.apply(vmURI);
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkGuestCustomizationSection(section);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void getNetworkConnectionSection(Function<URI, NetworkConnectionSection> getNetworkConnectionSection) {
|
||||
// Get URI for child VM
|
||||
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
|
||||
|
||||
// The method under test
|
||||
try {
|
||||
NetworkConnectionSection section = getNetworkConnectionSection.apply(vmURI);
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkNetworkConnectionSection(section);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE This method is also called by the BeforeClass method setupRequiredClients
|
||||
@AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps named 'test-vapp-*' or 'new-name-*'")
|
||||
protected void cleanUp() {
|
||||
// Find references in the Vdc with the VApp type and named 'test-vapp' or 'new-name'
|
||||
Iterable<Reference> vApps = Iterables.filter(
|
||||
vdc.getResourceEntities().getResourceEntities(),
|
||||
Predicates.and(
|
||||
ReferenceTypePredicates.<Reference>typeEquals(VCloudDirectorMediaType.VAPP),
|
||||
Predicates.or(
|
||||
ReferenceTypePredicates.<Reference>nameStartsWith("test-vapp-"),
|
||||
ReferenceTypePredicates.<Reference>nameStartsWith("new-name-")
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// If we found any references, delete the VApp they point to
|
||||
if (vApps != null && !Iterables.isEmpty(vApps)) {
|
||||
for (Reference each : vApps) {
|
||||
VApp found = vAppClient.getVApp(each.getHref());
|
||||
// debug(found);
|
||||
|
||||
// Shutdown and power off the VApp if necessary
|
||||
if (found.getStatus().equals(Status.POWERED_ON.getValue())) {
|
||||
Task shutdownTask = vAppClient.shutdown(found.getHref());
|
||||
retryTaskSuccess.apply(shutdownTask);
|
||||
}
|
||||
|
||||
// Undeploy the VApp if necessary
|
||||
if (found.isDeployed()) {
|
||||
UndeployVAppParams params = UndeployVAppParams.builder().build();
|
||||
Task undeployTask = vAppClient.undeploy(found.getHref(), params);
|
||||
retryTaskSuccess.apply(undeployTask);
|
||||
}
|
||||
|
||||
// Delete the VApp
|
||||
Task deleteTask = vAppClient.deleteVApp(found.getHref());
|
||||
retryTaskSuccess.apply(deleteTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static CimUnsignedInt cimUnsignedInt(long val) {
|
||||
CimUnsignedInt result = new CimUnsignedInt();
|
||||
result.setValue(val);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static CimString cimString(String val) {
|
||||
CimString result = new CimString();
|
||||
result.setValue(val);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void checkHasMatchingItem(final String context, final RasdItemsList items, final String instanceId, final String elementName) {
|
||||
Optional<RASD> found = Iterables.tryFind(items.getItems(), new Predicate<RASD>() {
|
||||
@Override
|
||||
public boolean apply(RASD item) {
|
||||
String itemInstanceId = item.getInstanceID().getValue();
|
||||
if (itemInstanceId.equals(instanceId)) {
|
||||
Assert.assertEquals(item.getElementName().getValue(), elementName,
|
||||
String.format(OBJ_FIELD_EQ, VAPP, context + "/" + instanceId + "/elementName", elementName, item.getElementName().getValue()));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
assertTrue(found.isPresent(), "no " + context + " item found with id " + instanceId + "; only found " + items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshals a JAXB annotated object into XML. The XML is output on {@link System#err}.
|
||||
*/
|
||||
protected void debug(Object object) {
|
||||
JAXBParser parser = new JAXBParser();
|
||||
try {
|
||||
String xml = parser.toXML(object);
|
||||
|
||||
System.err.println(Strings.padStart(Strings.padEnd(" " + object.getClass().toString() + " ", 70, '-'), 80, '-'));
|
||||
System.err.println(xml);
|
||||
System.err.println(Strings.repeat("-", 80));
|
||||
} catch (IOException ioe) {
|
||||
Throwables.propagate(ioe);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ package org.jclouds.vcloud.director.v1_5.features;
|
|||
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_EQUAL;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_NON_NULL;
|
||||
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.VCloudDirectorMediaType.ADMIN_USER;
|
||||
|
@ -50,14 +49,11 @@ import static org.testng.Assert.assertNotNull;
|
|||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.AccessSetting;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.AccessSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
||||
|
@ -83,11 +79,7 @@ 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.UndeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.cim.CimString;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.cim.CimUnsignedInt;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.NetworkSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.OperatingSystemSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.RASD;
|
||||
|
@ -95,69 +87,19 @@ import org.jclouds.vcloud.director.v1_5.domain.ovf.StartupSection;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.ovf.VirtualHardwareSection;
|
||||
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.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
|
||||
import org.jclouds.xml.internal.JAXBParser;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code VAppClient}
|
||||
* Tests behavior of the {@link VAppClient}.
|
||||
*
|
||||
* @author grkvlt@apache.org
|
||||
*/
|
||||
@Test(groups = { "live", "user", "vapp" }, singleThreaded = true, testName = "VAppClientLiveTest")
|
||||
public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||
|
||||
/*
|
||||
* Convenience reference to API clients.
|
||||
*/
|
||||
|
||||
protected CatalogClient catalogClient;
|
||||
protected OrgClient orgClient;
|
||||
protected VAppClient vAppClient;
|
||||
protected VAppTemplateClient vAppTemplateClient;
|
||||
protected VdcClient vdcClient;
|
||||
protected MetadataClient.Writeable metadataClient;
|
||||
|
||||
/*
|
||||
* Objects shared between tests.
|
||||
*/
|
||||
|
||||
private Vdc vdc;
|
||||
private VApp vApp;
|
||||
private VAppTemplate vAppTemplate;
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@BeforeClass(inheritGroups = true)
|
||||
@Override
|
||||
public void setupRequiredClients() {
|
||||
catalogClient = context.getApi().getCatalogClient();
|
||||
orgClient = context.getApi().getOrgClient();
|
||||
vAppClient = context.getApi().getVAppClient();
|
||||
vAppTemplateClient = context.getApi().getVAppTemplateClient();
|
||||
vdcClient = context.getApi().getVdcClient();
|
||||
metadataClient = vAppClient.getMetadataClient();
|
||||
}
|
||||
|
||||
@BeforeClass(inheritGroups = true)
|
||||
public void setupEnvironment() throws Exception {
|
||||
vdc = vdcClient.getVdc(vdcURI);
|
||||
assertNotNull(vdc, String.format(ENTITY_NON_NULL, VDC));
|
||||
|
||||
vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
assertNotNull(vAppTemplate, String.format(ENTITY_NON_NULL, VAPP_TEMPLATE));
|
||||
|
||||
cleanUp();
|
||||
}
|
||||
public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
||||
|
||||
/**
|
||||
* @see VAppClient#getVApp(URI)
|
||||
|
@ -171,7 +113,7 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
assertTrue(retryTaskSuccessLong.apply(instantiateTask), String.format(TASK_COMPLETE_TIMELY, "instantiateTask"));
|
||||
|
||||
// The method under test
|
||||
vApp = vAppClient.getVApp(vAppInstantiated.getHref());
|
||||
vApp = vAppClient.getVApp(vAppURI);
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkVApp(vApp);
|
||||
|
@ -451,14 +393,12 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "GET /vApp/{id}/guestCustomizationSection", dependsOnMethods = { "testGetVApp" })
|
||||
public void testGetGuestCustomizationSection() {
|
||||
// Get URI for child VM
|
||||
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
|
||||
|
||||
// The method under test
|
||||
GuestCustomizationSection section = vAppClient.getGuestCustomizationSection(vmURI);
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkGuestCustomizationSection(section);
|
||||
getGuestCustomizationSection(new Function<URI, GuestCustomizationSection>() {
|
||||
@Override
|
||||
public GuestCustomizationSection apply(URI uri) {
|
||||
return vAppClient.getGuestCustomizationSection(uri);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(testName = "PUT /vApp/{id}/guestCustomizationSection", dependsOnMethods = { "testGetGuestCustomizationSection" })
|
||||
|
@ -610,14 +550,12 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "GET /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testGetVApp" })
|
||||
public void testGetNetworkConnectionSection() {
|
||||
// Get URI for child VM
|
||||
URI vmURI = Iterables.getOnlyElement(vApp.getChildren().getVms()).getHref();
|
||||
|
||||
// The method under test
|
||||
NetworkConnectionSection section = vAppClient.getNetworkConnectionSection(vmURI);
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkNetworkConnectionSection(section);
|
||||
getNetworkConnectionSection(new Function<URI, NetworkConnectionSection>() {
|
||||
@Override
|
||||
public NetworkConnectionSection apply(URI uri) {
|
||||
return vAppClient.getNetworkConnectionSection(uri);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(testName = "PUT /vApp/{id}/networkConnectionSection", dependsOnMethods = { "testGetNetworkConnectionSection" })
|
||||
|
@ -1076,7 +1014,7 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "GET /vApp/{id}/metadata", dependsOnMethods = { "testGetVApp" })
|
||||
public void testGetMetadata() {
|
||||
Metadata metadata = metadataClient.getMetadata(vApp.getHref());
|
||||
Metadata metadata = vAppClient.getMetadataClient().getMetadata(vApp.getHref());
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkMetadataFor(VAPP, metadata);
|
||||
|
@ -1088,10 +1026,10 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
String key = Integer.toString(random.nextInt());
|
||||
String value = Integer.toString(random.nextInt());
|
||||
MetadataValue metadataValue = MetadataValue.builder().value(value).build();
|
||||
metadataClient.setMetadata(vApp.getHref(), key, metadataValue);
|
||||
vAppClient.getMetadataClient().setMetadata(vApp.getHref(), key, metadataValue);
|
||||
|
||||
// Retrieve the value, and assert it was set correctly
|
||||
MetadataValue newMetadataValue = metadataClient.getMetadataValue(vApp.getHref(), key);
|
||||
MetadataValue newMetadataValue = vAppClient.getMetadataClient().getMetadataValue(vApp.getHref(), key);
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkMetadataValueFor(VAPP, newMetadataValue, value);
|
||||
|
@ -1102,14 +1040,14 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
// Store a value, to be deleted
|
||||
String key = Integer.toString(random.nextInt());
|
||||
MetadataValue metadataValue = MetadataValue.builder().value("myval").build();
|
||||
metadataClient.setMetadata(vApp.getHref(), key, metadataValue);
|
||||
vAppClient.getMetadataClient().setMetadata(vApp.getHref(), key, metadataValue);
|
||||
|
||||
// Delete the entry
|
||||
Task task = metadataClient.deleteMetadataEntry(vApp.getHref(), key);
|
||||
Task task = vAppClient.getMetadataClient().deleteMetadataEntry(vApp.getHref(), key);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
// Confirm the entry has been deleted
|
||||
Metadata newMetadata = metadataClient.getMetadata(vApp.getHref());
|
||||
Metadata newMetadata = vAppClient.getMetadataClient().getMetadata(vApp.getHref());
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkMetadataKeyAbsentFor(VAPP, newMetadata, key);
|
||||
|
@ -1117,7 +1055,7 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "POST /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" })
|
||||
public void testMergeMetadata() {
|
||||
Metadata oldMetadata = metadataClient.getMetadata(vApp.getHref());
|
||||
Metadata oldMetadata = vAppClient.getMetadataClient().getMetadata(vApp.getHref());
|
||||
Map<String, String> oldMetadataMap = Checks.metadataToMap(oldMetadata);
|
||||
|
||||
// Store a value, to be deleted
|
||||
|
@ -1126,11 +1064,11 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
Metadata addedMetadata = Metadata.builder()
|
||||
.entry(MetadataEntry.builder().key(key).value(value).build())
|
||||
.build();
|
||||
Task task = metadataClient.mergeMetadata(vApp.getHref(), addedMetadata);
|
||||
Task task = vAppClient.getMetadataClient().mergeMetadata(vApp.getHref(), addedMetadata);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
// Confirm the entry contains everything that was there, and everything that was being added
|
||||
Metadata newMetadata = metadataClient.getMetadata(vApp.getHref());
|
||||
Metadata newMetadata = vAppClient.getMetadataClient().getMetadata(vApp.getHref());
|
||||
Map<String, String> expectedMetadataMap = ImmutableMap.<String, String>builder()
|
||||
.putAll(oldMetadataMap)
|
||||
.put(key, value)
|
||||
|
@ -1157,72 +1095,4 @@ public class VAppClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
vApp = null;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE This method is also called by the BeforeClass method setupRequiredClients
|
||||
@AfterClass(alwaysRun = true, description = "Clean up the environment by deleting created VApps named 'test-vapp' or 'new-name'")
|
||||
public void cleanUp() throws Exception {
|
||||
// Find references in the Vdc with the VApp type and named 'test-vapp' or 'new-name'
|
||||
Iterable<Reference> vApps = Iterables.filter(
|
||||
vdc.getResourceEntities().getResourceEntities(),
|
||||
Predicates.and(
|
||||
ReferenceTypePredicates.<Reference> typeEquals(VCloudDirectorMediaType.VAPP),
|
||||
Predicates.or(
|
||||
ReferenceTypePredicates.<Reference> nameEquals("test-vapp"),
|
||||
ReferenceTypePredicates.<Reference> nameEquals("new-name")
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// If we found any references, delete the VApp they point to
|
||||
if (vApps != null && !Iterables.isEmpty(vApps)) {
|
||||
for (Reference each : vApps) {
|
||||
cleanUpVApp(each.getHref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshals a JAXB annotated object into XML. The XML is output on {@link System#err}.
|
||||
*/
|
||||
private void debug(Object object) {
|
||||
JAXBParser parser = new JAXBParser();
|
||||
try {
|
||||
String xml = parser.toXML(object);
|
||||
|
||||
System.err.println(Strings.repeat("-", 80));
|
||||
System.err.println(xml);
|
||||
System.err.println(Strings.repeat("-", 80));
|
||||
} catch (IOException ioe) {
|
||||
Throwables.propagate(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private CimUnsignedInt newCimUnsignedInt(long val) {
|
||||
CimUnsignedInt result = new CimUnsignedInt();
|
||||
result.setValue(val);
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private CimString newCimString(String val) {
|
||||
CimString result = new CimString();
|
||||
result.setValue(val);
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void checkHasMatchingItem(String context, RasdItemsList items, String instanceId, String elementName) {
|
||||
boolean found = false;
|
||||
for (RASD item : items.getItems()) {
|
||||
String itemInstanceId = item.getInstanceID().getValue();
|
||||
if (itemInstanceId.equals(instanceId)) {
|
||||
assertEquals(item.getElementName().getValue(), elementName,
|
||||
String.format(OBJ_FIELD_EQ, VAPP, context+"/"+instanceId+"/elementName", elementName, ""+item.getElementName().getValue()));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(found, "no "+context+" item found with id "+instanceId+"; only found "+items);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,17 +18,30 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkCustomizationSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkGuestCustomizationSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkLeaseSettingsSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfEnvelope;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfNetworkSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOwner;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkProductSectionList;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVAppTemplate;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.metadataToMap;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.CloneVAppTemplateParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.CustomizationSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection;
|
||||
|
@ -43,52 +56,25 @@ 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.Reference;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.RelocateParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntityType.Status;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.UndeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.Envelope;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.NetworkSection;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests the request/response behavior of {@link org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient}
|
||||
* Tests the request/response behavior of {@link VAppTemplateClient}
|
||||
*
|
||||
* NOTE The environment MUST have at least one template configured
|
||||
*
|
||||
* @author Aled Sage
|
||||
*/
|
||||
@Test(groups = {"live", "unit", "user"}, testName = "VAppTemplateClientLiveTest")
|
||||
public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||
|
||||
private VAppTemplateClient vappTemplateClient;
|
||||
private VdcClient vdcClient;
|
||||
private VAppClient vappClient;
|
||||
|
||||
private VApp vApp;
|
||||
private Vm vm;
|
||||
|
||||
@BeforeClass(inheritGroups = true)
|
||||
@Override
|
||||
public void setupRequiredClients() throws Exception {
|
||||
vappTemplateClient = context.getApi().getVAppTemplateClient();
|
||||
vdcClient = context.getApi().getVdcClient();
|
||||
vappClient = context.getApi().getVAppClient();
|
||||
}
|
||||
|
||||
// TODO remove duplication from other tests
|
||||
@AfterClass(groups = { "live" })
|
||||
public void cleanUp() throws Exception {
|
||||
if (vApp != null) cleanUpVApp(vApp);
|
||||
}
|
||||
@Test(groups = { "live", "user", "vapptemplate" }, singleThreaded = true, testName = "VAppTemplateClientLiveTest")
|
||||
public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
||||
|
||||
// FIXME cloneVAppTemplate is giving back 500 error
|
||||
private VAppTemplate cloneVAppTemplate(boolean waitForTask) throws Exception {
|
||||
|
@ -106,114 +92,108 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
return clonedVappTemplate;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstantiateAndStartVApp() throws Exception {
|
||||
vApp = instantiateVApp();
|
||||
Task instantiateTask = Iterables.getFirst(vApp.getTasks(), null);
|
||||
if (instantiateTask != null) {
|
||||
assertTaskSucceedsLong(instantiateTask);
|
||||
}
|
||||
|
||||
// Start the vApp so that it has VMs
|
||||
Task task = vappClient.powerOn(vApp.getHref());
|
||||
assertTaskSucceedsLong(task);
|
||||
|
||||
// Get a VM
|
||||
vApp = vappClient.getVApp(vApp.getHref()); // refresh
|
||||
List<Vm> vms = vApp.getChildren().getVms();
|
||||
vm = Iterables.getFirst(vms, null);
|
||||
assertNotNull(vm, "started vApp "+vApp+" must have at least one VM");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVAppTemplate() {
|
||||
VAppTemplate template = vappTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
|
||||
Checks.checkVAppTemplate(template);
|
||||
assertEquals(template.getHref(), vAppTemplateURI);
|
||||
checkVAppTemplate(vAppTemplate);
|
||||
assertEquals(vAppTemplate.getHref(), vAppTemplateURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOwner() {
|
||||
Owner owner = vappTemplateClient.getOwnerOfVAppTemplate(vAppTemplateURI);
|
||||
public void testGetVAppTemplateOwner() {
|
||||
Owner owner = vAppTemplateClient.getOwnerOfVAppTemplate(vAppTemplateURI);
|
||||
|
||||
Checks.checkOwner(owner);
|
||||
assertEquals(owner.getUser(), vappTemplateClient.getVAppTemplate(vAppTemplateURI).getOwner().getUser());
|
||||
checkOwner(owner);
|
||||
assertEquals(owner.getUser(), vAppTemplateClient.getVAppTemplate(vAppTemplateURI).getOwner().getUser());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCustomizationSection() {
|
||||
CustomizationSection customizationSection = vappTemplateClient.getVAppTemplateCustomizationSection(vAppTemplateURI);
|
||||
CustomizationSection customizationSection = vAppTemplateClient.getVAppTemplateCustomizationSection(vAppTemplateURI);
|
||||
|
||||
Checks.checkCustomizationSection(customizationSection);
|
||||
checkCustomizationSection(customizationSection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProductSections() {
|
||||
ProductSectionList productSectionList = vappTemplateClient.getProductSectionsForVAppTemplate(vAppTemplateURI);
|
||||
ProductSectionList productSectionList = vAppTemplateClient.getProductSectionsForVAppTemplate(vAppTemplateURI);
|
||||
|
||||
Checks.checkProductSectionList(productSectionList);
|
||||
checkProductSectionList(productSectionList);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = { "testInstantiateAndStartVApp" } )
|
||||
@Test(testName = "GET /vAppTemplate/{id}/guestCustomizationSection")
|
||||
public void testGetGuestCustomizationSection() {
|
||||
GuestCustomizationSection guestCustomizationSection = vappTemplateClient.getVAppTemplateGuestCustomizationSection(vm.getHref());
|
||||
getGuestCustomizationSection(new Function<URI, GuestCustomizationSection>() {
|
||||
@Override
|
||||
public GuestCustomizationSection apply(URI uri) {
|
||||
return vAppTemplateClient.getVAppTemplateGuestCustomizationSection(uri);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Checks.checkGuestCustomizationSection(guestCustomizationSection);
|
||||
@Test
|
||||
public void testGetProductSectionsForVAppTemplate() {
|
||||
ProductSectionList productSectionList = vAppTemplateClient.getProductSectionsForVAppTemplate(vAppTemplateURI);
|
||||
|
||||
checkProductSectionList(productSectionList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLeaseSettingsSection() {
|
||||
// FIXME Wrong case for Vapp
|
||||
LeaseSettingsSection leaseSettingsSection = vappTemplateClient.getVappTemplateLeaseSettingsSection(vAppTemplateURI);
|
||||
LeaseSettingsSection leaseSettingsSection = vAppTemplateClient.getVappTemplateLeaseSettingsSection(vAppTemplateURI);
|
||||
|
||||
Checks.checkLeaseSettingsSection(leaseSettingsSection);
|
||||
checkLeaseSettingsSection(leaseSettingsSection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMetadata() {
|
||||
Metadata metadata = vappTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
public void testGetVAppTemplateMetadata() {
|
||||
Metadata metadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
|
||||
Checks.checkMetadata(metadata);
|
||||
checkMetadata(metadata);
|
||||
}
|
||||
|
||||
@Test // implicitly tested by testEditVAppTemplateMetadataValue, which first creates the metadata entry; otherwise no entry may exist
|
||||
public void testGetMetadataValue() {
|
||||
Metadata metadata = vappTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Metadata metadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
MetadataEntry entry = Iterables.get(metadata.getMetadataEntries(), 0);
|
||||
|
||||
MetadataValue val = vappTemplateClient.getVAppTemplateMetadataValue(vAppTemplateURI, entry.getKey());
|
||||
MetadataValue val = vAppTemplateClient.getVAppTemplateMetadataValue(vAppTemplateURI, entry.getKey());
|
||||
|
||||
Checks.checkMetadataValue(val);
|
||||
checkMetadataValue(val);
|
||||
assertEquals(val.getValue(), entry.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNetworkConfigSection() {
|
||||
NetworkConfigSection networkConfigSection = vappTemplateClient.getVAppTemplateNetworkConfigSection(vAppTemplateURI);
|
||||
public void testGetVAppTemplateNetworkConfigSection() {
|
||||
NetworkConfigSection networkConfigSection = vAppTemplateClient.getVAppTemplateNetworkConfigSection(vAppTemplateURI);
|
||||
|
||||
Checks.checkNetworkConfigSection(networkConfigSection);
|
||||
checkNetworkConfigSection(networkConfigSection);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = { "testInstantiateAndStartVApp" } )
|
||||
@Test(testName = "GET /vAppTemplate/{id}/networkConnectionSection")
|
||||
public void testGetNetworkConnectionSection() {
|
||||
NetworkConnectionSection networkConnectionSection = vappTemplateClient.getVAppTemplateNetworkConnectionSection(vm.getHref());
|
||||
|
||||
Checks.checkNetworkConnectionSection(networkConnectionSection);
|
||||
getNetworkConnectionSection(new Function<URI, NetworkConnectionSection>() {
|
||||
@Override
|
||||
public NetworkConnectionSection apply(URI uri) {
|
||||
return vAppTemplateClient.getVAppTemplateNetworkConnectionSection(uri);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNetworkSection() {
|
||||
NetworkSection networkSection = vappTemplateClient.getVAppTemplateNetworkSection(vAppTemplateURI);
|
||||
public void testGetVAppTemplateNetworkSection() {
|
||||
NetworkSection networkSection = vAppTemplateClient.getVAppTemplateNetworkSection(vAppTemplateURI);
|
||||
|
||||
Checks.checkOvfNetworkSection(networkSection);
|
||||
checkOvfNetworkSection(networkSection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOvf() {
|
||||
Envelope envelope = vappTemplateClient.getVAppTemplateOvf(vAppTemplateURI);
|
||||
public void testGetVAppTemplateOvf() {
|
||||
Envelope envelope = vAppTemplateClient.getVAppTemplateOvf(vAppTemplateURI);
|
||||
|
||||
Checks.checkOvfEnvelope(envelope);
|
||||
checkOvfEnvelope(envelope);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -226,10 +206,10 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
.description(description)
|
||||
.build();
|
||||
|
||||
final Task task = vappTemplateClient.editVAppTemplate(vAppTemplateURI, template);
|
||||
final Task task = vAppTemplateClient.editVAppTemplate(vAppTemplateURI, template);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
VAppTemplate newTemplate = vappTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
VAppTemplate newTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
assertEquals(newTemplate.getName(), name);
|
||||
assertEquals(newTemplate.getDescription(), description);
|
||||
}
|
||||
|
@ -238,8 +218,8 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
public void testEditMetadata() {
|
||||
// TODO Cleanup after ourselves..
|
||||
|
||||
Metadata oldMetadata = vappTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Map<String,String> oldMetadataMap = Checks.metadataToMap(oldMetadata);
|
||||
Metadata oldMetadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Map<String,String> oldMetadataMap = metadataToMap(oldMetadata);
|
||||
|
||||
String uid = ""+random.nextInt();
|
||||
String key = "mykey-"+uid;
|
||||
|
@ -247,15 +227,15 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).build();
|
||||
Metadata metadata = Metadata.builder().fromMetadata(oldMetadata).entry(metadataEntry).build();
|
||||
|
||||
final Task task = vappTemplateClient.editVAppTemplateMetadata(vAppTemplateURI, metadata);
|
||||
final Task task = vAppTemplateClient.editVAppTemplateMetadata(vAppTemplateURI, metadata);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
Metadata newMetadata = vappTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Metadata newMetadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Map<String,String> expectedMetadataMap = ImmutableMap.<String,String>builder()
|
||||
.putAll(oldMetadataMap)
|
||||
.put(key, val)
|
||||
.build();
|
||||
Checks.checkMetadataFor("vAppTemplate", newMetadata, expectedMetadataMap);
|
||||
checkMetadataFor("vAppTemplate", newMetadata, expectedMetadataMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -267,10 +247,10 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
String val = "myval-"+uid;
|
||||
MetadataValue metadataValue = MetadataValue.builder().value(val).build();
|
||||
|
||||
final Task task = vappTemplateClient.editVAppTemplateMetadataValue(vAppTemplateURI, key, metadataValue);
|
||||
final Task task = vAppTemplateClient.editVAppTemplateMetadataValue(vAppTemplateURI, key, metadataValue);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
MetadataValue newMetadataValue = vappTemplateClient.getVAppTemplateMetadataValue(vAppTemplateURI, key);
|
||||
MetadataValue newMetadataValue = vAppTemplateClient.getVAppTemplateMetadataValue(vAppTemplateURI, key);
|
||||
assertEquals(newMetadataValue.getValue(), metadataValue.getValue());
|
||||
}
|
||||
|
||||
|
@ -279,19 +259,19 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
// First store a value
|
||||
String key = "mykey-"+random.nextInt();
|
||||
MetadataValue metadataValue = MetadataValue.builder().value("myval").build();
|
||||
final Task task = vappTemplateClient.editVAppTemplateMetadataValue(vAppTemplateURI, key, metadataValue);
|
||||
final Task task = vAppTemplateClient.editVAppTemplateMetadataValue(vAppTemplateURI, key, metadataValue);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
// Then delete the entry
|
||||
final Task deletionTask = vappTemplateClient.deleteVAppTemplateMetadataValue(vAppTemplateURI, key);
|
||||
final Task deletionTask = vAppTemplateClient.deleteVAppTemplateMetadataValue(vAppTemplateURI, key);
|
||||
retryTaskSuccess.apply(deletionTask);
|
||||
|
||||
// Then confirm the entry is not there
|
||||
Metadata newMetadata = vappTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
Checks.checkMetadataKeyAbsentFor("vAppTemplate", newMetadata, key);
|
||||
Metadata newMetadata = vAppTemplateClient.getVAppTemplateMetadata(vAppTemplateURI);
|
||||
checkMetadataKeyAbsentFor("vAppTemplate", newMetadata, key);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = { "testInstantiateAndStartVApp" } )
|
||||
@Test
|
||||
public void testEditGuestCustomizationSection() {
|
||||
String computerName = "a"+random.nextInt(Integer.MAX_VALUE);
|
||||
GuestCustomizationSection newSection = GuestCustomizationSection.builder()
|
||||
|
@ -299,32 +279,15 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
.computerName(computerName)
|
||||
.build();
|
||||
|
||||
final Task task = vappTemplateClient.editVAppTemplateGuestCustomizationSection(vm.getHref(), newSection);
|
||||
final Task task = vAppTemplateClient.editVAppTemplateGuestCustomizationSection(vm.getHref(), newSection);
|
||||
assertTaskSucceeds(task);
|
||||
|
||||
GuestCustomizationSection modified = vappTemplateClient.getVAppTemplateGuestCustomizationSection(vm.getHref());
|
||||
GuestCustomizationSection modified = vAppTemplateClient.getVAppTemplateGuestCustomizationSection(vm.getHref());
|
||||
|
||||
Checks.checkGuestCustomizationSection(modified);
|
||||
checkGuestCustomizationSection(modified);
|
||||
assertEquals(modified.getComputerName(), computerName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditCustomizationSection() {
|
||||
boolean oldVal = vappTemplateClient.getVAppTemplateCustomizationSection(vAppTemplateURI).isCustomizeOnInstantiate();
|
||||
boolean newVal = !oldVal;
|
||||
|
||||
CustomizationSection customizationSection = CustomizationSection.builder()
|
||||
.info("my info")
|
||||
.customizeOnInstantiate(newVal)
|
||||
.build();
|
||||
|
||||
final Task task = vappTemplateClient.editVAppTemplateCustomizationSection(vAppTemplateURI, customizationSection);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
CustomizationSection newCustomizationSection = vappTemplateClient.getVAppTemplateCustomizationSection(vAppTemplateURI);
|
||||
assertEquals(newCustomizationSection.isCustomizeOnInstantiate(), newVal);
|
||||
}
|
||||
|
||||
@Test // FIXME deploymentLeaseInSeconds returned is null
|
||||
public void testEditLeaseSettingsSection() throws Exception {
|
||||
// Note: use smallish number for storageLeaseInSeconds; it seems to be capped at 5184000?
|
||||
|
@ -336,19 +299,19 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
.deploymentLeaseInSeconds(deploymentLeaseInSeconds)
|
||||
.build();
|
||||
|
||||
final Task task = vappTemplateClient.editVappTemplateLeaseSettingsSection(vAppTemplateURI, leaseSettingSection);
|
||||
final Task task = vAppTemplateClient.editVappTemplateLeaseSettingsSection(vAppTemplateURI, leaseSettingSection);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
LeaseSettingsSection newLeaseSettingsSection = vappTemplateClient.getVappTemplateLeaseSettingsSection(vAppTemplateURI);
|
||||
LeaseSettingsSection newLeaseSettingsSection = vAppTemplateClient.getVappTemplateLeaseSettingsSection(vAppTemplateURI);
|
||||
assertEquals(newLeaseSettingsSection.getStorageLeaseInSeconds(), (Integer)storageLeaseInSeconds);
|
||||
assertEquals(newLeaseSettingsSection.getDeploymentLeaseInSeconds(), (Integer)deploymentLeaseInSeconds);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = { "testInstantiateAndStartVApp" } )
|
||||
@Test
|
||||
public void testEditNetworkConfigSection() {
|
||||
// TODO What to modify?
|
||||
|
||||
NetworkConfigSection oldSection = vappTemplateClient.getVAppTemplateNetworkConfigSection(vApp.getHref());
|
||||
NetworkConfigSection oldSection = vAppTemplateClient.getVAppTemplateNetworkConfigSection(vApp.getHref());
|
||||
NetworkConfigSection newSection = oldSection.toBuilder().build();
|
||||
|
||||
// String networkName = ""+random.nextInt();
|
||||
|
@ -365,11 +328,11 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
// .networkConfigs(vappNetworkConfigurations)
|
||||
// .build();
|
||||
|
||||
final Task task = vappTemplateClient.editVAppTemplateNetworkConfigSection(vApp.getHref(), newSection);
|
||||
final Task task = vAppTemplateClient.editVAppTemplateNetworkConfigSection(vApp.getHref(), newSection);
|
||||
assertTaskSucceeds(task);
|
||||
|
||||
NetworkConfigSection modified = vappTemplateClient.getVAppTemplateNetworkConfigSection(vAppTemplateURI);
|
||||
Checks.checkNetworkConfigSection(modified);
|
||||
NetworkConfigSection modified = vAppTemplateClient.getVAppTemplateNetworkConfigSection(vAppTemplateURI);
|
||||
checkNetworkConfigSection(modified);
|
||||
|
||||
// assertEquals(modified§.getNetworkConfigs().size(), 1);
|
||||
//
|
||||
|
@ -377,19 +340,19 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
// assertEquals(newVAppNetworkConfig.getNetworkName(), networkName);
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = { "testInstantiateAndStartVApp" } )
|
||||
@Test
|
||||
public void testEditNetworkConnectionSection() {
|
||||
// TODO Modify a field so can assert that the change really took effect
|
||||
|
||||
NetworkConnectionSection oldSection = vappTemplateClient.getVAppTemplateNetworkConnectionSection(vm.getHref());
|
||||
NetworkConnectionSection oldSection = vAppTemplateClient.getVAppTemplateNetworkConnectionSection(vm.getHref());
|
||||
NetworkConnectionSection newSection = oldSection.toBuilder()
|
||||
.build();
|
||||
|
||||
final Task task = vappTemplateClient.editVAppTemplateNetworkConnectionSection(vm.getHref(), newSection);
|
||||
final Task task = vAppTemplateClient.editVAppTemplateNetworkConnectionSection(vm.getHref(), newSection);
|
||||
assertTaskSucceeds(task);
|
||||
|
||||
NetworkConnectionSection modified = vappTemplateClient.getVAppTemplateNetworkConnectionSection(vm.getHref());
|
||||
Checks.checkNetworkConnectionSection(modified);
|
||||
NetworkConnectionSection modified = vAppTemplateClient.getVAppTemplateNetworkConnectionSection(vm.getHref());
|
||||
checkNetworkConnectionSection(modified);
|
||||
}
|
||||
|
||||
@Test // FIXME cloneVAppTemplate is giving back 500 error
|
||||
|
@ -397,16 +360,16 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
VAppTemplate clonedVappTemplate = cloneVAppTemplate(true);
|
||||
|
||||
// Confirm that "get" works pre-delete
|
||||
VAppTemplate vAppTemplatePreDelete = vappTemplateClient.getVAppTemplate(clonedVappTemplate.getHref());
|
||||
Checks.checkVAppTemplate(vAppTemplatePreDelete);
|
||||
VAppTemplate vAppTemplatePreDelete = vAppTemplateClient.getVAppTemplate(clonedVappTemplate.getHref());
|
||||
checkVAppTemplate(vAppTemplatePreDelete);
|
||||
|
||||
// Delete the template
|
||||
final Task task = vappTemplateClient.deleteVappTemplate(clonedVappTemplate.getHref());
|
||||
final Task task = vAppTemplateClient.deleteVappTemplate(clonedVappTemplate.getHref());
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
// Confirm that can't access post-delete, i.e. template has been deleted
|
||||
try {
|
||||
vappTemplateClient.getVAppTemplate(clonedVappTemplate.getHref());
|
||||
vAppTemplateClient.getVAppTemplate(clonedVappTemplate.getHref());
|
||||
} catch (VCloudDirectorException e) {
|
||||
// success; should get a 403 because vAppTemplate no longer exists
|
||||
}
|
||||
|
@ -414,14 +377,14 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
|
||||
@Test
|
||||
public void testDisableVAppTemplateDownload() throws Exception {
|
||||
vappTemplateClient.disableDownloadVappTemplate(vAppTemplateURI);
|
||||
vAppTemplateClient.disableDownloadVappTemplate(vAppTemplateURI);
|
||||
|
||||
// TODO Check that it really is disabled. The only thing I can see for determining this
|
||||
// is the undocumented "download" link in the VAppTemplate. But that is brittle and we
|
||||
// don't know what timing guarantees there are for adding/removing the link.
|
||||
//
|
||||
// For example:
|
||||
// VAppTemplate vAppTemplate = vappTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
// VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
// Set<Link> links = vAppTemplate.getLinks();
|
||||
// assertFalse(hasLinkMatchingRel(links, "download.*"), "Should not offer download link after disabling download: "+vAppTemplate);
|
||||
}
|
||||
|
@ -429,8 +392,8 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
@Test
|
||||
public void testEnableVAppTemplateDownload() throws Exception {
|
||||
// First disable so that enable really has some work to do...
|
||||
vappTemplateClient.disableDownloadVappTemplate(vAppTemplateURI);
|
||||
final Task task = vappTemplateClient.enableDownloadVappTemplate(vAppTemplateURI);
|
||||
vAppTemplateClient.disableDownloadVappTemplate(vAppTemplateURI);
|
||||
final Task task = vAppTemplateClient.enableDownloadVappTemplate(vAppTemplateURI);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
// TODO Check that it really is enabled. The only thing I can see for determining this
|
||||
|
@ -438,7 +401,7 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
// don't know what timing guarantees there are for adding/removing the link.
|
||||
//
|
||||
// For example:
|
||||
// VAppTemplate vAppTemplate = vappTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
// VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
// Set<Link> links = vAppTemplate.getLinks();
|
||||
// assertTrue(hasLinkMatchingRel(links, "download.*"), "Should offer download link after enabling download: "+vAppTemplate);
|
||||
}
|
||||
|
@ -453,12 +416,12 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
return false;
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testInstantiateAndStartVApp" } )
|
||||
@Test
|
||||
public void testConsolidateVAppTemplate() throws Exception {
|
||||
// TODO Need assertion that command had effect
|
||||
|
||||
System.out.println("About to try to consolidate "+vm);
|
||||
final Task task = vappTemplateClient.consolidateVappTemplate(vm.getHref());
|
||||
final Task task = vAppTemplateClient.consolidateVappTemplate(vm.getHref());
|
||||
assertTaskSucceedsLong(task);
|
||||
}
|
||||
|
||||
|
@ -470,7 +433,7 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
.datastore(dataStore)
|
||||
.build();
|
||||
|
||||
final Task task = vappTemplateClient.relocateVappTemplate(vAppTemplateURI, relocateParams);
|
||||
final Task task = vAppTemplateClient.relocateVappTemplate(vAppTemplateURI, relocateParams);
|
||||
assertTaskSucceedsLong(task);
|
||||
}
|
||||
|
||||
|
@ -479,12 +442,12 @@ public class VAppTemplateClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
@Test
|
||||
public void testCompletedTaskNotIncludedInVAppTemplate() throws Exception {
|
||||
// Kick off a task, and wait for it to complete
|
||||
vappTemplateClient.disableDownloadVappTemplate(vAppTemplateURI);
|
||||
final Task task = vappTemplateClient.enableDownloadVappTemplate(vAppTemplateURI);
|
||||
vAppTemplateClient.disableDownloadVappTemplate(vAppTemplateURI);
|
||||
final Task task = vAppTemplateClient.enableDownloadVappTemplate(vAppTemplateURI);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
||||
// Ask the VAppTemplate for its tasks, and the status of the matching task if it exists
|
||||
VAppTemplate vAppTemplate = vappTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
VAppTemplate vAppTemplate = vAppTemplateClient.getVAppTemplate(vAppTemplateURI);
|
||||
Set<Task> tasks = vAppTemplate.getTasks();
|
||||
if (tasks != null) {
|
||||
for (Task contender : tasks) {
|
||||
|
|
Loading…
Reference in New Issue