CP-41573: Add blocking problem if POST82X hosts cannot fetch the EUA

Also:
- Remove unused `button_click` event handler in `AcceptEuaDialog`
- Load EUAs within the `UpgradeRequiresEua` `Check` and removed the spinner from `AcceptEuaDialog`
- Remove `_errors` from `AcceptEuaDialog`

Signed-off-by: Danilo Del Busso <danilo.delbusso@cloud.com>
This commit is contained in:
Danilo Del Busso 2023-05-22 10:18:28 +01:00 committed by Konstantina Chremmou
parent de6372f680
commit c463601e52
9 changed files with 183 additions and 138 deletions

View File

@ -43,6 +43,8 @@ namespace XenAdmin.Diagnostics.Checks
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()?.DeclaringType);
private readonly Uri _targetUri;
private readonly HashSet<string> _euas;
private readonly HashSet<IXenObject> _hostsFailedToFetchEua;
public UpgradeRequiresEua(List<Host> hosts, IReadOnlyDictionary<string, string> installMethodConfig)
: base(hosts)
{
@ -57,13 +59,44 @@ namespace XenAdmin.Diagnostics.Checks
{
Log.Error(ex);
}
_euas = new HashSet<string>();
_hostsFailedToFetchEua = new HashSet<IXenObject>();
}
public override bool CanRun() => _targetUri != null && Hosts.Any(Helpers.Post82X);
private void FetchHostEua(Host host)
{
string eua = null;
if (Helpers.Post82X(host) && !Helpers.TryLoadHostEua(host, _targetUri, out eua))
{
lock (_hostsFailedToFetchEua)
{
_hostsFailedToFetchEua.Add(host);
}
return;
}
lock (_euas)
{
_euas.Add(eua);
}
}
protected override Problem RunCheck()
{
return new EuaNotAcceptedProblem( this, Hosts.Where(Helpers.Post82X).ToList(), _targetUri);
Hosts.AsParallel().ForAll(FetchHostEua);
lock (_hostsFailedToFetchEua)
{
if (_hostsFailedToFetchEua.Count > 0)
{
return new EuaNotFoundProblem(this, _hostsFailedToFetchEua.ToList());
}
}
lock (_euas)
{
return new EuaNotAcceptedProblem( this, _euas.ToList());
}
}
public override string Description => Messages.ACCEPT_EUA_CHECK_DESCRIPTION;
@ -75,6 +108,27 @@ namespace XenAdmin.Diagnostics.Checks
return false;
}
// if the number of hosts that failed to fetch the EUA is not zero, we
// never consider the Checks equal. This is because this Check is used as a
// permanent check
lock (_hostsFailedToFetchEua)
{
if (_hostsFailedToFetchEua != null)
{
if (_hostsFailedToFetchEua.Count > 0)
{
return false;
}
lock (item._hostsFailedToFetchEua)
{
if (item._hostsFailedToFetchEua != null && item._hostsFailedToFetchEua.Count > 0)
{
return false;
}
}
}
}
return _targetUri.Equals(item._targetUri) && base.Equals(obj);
}

View File

@ -28,34 +28,30 @@
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Diagnostics.Checks;
using XenAdmin.Dialogs;
using XenAPI;
namespace XenAdmin.Diagnostics.Problems.UtilityProblem
{
internal class EuaNotAcceptedProblem : Problem
{
private readonly List<Host> _hosts;
private readonly List<string> _euas;
private readonly Check _check;
private readonly Uri _targetUri;
public EuaNotAcceptedProblem(Check check, List<Host> hosts, Uri targetUri)
public EuaNotAcceptedProblem(Check check, List<string> euas)
: base(check)
{
_check = check;
_hosts = hosts;
_targetUri = targetUri;
_euas = euas;
}
public override string Description => Messages.ACCEPT_EUA_PROBLEM_DESCRIPTION;
protected override AsyncAction CreateAction(out bool cancelled)
{
using (var d = new AcceptEuaDialog(_hosts, _targetUri))
using (var d = new AcceptEuaDialog(_euas))
{
_check.Completed = d.ShowDialog(Program.MainWindow) == DialogResult.Yes;
}
@ -74,12 +70,12 @@ namespace XenAdmin.Diagnostics.Problems.UtilityProblem
return false;
}
return _targetUri.Equals(item._targetUri) && base.Equals(obj);
return _euas.Equals(item._euas) && base.Equals(obj);
}
public override int GetHashCode()
{
return _targetUri.GetHashCode() ^ base.GetHashCode();
return _euas.GetHashCode() ^ base.GetHashCode();
}
}
}

