mirror of https://github.com/apache/jclouds.git
Fixed template status, network selection and domain live tests
This commit is contained in:
parent
03867b97b2
commit
134797844a
|
@ -62,6 +62,7 @@ public class Template implements Comparable<Template> {
|
|||
// These states are specifically used for extraction of resources out of CS(ironically shown
|
||||
// as download template in the UI, API - extractTemplate ). Some of the generic states (like
|
||||
// abandoned, unknown) above are used for the extraction tasks as well.
|
||||
|
||||
/**
|
||||
* the resource has been uploaded
|
||||
*/
|
||||
|
@ -80,6 +81,9 @@ public class Template implements Comparable<Template> {
|
|||
UPLOAD_IN_PROGRESS, UNRECOGNIZED;
|
||||
|
||||
public static Status fromValue(String state) {
|
||||
if (state.equals("Download Complete")) {
|
||||
return DOWNLOADED;
|
||||
}
|
||||
try {
|
||||
return valueOf(checkNotNull(state, "state"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -18,9 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import com.google.common.collect.Sets;
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import java.util.NoSuchElementException;
|
||||
import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.name;
|
||||
import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
@ -45,19 +52,20 @@ public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
public void testListDomains() {
|
||||
skipIfNotDomainAdmin();
|
||||
|
||||
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
|
||||
|
||||
Domain root = find(allDomains, withName("ROOT"));
|
||||
assertEquals(root, domainAdminClient.getDomainClient().getDomainById(root.getId()));
|
||||
assertEquals(root.getLevel(), 0);
|
||||
assertEquals(root.getParentDomainId(), 0);
|
||||
assertNull(root.getParentDomainName());
|
||||
if (allDomains.size() > 1) {
|
||||
assertTrue(root.hasChild());
|
||||
Set<Domain> domains = domainAdminClient.getDomainClient().listDomains();
|
||||
for (Domain candidate : domains) {
|
||||
checkDomain(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
for (Domain domain : allDomains) {
|
||||
checkDomain(domain, allDomains);
|
||||
private void checkDomain(Domain domain) {
|
||||
assertNotNull(domain.getId());
|
||||
if (domain.getLevel() == 0 /* global ROOT */) {
|
||||
assertNull(domain.getParentDomainName());
|
||||
assertNull(domain.getParentDomainId());
|
||||
} else {
|
||||
assertNotNull(domain.getParentDomainName());
|
||||
assertNotNull(domain.getParentDomainId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,33 +73,33 @@ public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
public void testListDomainChildren() {
|
||||
skipIfNotDomainAdmin();
|
||||
|
||||
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
|
||||
Domain root = find(allDomains, withName("ROOT"));
|
||||
Set<Domain> domains = domainAdminClient.getDomainClient().listDomains();
|
||||
Domain root = findRootOfVisibleTree(domains);
|
||||
if (domains.size() > 1) {
|
||||
assertTrue(root.hasChild());
|
||||
}
|
||||
|
||||
Set<Domain> children = domainAdminClient.getDomainClient()
|
||||
.listDomainChildren(parentDomainId(root.getId()).isRecursive(true));
|
||||
assertEquals(allDomains.size() - 1, children.size());
|
||||
|
||||
for (Domain domain : children) {
|
||||
checkDomain(domain, allDomains);
|
||||
}
|
||||
assertEquals(domains.size() - 1, children.size());
|
||||
assertTrue(Sets.difference(domains, children).contains(root));
|
||||
}
|
||||
|
||||
private Predicate<Domain> withName(final String name) {
|
||||
return new Predicate<Domain>() {
|
||||
private Domain findRootOfVisibleTree(Set<Domain> domains) {
|
||||
final Set<String> names = newHashSet(Iterables.transform(domains,
|
||||
new Function<Domain, String>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Domain domain) {
|
||||
return domain != null && domain.getName().equals(name);
|
||||
}
|
||||
};
|
||||
public String apply(Domain domain) {
|
||||
return domain.getName();
|
||||
}
|
||||
}));
|
||||
|
||||
private void checkDomain(Domain domain, Set<Domain> allDomains) {
|
||||
assert domain.getId() != null : domain;
|
||||
if (domain.getParentDomainName() != null) {
|
||||
Domain parent = find(allDomains, withName(domain.getParentDomainName()));
|
||||
assertEquals(parent.getId(), domain.getParentDomainId());
|
||||
assertTrue(parent.hasChild());
|
||||
for (Domain candidate : domains) {
|
||||
if (candidate.getParentDomainId() == null ||
|
||||
!names.contains(candidate.getParentDomainName())) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
throw new NoSuchElementException("No root node found in this tree");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assert template.getZone() != null : template;
|
||||
assert template.getZoneId() != null : template;
|
||||
assert (template.getStatus() == null ||
|
||||
template.getStatus().equals("Download Complete")) : template;
|
||||
template.getStatus() == Template.Status.DOWNLOADED) : template;
|
||||
assert template.getType() != null && template.getType() != Template.Type.UNRECOGNIZED : template;
|
||||
assert template.getHypervisor() != null : template;
|
||||
assert template.getDomain() != null : template;
|
||||
|
@ -160,7 +160,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
networks = Iterables.filter(networks, new Predicate<Network>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Network network) {
|
||||
return network != null && network.getState().equals("Implemented");
|
||||
return network != null && network.getName().equals("Virtual Network");
|
||||
}
|
||||
});
|
||||
assertEquals(Iterables.size(networks), 1);
|
||||
|
@ -184,7 +184,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
if (template == null) return false;
|
||||
Template t2 = client.getTemplateClient().getTemplateInZone(template.getId(), zoneId);
|
||||
Logger.CONSOLE.info("%s", t2.getStatus());
|
||||
return "Download Complete".equals(t2.getStatus());
|
||||
return t2.getStatus() == Template.Status.DOWNLOADED;
|
||||
}
|
||||
};
|
||||
assertTrue(new RetryablePredicate<Template>(templateReadyPredicate, 60000).apply(registeredTemplate));
|
||||
|
|
|
@ -91,7 +91,12 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
RetryablePredicate<String> jobComplete, RetryablePredicate<VirtualMachine> virtualMachineRunning) {
|
||||
Set<Network> networks = client.getNetworkClient().listNetworks(isDefault(true));
|
||||
if (networks.size() > 0) {
|
||||
Network network = get(networks, 0);
|
||||
Network network = get(filter(networks, new Predicate<Network>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Network network) {
|
||||
return network != null && network.getState().equals("Implemented");
|
||||
}
|
||||
}), 0);
|
||||
return createVirtualMachineInNetwork(network,
|
||||
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
|
||||
virtualMachineRunning);
|
||||
|
@ -185,7 +190,10 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
checkVm(vm);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateVirtualMachineWithSpecificIp() throws Exception {
|
||||
skipIfNotGlobalAdmin();
|
||||
|
||||
String templateId = (imageId != null && !"".equals(imageId)) ? imageId : null;
|
||||
Network network = null;
|
||||
|
||||
|
|
Loading…
Reference in New Issue