CP-35471: Refactor HostNotSafeToUpgrade classes to avoid code repetition.

Also:
- added count check when generating the prechecks
- message correction

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2021-03-09 15:35:07 +00:00 committed by Konstantina Chremmou
parent 9f6ce35a04
commit c6710b7ffd
5 changed files with 94 additions and 118 deletions

View File

@ -44,6 +44,8 @@ namespace XenAdmin.Diagnostics.Checks
{
}
public override bool CanRun() => Helpers.KolkataOrGreater(Host.Connection) && !Helpers.LimaOrGreater(Host.Connection);
protected override Problem RunHostCheck()
{
var clusteringEnabled = Host.Connection.Cache.Cluster_hosts.Any(cluster => cluster.enabled);

View File

@ -40,116 +40,91 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
public class HostNotSafeToUpgradeWarning : WarningWithMoreInfo
{
private readonly Host _host;
private readonly HostNotSafeToUpgradeReason _reason;
private readonly string _shortMessage;
public HostNotSafeToUpgradeWarning(Check check, Host host, HostNotSafeToUpgradeReason reason)
: base(check)
{
this._host = host;
this._reason = reason;
_host = host;
var newPartitionInfo = string.Format(Messages.NOT_SAFE_TO_UPGRADE_NEW_PARTITION_INFO, BrandManager.ProductVersionPost82);
string detail;
switch (reason)
{
case HostNotSafeToUpgradeReason.NotEnoughSpace:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_WARNING, BrandManager.ProductVersionPost82);
break;
case HostNotSafeToUpgradeReason.VdiPresent:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT_WARNING, BrandManager.ProductVersionPost82);
break;
case HostNotSafeToUpgradeReason.UtilityPartitionPresent:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION_WARNING, BrandManager.ProductVersionPost82);
break;
case HostNotSafeToUpgradeReason.LegacyPartitionTable:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE_WARNING, BrandManager.ProductVersionPost82);
break;
default:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_DEFAULT;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_DEFAULT_WARNING, BrandManager.ProductVersionPost82);
break;
}
Message = $"{_shortMessage}\n\n{newPartitionInfo}\n\n{detail}";
}
public override string Message { get; }
public override string Title => Description;
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, _host.name_label, ShortMessage);
public override string Message
{
get
{
var newPartitionInfo = string.Format(Messages.NOT_SAFE_TO_UPGRADE_NEW_PARTITION_INFO, BrandManager.ProductVersionPost82);
switch (_reason)
{
case HostNotSafeToUpgradeReason.NotEnoughSpace:
return $"{Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_WARNING, BrandManager.ProductVersionPost82)}";
case HostNotSafeToUpgradeReason.VdiPresent:
return $"{Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT_WARNING, BrandManager.ProductVersionPost82)}";
case HostNotSafeToUpgradeReason.UtilityPartitionPresent:
return $"{Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION_WARNING, BrandManager.ProductVersionPost82)}";
case HostNotSafeToUpgradeReason.LegacyPartitionTable:
return $"{Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE_WARNING, BrandManager.ProductVersionPost82)}";
default:
return $"{Messages.NOT_SAFE_TO_UPGRADE_DEFAULT}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_DEFAULT_WARNING, BrandManager.ProductVersionPost82)}";
}
}
}
private string ShortMessage
{
get
{
switch (_reason)
{
case HostNotSafeToUpgradeReason.NotEnoughSpace:
return Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE;
case HostNotSafeToUpgradeReason.VdiPresent:
return Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT;
case HostNotSafeToUpgradeReason.UtilityPartitionPresent:
return Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION;
case HostNotSafeToUpgradeReason.LegacyPartitionTable:
return Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE;
default:
return Messages.NOT_SAFE_TO_UPGRADE_DEFAULT;
}
}
}
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, _host.name_label, _shortMessage);
}
public class HostNotSafeToUpgradeProblem : ProblemWithMoreInfo
{
private readonly Host _host;
private readonly HostNotSafeToUpgradeReason _reason;
private readonly string _shortMessage;
public HostNotSafeToUpgradeProblem(Check check, Host host, HostNotSafeToUpgradeReason reason)
: base(check)
{
this._host = host;
this._reason = reason;
_host = host;
var newPartitionInfo = string.Format(Messages.NOT_SAFE_TO_UPGRADE_NEW_PARTITION_INFO, BrandManager.ProductVersionPost82);
string detail;
switch (reason)
{
case HostNotSafeToUpgradeReason.NotEnoughSpace:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_PROBLEM, BrandManager.ProductVersionPost82);
break;
case HostNotSafeToUpgradeReason.VdiPresent:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT_PROBLEM, BrandManager.ProductVersionPost82);
break;
case HostNotSafeToUpgradeReason.UtilityPartitionPresent:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION_PROBLEM, BrandManager.ProductVersionPost82);
break;
case HostNotSafeToUpgradeReason.LegacyPartitionTable:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE_PROBLEM, BrandManager.ProductVersionPost82);
break;
default:
_shortMessage = Messages.NOT_SAFE_TO_UPGRADE_DEFAULT;
detail = string.Format(Messages.NOT_SAFE_TO_UPGRADE_DEFAULT_PROBLEM, BrandManager.ProductVersionPost82);
break;
}
Message = $"{_shortMessage}\n\n{newPartitionInfo}\n\n{detail}";
}
public override string Message { get; }
public override string Title => Description;
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, _host.name_label, ShortMessage);
public override string Message
{
get
{
var newPartitionInfo = string.Format(Messages.NOT_SAFE_TO_UPGRADE_NEW_PARTITION_INFO, BrandManager.ProductVersionPost82);
switch (_reason)
{
case HostNotSafeToUpgradeReason.NotEnoughSpace:
return $"{Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_PROBLEM, BrandManager.ProductVersionPost82)}";
case HostNotSafeToUpgradeReason.VdiPresent:
return $"{Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT_PROBLEM, BrandManager.ProductVersionPost82)}";
case HostNotSafeToUpgradeReason.UtilityPartitionPresent:
return $"{Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION_PROBLEM, BrandManager.ProductVersionPost82)}";
case HostNotSafeToUpgradeReason.LegacyPartitionTable:
return $"{Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE_PROBLEM, BrandManager.ProductVersionPost82)}";
default:
return $"{Messages.NOT_SAFE_TO_UPGRADE_DEFAULT}\n\n{newPartitionInfo}\n\n{string.Format(Messages.NOT_SAFE_TO_UPGRADE_DEFAULT_PROBLEM, BrandManager.ProductVersionPost82)}";
}
}
}
private string ShortMessage
{
get
{
switch (_reason)
{
case HostNotSafeToUpgradeReason.NotEnoughSpace:
return Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE;
case HostNotSafeToUpgradeReason.VdiPresent:
return Messages.NOT_SAFE_TO_UPGRADE_VDI_PRESENT;
case HostNotSafeToUpgradeReason.UtilityPartitionPresent:
return Messages.NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION;
case HostNotSafeToUpgradeReason.LegacyPartitionTable:
return Messages.NOT_SAFE_TO_UPGRADE_LEGACY_PARTITION_TABLE;
default:
return Messages.NOT_SAFE_TO_UPGRADE_DEFAULT;
}
}
}
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, _host.name_label, _shortMessage);
}
}

