Reduced the number of failing tests from 48 to 23

* ID equality test fixes. Changed from == to .equals
* throw ResourceNotFoundException for all server responses
with code 431 that contain "does not exist"
* skip tests rather than failing when running the suite
as a regular or domain admin user. It's not possible to
have global admin access on public clouds
This commit is contained in:
Andrei Savu 2012-06-06 16:53:57 +03:00
parent c18c97552f
commit 03867b97b2
22 changed files with 50 additions and 28 deletions

View File

@ -71,8 +71,7 @@ public class CloudStackErrorHandler implements HttpErrorHandler {
break;
case 409:
case 431:
if (command.getCurrentRequest().getRequestLine().indexOf("delete") != -1
&& message.indexOf("does not exist") != -1) {
if (message.contains("does not exist")) {
exception = new ResourceNotFoundException(message, exception);
} else {
exception = new IllegalStateException(message, exception);

View File

@ -49,7 +49,7 @@ public class AccountClientLiveTest extends BaseCloudStackClientLiveTest {
assert user.getName() != null : user;
assert user.getAccountType().equals(account.getType()) : user;
assert user.getDomain().equals(account.getDomain()) : user;
assert user.getDomainId() == account.getDomainId() : user;
assert user.getDomainId().equals(account.getDomainId()) : user;
assert user.getApiKey() != null : user;
assert user.getCreated() != null : user;
assert user.getEmail() != null : user;

View File

@ -57,6 +57,7 @@ import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.SkipException;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
@ -270,6 +271,18 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte
return currentUser;
}
protected void skipIfNotDomainAdmin() {
if (!domainAdminEnabled) {
throw new SkipException("Test cannot run without domain admin identity and credentials");
}
}
protected void skipIfNotGlobalAdmin() {
if (!globalAdminEnabled) {
throw new SkipException("Test cannot run without global admin identity and credentials");
}
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (cloudStackContext != null)

View File

@ -38,7 +38,7 @@ public class DomainAccountClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testEnableDisableAccount() {
assert globalAdminEnabled;
skipIfNotGlobalAdmin();
Account testAccount = null;
try {

View File

@ -43,7 +43,7 @@ public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testListDomains() {
assert domainAdminEnabled;
skipIfNotDomainAdmin();
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
@ -63,7 +63,7 @@ public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testListDomainChildren() {
assert domainAdminEnabled;
skipIfNotDomainAdmin();
Set<Domain> allDomains = domainAdminClient.getDomainClient().listDomains();
Domain root = find(allDomains, withName("ROOT"));

View File

@ -40,7 +40,7 @@ public class DomainUserClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testListUsers() {
assert domainAdminEnabled;
skipIfNotDomainAdmin();
Set<User> users = domainAdminClient.getUserClient().listUsers();
@ -60,7 +60,8 @@ public class DomainUserClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testEnableDisableUser() {
assert globalAdminEnabled && domainAdminEnabled;
skipIfNotDomainAdmin();
skipIfNotDomainAdmin();
Account testAccount = null;
User testUser = null;

View File

@ -42,7 +42,7 @@ public class GlobalAccountClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testCreateAndRemoveAccount() {
assert globalAdminEnabled;
skipIfNotGlobalAdmin();
Account account = null;
try {

View File

@ -38,7 +38,7 @@ public class GlobalAlertClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testListAlerts() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
final Set<Alert> response = globalAdminClient.getAlertClient().listAlerts(ListAlertsOptions.Builder.id("20"));
assert null != response;

View File

@ -36,7 +36,7 @@ public class GlobalCapacityClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testListCapacity() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
final Set<Capacity> response = globalAdminClient.getCapacityClient().listCapacity();
assert null != response;

View File

@ -45,7 +45,7 @@ public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveT
@Test
public void testListConfigurationEntries() {
assert globalAdminEnabled;
skipIfNotGlobalAdmin();
Set<ConfigurationEntry> entries = globalAdminClient
.getConfigurationClient().listConfigurationEntries();
@ -62,7 +62,7 @@ public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveT
@Test
public void testUpdateConfigurationEntry() {
assert globalAdminEnabled;
skipIfNotGlobalAdmin();
Set<ConfigurationEntry> entries = globalAdminClient
.getConfigurationClient().listConfigurationEntries();

View File

@ -55,7 +55,7 @@ public class GlobalDomainClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testCreateUpdateDeleteDomain() {
assert globalAdminEnabled;
skipIfNotDomainAdmin();
Domain domain = null;
try {

View File

@ -40,7 +40,7 @@ public class GlobalHostClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testListHosts() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
Set<Host> hosts = globalAdminClient.getHostClient().listHosts();
assert hosts.size() > 0 : hosts;
@ -68,7 +68,7 @@ public class GlobalHostClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testListClusters() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
Set<Cluster> clusters = globalAdminClient.getHostClient().listClusters();
assert clusters.size() > 0 : clusters;

View File

@ -50,7 +50,7 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testCreateServiceOffering() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
String name = prefix + "-test-create-service-offering";
String displayText = name + "-display";
@ -90,7 +90,7 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testCreateDiskOffering() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
String name = prefix + "-test-create-disk-offering";
String displayText = name + "-display";
@ -127,7 +127,7 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testUpdateNetworkOffering() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
NetworkOffering offering = getFirst(globalAdminClient.getOfferingClient().listNetworkOfferings(), null);
assertNotNull(offering, "Unable to test, no network offering found.");

View File

@ -51,10 +51,13 @@ public class GlobalPodClientLiveTest extends BaseCloudStackClientLiveTest {
private Pod pod;
public void testListPods() throws Exception {
skipIfNotGlobalAdmin();
Set<Pod> response = globalAdminClient.getPodClient().listPods();
assert null != response;
long podCount = response.size();
assertTrue(podCount >= 0);
for (Pod pod : response) {
Pod newDetails = Iterables.getOnlyElement(globalAdminClient.getPodClient().listPods(
ListPodsOptions.Builder.id(pod.getId())));
@ -74,7 +77,7 @@ public class GlobalPodClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testCreatePod() {
assertTrue(globalAdminEnabled, "Global admin credentials must be given");
skipIfNotGlobalAdmin();
zone = globalAdminClient.getZoneClient().createZone(prefix + "-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10");
pod = globalAdminClient.getPodClient().createPod(prefix + "-pod", zone.getId(), "172.20.0.1", "172.20.0.250", "172.20.0.254", "255.255.255.0",

View File

@ -39,7 +39,7 @@ public class GlobalStoragePoolClientLiveTest extends BaseCloudStackClientLiveTes
@Test(groups = "live", enabled = true)
public void testListStoragePools() throws Exception {
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
skipIfNotGlobalAdmin();
Set<StoragePool> result = globalAdminClient.getStoragePoolClient().listStoragePools();
assertNotNull(result);

View File

@ -42,6 +42,8 @@ public class GlobalUsageClientLiveTest extends BaseCloudStackClientLiveTest {
@Test(groups = "live", enabled = true)
public void testListUsage() {
skipIfNotGlobalAdmin();
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Date end = c.getTime();
c.add(Calendar.MONTH, -1);

View File

@ -50,7 +50,7 @@ public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testCreateUser() {
assert globalAdminEnabled;
skipIfNotGlobalAdmin();
Account testAccount = createTestAccount(globalAdminClient, prefix);
User testUser = null;

View File

@ -57,10 +57,13 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
private VlanIPRange range;
public void testListVlanIPRanges() throws Exception {
skipIfNotGlobalAdmin();
Set<VlanIPRange> response = globalAdminClient.getVlanClient().listVlanIPRanges();
assert null != response;
long rangeCount = response.size();
assertTrue(rangeCount >= 0);
for (VlanIPRange range : response) {
VlanIPRange newDetails = Iterables.getOnlyElement(globalAdminClient.getVlanClient().listVlanIPRanges(
ListVlanIPRangesOptions.Builder.id(range.getId())));
@ -90,7 +93,7 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
new Predicate<Network>() {
@Override
public boolean apply(Network network) {
return network.getNetworkOfferingId() == offering.getId();
return network.getNetworkOfferingId().equals(offering.getId());
}
});

View File

@ -38,7 +38,7 @@ public class GlobalZoneClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testCreateUpdateDeleteZone() {
assert globalAdminEnabled;
skipIfNotGlobalAdmin();
Zone zone = null;
String zoneName = prefix + "-zone";

View File

@ -44,11 +44,12 @@ public class SessionClientLiveTest extends BaseCloudStackClientLiveTest {
@Test
public void testCreateContextUsingUserAndPasswordAuthentication() {
String endpoint = cloudStackContext.getProviderMetadata().getEndpoint();
assert globalAdminEnabled;
skipIfNotGlobalAdmin();
String endpoint = cloudStackContext.getProviderMetadata().getEndpoint();
Account testAccount = null;
User testUser = null;
String prefix = this.prefix + "-session";
try {
testAccount = createTestAccount(globalAdminClient, prefix);

View File

@ -147,7 +147,7 @@ public class SnapshotClientLiveTest extends BaseCloudStackClientLiveTest {
return find(client.getSnapshotClient().listSnapshots(), new Predicate<Snapshot>() {
@Override
public boolean apply(Snapshot arg0) {
return arg0.getId() == id;
return arg0.getId().equals(id);
}
});
}

View File

@ -246,7 +246,7 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
static Volume findVolumeWithId(final CloudStackClient client, final String id) {
for (Volume v: client.getVolumeClient().listVolumes())
if (v.getId()==id) return v;
if (v.getId().equals(id)) return v;
throw new NoSuchElementException("no volume with id "+id);
}