Adding tests of Host Administration extension

This commit is contained in:
Adam Lowe 2012-04-19 07:32:11 +01:00
parent 400221820a
commit 80c48193ee
3 changed files with 119 additions and 0 deletions

View File

@ -32,6 +32,7 @@ import org.jclouds.openstack.services.ServiceType;
/**
* Provides asynchronous access to Host Administration features via the REST API.
* <p/>
* TODO reboot, shutdown, startup, update
*
* @author Adam Lowe
* @see HostAdministrationAsyncClient

View File

@ -0,0 +1,63 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.extensions;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
/**
* Tests HostAdministrationClient guice wiring and parsing
*
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "HostAdministrationClientExpectTest")
public class HostAdministrationClientExpectTest extends BaseNovaClientExpectTest {
public void testList() throws Exception {
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-hosts");
HostAdministrationClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
.endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
client.listHosts();
}
public void testGet() throws Exception {
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-hosts/xyz");
HostAdministrationClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
.endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
client.getHostResourceUsage("xyz");
}
}

View File

@ -0,0 +1,55 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertNotNull;
import java.util.Set;
import org.jclouds.openstack.nova.v1_1.domain.Host;
import org.jclouds.openstack.nova.v1_1.domain.SimpleTenantUsage;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
import org.testng.annotations.Test;
import com.google.common.base.Optional;
/**
* Tests behavior of HostAdministrationClient
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "HostAdministrationClientLiveTest")
public class HostAdministrationClientLiveTest extends BaseNovaClientLiveTest {
public void testListAndGet() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) {
Optional<HostAdministrationClient> optClient = novaContext.getApi().getHostAdministrationExtensionForZone(zoneId);
if (optClient.isPresent()) {
HostAdministrationClient client = optClient.get();
Set<Host> hosts = client.listHosts();
assertNotNull(hosts);
for(Host host : hosts) {
client.getHostResourceUsage(host.getName());
}
}
}
}
}