View File

@ -199,7 +199,8 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
var prepareToUpgradeChecks = (from Host host in hostsToUpgrade
select new PrepareToUpgradeCheck(host, InstallMethodConfig) as Check).ToList();
groups.Add(new CheckGroup(Messages.CHECKING_PREPARE_TO_UPGRADE, prepareToUpgradeChecks));
if (prepareToUpgradeChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_PREPARE_TO_UPGRADE, prepareToUpgradeChecks));
}
//vSwitch controller check - for each pool
@ -241,41 +242,39 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
//HA checks - for each pool
var haChecks = (from Host server in SelectedMasters
select new HAOffCheck(server) as Check).ToList();
groups.Add(new CheckGroup(Messages.CHECKING_HA_STATUS, haChecks));
if (haChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_HA_STATUS, haChecks));
//Checking can evacuate host - for hosts that will be upgraded or updated
var evacuateChecks = new List<Check>();
foreach (Host host in hostsToUpgradeOrUpdate)
evacuateChecks.Add(new AssertCanEvacuateUpgradeCheck(host));
groups.Add(new CheckGroup(Messages.CHECKING_CANEVACUATE_STATUS, evacuateChecks));
var evacuateChecks = (from Host host in hostsToUpgradeOrUpdate
select new AssertCanEvacuateUpgradeCheck(host) as Check).ToList();
if (evacuateChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_CANEVACUATE_STATUS, evacuateChecks));
//PBDsPluggedCheck - for hosts that will be upgraded or updated
var pbdChecks = new List<Check>();
foreach (Host host in hostsToUpgradeOrUpdate)
pbdChecks.Add(new PBDsPluggedCheck(host));
groups.Add(new CheckGroup(Messages.CHECKING_STORAGE_CONNECTIONS_STATUS, pbdChecks));
var pbdChecks = (from Host host in hostsToUpgradeOrUpdate
select new PBDsPluggedCheck(host) as Check).ToList();
if(pbdChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_STORAGE_CONNECTIONS_STATUS, pbdChecks));
//HostMemoryPostUpgradeCheck - for hosts that will be upgraded
var mostMemoryPostUpgradeChecks = new List<Check>();
foreach (var host in hostsToUpgrade)
{
mostMemoryPostUpgradeChecks.Add(new HostMemoryPostUpgradeCheck(host, InstallMethodConfig));
}
var mostMemoryPostUpgradeChecks = (from Host host in hostsToUpgrade
select new HostMemoryPostUpgradeCheck(host, InstallMethodConfig) as Check).ToList();
if (mostMemoryPostUpgradeChecks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_HOST_MEMORY_POST_UPGRADE, mostMemoryPostUpgradeChecks));
var gfs2Checks = new List<Check>();
foreach (Pool pool in SelectedPools.Where(p =>
Helpers.KolkataOrGreater(p.Connection) && !Helpers.LimaOrGreater(p.Connection)))
{
Host host = pool.Connection.Resolve(pool.master);
gfs2Checks.Add(new PoolHasGFS2SR(host));
}
if (gfs2Checks.Count > 0)
{
//PoolHasGFS2SR checks
var gfs2Checks = (from Host host in SelectedMasters
let check = new PoolHasGFS2SR(host)
where check.CanRun()
select check as Check).ToList();
if (gfs2Checks.Count > 0)
groups.Add(new CheckGroup(Messages.CHECKING_CLUSTERING_STATUS, gfs2Checks));
}
//Checking automated updates are possible if apply updates checkbox is ticked
if (ApplyUpdatesToNewVersion)

