Improving Host Administration extension tests

This commit is contained in:
Adam Lowe 2012-04-19 10:37:17 +01:00
parent 43d258837d
commit f45b9ca849
3 changed files with 33 additions and 8 deletions

View File

@ -18,16 +18,23 @@
*/ */
package org.jclouds.openstack.nova.v1_1.extensions; package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Set;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.domain.Host;
import org.jclouds.openstack.nova.v1_1.domain.HostResourceUsage;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/** /**
* Tests HostAdministrationClient guice wiring and parsing * Tests HostAdministrationClient guice wiring and parsing
@ -44,9 +51,16 @@ public class HostAdministrationClientExpectTest extends BaseNovaClientExpectTest
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken)) HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
.endpoint(endpoint).build(), .endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); HttpResponse.builder().statusCode(200).payload(payloadFromResource("/hosts_list.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
client.listHosts(); Host expected = Host.builder().name("ubuntu").service("compute").build();
Set<Host> result = client.listHosts();
Host host = Iterables.getOnlyElement(result);
assertEquals(host.getName(), "ubuntu");
assertEquals(host.getService(), "compute");
assertEquals(host, expected);
} }
public void testGet() throws Exception { public void testGet() throws Exception {
@ -55,9 +69,16 @@ public class HostAdministrationClientExpectTest extends BaseNovaClientExpectTest
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken)) HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
.endpoint(endpoint).build(), .endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
client.getHostResourceUsage("xyz"); Set<HostResourceUsage> expected = ImmutableSet.of(
HostResourceUsage.builder().memoryMb(16083).project("(total)").cpu(4).diskGb(181).host("ubuntu").build(),
HostResourceUsage.builder().memoryMb(3396).project("(used_now)").cpu(3).diskGb(5).host("ubuntu").build(),
HostResourceUsage.builder().memoryMb(6144).project("(used_max)").cpu(3).diskGb(80).host("ubuntu").build(),
HostResourceUsage.builder().memoryMb(6144).project("f8535069c3fb404cb61c873b1a0b4921").cpu(3).diskGb(80).host("ubuntu").build()
);
assertEquals(client.getHostResourceUsage("xyz"), expected);
} }
} }

View File

@ -18,11 +18,13 @@
*/ */
package org.jclouds.openstack.nova.v1_1.extensions; package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.util.Set; import java.util.Set;
import org.jclouds.openstack.nova.v1_1.domain.Host; import org.jclouds.openstack.nova.v1_1.domain.Host;
import org.jclouds.openstack.nova.v1_1.domain.HostResourceUsage;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -36,16 +38,18 @@ import com.google.common.base.Optional;
@Test(groups = "live", testName = "HostAdministrationClientLiveTest") @Test(groups = "live", testName = "HostAdministrationClientLiveTest")
public class HostAdministrationClientLiveTest extends BaseNovaClientLiveTest { public class HostAdministrationClientLiveTest extends BaseNovaClientLiveTest {
public void testListAndGet() throws Exception { public void testListAndGet() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) { for (String zoneId : novaContext.getApi().getConfiguredZones()) {
Optional<HostAdministrationClient> optClient = novaContext.getApi().getHostAdministrationExtensionForZone(zoneId); Optional<HostAdministrationClient> optClient = novaContext.getApi().getHostAdministrationExtensionForZone(zoneId);
if (optClient.isPresent()) { if (optClient.isPresent() && identity.endsWith(":admin")) {
HostAdministrationClient client = optClient.get(); HostAdministrationClient client = optClient.get();
Set<Host> hosts = client.listHosts(); Set<Host> hosts = client.listHosts();
assertNotNull(hosts); assertNotNull(hosts);
for(Host host : hosts) { for(Host host : hosts) {
client.getHostResourceUsage(host.getName()); for (HostResourceUsage usage : client.getHostResourceUsage(host.getName())) {
assertEquals(usage.getHost(), host.getName());
assertNotNull(usage);
}
} }
} }
} }

View File

@ -1 +1 @@
["hosts": [{"host_name": "ubuntu", "service": "compute"}] {"hosts": [{"host_name": "ubuntu", "service": "compute"}]}