View File

@ -0,0 +1,84 @@
/* 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.Collections.Generic;
using System.Linq;
using XenAdmin.Core;
using XenAdmin.Diagnostics.Checks;
using XenAdmin.Dialogs;
using XenAPI;
namespace XenAdmin.Diagnostics.Problems.UtilityProblem
{
internal class EuaNotFoundProblem : Problem
{
private readonly List<IXenObject> _hosts;
private readonly Check _check;
public EuaNotFoundProblem(Check check, List<IXenObject> hosts)
: base(check)
{
_check = check;
_hosts = hosts;
}
public override string Description => string.Format(Messages.EUA_NOT_FOUND_PROBLEM_DESCRIPTION, BrandManager.BrandConsole);
public sealed override string Title => string.Empty;
public override string HelpMessage => Messages.MORE_INFO;
protected override Actions.AsyncAction CreateAction(out bool cancelled)
{
Program.Invoke(Program.MainWindow, () =>
{
using (var dlg = new InformationDialog(Messages.EUA_NOT_FOUND_PROBLEM_MORE_INFO))
dlg.ShowDialog();
});
cancelled = true;
return null;
}
public override bool Equals(object obj)
{
if (!(obj is EuaNotFoundProblem item))
{
return false;
}
return _hosts.SequenceEqual(item._hosts);
}
public override int GetHashCode()
{
return _hosts.GetHashCode() ^ base.GetHashCode();
}
}
}

View File

@ -39,13 +39,11 @@ namespace XenAdmin.Dialogs
this.buttonsFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
this.declineButton = new System.Windows.Forms.Button();
this.acceptButton = new System.Windows.Forms.Button();
this.spinnerIcon = new XenAdmin.Controls.SpinnerIcon();
this.tableLayoutPanel.SuspendLayout();
this.warningTableLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.warningPictureBox)).BeginInit();
this.euaPanel.SuspendLayout();
this.buttonsFlowLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.spinnerIcon)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel
@ -86,7 +84,6 @@ namespace XenAdmin.Dialogs
//
// euaPanel
//
this.euaPanel.Controls.Add(this.spinnerIcon);
this.euaPanel.Controls.Add(this.euaTextBox);
resources.ApplyResources(this.euaPanel, "euaPanel");
this.euaPanel.Name = "euaPanel";
@ -120,13 +117,6 @@ namespace XenAdmin.Dialogs
this.acceptButton.Name = "acceptButton";
this.acceptButton.UseVisualStyleBackColor = true;
//
// spinnerIcon
//
this.spinnerIcon.BackColor = System.Drawing.SystemColors.ControlLightLight;
resources.ApplyResources(this.spinnerIcon, "spinnerIcon");
this.spinnerIcon.Name = "spinnerIcon";
this.spinnerIcon.TabStop = false;
//
// AcceptEuaDialog
//
resources.ApplyResources(this, "$this");
@ -142,7 +132,6 @@ namespace XenAdmin.Dialogs
this.euaPanel.ResumeLayout(false);
this.buttonsFlowLayoutPanel.ResumeLayout(false);
this.buttonsFlowLayoutPanel.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.spinnerIcon)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -156,7 +145,6 @@ namespace XenAdmin.Dialogs
private System.Windows.Forms.PictureBox warningPictureBox;
private System.Windows.Forms.Label warningLabel;
private System.Windows.Forms.Panel euaPanel;
private Controls.SpinnerIcon spinnerIcon;
private System.Windows.Forms.RichTextBox euaTextBox;
private System.Windows.Forms.FlowLayoutPanel buttonsFlowLayoutPanel;
private System.Windows.Forms.Button declineButton;

View File

@ -30,53 +30,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using XenAdmin.Core;
using XenAPI;
namespace XenAdmin.Dialogs
{
public partial class AcceptEuaDialog : XenDialogBase
{
private readonly List<Host> _hosts;
private readonly Uri _targetUri;
private readonly HashSet<string> _euas;
private readonly HashSet<string> _errors;
private readonly List<string> _euas;
private readonly HashSet<string> _warnings;
public AcceptEuaDialog(List<Host> hosts, Uri targetUri)
public AcceptEuaDialog(List<string> euas)
{
InitializeComponent();
_hosts = hosts;
_targetUri = targetUri;
_euas = new HashSet<string>();
_errors = new HashSet<string>();
_euas = euas;
_warnings = new HashSet<string>();
SetLoading(true);
warningTableLayoutPanel.Visible = false;
ThreadPool.QueueUserWorkItem(LoadEuas, null);
LoadEuas();
}
private void LoadEuas(object _)
{
_hosts.AsParallel().ForAll(FetchHostEua);
Program.BeginInvoke(this, () =>
private void LoadEuas()
{
if (_euas.Count > 1)
{
_warnings.Add(Messages.ACCEPT_EUA_MORE_THAN_ONE_FOUND);
}
if (_warnings.Count > 0 || _errors.Count > 0)
if (_warnings.Count > 0)
{
warningTableLayoutPanel.Visible = true;
warningLabel.Text = string.Join(Environment.NewLine, _errors.Concat(_warnings));
warningLabel.Text = string.Join(Environment.NewLine, _warnings);
}
else
{
@ -84,43 +67,6 @@ namespace XenAdmin.Dialogs
}
euaTextBox.Text = string.Join($"{Environment.NewLine}___________________________{Environment.NewLine}", _euas);
SetLoading(false);
});
}
private void FetchHostEua(Host host)
{
if (!Helpers.TryLoadHostEua(host, _targetUri, out var eua) && Helpers.Post82X(host))
{
_errors.Add(string.Format(Messages.ACCEPT_EUA_CANNOT_FETCH, BrandManager.BrandConsole));
return;
}
lock (_euas)
{
_euas.Add(eua);
}
}
private void SetLoading(bool loading)
{
if (loading)
{
spinnerIcon.StartSpinning();
}
else
{
spinnerIcon.StopSpinning();
}
lock (_euas)
{
acceptButton.Enabled = euaTextBox.Visible = !loading && _euas.Count > 0 && _errors.Count == 0;
}
}
private void button_click(object sender, EventArgs e)
{
Close();
}
}
}

View File

@ -273,39 +273,6 @@
<data name="warningTableLayoutPanel.LayoutSettings" type="System.Windows.Forms.TableLayoutSettings, System.Windows.Forms">
<value>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;TableLayoutSettings&gt;&lt;Controls&gt;&lt;Control Name="warningPictureBox" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /&gt;&lt;Control Name="warningLabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;/Controls&gt;&lt;Columns Styles="Absolute,40,AutoSize,0" /&gt;&lt;Rows Styles="Percent,100" /&gt;&lt;/TableLayoutSettings&gt;</value>
</data>
<data name="spinnerIcon.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="spinnerIcon.Font" type="System.Drawing.Font, System.Drawing">
<value>Segoe UI, 9pt</value>
</data>
<data name="spinnerIcon.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="spinnerIcon.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value>
</data>
<data name="spinnerIcon.Size" type="System.Drawing.Size, System.Drawing">
<value>600, 359</value>
</data>
<data name="spinnerIcon.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<value>CenterImage</value>
</data>
<data name="spinnerIcon.TabIndex" type="System.Int32, mscorlib">
<value>21</value>
</data>
<data name="&gt;&gt;spinnerIcon.Name" xml:space="preserve">
<value>spinnerIcon</value>
</data>
<data name="&gt;&gt;spinnerIcon.Type" xml:space="preserve">
<value>XenAdmin.Controls.SpinnerIcon, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;spinnerIcon.Parent" xml:space="preserve">
<value>euaPanel</value>
</data>
<data name="&gt;&gt;spinnerIcon.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="euaTextBox.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
@ -334,7 +301,7 @@
<value>euaPanel</value>
</data>
<data name="&gt;&gt;euaTextBox.ZOrder" xml:space="preserve">
<value>1</value>
<value>0</value>
</data>
<data name="euaPanel.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
@ -941,9 +908,6 @@
AADAAwAA4AcAAPAPAAA=
</value>
</data>
<data name="$this.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
<value>CenterParent</value>
</data>

View File

@ -270,6 +270,7 @@
<Compile Include="Diagnostics\Problems\PoolProblem\NotLicensedForAutomatedUpdatesWarning.cs" />
<Compile Include="Diagnostics\Problems\PoolProblem\ServerSelectionProblem.cs" />
<Compile Include="Diagnostics\Problems\PoolProblem\VSwitchControllerProblem.cs" />
<Compile Include="Diagnostics\Problems\UtilityProblem\EuaNotFoundProblem.cs" />
<Compile Include="Diagnostics\Problems\UtilityProblem\EuaNotAcceptedProblem.cs" />
<Compile Include="Diagnostics\Problems\UtilityProblem\CfuNotAvailableProblem.cs" />
<Compile Include="Diagnostics\Problems\VMProblem\InvalidVCPUConfiguration.cs" />

View File

@ -60,15 +60,6 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to {0} encountered an issue while trying to fetch the EUA. Ensure that the selected source URI is valid and that all the pool coordinators can access its contents..
/// </summary>
public static string ACCEPT_EUA_CANNOT_FETCH {
get {
return ResourceManager.GetString("ACCEPT_EUA_CANNOT_FETCH", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Checking for the presence of an EUA.
/// </summary>
@ -16219,6 +16210,24 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to {0} encountered an issue while trying to fetch the EUA..
/// </summary>
public static string EUA_NOT_FOUND_PROBLEM_DESCRIPTION {
get {
return ResourceManager.GetString("EUA_NOT_FOUND_PROBLEM_DESCRIPTION", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} could not fetch an End User Agreement (EUA), but expected one. Please ensure that the selected source URI is valid and that all the pool coordinators can access its contents..
/// </summary>
public static string EUA_NOT_FOUND_PROBLEM_MORE_INFO {
get {
return ResourceManager.GetString("EUA_NOT_FOUND_PROBLEM_MORE_INFO", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to EULA.
/// </summary>

View File

@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ACCEPT_EUA_CANNOT_FETCH" xml:space="preserve">
<value>{0} encountered an issue while trying to fetch the EUA. Ensure that the selected source URI is valid and that all the pool coordinators can access its contents.</value>
</data>
<data name="ACCEPT_EUA_CHECK_DESCRIPTION" xml:space="preserve">
<value>Checking for the presence of an EUA</value>
</data>
@ -5698,6 +5695,12 @@ Would you like to eject these ISOs before continuing?</value>
<data name="ERROR_VM_NOT_HALTED" xml:space="preserve">
<value>Please shut down or suspend VM '{0}' before exporting.</value>
</data>
<data name="EUA_NOT_FOUND_PROBLEM_DESCRIPTION" xml:space="preserve">
<value>{0} encountered an issue while trying to fetch the EUA.</value>
</data>
<data name="EUA_NOT_FOUND_PROBLEM_MORE_INFO" xml:space="preserve">
<value>{0} could not fetch an End User Agreement (EUA), but expected one. Please ensure that the selected source URI is valid and that all the pool coordinators can access its contents.</value>
</data>
<data name="EULA" xml:space="preserve">
<value>EULA</value>
</data>