CA-292626: Consider the contains-livepatch flag when doing prechecks in the automated updates mode.

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2018-07-26 16:01:48 +01:00 committed by Konstantina Chremmou
parent 6cf48a9125
commit 9dc0d77ef6
4 changed files with 46 additions and 38 deletions

View File

@ -30,6 +30,8 @@
*/
using System.Collections.Generic;
using System.Linq;
using XenAdmin.Core;
using XenAPI;
using XenAdmin.Diagnostics.Problems;
using XenAdmin.Diagnostics.Problems.HostProblem;
@ -41,6 +43,7 @@ namespace XenAdmin.Diagnostics.Checks
private readonly Dictionary<string, livepatch_status> livePatchCodesByHost;
private readonly List<after_apply_guidance> patchGuidance;
private readonly List<update_after_apply_guidance> updateGuidance;
private readonly List<XenServerPatch> restartHostPatches;
private string successfulCheckDescription;
@ -58,18 +61,29 @@ namespace XenAdmin.Diagnostics.Checks
patchGuidance = guidance;
}
public HostNeedsRebootCheck(Host host, List<XenServerPatch> restartHostPatches)
: base(host)
{
this.restartHostPatches = restartHostPatches;
}
protected override Problem RunHostCheck()
{
var updateSequenceIsLivePatchable = restartHostPatches != null && restartHostPatches.Count > 0 && restartHostPatches.All(p => p.ContainsLivepatch);
// when livepatching is available, no restart is expected
if (livePatchCodesByHost != null && livePatchCodesByHost.ContainsKey(Host.uuid) &&
livePatchCodesByHost[Host.uuid] == livepatch_status.ok_livepatch_complete)
livePatchCodesByHost[Host.uuid] == livepatch_status.ok_livepatch_complete
|| updateSequenceIsLivePatchable)
{
successfulCheckDescription = string.Format(Messages.UPDATES_WIZARD_NO_REBOOT_NEEDED_LIVE_PATCH, Host);
return null;
}
if ((updateGuidance != null && updateGuidance.Contains(update_after_apply_guidance.restartHost))
|| (patchGuidance != null && patchGuidance.Contains(after_apply_guidance.restartHost)))
|| (patchGuidance != null && patchGuidance.Contains(after_apply_guidance.restartHost))
|| (restartHostPatches != null && restartHostPatches.Count > 0))
{
return new HostNeedsReboot(this, Host);
}

View File

@ -392,10 +392,12 @@ namespace XenAdmin.Wizards.PatchingWizard
groups.Add(new CheckGroup(Messages.CHECKING_STORAGE_CONNECTIONS_STATUS, pbdChecks));
//Disk space check for automated updates
//Disk space, reboot required and can evacuate host checks for automated and version updates
if (WizardMode != WizardMode.SingleUpdate)
{
var diskChecks = new List<Check>();
var rebootChecks = new List<Check>();
var evacuateChecks = new List<Check>();
foreach (Pool pool in SelectedPools)
{
@ -424,28 +426,24 @@ namespace XenAdmin.Wizards.PatchingWizard
foreach (Host host in us.Keys)
{
diskChecks.Add(new DiskSpaceForAutomatedUpdatesCheck(host, us));
if (us[host] != null && us[host].Count > 0)
{
var restartHostPatches = us[host].Where(p => p.after_apply_guidance == after_apply_guidance.restartHost).ToList();
rebootChecks.Add(new HostNeedsRebootCheck(host, restartHostPatches));
if (restartHostPatches.Any(p => !p.ContainsLivepatch))
evacuateChecks.Add(new AssertCanEvacuateCheck(host));
}
}
}
groups.Add(new CheckGroup(Messages.PATCHINGWIZARD_PRECHECKPAGE_CHECKING_DISK_SPACE, diskChecks));
if (rebootChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_SERVER_NEEDS_REBOOT, rebootChecks));
if (evacuateChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_CANEVACUATE_STATUS, evacuateChecks));
}
//Checking reboot required and can evacuate host for version updates
if (WizardMode == WizardMode.NewVersion && UpdateAlert != null && UpdateAlert.Patch != null && UpdateAlert.Patch.after_apply_guidance == after_apply_guidance.restartHost)
{
var guidance = new List<after_apply_guidance> {UpdateAlert.Patch.after_apply_guidance};
var rebootChecks = new List<Check>();
foreach (var host in SelectedServers)
rebootChecks.Add(new HostNeedsRebootCheck(host, guidance, LivePatchCodesByHost));
groups.Add(new CheckGroup(Messages.CHECKING_SERVER_NEEDS_REBOOT, rebootChecks));
var evacuateChecks = new List<Check>();
foreach (Host host in SelectedServers)
evacuateChecks.Add(new AssertCanEvacuateCheck(host, LivePatchCodesByHost));
groups.Add(new CheckGroup(Messages.CHECKING_CANEVACUATE_STATUS, evacuateChecks));
}
//GFS2 check for version updates
if (WizardMode == WizardMode.NewVersion)
{
var gfs2Checks = new List<Check>();
@ -503,7 +501,7 @@ namespace XenAdmin.Wizards.PatchingWizard
//Checking can evacuate host
//CA-97061 - evacuate host -> suspended VMs. This is only needed for restartHost
//Also include this check for the supplemental packs (patch == null), as their guidance is restartHost
if (WizardMode != WizardMode.NewVersion && (patch == null || patch.after_apply_guidance.Contains(after_apply_guidance.restartHost)))
if (WizardMode == WizardMode.SingleUpdate && (patch == null || patch.after_apply_guidance.Contains(after_apply_guidance.restartHost)))
{
var evacuateChecks = new List<Check>();
foreach (Host host in applicableServers)
@ -568,7 +566,7 @@ namespace XenAdmin.Wizards.PatchingWizard
}
//Checking can evacuate host
if (update == null || update.after_apply_guidance.Contains(update_after_apply_guidance.restartHost))
if (WizardMode == WizardMode.SingleUpdate && (update == null || update.after_apply_guidance.Contains(update_after_apply_guidance.restartHost)))
{
var evacuateChecks = new List<Check>();
foreach (Host host in applicableServers)

View File

@ -166,6 +166,7 @@ namespace XenAdmin.Actions
string priority = "";
string installationSize = "";
string downloadSize = "";
string containsLivepatch = "";
foreach (XmlAttribute attrib in version.Attributes)
{
@ -193,13 +194,15 @@ namespace XenAdmin.Actions
installationSize = attrib.Value;
else if (attrib.Name == "download-size")
downloadSize = attrib.Value;
else if (attrib.Name == "contains-livepatch")
containsLivepatch = attrib.Value;
}
var conflictingPatches = GetPatchDependencies(version, ConflictingPatchesNode, ConflictingPatchNode);
var requiredPatches = GetPatchDependencies(version, RequiredPatchesNode, RequiredPatchNode);
XenServerPatches.Add(new XenServerPatch(uuid, name, description, guidance, guidance_mandatory, patchVersion, url,
patchUrl, timestamp, priority, installationSize, downloadSize, conflictingPatches, requiredPatches));
patchUrl, timestamp, priority, installationSize, downloadSize, containsLivepatch, conflictingPatches, requiredPatches));
}
}
}

