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
|
// 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
|
// 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.
|
// abandoned, unknown) above are used for the extraction tasks as well.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the resource has been uploaded
|
* the resource has been uploaded
|
||||||
*/
|
*/
|
||||||
|
@ -80,6 +81,9 @@ public class Template implements Comparable<Template> {
|
||||||
UPLOAD_IN_PROGRESS, UNRECOGNIZED;
|
UPLOAD_IN_PROGRESS, UNRECOGNIZED;
|
||||||
|
|
||||||
public static Status fromValue(String state) {
|
public static Status fromValue(String state) {
|
||||||
|
if (state.equals("Download Complete")) {
|
||||||
|
return DOWNLOADED;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return valueOf(checkNotNull(state, "state"));
|
return valueOf(checkNotNull(state, "state"));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
|
@ -18,9 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudstack.features;
|
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 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.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -45,19 +52,20 @@ public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
public void testListDomains() {
|
public void testListDomains() {
|
||||||
skipIfNotDomainAdmin();
|
skipIfNotDomainAdmin();
|
||||||
|
|
||||||
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
|
Set<Domain> domains = domainAdminClient.getDomainClient().listDomains();
|
||||||
|
for (Domain candidate : domains) {
|
||||||
Domain root = find(allDomains, withName("ROOT"));
|
checkDomain(candidate);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Domain domain : allDomains) {
|
private void checkDomain(Domain domain) {
|
||||||
checkDomain(domain, allDomains);
|
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() {
|
public void testListDomainChildren() {
|
||||||
skipIfNotDomainAdmin();
|
skipIfNotDomainAdmin();
|
||||||
|
|
||||||
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
|
Set<Domain> domains = domainAdminClient.getDomainClient().listDomains();
|
||||||
Domain root = find(allDomains, withName("ROOT"));
|
Domain root = findRootOfVisibleTree(domains);
|
||||||
|
if (domains.size() > 1) {
|
||||||
|
assertTrue(root.hasChild());
|
||||||
|
}
|
||||||
|
|
||||||
Set<Domain> children = domainAdminClient.getDomainClient()
|
Set<Domain> children = domainAdminClient.getDomainClient()
|
||||||
.listDomainChildren(parentDomainId(root.getId()).isRecursive(true));
|
.listDomainChildren(parentDomainId(root.getId()).isRecursive(true));
|
||||||
assertEquals(allDomains.size() - 1, children.size());
|
assertEquals(domains.size() - 1, children.size());
|
||||||
|
assertTrue(Sets.difference(domains, children).contains(root));
|
||||||
for (Domain domain : children) {
|
|
||||||
checkDomain(domain, allDomains);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<Domain> withName(final String name) {
|
private Domain findRootOfVisibleTree(Set<Domain> domains) {
|
||||||
return new Predicate<Domain>() {
|
final Set<String> names = newHashSet(Iterables.transform(domains,
|
||||||
@Override
|
new Function<Domain, String>() {
|
||||||
public boolean apply(@Nullable Domain domain) {
|
@Override
|
||||||
return domain != null && domain.getName().equals(name);
|
public String apply(Domain domain) {
|
||||||
|
return domain.getName();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (Domain candidate : domains) {
|
||||||
|
if (candidate.getParentDomainId() == null ||
|
||||||
|
!names.contains(candidate.getParentDomainName())) {
|
||||||
|
return candidate;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
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.getZone() != null : template;
|
||||||
assert template.getZoneId() != null : template;
|
assert template.getZoneId() != null : template;
|
||||||
assert (template.getStatus() == null ||
|
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.getType() != null && template.getType() != Template.Type.UNRECOGNIZED : template;
|
||||||
assert template.getHypervisor() != null : template;
|
assert template.getHypervisor() != null : template;
|
||||||
assert template.getDomain() != null : template;
|
assert template.getDomain() != null : template;
|
||||||
|
@ -160,7 +160,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
networks = Iterables.filter(networks, new Predicate<Network>() {
|
networks = Iterables.filter(networks, new Predicate<Network>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable Network network) {
|
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);
|
assertEquals(Iterables.size(networks), 1);
|
||||||
|
@ -184,7 +184,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
if (template == null) return false;
|
if (template == null) return false;
|
||||||
Template t2 = client.getTemplateClient().getTemplateInZone(template.getId(), zoneId);
|
Template t2 = client.getTemplateClient().getTemplateInZone(template.getId(), zoneId);
|
||||||
Logger.CONSOLE.info("%s", t2.getStatus());
|
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));
|
assertTrue(new RetryablePredicate<Template>(templateReadyPredicate, 60000).apply(registeredTemplate));
|
||||||
|
|
|
@ -91,7 +91,12 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
RetryablePredicate<String> jobComplete, RetryablePredicate<VirtualMachine> virtualMachineRunning) {
|
RetryablePredicate<String> jobComplete, RetryablePredicate<VirtualMachine> virtualMachineRunning) {
|
||||||
Set<Network> networks = client.getNetworkClient().listNetworks(isDefault(true));
|
Set<Network> networks = client.getNetworkClient().listNetworks(isDefault(true));
|
||||||
if (networks.size() > 0) {
|
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,
|
return createVirtualMachineInNetwork(network,
|
||||||
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
|
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
|
||||||
virtualMachineRunning);
|
virtualMachineRunning);
|
||||||
|
@ -185,7 +190,10 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
checkVm(vm);
|
checkVm(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateVirtualMachineWithSpecificIp() throws Exception {
|
public void testCreateVirtualMachineWithSpecificIp() throws Exception {
|
||||||
|
skipIfNotGlobalAdmin();
|
||||||
|
|
||||||
String templateId = (imageId != null && !"".equals(imageId)) ? imageId : null;
|
String templateId = (imageId != null && !"".equals(imageId)) ? imageId : null;
|
||||||
Network network = null;
|
Network network = null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue