Exemple #1
0
        protected override void Run()
        {
            SafeToExit = false;

            if (patch.AppliedOn(host) != DateTime.MaxValue)
            {
                return;
            }

            XenRef <Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);

            Description = string.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());
            log.DebugFormat("Applying update '{0}' to server '{1}'", patch.Name(), host.Name());

            try
            {
                RelatedTask = Pool_patch.async_apply(Session, patchRef, host.opaque_ref);
                PollToCompletion();
            }
            catch (Failure f)
            {
                log.ErrorFormat("Failed to apply patch '{0}' on server '{1}': '{2}'",
                                patch.Name(), host.Name(), string.Join(", ", f.ErrorDescription)); //CA-339237
                throw;
            }

            log.DebugFormat("Applied update '{0}' to server '{1}'. Result: {2}.", patch.Name(), host.Name(), Result);
            Description = string.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
        }
        protected override void Run()
        {
            SafeToExit = false;

            if (patch.AppliedOn(host) == DateTime.MaxValue)
            {
                ApplyPatch();
            }
        }
Exemple #3
0
        protected virtual List <KeyValuePair <string, List <Check> > > GenerateChecks(Pool_patch patch)
        {
            List <Host> applicableServers = patch != null?SelectedServers.Where(h => patch.AppliedOn(h) == DateTime.MaxValue).ToList() : SelectedServers;

            List <KeyValuePair <string, List <Check> > > checks = GenerateCommonChecks(applicableServers);

            List <Check> checkGroup;

            //Checking other things
            if (patch != null)
            {
                checks.Add(new KeyValuePair <string, List <Check> >(Messages.CHECKING_SERVER_SIDE_STATUS, new List <Check>()));
                checkGroup = checks[checks.Count - 1].Value;
                foreach (Host host in SelectedServers)
                {
                    List <Pool_patch> poolPatches       = new List <Pool_patch>(host.Connection.Cache.Pool_patches);
                    Pool_patch        poolPatchFromHost = poolPatches.Find(otherPatch => string.Equals(otherPatch.uuid, patch.uuid, StringComparison.OrdinalIgnoreCase));
                    checkGroup.Add(new PatchPrecheckCheck(host, poolPatchFromHost, LivePatchCodesByHost));
                }
            }

            //Checking if the host needs a reboot
            if (!IsInAutomatedUpdatesMode)
            {
                checks.Add(new KeyValuePair <string, List <Check> >(Messages.CHECKING_SERVER_NEEDS_REBOOT, new List <Check>()));
                checkGroup = checks[checks.Count - 1].Value;
                var guidance = patch != null
                    ? patch.after_apply_guidance
                    : new List <after_apply_guidance> {
                    after_apply_guidance.restartHost
                };
                foreach (var host in applicableServers)
                {
                    checkGroup.Add(new HostNeedsRebootCheck(host, guidance, LivePatchCodesByHost));
                }
            }

            //Checking can evacuate host
            //CA-97061 - evacuate host -> suspended VMs. This is only needed for restartHost
            //Also include this check for the supplemental packs (patch == null), as their guidance is restartHost
            if (patch == null || patch.after_apply_guidance.Contains(after_apply_guidance.restartHost))
            {
                checks.Add(new KeyValuePair <string, List <Check> >(Messages.CHECKING_CANEVACUATE_STATUS, new List <Check>()));
                checkGroup = checks[checks.Count - 1].Value;
                foreach (Host host in applicableServers)
                {
                    checkGroup.Add(new AssertCanEvacuateCheck(host, LivePatchCodesByHost));
                }
            }

            return(checks);
        }
Exemple #4
0
        protected override void Run()
        {
            SafeToExit = false;

            if (patch.AppliedOn(host) != DateTime.MaxValue)
            {
                return;
            }

            XenRef <Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);

            Description = string.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());
            log.Debug(Description);

            var result = Pool_patch.apply(Session, patchRef, host.opaque_ref);

            log.DebugFormat(Messages.APPLY_PATCH_LOG_MESSAGE, patch.Name(), host.Name(), result);
            Description = string.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
        }
        protected override void Run()
        {
            SafeToExit = false;

            if (patch.AppliedOn(host) != DateTime.MaxValue)
            {
                return;
            }

            XenRef <Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);

            Description = string.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());
            log.DebugFormat("Applying update '{0}' to server '{1}'", patch.Name(), host.Name());

            RelatedTask = Pool_patch.async_apply(Session, patchRef, host.opaque_ref);
            PollToCompletion();

            log.DebugFormat("Applied update '{0}' to server '{1}'. Result: {2}.", patch.Name(), host.Name(), Result);
            Description = string.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
        }
