diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard.cs index 87ca93add..cb9e9cdfd 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard.cs @@ -42,6 +42,8 @@ using XenAdmin.Core; namespace XenAdmin.Wizards.PatchingWizard { + public enum WizardMode { SingleUpdate, AutomatedUpdates, NewVersion } + /// /// Remember that equals for patches dont work across connections because /// we are not allow to override equals. YOU SHOULD NOT USE ANY OPERATION THAT IMPLIES CALL EQUALS OF Pool_path or Host_patch @@ -106,7 +108,8 @@ namespace XenAdmin.Wizards.PatchingWizard if (prevPageType == typeof(PatchingWizard_SelectPatchPage)) { - var wizardIsInAutomatedUpdatesMode = PatchingWizard_SelectPatchPage.IsInAutomatedUpdatesMode; + var wizardMode = PatchingWizard_SelectPatchPage.WizardMode; + var wizardIsInAutomatedUpdatesMode = wizardMode == WizardMode.AutomatedUpdates; var updateType = wizardIsInAutomatedUpdatesMode ? UpdateType.NewRetail : PatchingWizard_SelectPatchPage.SelectedUpdateType; var newPatch = wizardIsInAutomatedUpdatesMode ? null : PatchingWizard_SelectPatchPage.SelectedNewPatch; @@ -114,24 +117,23 @@ namespace XenAdmin.Wizards.PatchingWizard var alertPatch = wizardIsInAutomatedUpdatesMode ? null : PatchingWizard_SelectPatchPage.SelectedUpdateAlert; var fileFromDiskAlertPatch = wizardIsInAutomatedUpdatesMode ? null : PatchingWizard_SelectPatchPage.FileFromDiskAlert; - PatchingWizard_SelectServers.IsInAutomaticMode = wizardIsInAutomatedUpdatesMode; + PatchingWizard_SelectServers.WizardMode = wizardMode; PatchingWizard_SelectServers.SelectedUpdateType = updateType; PatchingWizard_SelectServers.Patch = existPatch; PatchingWizard_SelectServers.SelectedUpdateAlert = alertPatch; - PatchingWizard_PrecheckPage.UpdateAlert = alertPatch ?? fileFromDiskAlertPatch; PatchingWizard_SelectServers.FileFromDiskAlert = fileFromDiskAlertPatch; RemovePage(PatchingWizard_UploadPage); RemovePage(PatchingWizard_ModePage); RemovePage(PatchingWizard_PatchingPage); RemovePage(PatchingWizard_AutomatedUpdatesPage); - if (!wizardIsInAutomatedUpdatesMode) + if (wizardMode == WizardMode.SingleUpdate) { AddAfterPage(PatchingWizard_SelectServers, PatchingWizard_UploadPage); AddAfterPage(PatchingWizard_PrecheckPage, PatchingWizard_ModePage); AddAfterPage(PatchingWizard_ModePage, PatchingWizard_PatchingPage); } - else + else // AutomatedUpdates or NewVersion { AddAfterPage(PatchingWizard_PrecheckPage, PatchingWizard_AutomatedUpdatesPage); } @@ -142,17 +144,18 @@ namespace XenAdmin.Wizards.PatchingWizard PatchingWizard_UploadPage.SelectedUpdateAlert = alertPatch; PatchingWizard_ModePage.Patch = existPatch; - PatchingWizard_ModePage.SelectedUpdateAlert = alertPatch; - - PatchingWizard_PrecheckPage.IsInAutomatedUpdatesMode = wizardIsInAutomatedUpdatesMode; - PatchingWizard_PrecheckPage.Patch = existPatch; - PatchingWizard_PatchingPage.Patch = existPatch; - - PatchingWizard_PrecheckPage.SelectedUpdateType = updateType; - PatchingWizard_ModePage.SelectedUpdateType = updateType; + PatchingWizard_PrecheckPage.WizardMode = wizardMode; + PatchingWizard_PrecheckPage.Patch = existPatch; + PatchingWizard_PrecheckPage.SelectedUpdateType = updateType; + PatchingWizard_PrecheckPage.UpdateAlert = alertPatch ?? fileFromDiskAlertPatch; + + PatchingWizard_AutomatedUpdatesPage.WizardMode = wizardMode; + PatchingWizard_AutomatedUpdatesPage.UpdateAlert = alertPatch ?? fileFromDiskAlertPatch; + PatchingWizard_PatchingPage.SelectedUpdateType = updateType; + PatchingWizard_PatchingPage.Patch = existPatch; PatchingWizard_PatchingPage.SelectedNewPatch = newPatch; } else if (prevPageType == typeof(PatchingWizard_SelectServers)) @@ -328,11 +331,9 @@ namespace XenAdmin.Wizards.PatchingWizard private void RemoveDownloadedPatches() { - var isInAutomaticMode = PatchingWizard_SelectPatchPage.IsInAutomatedUpdatesMode; - List listOfDownloadedFiles = new List(); - if (isInAutomaticMode) + if (PatchingWizard_SelectPatchPage.WizardMode != WizardMode.SingleUpdate) // AutomatedUpdates or NewVersion { listOfDownloadedFiles.AddRange(PatchingWizard_AutomatedUpdatesPage.AllDownloadedPatches.Values); } diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_AutomatedUpdatesPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_AutomatedUpdatesPage.cs index 49fcd8924..56ce46b5a 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_AutomatedUpdatesPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_AutomatedUpdatesPage.cs @@ -48,6 +48,7 @@ using XenAdmin.Core; using XenAdmin.Network; using System.Text; using System.Diagnostics; +using XenAdmin.Alerts; namespace XenAdmin.Wizards.PatchingWizard { @@ -62,6 +63,9 @@ namespace XenAdmin.Wizards.PatchingWizard public List SelectedPools { private get; set; } + public XenServerPatchAlert UpdateAlert { private get; set; } + public WizardMode WizardMode { private get; set; } + private List patchMappings = new List(); public Dictionary AllDownloadedPatches = new Dictionary(); @@ -135,6 +139,8 @@ namespace XenAdmin.Wizards.PatchingWizard return; } + Debug.Assert(WizardMode != WizardMode.NewVersion || (WizardMode == WizardMode.NewVersion && UpdateAlert != null), "For version updates the UpdateAlert shouldn't be null"); + foreach (var pool in SelectedPools) { var master = Helpers.GetMaster(pool.Connection); @@ -147,9 +153,9 @@ namespace XenAdmin.Wizards.PatchingWizard delayedActionsByHost.Add(host, new List()); } - var hosts = pool.Connection.Cache.Hosts; - - var us = Updates.GetUpgradeSequence(pool.Connection); + var us = WizardMode == WizardMode.NewVersion + ? Updates.GetUpgradeSequence(pool.Connection, UpdateAlert, true) + : Updates.GetUpgradeSequence(pool.Connection); Debug.Assert(us != null, "Update sequence should not be null."); diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_ModePage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_ModePage.cs index e8d138e12..b660055d8 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_ModePage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_ModePage.cs @@ -45,8 +45,6 @@ namespace XenAdmin.Wizards.PatchingWizard { private bool _tooltipShowing; - public XenServerPatchAlert SelectedUpdateAlert { private get; set; } - public PatchingWizard_ModePage() { InitializeComponent(); diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs index 5f534bad0..a302758b0 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs @@ -56,7 +56,6 @@ namespace XenAdmin.Wizards.PatchingWizard private BackgroundWorker _worker = null; public List SelectedServers = new List(); public List ProblemsResolvedPreCheck = new List(); - public bool IsInAutomatedUpdatesMode { get; set; } private AsyncAction resolvePrechecksAction = null; protected List SelectedPools @@ -68,6 +67,7 @@ namespace XenAdmin.Wizards.PatchingWizard } public XenServerPatchAlert UpdateAlert { private get; set; } + public WizardMode WizardMode { private get; set; } public PatchingWizard_PrecheckPage() { @@ -126,7 +126,7 @@ namespace XenAdmin.Wizards.PatchingWizard if (direction == PageLoadedDirection.Back) return; - if (IsInAutomatedUpdatesMode) + if (WizardMode == WizardMode.AutomatedUpdates) { labelPrechecksFirstLine.Text = Messages.PATCHINGWIZARD_PRECHECKPAGE_FIRSTLINE_AUTOMATED_UPDATES_MODE; } @@ -385,14 +385,19 @@ namespace XenAdmin.Wizards.PatchingWizard } //Disk space check for automated updates - if (IsInAutomatedUpdatesMode) + if (WizardMode != WizardMode.SingleUpdate) { checks.Add(new KeyValuePair>(Messages.PATCHINGWIZARD_PRECHECKPAGE_CHECKING_DISK_SPACE, new List())); checkGroup = checks[checks.Count - 1].Value; foreach (Pool pool in SelectedPools) { - var us = Updates.GetUpgradeSequence(pool.Connection); + var us = WizardMode == WizardMode.NewVersion + ? Updates.GetUpgradeSequence(pool.Connection, UpdateAlert, true) + : Updates.GetUpgradeSequence(pool.Connection); + + if (us == null) + continue; bool elyOrGreater = Helpers.ElyOrGreater(pool.Connection); @@ -434,7 +439,7 @@ namespace XenAdmin.Wizards.PatchingWizard } //Checking if the host needs a reboot - if (!IsInAutomatedUpdatesMode) + if (WizardMode != WizardMode.SingleUpdate) { checks.Add(new KeyValuePair>(Messages.CHECKING_SERVER_NEEDS_REBOOT, new List())); checkGroup = checks[checks.Count - 1].Value; @@ -483,7 +488,7 @@ namespace XenAdmin.Wizards.PatchingWizard } //Checking if the host needs a reboot - if (!IsInAutomatedUpdatesMode) + if (WizardMode == WizardMode.SingleUpdate) { checks.Add(new KeyValuePair>(Messages.CHECKING_SERVER_NEEDS_REBOOT, new List())); checkGroup = checks[checks.Count - 1].Value; diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs index 90386760d..8ed1ff53f 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs @@ -156,7 +156,24 @@ namespace XenAdmin.Wizards.PatchingWizard } } - public bool IsInAutomatedUpdatesMode { get { return AutomatedUpdatesRadioButton.Visible && AutomatedUpdatesRadioButton.Checked; } } + private bool IsInAutomatedUpdatesMode { get { return AutomatedUpdatesRadioButton.Visible && AutomatedUpdatesRadioButton.Checked; } } + + public WizardMode WizardMode + { + get + { + if (AutomatedUpdatesRadioButton.Visible && AutomatedUpdatesRadioButton.Checked) + return WizardMode.AutomatedUpdates; + var updateAlert = downloadUpdateRadioButton.Checked && dataGridViewPatches.SelectedRows.Count > 0 + ? (XenServerPatchAlert) ((PatchGridViewRow) dataGridViewPatches.SelectedRows[0]).UpdateAlert + : selectFromDiskRadioButton.Checked + ? GetAlertFromFileName(fileNameTextBox.Text.ToLowerInvariant()) + : null; + if (updateAlert != null && updateAlert.NewServerVersion != null) + return WizardMode.NewVersion; + return WizardMode.SingleUpdate; + } + } public override void PageLeave(PageLoadedDirection direction, ref bool cancel) { diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs index 641cece99..29380f646 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs @@ -60,8 +60,8 @@ namespace XenAdmin.Wizards.PatchingWizard private bool poolSelectionOnly; public XenServerPatchAlert SelectedUpdateAlert { private get; set; } - public XenServerPatchAlert FileFromDiskAlert { private get; set; } + public WizardMode WizardMode { private get; set; } public PatchingWizard_SelectServers() { @@ -95,8 +95,8 @@ namespace XenAdmin.Wizards.PatchingWizard base.PageLoaded(direction); try { - poolSelectionOnly = IsInAutomaticMode || SelectedUpdateAlert != null || FileFromDiskAlert != null; - label1.Text = IsInAutomaticMode + poolSelectionOnly = WizardMode == WizardMode.AutomatedUpdates || SelectedUpdateAlert != null || FileFromDiskAlert != null; + label1.Text = WizardMode == WizardMode.AutomatedUpdates ? Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_AUTOMATED_MODE : poolSelectionOnly ? Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_POOL_SELECTION : Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_DEFAULT; @@ -142,16 +142,14 @@ namespace XenAdmin.Wizards.PatchingWizard { dataGridViewHosts.Select(); } - - public bool IsInAutomaticMode { set; get; } - + private void EnabledRow(Host host, UpdateType type, int index) { var row = (PatchingHostsDataGridViewRow)dataGridViewHosts.Rows[index]; var poolOfOne = Helpers.GetPoolOfOne(host.Connection); - if (IsInAutomaticMode) + if (WizardMode == WizardMode.AutomatedUpdates) { // This check is first because it generally can't be fixed, it's a property of the host if (poolOfOne != null && poolOfOne.IsAutoUpdateRestartsForbidden) // Forbids update auto restarts @@ -475,7 +473,7 @@ namespace XenAdmin.Wizards.PatchingWizard { if (poolSelectionOnly) { - if (IsInAutomaticMode) + if (WizardMode != WizardMode.SingleUpdate) //prechecks will fail in automated updates mode if one of the hosts is unreachable return SelectedPools.SelectMany(p => p.Connection.Cache.Hosts).ToList(); //prechecks will issue warning but allow updates to be installed on the reachable hosts only