From e0e8cb0d96275f8d87d0598450016c19e05ef9e8 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Fri, 5 Jul 2013 15:31:26 +0530 Subject: [PATCH] CLOUDSTACK-3273: ClassCastException when adding cache store via API Filter the detail map sent over the wire into Map before processing underneath by storage life cycle Signed-off-by: Prasanna Santhanam (cherry picked from commit f96b89f25e59a92b4e92a07fc54c8e6a9177b6c7) --- .../admin/storage/CreateCacheStoreCmd.java | 26 ++++++++++++++----- .../image/datastore/ImageStoreHelper.java | 2 +- tools/marvin/marvin/integration/lib/utils.py | 8 ++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/CreateCacheStoreCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/CreateCacheStoreCmd.java index ff01a40c1fa..f94207fda91 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/storage/CreateCacheStoreCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/storage/CreateCacheStoreCmd.java @@ -18,22 +18,22 @@ */ package org.apache.cloudstack.api.command.admin.storage; -import java.util.Map; - +import com.cloud.storage.ImageStore; +import com.cloud.user.Account; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; -import com.cloud.exception.DiscoveryException; -import com.cloud.storage.ImageStore; -import com.cloud.user.Account; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; @APICommand(name = "createCacheStore", description="create cache store.", responseObject=ImageStoreResponse.class) public class CreateCacheStoreCmd extends BaseCmd { @@ -76,7 +76,19 @@ public class CreateCacheStoreCmd extends BaseCmd { } public Map getDetails() { - return details; + Map detailsMap = null; + if (details != null && !details.isEmpty()) { + detailsMap = new HashMap(); + Collection props = details.values(); + Iterator iter = props.iterator(); + while (iter.hasNext()) { + HashMap detail = (HashMap) iter.next(); + String key = detail.get("key"); + String value = detail.get("value"); + detailsMap.put(key, value); + } + } + return detailsMap; } public String getScope() { diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java index a2d61f91fbe..a64114691c8 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java +++ b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java @@ -95,7 +95,7 @@ public class ImageStoreHelper { if (details != null) { Iterator keyIter = details.keySet().iterator(); while (keyIter.hasNext()) { - String key = keyIter.next(); + String key = keyIter.next().toString(); ImageStoreDetailVO detail = new ImageStoreDetailVO(); detail.setStoreId(store.getId()); detail.setName(key); diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index 9ab199ab7d4..4eca8baab20 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -185,16 +185,12 @@ def get_process_status(hostip, port, username, password, linklocalip, process, h return res -def isAlmostEqual(self, first_digit, second_digit, range=0): +def isAlmostEqual(first_digit, second_digit, range=0): digits_equal_within_range = False try: if ((first_digit - range) < second_digit < (first_digit + range)): digits_equal_within_range = True - except Exception as e: - self.fail( - "%s: Failed while comparing the numbers %s & %s" % - (e, first_digit, second_digit)) - + raise e return digits_equal_within_range