mirror of https://github.com/apache/jclouds.git
Merge pull request #545 from danikov/vcloud-director-admin-enabled-tests
Issue 830: vCloud director Bugfix
This commit is contained in:
commit
d09ad94ffa
|
@ -21,6 +21,8 @@ package org.jclouds.vcloud.director.v1_5.domain;
|
|||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -29,7 +31,8 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
|
@ -57,7 +60,7 @@ public class ControlAccessParams {
|
|||
|
||||
private Boolean sharedToEveryone = Boolean.FALSE;
|
||||
private String everyoneAccessLevel;
|
||||
private Set<AccessSetting> accessSettings = Sets.newLinkedHashSet();
|
||||
private Set<AccessSetting> accessSettings;
|
||||
|
||||
/**
|
||||
* @see ControlAccessParams#getIsSharedToEveryone()
|
||||
|
@ -95,7 +98,7 @@ public class ControlAccessParams {
|
|||
* @see ControlAccessParams#getAccessSettings()
|
||||
*/
|
||||
public Builder accessSettings(Iterable<AccessSetting> accessSettings) {
|
||||
this.accessSettings = Sets.newLinkedHashSet(checkNotNull(accessSettings, "accessSettings"));
|
||||
this.accessSettings = Sets.newLinkedHashSet(checkNotNull(accessSettings));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,10 @@ public class ControlAccessParams {
|
|||
* @see ControlAccessParams#getAccessSettings()
|
||||
*/
|
||||
public Builder accessSetting(AccessSetting accessSetting) {
|
||||
this.accessSettings.add(checkNotNull(accessSetting, "accessSetting"));
|
||||
if (accessSettings == null) {
|
||||
accessSettings = Sets.newLinkedHashSet();
|
||||
}
|
||||
accessSettings.add(checkNotNull(accessSetting, "accessSetting"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -124,7 +130,10 @@ public class ControlAccessParams {
|
|||
public ControlAccessParams(Boolean sharedToEveryone, String everyoneAccessLevel, Iterable<AccessSetting> accessSettings) {
|
||||
this.sharedToEveryone = sharedToEveryone;
|
||||
this.everyoneAccessLevel = everyoneAccessLevel;
|
||||
this.accessSettings = accessSettings == null ? Sets.<AccessSetting>newLinkedHashSet() : ImmutableSet.copyOf(accessSettings);
|
||||
if (sharedToEveryone) {
|
||||
checkNotNull(accessSettings, "accessSettings");
|
||||
}
|
||||
this.accessSettings = Iterables.isEmpty(accessSettings) ? null : ImmutableList.copyOf(accessSettings);
|
||||
}
|
||||
|
||||
@XmlElement(name = "IsSharedToEveryone", required = true)
|
||||
|
@ -133,7 +142,7 @@ public class ControlAccessParams {
|
|||
protected String everyoneAccessLevel;
|
||||
@XmlElementWrapper(name = "AccessSettings")
|
||||
@XmlElement(name = "AccessSetting")
|
||||
protected Set<AccessSetting> accessSettings = Sets.newLinkedHashSet();
|
||||
protected List<AccessSetting> accessSettings;
|
||||
|
||||
/**
|
||||
* If true, this means that the resource is shared with everyone in the organization.
|
||||
|
@ -156,8 +165,8 @@ public class ControlAccessParams {
|
|||
*
|
||||
* Required on create and modify if {@link #isSharedToEveryone()} is false.
|
||||
*/
|
||||
public Set<AccessSetting> getAccessSettings() {
|
||||
return accessSettings;
|
||||
public List<AccessSetting> getAccessSettings() {
|
||||
return accessSettings == null ? Collections.<AccessSetting>emptyList() : accessSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -178,7 +178,7 @@ public interface QueryClient {
|
|||
QueryResultRecords vmsQuery(String filter);
|
||||
|
||||
/**
|
||||
* Retrieves a list of {@link Medias by using REST API general QueryHandler.
|
||||
* Retrieves a list of {@link Media}s by using REST API general QueryHandler.
|
||||
*
|
||||
* <pre>
|
||||
* GET /mediaList/query
|
||||
|
|
|
@ -106,8 +106,8 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
*
|
||||
* @see BaseVCloudDirectorClientLiveTest#setupRequiredClients()
|
||||
*/
|
||||
@BeforeClass(alwaysRun = true, description = "Retrieves the required clients from the REST API context")
|
||||
@Override
|
||||
@BeforeClass(alwaysRun = true, description = "Retrieves the required clients from the REST API context")
|
||||
protected void setupRequiredClients() {
|
||||
assertNotNull(context.getApi());
|
||||
|
||||
|
@ -116,6 +116,8 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
vAppClient = context.getApi().getVAppClient();
|
||||
vAppTemplateClient = context.getApi().getVAppTemplateClient();
|
||||
vdcClient = context.getApi().getVdcClient();
|
||||
|
||||
setupEnvironment();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,7 +126,6 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
* Retrieves the test {@link Vdc} and {@link VAppTemplate} from their configured {@link URI}s.
|
||||
* Instantiates a new test VApp.
|
||||
*/
|
||||
@BeforeClass(alwaysRun = true, description = "Sets up the environment", dependsOnMethods = { "setupRequiredClients" })
|
||||
protected void setupEnvironment() {
|
||||
// Get the configured Vdc for the tests
|
||||
vdc = vdcClient.getVdc(vdcURI);
|
||||
|
|
|
@ -48,6 +48,8 @@ public class VCloudDirectorLiveTestConstants {
|
|||
public static final String OBJ_FIELD_CONTAINS = "ERR-107: %s %s must contain the values \"%s\" (%s)";
|
||||
|
||||
public static final String OBJ_FIELD_GTE_0 = "ERR-108: %s field %s must be greater than to equal to 0 (%d)";
|
||||
|
||||
public static final String OBJ_FIELD_GTE_1 = "ERR-108: %s field %s must be greater than to equal to 0 (%d)";
|
||||
|
||||
public static final String GETTER_RETURNS_SAME_OBJ = "ERR-109: %s should return the same %s as %s (%s, %s)";
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
|
|||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_REQ;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_GTE_0;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_GTE_1;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT;
|
||||
|
@ -684,6 +685,8 @@ public class Checks {
|
|||
// Check optional fields, dependant on IsSharedToEveryone state
|
||||
if (params.isSharedToEveryone()) {
|
||||
assertNotNull(params.getEveryoneAccessLevel(), String.format(OBJ_FIELD_REQ, "ControlAccessParams", "EveryoneAccessLevel"));
|
||||
assertNotNull(params.getAccessSettings(), String.format(OBJ_FIELD_REQ, "ControlAccessParams", "AccessSettings when isSharedToEveryone"));
|
||||
assertTrue(params.getAccessSettings().size() >= 1, String.format(OBJ_FIELD_GTE_1, "ControlAccessParams", "AccessSettings.size", params.getAccessSettings().size()));
|
||||
} else {
|
||||
for (AccessSetting setting : params.getAccessSettings()) {
|
||||
checkAccessSetting(setting);
|
||||
|
|
|
@ -33,6 +33,7 @@ import static org.testng.Assert.assertNotNull;
|
|||
import java.net.URI;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ControlAccessParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
|
||||
|
@ -59,29 +60,35 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
*/
|
||||
|
||||
private OrgClient orgClient;
|
||||
private URI catalogRef;
|
||||
private String testCatalogId;
|
||||
|
||||
@Override
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void setupRequiredClients() {
|
||||
orgClient = context.getApi().getOrgClient();
|
||||
testCatalogId = catalogId;
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void cleanUp() throws Exception {
|
||||
if (metadataSet) {
|
||||
if (adminMembersSet) {
|
||||
adminContext.getApi().getOrgClient().getMetadataClient()
|
||||
.deleteMetadataEntry(toAdminUri(orgURI), "KEY");
|
||||
|
||||
adminContext.getApi().getCatalogClient()
|
||||
.deleteCatalog(catalogRef);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Shared state between dependant tests.
|
||||
* Shared state between dependent tests.
|
||||
*/
|
||||
|
||||
private OrgList orgList;
|
||||
private URI orgURI;
|
||||
private Org org;
|
||||
private boolean metadataSet = false;
|
||||
private boolean adminMembersSet = false; // track if test entities have been created
|
||||
|
||||
@Test(description = "GET /org")
|
||||
public void testGetOrgList() {
|
||||
|
@ -110,19 +117,33 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
org = orgClient.getOrg(orgURI);
|
||||
|
||||
checkOrg(org);
|
||||
|
||||
if (adminContext != null) {
|
||||
setupAdminMembers();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMetadata() {
|
||||
/**
|
||||
* If we're running in an admin context, it's cleaner to make temporary entities, plus eliminates the need for configuration
|
||||
*/
|
||||
private void setupAdminMembers() {
|
||||
adminContext.getApi().getOrgClient().getMetadataClient().setMetadata(toAdminUri(orgURI),
|
||||
"KEY", MetadataValue.builder().value("VALUE").build());
|
||||
metadataSet = true;
|
||||
"KEY", MetadataValue.builder().value("VALUE").build());
|
||||
|
||||
AdminCatalog newCatalog = AdminCatalog.builder()
|
||||
.name("Test Catalog "+getTestDateTimeStamp())
|
||||
.description("created by testOrg()")
|
||||
.build();
|
||||
newCatalog = adminContext.getApi().getCatalogClient().createCatalog(toAdminUri(orgURI), newCatalog);
|
||||
|
||||
catalogRef = newCatalog.getHref();
|
||||
testCatalogId = newCatalog.getId().substring("urn:vcloud:catalog:".length());
|
||||
|
||||
adminMembersSet = true;
|
||||
}
|
||||
|
||||
@Test(description = "GET /org/{id}/metadata", dependsOnMethods = { "testGetOrg" })
|
||||
public void testGetOrgMetadata() {
|
||||
if (adminContext != null) {
|
||||
setupMetadata();
|
||||
}
|
||||
|
||||
// Call the method being tested
|
||||
Metadata metadata = orgClient.getMetadataClient().getMetadata(orgURI);
|
||||
|
@ -151,7 +172,7 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
@Test(description = "GET /org/{id}/catalog/{catalogId}/controlAccess", dependsOnMethods = { "testGetOrg" })
|
||||
public void testGetControlAccess() {
|
||||
// Call the method being tested
|
||||
ControlAccessParams params = orgClient.getControlAccess(orgURI, catalogId);
|
||||
ControlAccessParams params = orgClient.getControlAccess(orgURI, testCatalogId);
|
||||
|
||||
// Check params are well formed
|
||||
checkControlAccessParams(params);
|
||||
|
@ -160,10 +181,10 @@ public class OrgClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
@Test(description = "GET /org/{id}/catalog/{catalogId}/action/controlAccess", dependsOnMethods = { "testGetControlAccess" })
|
||||
public void testModifyControlAccess() {
|
||||
// Setup params
|
||||
ControlAccessParams params = orgClient.getControlAccess(orgURI, catalogId);
|
||||
ControlAccessParams params = orgClient.getControlAccess(orgURI, testCatalogId);
|
||||
|
||||
// Call the method being tested
|
||||
ControlAccessParams modified = orgClient.modifyControlAccess(orgURI, catalogId, params);
|
||||
ControlAccessParams modified = orgClient.modifyControlAccess(orgURI, testCatalogId, params);
|
||||
|
||||
// Check params are well formed
|
||||
checkControlAccessParams(modified);
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import static com.google.common.base.Predicates.and;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.contains;
|
||||
import static com.google.common.collect.Iterables.getFirst;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_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;
|
||||
|
@ -49,6 +53,8 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkStartupSection
|
|||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVApp;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVirtualHardwareSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkVmPendingQuestion;
|
||||
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.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
@ -62,14 +68,18 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.vcloud.director.v1_5.AbstractVAppClientLiveTest;
|
||||
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.Checks;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ControlAccessParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.DeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.LeaseSettingsSection;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Media;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.MediaInsertOrEjectParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
|
||||
|
@ -103,6 +113,8 @@ 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.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -121,6 +133,62 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
|
||||
private MetadataValue metadataValue;
|
||||
private String key;
|
||||
private URI mediaURI;
|
||||
private URI testUserURI;
|
||||
|
||||
@Override
|
||||
@BeforeClass(alwaysRun = true)
|
||||
protected void setupRequiredClients() {
|
||||
super.setupRequiredClients();
|
||||
|
||||
Set<Link> links = vdcClient.getVdc(vdcURI).getLinks();
|
||||
Predicate<Link> addMediaLink = and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA));
|
||||
|
||||
if (contains(links, addMediaLink)) {
|
||||
Link addMedia = find(links, addMediaLink);
|
||||
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||
|
||||
Media sourceMedia = Media.builder()
|
||||
.type(VCloudDirectorMediaType.MEDIA)
|
||||
.name("Test media "+random.nextInt())
|
||||
.size(iso.length)
|
||||
.imageType(Media.ImageType.ISO)
|
||||
.description("Test media generated by vAppClientLiveTest")
|
||||
.build();
|
||||
Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
|
||||
|
||||
Link uploadLink = getFirst(getFirst(media.getFiles(), null).getLinks(), null);
|
||||
context.getApi().getUploadClient().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
|
||||
|
||||
media = context.getApi().getMediaClient().getMedia(media.getHref());
|
||||
|
||||
if (media.getTasks().size() == 1) {
|
||||
Task uploadTask = Iterables.getOnlyElement(media.getTasks());
|
||||
Checks.checkTask(uploadTask);
|
||||
assertEquals(uploadTask.getStatus(), "running");
|
||||
assertTrue(retryTaskSuccess.apply(uploadTask), String.format(TASK_COMPLETE_TIMELY, "uploadTask"));
|
||||
media = context.getApi().getMediaClient().getMedia(media.getHref());
|
||||
}
|
||||
|
||||
mediaURI = media.getHref();
|
||||
} else {
|
||||
mediaURI = super.mediaURI;
|
||||
}
|
||||
|
||||
if (adminContext != null) {
|
||||
Link orgLink = find(links, and(relEquals("up"), typeEquals(VCloudDirectorMediaType.ORG)));
|
||||
testUserURI = adminContext.getApi().getUserClient().createUser(toAdminUri(orgLink), randomTestUser("VAppAccessTest")).getHref();
|
||||
} else {
|
||||
testUserURI = userURI;
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void cleanUp() {
|
||||
if (adminContext != null && mediaURI != null) {
|
||||
assertTaskDoneEventually(context.getApi().getMediaClient().deleteMedia(mediaURI));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VAppClient#getVApp(URI)
|
||||
|
@ -326,7 +394,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
ControlAccessParams params = ControlAccessParams.builder()
|
||||
.notSharedToEveryone()
|
||||
.accessSetting(AccessSetting.builder()
|
||||
.subject(Reference.builder().href(userURI).type(ADMIN_USER).build())
|
||||
.subject(Reference.builder().href(testUserURI).type(ADMIN_USER).build())
|
||||
.accessLevel("ReadOnly")
|
||||
.build())
|
||||
.build();
|
||||
|
@ -725,7 +793,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
|
||||
@Test(description = "PUT /vApp/{id}/owner", dependsOnMethods = { "testGetOwner" })
|
||||
public void testModifyOwner() {
|
||||
Owner newOwner = Owner.builder().user(Reference.builder().href(userURI).type(ADMIN_USER).build()).build();
|
||||
Owner newOwner = Owner.builder().user(Reference.builder().href(testUserURI).type(ADMIN_USER).build()).build();
|
||||
|
||||
// The method under test
|
||||
vAppClient.modifyOwner(vApp.getHref(), newOwner);
|
||||
|
|
|
@ -84,8 +84,8 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
protected void tidyUp() {
|
||||
if (catalog != null) {
|
||||
catalogClient.deleteCatalog(catalog.getHref());
|
||||
try {
|
||||
catalogClient.getCatalog(catalog.getHref());
|
||||
try { //TODO: predicate to retry for a short while?
|
||||
catalogClient.getCatalog(catalog.getHref());
|
||||
fail("The Catalog should have been deleted");
|
||||
} catch (VCloudDirectorException vcde) {
|
||||
checkError(vcde.getError());
|
||||
|
|
Loading…
Reference in New Issue