Merge pull request #1007 from jclouds/cloudstack-iso-fix

Fix CloudStack ISOClient.get and list ISOs based
This commit is contained in:
Adrian Cole 2012-11-27 11:40:37 -08:00
commit 9e836b12e8
6 changed files with 178 additions and 50 deletions

View File

@ -435,7 +435,7 @@ public class ISO {
private final String zoneName;
@ConstructorProperties({
"id", "account", "accountid", "bootable", "checksum", "created", "crossZones", "displaytext", "domain", "domainId", "format", "hostid", "hostname", "hypervisor", "isextractable", "isfeatured", "ispublic", "isready", "jobid", "jobstatus", "name", "ostypeid", "ostypename", "passwordenabled", "removed", "size", "sourcetemplateid", "status", "templatetag", "templatetype", "zoneid", "zonename"
"id", "account", "accountid", "bootable", "checksum", "created", "crossZones", "displaytext", "domain", "domainid", "format", "hostid", "hostname", "hypervisor", "isextractable", "isfeatured", "ispublic", "isready", "jobid", "jobstatus", "name", "ostypeid", "ostypename", "passwordenabled", "removed", "size", "sourcetemplateid", "status", "templatetag", "templatetype", "zoneid", "zonename"
})
protected ISO(String id, @Nullable String account, @Nullable String accountId, boolean bootable, @Nullable String checksum,
@Nullable Date created, boolean crossZones, @Nullable String displayText, @Nullable String domain,

View File

@ -37,12 +37,15 @@ import org.jclouds.cloudstack.options.ListISOsOptions;
import org.jclouds.cloudstack.options.RegisterISOOptions;
import org.jclouds.cloudstack.options.UpdateISOOptions;
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -95,6 +98,7 @@ public interface ISOAsyncClient {
@QueryParams(keys = { "command", "listAll" }, values = { "listIsos", "true" })
@SelectJson("iso")
@OnlyElement
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ISO> getISO(@QueryParam("id") String id);
/**
@ -107,6 +111,7 @@ public interface ISOAsyncClient {
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = { "command", "listAll" }, values = { "listIsos", "true" })
@SelectJson("iso")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<ISO>> listISOs(ListISOsOptions... options);
/**

View File

@ -21,13 +21,11 @@ package org.jclouds.cloudstack.features;
import java.lang.reflect.Method;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.domain.PermissionOperation;
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
import org.jclouds.cloudstack.options.AccountInDomainOptions;
import org.jclouds.cloudstack.options.DeleteISOOptions;
import org.jclouds.cloudstack.options.ExtractISOOptions;
import org.jclouds.cloudstack.options.ListISOsOptions;
import org.jclouds.cloudstack.options.RegisterISOOptions;
import org.jclouds.cloudstack.options.UpdateISOOptions;
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
@ -84,53 +82,6 @@ public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTest<ISOAsyncCl
checkFilters(httpRequest);
}
public void testGetISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("getISO", String.class);
HttpRequest httpRequest = processor.createRequest(method, 3);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listIsos&listAll=true&id=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testListISOs() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("listISOs", ListISOsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listIsos&listAll=true HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testListISOsOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("listISOs", ListISOsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, ListISOsOptions.Builder.accountInDomain("fred", "5").bootable().hypervisor("xen").id("3").isoFilter(ISO.ISOFilter.featured).isPublic().isReady().keyword("bob").name("bob's iso").zoneId("7"));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listIsos&listAll=true&account=fred&domainid=5&bootable=true&hypervisor=xen&id=3&isofilter=featured&ispublic=true&isready=true&keyword=bob&name=bob%27s%20iso&zoneid=7 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testRegisterISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("registerISO", String.class, String.class, String.class, String.class, RegisterISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, "bob's iso", "bob's copy of linux", "http://example.com/", 9);

View File

@ -0,0 +1,170 @@
/**
* 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.cloudstack.features;
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.accountInDomain;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import org.jclouds.cloudstack.CloudStackContext;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Test the CloudStack ISOClient
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ISOClientExpectTest")
public class ISOClientExpectTest extends BaseCloudStackExpectTest<ISOClient> {
private static final ISO iso1 = ISO.builder()
.id("018e0928-8205-4d8e-9329-f731a9ccd488")
.name("xs-tools.iso")
.displayText("xen-pv-drv-iso")
.isPublic(true)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530"))
.isReady(true)
.passwordEnabled(false)
.bootable(false)
.isFeatured(true)
.crossZones(false)
.account("system")
.domain("ROOT")
.domainid("9d189ea2-097e-4b2b-9bae-d885f5430d69")
.isExtractable(false).build();
private static final ISO iso2 = ISO.builder()
.id("1e29244b-9cf0-4ff2-9978-677eb83f6bfb")
.name("vmware-tools.iso")
.displayText("VMware Tools Installer ISO")
.isPublic(true)
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530"))
.isReady(true)
.passwordEnabled(false)
.bootable(false)
.isFeatured(true)
.crossZones(false)
.account("system")
.domain("ROOT")
.domainid("9d189ea2-097e-4b2b-9bae-d885f5430d69")
.isExtractable(false).build();
HttpRequest listIsos = HttpRequest.builder().method("GET")
.endpoint("http://localhost:8080/client/api")
.addQueryParam("response", "json")
.addQueryParam("command", "listIsos")
.addQueryParam("listAll", "true")
.addQueryParam("apiKey", "identity")
.addQueryParam("signature", "qUUF6hCDc57Bc%2FnHriS9umbZBKA%3D")
.addHeader("Accept", "application/json")
.build();
public void testListISOsWhenResponseIs2xx() {
ISOClient client = requestSendsResponse(listIsos,
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/listisosresponse.json"))
.build());
assertEquals(client.listISOs().toString(), ImmutableSet.of(iso1, iso2).toString());
}
public void testListISOsWhenResponseIs404() {
ISOClient client = requestSendsResponse(listIsos,
HttpResponse.builder()
.statusCode(404)
.build());
assertEquals(client.listISOs(), ImmutableSet.of());
}
HttpRequest listIsosOptions = HttpRequest.builder().method("GET")
.endpoint("http://localhost:8080/client/api")
.addQueryParam("response", "json")
.addQueryParam("command", "listIsos")
.addQueryParam("listAll", "true")
.addQueryParam("account", "fred")
.addQueryParam("domainid", "5")
.addQueryParam("bootable", "true")
.addQueryParam("hypervisor", "xen")
.addQueryParam("id", "3")
.addQueryParam("isofilter", "featured")
.addQueryParam("ispublic", "true")
.addQueryParam("isready", "true")
.addQueryParam("keyword", "bob")
.addQueryParam("name", "bob%27s%20iso")
.addQueryParam("zoneid", "7")
.addQueryParam("apiKey", "identity")
.addQueryParam("signature", "4S5ustbaBErEnpymWLSj1rEJ%2Fnk%3D")
.addHeader("Accept", "application/json")
.build();
public void testListISOsOptionsWhenResponseIs2xx() {
ISOClient client = requestSendsResponse(listIsosOptions,
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/listisosresponse.json"))
.build());
assertEquals(client.listISOs(accountInDomain("fred", "5").bootable().hypervisor("xen").id("3").isoFilter(ISO.ISOFilter.featured).isPublic().isReady().keyword("bob").name("bob's iso").zoneId("7")).toString(), ImmutableSet.of(iso1, iso2).toString());
}
HttpRequest getIso = HttpRequest.builder().method("GET")
.endpoint("http://localhost:8080/client/api")
.addQueryParam("response", "json")
.addQueryParam("command", "listIsos")
.addQueryParam("listAll", "true")
.addQueryParam("id", "018e0928-8205-4d8e-9329-f731a9ccd488")
.addQueryParam("apiKey", "identity")
.addQueryParam("signature", "uZyPUJt6ThMDcQSDa%2BEv5LMs%2B2U%3D")
.addHeader("Accept", "application/json")
.build();
public void testGetISOWhenResponseIs2xx() {
ISOClient client = requestSendsResponse(getIso,
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/getisoresponse.json"))
.build());
assertEquals(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488").toString(), iso1.toString());
}
public void testGetISOWhenResponseIs404() {
ISOClient client = requestSendsResponse(getIso,
HttpResponse.builder()
.statusCode(404)
.build());
assertNull(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488"));
}
@Override
protected ISOClient clientFrom(CloudStackContext context) {
return context.getProviderSpecificContext().getApi().getISOClient();
}
}

View File

@ -0,0 +1 @@
{ "listisosresponse" : { "count":1 ,"iso" : [ {"id":"018e0928-8205-4d8e-9329-f731a9ccd488","name":"xs-tools.iso","displaytext":"xen-pv-drv-iso","ispublic":true,"created":"2012-08-21T15:45:01+0530","isready":true,"passwordenabled":false,"bootable":false,"isfeatured":true,"crossZones":false,"account":"system","domain":"ROOT","domainid":"9d189ea2-097e-4b2b-9bae-d885f5430d69","isextractable":false,"tags":[]} ] } }

View File

@ -0,0 +1 @@
{ "listisosresponse" : { "count":2 ,"iso" : [ {"id":"018e0928-8205-4d8e-9329-f731a9ccd488","name":"xs-tools.iso","displaytext":"xen-pv-drv-iso","ispublic":true,"created":"2012-08-21T15:45:01+0530","isready":true,"passwordenabled":false,"bootable":false,"isfeatured":true,"crossZones":false,"account":"system","domain":"ROOT","domainid":"9d189ea2-097e-4b2b-9bae-d885f5430d69","isextractable":false,"tags":[]}, {"id":"1e29244b-9cf0-4ff2-9978-677eb83f6bfb","name":"vmware-tools.iso","displaytext":"VMware Tools Installer ISO","ispublic":true,"created":"2012-08-21T15:45:01+0530","isready":true,"passwordenabled":false,"bootable":false,"isfeatured":true,"crossZones":false,"account":"system","domain":"ROOT","domainid":"9d189ea2-097e-4b2b-9bae-d885f5430d69","isextractable":false,"tags":[]} ] } }