From 4f4217a2b1c4f7b4c421be5e653c40ae85064731 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Wed, 20 May 2020 03:13:17 +0100 Subject: [PATCH] CA-339685: Corrected calculation of completion percentage and added checks for division by zero. Also, some simplifications and removal of unused variables and fields. Signed-off-by: Konstantina Chremmou --- XenModel/Actions/Network/DestroyBondAction.cs | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/XenModel/Actions/Network/DestroyBondAction.cs b/XenModel/Actions/Network/DestroyBondAction.cs index 652ff713a..11b588272 100644 --- a/XenModel/Actions/Network/DestroyBondAction.cs +++ b/XenModel/Actions/Network/DestroyBondAction.cs @@ -31,12 +31,12 @@ using System; using System.Collections.Generic; -using System.Threading; +using System.Net; using XenAPI; using XenAdmin.Core; - using XenAdmin.Network; + namespace XenAdmin.Actions { public class DestroyBondAction : AsyncAction @@ -53,11 +53,6 @@ namespace XenAdmin.Actions /// private readonly List Masters = new List(); - /// - /// Masters that held secondary management interfaces. These are discovered when bringing masters down. - /// - private readonly List Secondaries = new List(); - /// /// All slaves under each bond in Bonds. These will be plugged at the end, in order to /// get metrics like the carrier flag, if they haven't already been brought up as a @@ -70,11 +65,6 @@ namespace XenAdmin.Actions /// private readonly Dictionary FirstSlaves = new Dictionary(); - /// - /// A dictionary of copies of the equivalent entries in FirstSlaves, but with the IP details that we're carrying across. - /// - private readonly Dictionary NewFirstSlaves = new Dictionary(); - /// /// The network that we're either going to destroy or rename. /// @@ -152,39 +142,51 @@ namespace XenAdmin.Actions protected override void Run() { + PercentComplete = 0; Connection.ExpectDisruption = true; - List unplugged_vifs = new List(); - string old_network_name = Network == null ? "" : Network.Name(); - Exception e = null; - BestEffort(ref e, ReconfigureManagementInterfaces); + int incr = Masters.Count > 0 ? 50 / Masters.Count : 0; - if (e != null) - throw e; + try + { + foreach (PIF master in Masters) + { + NetworkingActionHelpers.MoveManagementInterfaceName(this, master, FirstSlaves[master]); + PercentComplete += incr; + } + } + catch (WebException we) + { + //ignore keep-alive failure since disruption is expected + if (we.Status != WebExceptionStatus.KeepAliveFailure) + throw; + } PercentComplete = 50; - int inc = 40 / Bonds.Count; + Exception e = null; + + int inc = Bonds.Count > 0 ? 40 / Bonds.Count : 0; - int lo = PercentComplete; foreach (Bond bond in Bonds) { Bond bond1 = bond; - int lo1 = lo; BestEffort(ref e, delegate() { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref);}); - PollToCompletion(lo1, lo1 + inc); - - lo += inc; + PollToCompletion(PercentComplete, PercentComplete + inc); } + PercentComplete = 90; + if (Network != null) { + string oldNetworkName = Network.Name(); + // Destroy the old network - log.DebugFormat("Destroying network {0} ({1})...", old_network_name, Network.uuid); + log.DebugFormat("Destroying network {0} ({1})...", oldNetworkName, Network.uuid); BestEffort(ref e, delegate() { XenAPI.Network.destroy(Session, Network.opaque_ref); - log.DebugFormat("Network {0} ({1}) destroyed.", old_network_name, Network.uuid); + log.DebugFormat("Network {0} ({1}) destroyed.", oldNetworkName, Network.uuid); }); } @@ -194,18 +196,6 @@ namespace XenAdmin.Actions Description = string.Format(Messages.ACTION_DESTROY_BOND_DONE, Name); } - private void ReconfigureManagementInterfaces() - { - int progress = 0; - int inc = 50 / Masters.Count; - - foreach (PIF master in Masters) - { - progress += inc; - NetworkingActionHelpers.MoveManagementInterfaceName(this, master, FirstSlaves[master]); - } - } - private void UnlockAll() { foreach (Bond bond in Bonds)