Exemple #6
0
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);

            if (_thisPageHasBeenCompleted)
            {
                actionsWorker = null;
                return;
            }

            if (!IsAutomaticMode)
            {
                textBoxLog.Text = ManualTextInstructions;

                List <AsyncAction> actions = new List <AsyncAction>();

                if (SelectedUpdateType == UpdateType.ISO && PoolUpdate != null)
                {
                    //Ely or greater: iso update format
                    foreach (var server in SelectedServers)
                    {
                        actions.Add(new ApplyUpdateAction(PoolUpdate, server));
                    }
                }
                else
                {
                    //legacy mode
                    if (SelectedUpdateType != UpdateType.ISO)
                    {
                        foreach (var server in SelectedServers)
                        {
                            actions.Add(new ApplyPatchAction(Patch, server));
                        }
                    }
                    else
                    {
                        actions.Add(new InstallSupplementalPackAction(SuppPackVdis, false));
                    }
                }

                if (RemoveUpdateFile && SelectedUpdateType != UpdateType.ISO)
                {
                    foreach (Pool pool in SelectedPools)
                    {
                        actions.Add(new PoolPatchCleanAction(pool, Patch, false));
                    }
                }

                using (var multipleAction = new MultipleAction(Connection, "", "", "", actions, true, true, true))
                {
                    multipleAction.Changed   += action_Changed;
                    multipleAction.Completed += action_Completed;
                    multipleAction.RunAsync();
                }
                return;
            }

            _nextEnabled = false;
            OnPageUpdated();

            List <PlanAction> planActions = new List <PlanAction>();

            foreach (Pool pool in SelectedPools)
            {
                var  poolHosts = new List <Host>(pool.Connection.Cache.Hosts);
                Host master    = SelectedServers.Find(host => host.IsMaster() && poolHosts.Contains(host));

                //For Ely or greater: ISO updates only
                if (SelectedUpdateType == UpdateType.ISO && Helpers.ElyOrGreater(pool.Connection)) //updates for Ely (or higher) are always ISO
                {
                    var poolUpdates = new List <Pool_update>(pool.Connection.Cache.Pool_updates);
                    var poolUpdate  = poolUpdates.FirstOrDefault(u => u != null && string.Equals(u.uuid, PoolUpdate.uuid, StringComparison.OrdinalIgnoreCase));

                    //master first
                    if (master != null && !poolUpdate.AppliedOn(master))
                    {
                        planActions.AddRange(CompilePoolUpdateActionList(master, poolUpdate));
                    }

                    //other hosts
                    foreach (var host in SelectedServers.Where(s => poolHosts.Contains(s) && !s.IsMaster() && !poolUpdate.AppliedOn(s)).ToList())
                    {
                        planActions.AddRange(CompilePoolUpdateActionList(host, poolUpdate));
                    }
                }
                // Legacy (pre-Ely) case: either ISO for supplemental packs (Pool_patch == null) or patch (Pool_patch != null)
                else
                {
                    Pool_patch poolPatch = null;

                    if (SelectedUpdateType != UpdateType.ISO)
                    {
                        List <Pool_patch> poolPatches = new List <Pool_patch>(pool.Connection.Cache.Pool_patches);

                        poolPatch = poolPatches.Find(delegate(Pool_patch otherPatch)
                        {
                            if (Patch != null)
                            {
                                return(string.Equals(otherPatch.uuid, Patch.uuid, StringComparison.OrdinalIgnoreCase));
                            }
                            return(false);
                        });
                    }

                    //master first
                    if (master != null && (poolPatch == null || poolPatch.AppliedOn(master) == DateTime.MaxValue))
                    {
                        planActions.AddRange(CompileActionList(master, poolPatch));
                    }

                    foreach (Host server in SelectedServers)
                    {
                        if (poolHosts.Contains(server))
                        {
                            if (!server.IsMaster())
                            {
                                // check patch isn't already applied here
                                if (poolPatch == null || poolPatch.AppliedOn(server) == DateTime.MaxValue)
                                {
                                    planActions.AddRange(CompileActionList(server, poolPatch));
                                }
                            }
                        }
                    }

                    if (RemoveUpdateFile)
                    {
                        planActions.Add(new RemoveUpdateFile(pool, poolPatch));
                    }
                }
            } //end pool in foreach

            planActions.Add(new UnwindProblemsAction(ProblemsResolvedPreCheck));

            actionsWorker         = new BackgroundWorker();
            actionsWorker.DoWork += new DoWorkEventHandler(PatchingWizardAutomaticPatchWork);
            actionsWorker.WorkerReportsProgress      = true;
            actionsWorker.ProgressChanged           += new ProgressChangedEventHandler(actionsWorker_ProgressChanged);
            actionsWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(actionsWorker_RunWorkerCompleted);
            actionsWorker.WorkerSupportsCancellation = true;
            actionsWorker.RunWorkerAsync(planActions);
        }
        protected virtual List <CheckGroup> GenerateChecks(Pool_patch patch)
        {
            List <Host> applicableServers = patch != null?SelectedServers.Where(h => patch.AppliedOn(h) == DateTime.MaxValue).ToList() : SelectedServers;

            var groups = GenerateCommonChecks(applicableServers);

            //Checking other things
            if (patch != null)
            {
                var serverChecks = new List <Check>();
                foreach (Host host in SelectedServers)
                {
                    List <Pool_patch> poolPatches       = new List <Pool_patch>(host.Connection.Cache.Pool_patches);
                    Pool_patch        poolPatchFromHost = poolPatches.Find(otherPatch => string.Equals(otherPatch.uuid, patch.uuid, StringComparison.OrdinalIgnoreCase));
                    serverChecks.Add(new PatchPrecheckCheck(host, poolPatchFromHost, LivePatchCodesByHost));
                }
                groups.Add(new CheckGroup(Messages.CHECKING_SERVER_SIDE_STATUS, serverChecks));
            }

            //Checking if the host needs a reboot
            if (WizardMode == WizardMode.SingleUpdate)
            {
                var rebootChecks = new List <Check>();
                var guidance     = patch != null
                    ? patch.after_apply_guidance
                    : new List <after_apply_guidance> {
                    after_apply_guidance.restartHost
                };

                foreach (var host in applicableServers)
                {
                    rebootChecks.Add(new HostNeedsRebootCheck(host, guidance, LivePatchCodesByHost));
                }

                groups.Add(new CheckGroup(Messages.CHECKING_SERVER_NEEDS_REBOOT, rebootChecks));
            }

            //Checking can evacuate host
            //CA-97061 - evacuate host -> suspended VMs. This is only needed for restartHost
            //Also include this check for the supplemental packs (patch == null), as their guidance is restartHost
            if (WizardMode == WizardMode.SingleUpdate && (patch == null || patch.after_apply_guidance.Contains(after_apply_guidance.restartHost)))
            {
                var evacuateChecks = new List <Check>();
                foreach (Host host in applicableServers)
                {
                    evacuateChecks.Add(new AssertCanEvacuateCheck(host, LivePatchCodesByHost));
                }

                groups.Add(new CheckGroup(Messages.CHECKING_CANEVACUATE_STATUS, evacuateChecks));
            }

            //Checking if a reboot is pending on master
            var restartChecks = new List <Check>();

            foreach (var pool in SelectedPools)
            {
                restartChecks.Add(new RestartHostOrToolstackPendingOnMasterCheck(pool, patch == null ? null : patch.uuid));
            }

            groups.Add(new CheckGroup(Messages.CHECKING_FOR_PENDING_RESTART, restartChecks));

            return(groups);
        }
