mirror of https://github.com/apache/jclouds.git
Improving Host Administration extension tests
This commit is contained in:
parent
43d258837d
commit
f45b9ca849
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
["hosts": [{"host_name": "ubuntu", "service": "compute"}]
|
{"hosts": [{"host_name": "ubuntu", "service": "compute"}]}
|
Loading…
Reference in New Issue