View File

@ -43,7 +43,7 @@ namespace XenAdmin.Core
public readonly string Name;
public readonly string Description;
public readonly string Guidance;
public readonly string Guidance_mandatory;
public readonly bool GuidanceMandatory;
public readonly Version Version;
public readonly string Url;
public readonly string PatchUrl;
@ -51,6 +51,7 @@ namespace XenAdmin.Core
public readonly int Priority;
public readonly long InstallationSize; // installation size, in btyes
public readonly long DownloadSize; // download size, in btyes
public readonly bool ContainsLivepatch;
public readonly List<string> ConflictingPatches;
public readonly List<string> RequiredPatches;
@ -58,13 +59,13 @@ namespace XenAdmin.Core
private const int DEFAULT_PRIORITY = 2;
public XenServerPatch(string uuid, string name, string description, string guidance, string guidance_mandatory , string version, string url,
string patchUrl, string timestamp, string priority, string installationSize, string downloadSize)
string patchUrl, string timestamp, string priority, string installationSize, string downloadSize, string containsLivepatch = "false")
{
_uuid = uuid;
Name = name;
Description = description;
Guidance = guidance;
Guidance_mandatory = guidance_mandatory;
GuidanceMandatory = !string.IsNullOrEmpty(guidance_mandatory) && guidance_mandatory.ToLowerInvariant().Contains("true");
Version = new Version(version);
Url = url;
PatchUrl = patchUrl;
@ -75,11 +76,12 @@ namespace XenAdmin.Core
InstallationSize = 0;
if (!Int64.TryParse(downloadSize, out DownloadSize))
DownloadSize = 0;
ContainsLivepatch = !string.IsNullOrEmpty(containsLivepatch) && containsLivepatch.ToLowerInvariant().Contains("true");
}
public XenServerPatch(string uuid, string name, string description, string guidance, string guidance_mandatory, string version, string url,
string patchUrl, string timestamp, string priority, string installationSize, string downloadSize, List<string> conflictingPatches, List<string> requiredPatches)
: this(uuid, name, description, guidance, guidance_mandatory, version, url, patchUrl, timestamp, priority, installationSize, downloadSize)
string patchUrl, string timestamp, string priority, string installationSize, string downloadSize, string containsLivepatch, List<string> conflictingPatches, List<string> requiredPatches)
: this(uuid, name, description, guidance, guidance_mandatory, version, url, patchUrl, timestamp, priority, installationSize, downloadSize, containsLivepatch)
{
ConflictingPatches = conflictingPatches;
@ -122,14 +124,5 @@ namespace XenAdmin.Core
}
}
}
public bool GuidanceMandatory
{
get
{
return !string.IsNullOrEmpty(Guidance_mandatory) && this.Guidance_mandatory.ToLowerInvariant().Contains("true");
}
}
}
}