From 959e43480cfe24b58205bd79d56fdfe2cb05230b Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Thu, 29 Mar 2018 14:32:39 +0100 Subject: [PATCH] CP-17099: Double probe for iSCSI - minor refactoring to reduce code duplication. Signed-off-by: Konstantina Chremmou --- .../NewSRWizard_Pages/Frontends/LVMoISCSI.cs | 75 ++++++++----------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/XenAdmin/Wizards/NewSRWizard_Pages/Frontends/LVMoISCSI.cs b/XenAdmin/Wizards/NewSRWizard_Pages/Frontends/LVMoISCSI.cs index 393804692..3db4558b2 100644 --- a/XenAdmin/Wizards/NewSRWizard_Pages/Frontends/LVMoISCSI.cs +++ b/XenAdmin/Wizards/NewSRWizard_Pages/Frontends/LVMoISCSI.cs @@ -143,20 +143,12 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends return; } - Dictionary dconf = GetDeviceConfig(SrType); - if (dconf == null) - { - cancel = true; - return; - } + // Start probe List srs; + var currentSrType = SrType; - // Start probe - SrProbeAction IscsiProbeAction = new SrProbeAction(Connection, master, SrType, dconf); - bool success = RunProbe(IscsiProbeAction, out srs); - - if (!success) + if (!RunProbe(master, currentSrType, out srs)) { cancel = iscsiProbeError = true; return; @@ -167,12 +159,9 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends if (performSecondProbe && srs.Count == 0) { // Start second probe - var secondSrType = SrType == SR.SRTypes.gfs2 ? SR.SRTypes.lvmoiscsi : SR.SRTypes.gfs2; - dconf = GetDeviceConfig(secondSrType); - IscsiProbeAction = new SrProbeAction(Connection, master, secondSrType, dconf); - success = RunProbe(IscsiProbeAction, out srs); + currentSrType = SrType == SR.SRTypes.gfs2 ? SR.SRTypes.lvmoiscsi : SR.SRTypes.gfs2; - if (!success) + if (!RunProbe(master, currentSrType, out srs)) { cancel = iscsiProbeError = true; return; @@ -181,18 +170,24 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends // Probe has been performed. Now ask the user if they want to Reattach/Format/Cancel. // Will return false on cancel - cancel = iscsiProbeError = !ExamineIscsiProbeResults(IscsiProbeAction, srs); + cancel = iscsiProbeError = !ExamineIscsiProbeResults(currentSrType, srs); } - private bool RunProbe(SrProbeAction action, out List srs) + private bool RunProbe(Host master, SR.SRTypes srType, out List srs) { + srs = null; + + Dictionary dconf = GetDeviceConfig(srType); + if (dconf == null) + return false; + + var action = new SrProbeAction(Connection, master, srType, dconf); using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee)) { dialog.ShowCancel = true; dialog.ShowDialog(this); } - srs = null; _srToIntroduce = null; if (action.Succeeded) { @@ -207,34 +202,24 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends } } - DoOnProbeFailure(action); - return false; - } - - private void DoOnProbeFailure(SrProbeAction action) - { - if (action.Succeeded) - return; - Exception exn = action.Exception; log.Warn(exn, exn); + Failure failure = exn as Failure; - if (failure != null && failure.ErrorDescription[0] == "SR_BACKEND_FAILURE_140") + if (failure != null) { errorIconAtHostOrIP.Visible = true; errorLabelAtHostname.Visible = true; - errorLabelAtHostname.Text = Messages.INVALID_HOST; - textBoxIscsiHost.Focus(); - } - else if (failure != null) - { - errorIconAtHostOrIP.Visible = true; - errorLabelAtHostname.Visible = true; - errorLabelAtHostname.Text = failure.ErrorDescription.Count > 2 - ? failure.ErrorDescription[2] - : failure.ErrorDescription[0]; + + errorLabelAtHostname.Text = failure.ErrorDescription[0] == "SR_BACKEND_FAILURE_140" + ? Messages.INVALID_HOST + : (failure.ErrorDescription.Count > 2 + ? failure.ErrorDescription[2] + : failure.ErrorDescription[0]); + textBoxIscsiHost.Focus(); } + return false; } bool iscsiProbeError = false; @@ -776,11 +761,11 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends /// Whether to continue or not - wheter to format or not is stored in /// iScsiFormatLUN. /// - private bool ExamineIscsiProbeResults(SrProbeAction action, List srs) + private bool ExamineIscsiProbeResults(SR.SRTypes currentSrType, List srs) { _srToIntroduce = null; - if (!action.Succeeded || srs == null) + if (srs == null) return false; try @@ -791,7 +776,7 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends if (srs.Count == 1 && srs[0].UUID == SrWizardType.UUID) { _srToIntroduce = srs[0]; - SrType = action.SrType; // the type of the existing SR + SrType = currentSrType; // the type of the existing SR return true; } @@ -852,21 +837,21 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends return false; _srToIntroduce = info; - SrType = action.SrType; // the type of the existing SR + SrType = currentSrType; // the type of the existing SR return true; } // An SR exists on this LUN. Ask the user if they want to attach it, format it and // create a new SR, or cancel. DialogResult result = Program.RunInAutomatedTestMode ? DialogResult.Yes : - new IscsiChoicesDialog(Connection, info, action.SrType, SrType).ShowDialog(this); + new IscsiChoicesDialog(Connection, info, currentSrType, SrType).ShowDialog(this); switch (result) { case DialogResult.Yes: // Reattach _srToIntroduce = srs[0]; - SrType = action.SrType; // the type of the existing SR + SrType = currentSrType; // the type of the existing SR return true; case DialogResult.No: