CP-11135: Expand patch precheck to account for OUT_OF_SPACE exception

- Pool_patch.precheck can fail with the xapi error OUT_OF_SPACE when is trying to copy the patch from master to the slaves. This happens before the patch-precheck checks if enough space is available for installation. Therefore is different from the error we are currently processing, PATCH_PRECHECK_FAILED_OUT_OF_SPACE
- If the precheck fails with OUT_OF_SPACE then we try and retrieve the disk space requirements and report a HostOutOfSpaceProblem.
- Changed the PatchPrecheckCheck to try and find problem from a xapi failure, as well as from the result of the precheck  call.
- Also removed ampersand from the the link labels (More Info and Clean up)

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2015-02-16 11:11:30 +00:00
parent 0f7e81d52c
commit 1a484b99ff
5 changed files with 122 additions and 51 deletions

View File

@ -38,6 +38,7 @@ using XenAdmin.Diagnostics.Problems.HostProblem;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml; using System.Xml;
using System.Collections.Generic; using System.Collections.Generic;
using XenAdmin.Actions;
namespace XenAdmin.Diagnostics.Checks namespace XenAdmin.Diagnostics.Checks
@ -78,7 +79,7 @@ namespace XenAdmin.Diagnostics.Checks
try try
{ {
return FindProblem(Pool_patch.precheck(session, Patch.opaque_ref, Host.opaque_ref), Host); return FindProblem(Pool_patch.precheck(session, Patch.opaque_ref, Host.opaque_ref));
} }
catch (Failure f) catch (Failure f)
@ -90,7 +91,11 @@ namespace XenAdmin.Diagnostics.Checks
log.Error(f.ErrorDescription[1]); log.Error(f.ErrorDescription[1]);
if (f.ErrorDescription.Count > 2) if (f.ErrorDescription.Count > 2)
log.Error(f.ErrorDescription[2]); log.Error(f.ErrorDescription[2]);
return new PrecheckFailed(this,Host, f); if (f.ErrorDescription.Count > 3)
log.Error(f.ErrorDescription[3]);
// try and find problem from the xapi failure
Problem problem = FindProblem(f);
return problem ?? new PrecheckFailed(this, Host, f);
} }
} }
@ -105,8 +110,19 @@ namespace XenAdmin.Diagnostics.Checks
} }
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Problem FindProblem(string result, Host host) /// <summary>
/// Find problem from xml result
/// </summary>
/// <param name="result">xml result, as returned by Pool_patch.precheck() call.
/// E.g.:
/// <error errorcode="PATCH_PRECHECK_FAILED_OUT_OF_SPACE">
/// <found>2049859584</found>
/// <required>10000000000</required>
/// </error>
/// </param>
/// <returns>Problem or null, if no problem found</returns>
private Problem FindProblem(string result)
{ {
if (!PrecheckErrorRegex.IsMatch(result.Replace("\n", ""))) if (!PrecheckErrorRegex.IsMatch(result.Replace("\n", "")))
return null; return null;
@ -118,61 +134,101 @@ namespace XenAdmin.Diagnostics.Checks
log.Error(m.ToString()); log.Error(m.ToString());
XmlNode errorNode = doc.FirstChild; XmlNode errorNode = doc.FirstChild;
string errorcode = errorNode.Attributes["errorcode"] != null string errorcode = errorNode.Attributes != null && errorNode.Attributes["errorcode"] != null
? errorNode.Attributes["errorcode"].Value ? errorNode.Attributes["errorcode"].Value
: string.Empty; : string.Empty;
if (errorcode == "")
return null;
var found = "";
var required = "";
foreach (XmlNode node in errorNode.ChildNodes)
{
if (node.Name == "found")
found = node.InnerXml;
else if (node.Name == "required")
required = node.InnerXml;
}
var problem = FindProblem(errorcode, found, required);
return problem ?? new PrecheckFailed(this, Host, new Failure(errorcode));
}
/// <summary>
/// Find problem from xapi Failure
/// </summary>
/// <param name="failure">Xapi failure, thrown by Pool_patch.precheck() call.
/// E.g.: failure.ErrorDescription.Count = 4
/// ErrorDescription[0] = "PATCH_PRECHECK_FAILED_WRONG_SERVER_VERSION"
/// ErrorDescription[1] = "OpaqueRef:612b5eee-03dc-bbf5-3385-6905fdc9b079"
/// ErrorDescription[2] = "6.5.0"
/// ErrorDescription[3] = "^6\\.2\\.0$"
/// E.g.: failure.ErrorDescription.Count = 2
/// ErrorDescription[0] = "OUT_OF_SPACE"
/// ErrorDescription[1] = "/var/patch"
/// </param>
/// <returns>Problem or null, if no problem found</returns>
private Problem FindProblem(Failure failure)
{
if (failure.ErrorDescription.Count == 0)
return null;
var errorcode = failure.ErrorDescription[0];
var found = "";
var required = "";
if (failure.ErrorDescription.Count > 2)
found = failure.ErrorDescription[2];
if (failure.ErrorDescription.Count > 3)
required = failure.ErrorDescription[3];
return FindProblem(errorcode, found, required);
}
private Problem FindProblem(string errorcode, string found, string required)
{
switch (errorcode) switch (errorcode)
{ {
case "PATCH_PRECHECK_FAILED_WRONG_SERVER_VERSION": case "PATCH_PRECHECK_FAILED_WRONG_SERVER_VERSION":
foreach (XmlNode node in errorNode.ChildNodes) return new WrongServerVersion(this, required, Host);
{
if (node.Name == "required")
{
return new WrongServerVersion(this, node.InnerXml,host);
}
}
break;
case "PATCH_PRECHECK_FAILED_OUT_OF_SPACE": case "PATCH_PRECHECK_FAILED_OUT_OF_SPACE":
long required = 0; long requiredSpace = 0;
long found = 0; long foundSpace = 0;
foreach (XmlNode node in errorNode.ChildNodes) long.TryParse(found, out foundSpace);
{ long.TryParse(required, out requiredSpace);
if (node.Name == "found")
{
long.TryParse(node.InnerText, out found);
}
if (node.Name == "required")
{
long.TryParse(node.InnerText, out required);
}
}
// get reclaimable disk space (excluding current patch) // get reclaimable disk space (excluding current patch)
long reclaimableDiskSpace = 0; long reclaimableDiskSpace = 0;
try try
{ {
var args = new Dictionary<string, string>(); var args = new Dictionary<string, string> { { "exclude", Patch.uuid } };
if (Patch != null) var resultReclaimable = Host.call_plugin(Host.Connection.Session, Host.opaque_ref, "disk-space", "get_reclaimable_disk_space", args);
args.Add("exclude", Patch.uuid); reclaimableDiskSpace = Convert.ToInt64(resultReclaimable);
var resultReclaimable = Host.call_plugin(host.Connection.Session, host.opaque_ref, "disk-space", "get_reclaimable_disk_space", args);
reclaimableDiskSpace = Convert.ToInt64(resultReclaimable);
} }
catch (Failure failure) catch (Failure failure)
{ {
log.WarnFormat("Plugin call disk-space.get_reclaimable_disk_space on {0} failed with {1}", Host.Name, failure.Message); log.WarnFormat("Plugin call disk-space.get_reclaimable_disk_space on {0} failed with {1}", Host.Name, failure.Message);
} }
var operation = XenAdmin.Actions.DiskSpaceRequirements.OperationTypes.install; var diskSpaceReq = new DiskSpaceRequirements(DiskSpaceRequirements.OperationTypes.install, Host, Patch.Name, requiredSpace, foundSpace, reclaimableDiskSpace);
var diskSpaceReq = new XenAdmin.Actions.DiskSpaceRequirements(operation, host, Patch.Name, required, found, reclaimableDiskSpace); return new HostOutOfSpaceProblem(this, Host, Patch, diskSpaceReq);
case "OUT_OF_SPACE":
return new HostOutOfSpaceProblem(this, host, Patch, diskSpaceReq); //if (Helpers.CreamOrGreater(host.Connection))
case "": {
return null; var action = new GetDiskSpaceRequirementsAction(Host, Patch, true);
default: try
return new PrecheckFailed(this, host,new Failure(errorcode)); {
action.RunExternal(action.Session);
}
catch
{
log.WarnFormat("Could not get disk space requirements");
}
if (action.Succeeded)
return new HostOutOfSpaceProblem(this, Host, Patch, action.DiskSpaceRequirements);
}
break;
} }
return null; return null;
} }

View File

@ -58,7 +58,12 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
public override string Description public override string Description
{ {
get { return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_INSTALL, Server.Name, patch.Name); } get
{
return string.Format(diskSpaceReq.Operation == DiskSpaceRequirements.OperationTypes.install
? Messages.NOT_ENOUGH_SPACE_MESSAGE_INSTALL
: Messages.NOT_ENOUGH_SPACE_MESSAGE_UPLOAD, Server.Name, patch.Name);
}
} }
protected override AsyncAction CreateAction(out bool cancelled) protected override AsyncAction CreateAction(out bool cancelled)
@ -75,7 +80,7 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
diskSpaceReq.GetSpaceRequirementsMessage()), diskSpaceReq.GetSpaceRequirementsMessage()),
new ThreeButtonDialog.TBDButton(Messages.YES, DialogResult.Yes, ThreeButtonDialog.ButtonType.ACCEPT, true), new ThreeButtonDialog.TBDButton(Messages.YES, DialogResult.Yes, ThreeButtonDialog.ButtonType.ACCEPT, true),
ThreeButtonDialog.ButtonNo ThreeButtonDialog.ButtonNo
).ShowDialog(Program.MainWindow); ).ShowDialog();
if (r == DialogResult.Yes) if (r == DialogResult.Yes)
@ -110,6 +115,5 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
return false; return false;
} }
} }
} }
} }