View File

@ -28237,7 +28237,7 @@ namespace XenAdmin {
}
/// <summary>
/// Looks up a localized string similar to However, there is a utility partition present which prevents repartitioning. The current partitioning scheme cannot be retained if you upgrade to {0} or above, so existing utility partition must be removed first..
/// Looks up a localized string similar to However, there is a utility partition present which prevents repartitioning. The current partitioning scheme cannot be retained if you upgrade to {0} or above, so the existing utility partition must be removed first..
/// </summary>
public static string NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION_WARNING {
get {

View File

@ -9801,7 +9801,7 @@ It is strongly recommended that you Cancel and apply the latest version of the p
<value>However, there is a utility partition present which prevents repartitioning. To upgrade to {0}, the utility partition must be removed.</value>
</data>
<data name="NOT_SAFE_TO_UPGRADE_UTILITY_PARTITION_WARNING" xml:space="preserve">
<value>However, there is a utility partition present which prevents repartitioning. The current partitioning scheme cannot be retained if you upgrade to {0} or above, so existing utility partition must be removed first.</value>
<value>However, there is a utility partition present which prevents repartitioning. The current partitioning scheme cannot be retained if you upgrade to {0} or above, so the existing utility partition must be removed first.</value>
</data>
<data name="NOT_SAFE_TO_UPGRADE_VDI_PRESENT" xml:space="preserve">
<value>VMs on local disk will prevent disk repartitioning.</value>