Skip to content

Commit

Permalink
CP-43267: Apply updates from CDN
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
  • Loading branch information
kc284 committed Aug 1, 2023
1 parent 5f4d24f commit 74bd91a
Show file tree
Hide file tree
Showing 34 changed files with 1,665 additions and 778 deletions.
20 changes: 12 additions & 8 deletions XenAdmin/Diagnostics/Checks/HostNeedsRebootCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ public HostNeedsRebootCheck(Host host, List<XenServerPatch> restartHostPatches)
this.restartHostPatches = restartHostPatches;
}

public HostNeedsRebootCheck(Host host)
: base(host)
{
}


protected override Problem RunHostCheck()
{
if (Helpers.CloudOrGreater(Host))
{
return new HostNeedsReboot(this, Host);
}

var updateSequenceIsLivePatchable = restartHostPatches != null && restartHostPatches.Count > 0 && restartHostPatches.All(p => p.ContainsLivepatch);

// when livepatching is available, no restart is expected
Expand Down Expand Up @@ -97,14 +107,8 @@ protected override Problem RunHostCheck()
return null;
}

public override string Description
{
get { return Messages.HOST_NEEDS_REBOOT_CHECK_DESCRIPTION; }
}
public override string Description => Messages.HOST_NEEDS_REBOOT_CHECK_DESCRIPTION;

public override string SuccessfulCheckDescription
{
get { return successfulCheckDescription; }
}
public override string SuccessfulCheckDescription => successfulCheckDescription;
}
}
65 changes: 65 additions & 0 deletions XenAdmin/Diagnostics/Checks/OutOfSyncWithCdnCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright (c) Cloud Software Group, Inc.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

using System;
using XenAdmin.Core;
using XenAdmin.Diagnostics.Problems;
using XenAdmin.Diagnostics.Problems.PoolProblem;
using XenAPI;


namespace XenAdmin.Diagnostics.Checks
{
public class OutOfSyncWithCdnCheck : PoolCheck
{
public OutOfSyncWithCdnCheck(Pool pool)
: base (pool)
{
}

public override bool CanRun()
{
return Helpers.CloudOrGreater(Pool.Connection);
}

protected override Problem RunCheck()
{
if (Helpers.XapiEqualOrGreater_23_18_0(Pool.Connection))
{
if (DateTime.UtcNow - Pool.last_update_sync >= TimeSpan.FromDays(7))
return new CdnOutOfSyncProblem(this, Pool);
}

return null;
}

public override string Description => Messages.CHECKING_LAST_CDN_SYNC_DESCRIPTION;
}
}
58 changes: 58 additions & 0 deletions XenAdmin/Diagnostics/Problems/PoolProblem/CdnOutOfSyncProblem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright (c) Cloud Software Group, Inc.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

using XenAdmin.Actions;
using XenAdmin.Core;
using XenAdmin.Diagnostics.Checks;
using XenAPI;


namespace XenAdmin.Diagnostics.Problems.PoolProblem
{
public class CdnOutOfSyncProblem : PoolProblem
{
public CdnOutOfSyncProblem(Check check, Pool pool)
: base(check, pool)
{
}

public override string Description => $"{Pool.Connection.Name}:{string.Format(Messages.ALERT_CDN_OUT_OF_SYNC_TITLE, 7)}";

public override string HelpMessage => Messages.UPDATES_GENERAL_TAB_SYNC_NOW;

protected override AsyncAction CreateAction(out bool cancelled)
{
cancelled = false;
var syncAction = new SyncWithCdnAction(Pool);
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
return syncAction;
}
}
}
2 changes: 1 addition & 1 deletion XenAdmin/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3085,7 +3085,7 @@
<value>195, 22</value>
</data>
<data name="installNewUpdateToolStripMenuItem.Text" xml:space="preserve">
<value>Install &amp;Update...</value>
<value>Install &amp;Updates...</value>
</data>
<data name="rollingUpgradeToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>195, 22</value>
Expand Down
2 changes: 1 addition & 1 deletion XenAdmin/TabPages/CdnUpdates/CdnExpandableRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public PostUpdateActionRow(CdnGuidance[] guidance, bool allLivePatches)
{
var msg = allLivePatches ? Messages.HOTFIX_POST_UPDATE_LIVEPATCH_ACTIONS : Messages.HOTFIX_POST_UPDATE_ACTIONS;

var text = string.Format(msg, string.Join("\n", guidance.Select(g => g.StringOf())));
var text = string.Format(msg, string.Join("\n", guidance.Select(Cdn.FriendlyInstruction)));
var img = allLivePatches ? Images.StaticImages.livepatch_16 : Images.StaticImages.rightArrowLong_Blue_16;

SetValues(text, img);
Expand Down
18 changes: 0 additions & 18 deletions XenAdmin/TabPages/CdnUpdates/CdnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ namespace XenAdmin.TabPages.CdnUpdates
{
internal static class CdnExtensions
{
internal static string StringOf(this CdnGuidance guidance)
{
switch (guidance)
{
case CdnGuidance.RebootHost:
return Messages.CDN_GUIDANCE_REBOOT_HOST;
case CdnGuidance.RestartDeviceModel:
return Messages.CDN_GUIDANCE_RESTART_DEVICE_MODEL;
case CdnGuidance.EvacuateHost:
return Messages.CDN_GUIDANCE_EVACUATE_HOST;
case CdnGuidance.RestartToolstack:
return Messages.CDN_GUIDANCE_RESTART_TOOLSTACK;
default:
case CdnGuidance.None:
return Messages.NONE;
}
}

internal static string InitialOf(this CdnUpdateType updateType)
{
switch (updateType)
Expand Down
32 changes: 32 additions & 0 deletions XenAdmin/TabPages/GeneralTabPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,15 @@ private void GenerateCdnUpdatesBox(Pool pool)
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
syncAction.RunAsync();
});

foreach (var host in pool.Connection.Cache.Hosts)
{
if (host.pending_guidances.Count > 0)
{
pdSectionUpdates.AddEntry(string.Format(Messages.CDN_PENDING_GUIDANCES_KEY, host.Name().Ellipsise(30)),
string.Format(Messages.CDN_PENDING_GUIDANCES_VALUE, string.Join(Environment.NewLine, host.pending_guidances.Select(GetPendingGuidance))));
}
}
}

private void GenerateHostUpdatesBox()
Expand Down Expand Up @@ -706,6 +715,12 @@ private void GenerateHostUpdatesBox()
GenerateCdnUpdatesBox(pool);
}