View File

@ -93,9 +93,20 @@ namespace XenAdmin.Actions
{ {
Description = String.Format(Messages.ACTION_GET_DISK_SPACE_REQUIREMENTS_DESCRIPTION, Host.Name); Description = String.Format(Messages.ACTION_GET_DISK_SPACE_REQUIREMENTS_DESCRIPTION, Host.Name);
long requiredDiskSpace = updateSize;
string result; string result;
// get required disk space
long requiredDiskSpace = updateSize;
try
{
result = Host.call_plugin(Session, Host.opaque_ref, "disk-space", "get_required_space", new Dictionary<string, string>());
requiredDiskSpace = Convert.ToInt64(result);
}
catch (Failure failure)
{
log.WarnFormat("Plugin call disk-space.get_required_space on {0} failed with {1}", Host.Name, failure.Message);
}
// get available disk space // get available disk space
long availableDiskSpace = 0; long availableDiskSpace = 0;
try try
@ -155,7 +166,7 @@ namespace XenAdmin.Actions
public bool CanCleanup public bool CanCleanup
{ {
get { return ReclaimableDiskSpace + AvailableDiskSpace > RequiredDiskSpace && RequiredDiskSpace > 0; } get { return ReclaimableDiskSpace + AvailableDiskSpace > RequiredDiskSpace && RequiredDiskSpace > 0 && ReclaimableDiskSpace > 0; }
} }
public string GetSpaceRequirementsMessage() public string GetSpaceRequirementsMessage()

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.34209 // Runtime Version:4.0.30319.18444
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
@ -24567,7 +24567,7 @@ namespace XenAdmin {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to &amp;Clean up.... /// Looks up a localized string similar to Clean up....
/// </summary> /// </summary>
public static string PATCHINGWIZARD_CLEANUP { public static string PATCHINGWIZARD_CLEANUP {
get { get {
@ -24639,7 +24639,7 @@ namespace XenAdmin {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to &amp;More info.... /// Looks up a localized string similar to More info....
/// </summary> /// </summary>
public static string PATCHINGWIZARD_MORE_INFO { public static string PATCHINGWIZARD_MORE_INFO {
get { get {

View File

@ -8487,7 +8487,7 @@ It is strongly recommended that you Cancel and apply the latest version of the p
<value>Paste</value> <value>Paste</value>
</data> </data>
<data name="PATCHINGWIZARD_CLEANUP" xml:space="preserve"> <data name="PATCHINGWIZARD_CLEANUP" xml:space="preserve">
<value>&amp;Clean up...</value> <value>Clean up...</value>
</data> </data>
<data name="PATCHINGWIZARD_MODEPAGE_NOACTION" xml:space="preserve"> <data name="PATCHINGWIZARD_MODEPAGE_NOACTION" xml:space="preserve">
<value>No action required</value> <value>No action required</value>
@ -8511,7 +8511,7 @@ It is strongly recommended that you Cancel and apply the latest version of the p
<value>Unknown</value> <value>Unknown</value>
</data> </data>
<data name="PATCHINGWIZARD_MORE_INFO" xml:space="preserve"> <data name="PATCHINGWIZARD_MORE_INFO" xml:space="preserve">
<value>&amp;More info...</value> <value>More info...</value>
</data> </data>
<data name="PATCHINGWIZARD_PATCHINGPAGE_POOL_RESOLVE" xml:space="preserve"> <data name="PATCHINGWIZARD_PATCHINGPAGE_POOL_RESOLVE" xml:space="preserve">
<value>Resolve pool problems</value> <value>Resolve pool problems</value>