Exemple #8
0
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);

            if (_thisPageHasBeenCompleted)
            {
                actionManualMode = null;
                actionsWorker    = null;
                return;
            }

            if (!IsAutomaticMode)
            {
                if (SelectedUpdateType != UpdateType.NewSuppPack)
                {
                    actionManualMode = new ApplyPatchAction(new List <Pool_patch> {
                        Patch
                    }, SelectedServers);
                }
                else
                {
                    actionManualMode = new InstallSupplementalPackAction(SuppPackVdis, false);
                }
                actionManualMode.Changed   += action_Changed;
                actionManualMode.Completed += action_Completed;
                textBoxLog.Text             = ManualTextInstructions;
                actionManualMode.RunAsync();
                return;
            }

            _nextEnabled = false;
            OnPageUpdated();

            List <PlanAction> planActions = new List <PlanAction>();

            foreach (Pool pool in SelectedPools)
            {
                Pool_patch poolPatch = null;
                if (SelectedUpdateType != UpdateType.NewSuppPack)
                {
                    List <Pool_patch> poolPatches = new List <Pool_patch>(pool.Connection.Cache.Pool_patches);
                    poolPatch = poolPatches.Find(delegate(Pool_patch otherPatch)
                    {
                        if (Patch != null)
                        {
                            return(otherPatch.uuid == Patch.uuid);
                        }
                        return(false);
                    });
                }

                List <Host> poolHosts = new List <Host>(pool.Connection.Cache.Hosts);
                Host        master    = SelectedServers.Find(host => host.IsMaster() && poolHosts.Contains(host));
                if (master != null)
                {
                    planActions.AddRange(CompileActionList(master, poolPatch));
                }
                foreach (Host server in SelectedServers)
                {
                    if (poolHosts.Contains(server))
                    {
                        if (!server.IsMaster())
                        {
                            // check patch isn't already applied here
                            if (poolPatch == null || poolPatch.AppliedOn(server) == DateTime.MaxValue)
                            {
                                planActions.AddRange(CompileActionList(server, poolPatch));
                            }
                        }
                    }
                }
                if (RemoveUpdateFile)
                {
                    planActions.Add(new RemoveUpdateFile(pool, poolPatch));
                }
            }
            planActions.Add(new UnwindProblemsAction(ProblemsResolvedPreCheck));

            actionsWorker         = new BackgroundWorker();
            actionsWorker.DoWork += new DoWorkEventHandler(PatchingWizardAutomaticPatchWork);
            actionsWorker.WorkerReportsProgress      = true;
            actionsWorker.ProgressChanged           += new ProgressChangedEventHandler(actionsWorker_ProgressChanged);
            actionsWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(actionsWorker_RunWorkerCompleted);
            actionsWorker.WorkerSupportsCancellation = true;
            actionsWorker.RunWorkerAsync(planActions);
        }
        protected override Problem RunCheck()
        {
            //
            // Check that the SR where the update was uploaded is still attached
            //
            if (srUploadedUpdates != null &&
                ((srUploadedUpdates.shared && !srUploadedUpdates.CanBeSeenFrom(Host)) ||
                 (!srUploadedUpdates.shared && srUploadedUpdates.IsBroken())))
            {
                return(new BrokenSRWarning(this, Host, srUploadedUpdates));
            }

            //
            // Check patch isn't already applied here
            //
            if ((Patch != null && Patch.AppliedOn(Host) != DateTime.MaxValue) ||
                (Update != null && Update.AppliedOn(Host)))
            {
                return(new PatchAlreadyApplied(this, Host));
            }

            if (!Host.IsLive())
            {
                return(new HostNotLiveWarning(this, Host));
            }

            if (!Host.Connection.IsConnected)
            {
                throw new EndOfStreamException(Helpers.GetName(Host.Connection));
            }

            Session session = Host.Connection.DuplicateSession();



            try
            {
                if (Patch != null)
                {
                    string result = Pool_patch.precheck(session, Patch.opaque_ref, Host.opaque_ref);
                    log.DebugFormat("Pool_patch.precheck returned: '{0}'", result);

                    return(FindProblem(result));
                }

                if (Update != null)
                {
                    var livepatchStatus = Pool_update.precheck(session, Update.opaque_ref, Host.opaque_ref);

                    log.DebugFormat("Pool_update.precheck returned livepatch_status: '{0}'", livepatchStatus);

                    if (livePatchCodesByHost != null)
                    {
                        livePatchCodesByHost[Host.uuid] = livepatchStatus;
                    }

                    return(null);
                }
                //trying to apply update to partially upgraded pool
                if (Helpers.ElyOrGreater(Helpers.GetMaster(Host.Connection)) && !Helpers.ElyOrGreater(Host))
                {
                    return(new WrongServerVersion(this, Host));
                }

                return(null);
            }
            catch (Failure f)
            {
                log.Error(f.ToString());
                if (f.ErrorDescription.Count > 0)
                {
                    log.Error(f.ErrorDescription[0]);
                }
                if (f.ErrorDescription.Count > 1)
                {
                    log.Error(f.ErrorDescription[1]);
                }
                if (f.ErrorDescription.Count > 2)
                {
                    log.Error(f.ErrorDescription[2]);
                }
                if (f.ErrorDescription.Count > 3)
                {
                    log.Error(f.ErrorDescription[3]);
                }
                // try and find problem from the xapi failure
                Problem problem = FindProblem(f);
                return(problem ?? new PrecheckFailed(this, Host, f));
            }
        }
Exemple #10
0
 public static string ModeRetailPatch(List <Host> servers, Pool_patch patch, Dictionary <string, LivePatchCode> LivePatchCodesByHost, out bool someHostMayRequireRestart)
 {
     return(Build(servers.Where(h => patch != null && patch.AppliedOn(h) == DateTime.MaxValue).ToList(), patch != null ? patch.after_apply_guidance : new List <after_apply_guidance>(), LivePatchCodesByHost, out someHostMayRequireRestart));
 }