if (host.pending_guidances.Count > 0)
{
pdSectionUpdates.AddEntry(string.Format(Messages.CDN_PENDING_GUIDANCES_KEY, host.Name().Ellipsise(30)),
string.Format(Messages.CDN_PENDING_GUIDANCES_VALUE, string.Join(Environment.NewLine, host.pending_guidances.Select(GetPendingGuidance))));
}

if (Helpers.XapiEqualOrGreater_22_20_0(host))
{
var unixMinDateTime = Util.GetUnixMinDateTime();
Expand All @@ -729,6 +744,23 @@ private void GenerateHostUpdatesBox()
}
}

private static string GetPendingGuidance(update_guidances guidance)
{
switch (guidance)
{
case update_guidances.reboot_host:
return Messages.CDN_GUIDANCE_REBOOT_HOST;
case update_guidances.reboot_host_on_livepatch_failure:
return Messages.CDN_GUIDANCE_REBOOT_HOST_LIVEPATCH_FAILURE;
case update_guidances.restart_toolstack:
return Messages.CDN_GUIDANCE_RESTART_TOOLSTACK;
case update_guidances.restart_device_model:
return Messages.CDN_GUIDANCE_RESTART_DEVICE_MODEL;
default:
return Messages.UNKNOWN;
}
}

private void GenerateHABox()
{
VM vm = xenObject as VM;
Expand Down
5 changes: 3 additions & 2 deletions XenAdmin/TabPages/ManageCdnUpdatesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ private void tsmiSynchronizeAll_Click(object sender, EventArgs e)

private void toolStripButtonUpdate_Click(object sender, EventArgs e)
{
Program.MainWindow.ShowForm(typeof(PatchingWizard));
var wizard = (PatchingWizard)Program.MainWindow.ShowForm(typeof(PatchingWizard));
wizard.PrepareToInstallUpdate(true);
}

private void toolStripButtonExportAll_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -463,7 +464,7 @@ private void toolStripButtonExportAll_Click(object sender, EventArgs e)
foreach (var hostUpdateInfo in poolUpdateInfo.HostsWithUpdates)
{
stream.WriteLine(connection.Resolve(new XenRef<Host>(hostUpdateInfo.HostOpaqueRef))?.Name());
stream.WriteLine(string.Join("\n", hostUpdateInfo.RecommendedGuidance.Select(g => g.StringOf())));
stream.WriteLine(string.Join("\n", hostUpdateInfo.RecommendedGuidance.Select(Cdn.FriendlyInstruction)));

var categories = hostUpdateInfo.GetUpdateCategories(poolUpdateInfo);
foreach (var category in categories)
Expand Down
3 changes: 2 additions & 1 deletion XenAdmin/TabPages/ManageUpdatesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,8 @@ private void toolStripButtonRefresh_Click(object sender, EventArgs e)

private void toolStripButtonUpdate_Click(object sender, EventArgs e)
{
Program.MainWindow.ShowForm(typeof(PatchingWizard));
var wizard = (PatchingWizard)Program.MainWindow.ShowForm(typeof(PatchingWizard));
wizard.PrepareToInstallUpdate(false);
}

private void toolStripButtonRestoreDismissed_Click(object sender, EventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions XenAdmin/TabPages/ManageUpdatesPage.resx
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@
<data name="spinner.Size" type="System.Drawing.Size, System.Drawing">
<value>16, 16</value>
</data>
<data name="spinner.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<value>StretchImage</value>
</data>
<data name="spinner.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
Expand Down
Loading

0 comments on commit 74bd91a

Please sign in to comment.