CLOUDSTACK-5689: System vm creation on local storage fails for hyper-v. A

null pointer exception was getting generated when a VolumeTO object was
serialized to create an answer object. If a local storage is used the uri
field will be null. Added null checks for the same.
This commit is contained in:
Devdeep Singh 2014-01-15 02:51:15 +05:30
parent f8681de07c
commit f58d77c8d1
2 changed files with 26 additions and 18 deletions

View File

@ -61,7 +61,7 @@ namespace HypervResource
get get
{ {
string uncPath = null; string uncPath = null;
if (uri.Scheme.Equals("cifs") || uri.Scheme.Equals("networkfilesystem")) if (uri != null && (uri.Scheme.Equals("cifs") || uri.Scheme.Equals("networkfilesystem")))
{ {
uncPath = @"\\" + uri.Host + uri.LocalPath; uncPath = @"\\" + uri.Host + uri.LocalPath;
} }
@ -73,8 +73,13 @@ namespace HypervResource
{ {
get get
{ {
var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query); string user = null;
return System.Web.HttpUtility.UrlDecode(queryDictionary["user"]); if (uri != null)
{
var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query);
user = System.Web.HttpUtility.UrlDecode(queryDictionary["user"]);
}
return user;
} }
} }
@ -82,8 +87,13 @@ namespace HypervResource
{ {
get get
{ {
var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query); string password = null;
return System.Web.HttpUtility.UrlDecode(queryDictionary["password"]); if (uri != null)
{
var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query);
password = System.Web.HttpUtility.UrlDecode(queryDictionary["password"]);
}
return password;
} }
} }
@ -91,12 +101,17 @@ namespace HypervResource
{ {
get get
{ {
var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query); string domain = null;
if (queryDictionary["domain"] != null) if (uri != null)
{ {
return System.Web.HttpUtility.UrlDecode(queryDictionary["domain"]); var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query);
if (queryDictionary["domain"] != null)
{
domain = System.Web.HttpUtility.UrlDecode(queryDictionary["domain"]);
}
else domain = uri.Host;
} }
else return uri.Host; return domain;
} }
} }

View File

@ -1474,15 +1474,8 @@ namespace HypervResource
{ {
// TODO: thin provision instead of copying the full file. // TODO: thin provision instead of copying the full file.
File.Copy(srcFile, destFile); File.Copy(srcFile, destFile);
VolumeObjectTO volume = new VolumeObjectTO(); destVolumeObjectTO.path = destFile;
volume.path = destFile; JObject ansObj = Utils.CreateCloudStackObject(CloudStackTypes.VolumeObjectTO, destVolumeObjectTO);
volume.dataStore = destVolumeObjectTO.dataStore;
volume.name = destVolumeObjectTO.name;
volume.size = ulong.Parse(destVolumeObjectTO.size.ToString());
volume.format = destVolumeObjectTO.format;
volume.nfsDataStore = destVolumeObjectTO.nfsDataStore;
volume.primaryDataStore = destVolumeObjectTO.primaryDataStore;
JObject ansObj = Utils.CreateCloudStackObject(CloudStackTypes.VolumeObjectTO, volume);
newData = ansObj; newData = ansObj;
result = true; result = true;
} }