Skip to content

Commit

Permalink
CP-39938: Flag a partially applied hotfix with red only if homogeneou…
Browse files Browse the repository at this point in the history
…s application is required.

Signed-off-by: Konstantina Chremmou <[email protected]>
  • Loading branch information
kc284 authored and danilo-delbusso committed Aug 22, 2022
1 parent 4f91b8a commit 7144528
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 67 deletions.
126 changes: 60 additions & 66 deletions XenAdmin/TabPages/GeneralTabPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,36 +546,83 @@ private void GenerateCustomFieldsBox()

private void GeneratePoolPatchesBox()
{
Pool pool = xenObject as Pool;
if (pool == null)
if (!(xenObject is Pool pool))
return;

PDSection s = pdSectionUpdates;

List<KeyValuePair<String, String>> messages = CheckPoolUpdate(pool);
var messages = CheckPoolUpdate(pool);
if (messages.Count > 0)
{
foreach (KeyValuePair<String, String> kvp in messages)
{
foreach (var kvp in messages)
s.AddEntry(kvp.Key, kvp.Value);
}
}

Host coordinator = Helpers.GetCoordinator(xenObject.Connection);
if (coordinator == null)
return;

var poolAppPatches = poolAppliedPatches();
if (!string.IsNullOrEmpty(poolAppPatches))
var fullyApplied = new List<string>();
var partAppliedError = new List<string>();
var partApplied = new List<string>();

var cache = xenObject.Connection.Cache;
var allHostCount = xenObject.Connection.Cache.HostCount;

if (Helpers.ElyOrGreater(xenObject.Connection))
{
s.AddEntry(FriendlyName("Pool_patch.fully_applied"), poolAppPatches);
foreach (var u in cache.Pool_updates)
{
var entry = Helpers.UpdatesFriendlyNameAndVersion(u);
var appliedHostCount = u.AppliedOnHosts().Count;

if (appliedHostCount == allHostCount)
{
fullyApplied.Add(entry);
}
else if (appliedHostCount > 0)
{
if (u.EnforceHomogeneity())
partAppliedError.Add(entry);
else
partApplied.Add(entry);
}
}
}
else
{
foreach (var p in cache.Pool_patches)
{
var entry = p.name_label;
var appliedHostCount = p.host_patches.Count;

if (appliedHostCount == allHostCount)
fullyApplied.Add(entry);
else if (appliedHostCount > 0)
partAppliedError.Add(entry);
}
}

if (fullyApplied.Count > 0)
{
fullyApplied.Sort(StringUtility.NaturalCompare);
s.AddEntry(FriendlyName("Pool_patch.fully_applied"), string.Join(Environment.NewLine, fullyApplied));
}

var poolPartPatches = poolPartialPatches();
if (!string.IsNullOrEmpty(poolPartPatches))
if (partApplied.Count > 0)
{
var menuItems = new ToolStripMenuItem[] {new CommandToolStripMenuItem(new InstallNewUpdateCommand(Program.MainWindow), true)};
partApplied.Sort(StringUtility.NaturalCompare);
s.AddEntry(FriendlyName("Pool_patch.partially_applied"), string.Join(Environment.NewLine, partApplied), menuItems);
}

s.AddEntry(FriendlyName("Pool_patch.partially_applied"), poolPartPatches, Color.Red,
new CommandToolStripMenuItem(new InstallNewUpdateCommand(Program.MainWindow), true));
if (partAppliedError.Count > 0)
{
var menuItems = new ToolStripMenuItem[] {new CommandToolStripMenuItem(new InstallNewUpdateCommand(Program.MainWindow), true)};
partAppliedError.Sort(StringUtility.NaturalCompare);
s.AddEntry(string.Format(Messages.STRING_SPACE_STRING,
FriendlyName("Pool_patch.partially_applied"), Messages.UPDATES_GENERAL_TAB_ENFORCE_HOMOGENEITY),
string.Join(Environment.NewLine, partAppliedError), Color.Red, menuItems);
}
}

Expand Down Expand Up @@ -1823,59 +1870,6 @@ private static string HVMBootMode(VM vm)

#endregion

#region Pool delegates

private string poolAppliedPatches()
{
return
Helpers.ElyOrGreater(xenObject.Connection)
? poolUpdateString(update => update.AppliedOnHosts().Count == xenObject.Connection.Cache.HostCount)
: poolPatchString(patch => patch.host_patches.Count == xenObject.Connection.Cache.HostCount);
}

private string poolPartialPatches()
{
return Helpers.ElyOrGreater(xenObject.Connection)
? poolUpdateString(update =>
{
var appliedOnHosts = update.AppliedOnHosts();
return appliedOnHosts.Count > 0 && appliedOnHosts.Count != xenObject.Connection.Cache.HostCount;
})
: poolPatchString(patch => patch.host_patches.Count > 0 && patch.host_patches.Count != xenObject.Connection.Cache.HostCount);
}

private string poolPatchString(Predicate<Pool_patch> predicate)
{
Pool_patch[] patches = xenObject.Connection.Cache.Pool_patches;

List<String> output = new List<String>();

foreach (Pool_patch patch in patches)
if (predicate(patch))
output.Add(patch.name_label);

output.Sort(StringUtility.NaturalCompare);

return string.Join(Environment.NewLine, output);
}

private string poolUpdateString(Predicate<Pool_update> predicate)
{
Pool_update[] updates = xenObject.Connection.Cache.Pool_updates;

List<String> output = new List<String>();

foreach (var update in updates)
if (predicate(update))
output.Add(Helpers.UpdatesFriendlyNameAndVersion(update));

output.Sort(StringUtility.NaturalCompare);

return string.Join(Environment.NewLine, output);
}

#endregion

/// <summary>
/// Checks for reboot warnings on all hosts in the pool and returns them as a list
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion XenModel/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions XenModel/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -12966,6 +12966,9 @@ Note that if RBAC is enabled, only updates which you have privileges to dismiss
<data name="UPDATES_DOWNLOAD_REQUIRED_XENCENTER" xml:space="preserve">
<value>Download {0}</value>
</data>
<data name="UPDATES_GENERAL_TAB_ENFORCE_HOMOGENEITY" xml:space="preserve">
<value>(full application required)</value>
</data>
<data name="UPDATES_WIZARD" xml:space="preserve">
<value>Install Update</value>
</data>
Expand Down

0 comments on commit 7144528

Please sign in to comment.