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

            if (update.AppliedOn(host))
            {
                return;
            }

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

            var poolUpdates = new List <Pool_update>(Connection.Cache.Pool_updates);
            var poolUpdate  = poolUpdates.FirstOrDefault(u => u != null && string.Equals(u.uuid, update.uuid, StringComparison.OrdinalIgnoreCase));

            if (poolUpdate == null)
            {
                throw new Failure(Failure.INTERNAL_ERROR, Messages.POOL_UPDATE_GONE);
            }

            if (!poolUpdate.AppliedOn(host))
            {
                RelatedTask = Pool_update.async_apply(Session, poolUpdate.opaque_ref, host.opaque_ref);
                PollToCompletion();
                Description = string.Format(Messages.PATCH_APPLIED, update.Name(), host.Name());
            }
            else
            {
                Description = string.Format(Messages.PATCH_APPLIED_ALREADY, update.Name(), host.Name());
            }
        }
Example #2
0
        protected override void Run()
        {
            SafeToExit = false;

            if (!update.AppliedOn(host))
            {
                ApplyUpdate();
            }
        }
        protected override Problem RunCheck()
        {
            if (!Host.IsLive())
            {
                return(new HostNotLiveWarning(this, Host));
            }

            if (update == null || !update.EnforceHomogeneity())
            {
                return(null);
            }

            if (pool.Connection.Cache.Hosts.Any(h => !update.AppliedOn(h) && !selectedServers.Contains(h)))
            {
                return(new ServerSelectionProblem(this, pool));
            }

            return(null);
        }
Example #4
0
        protected override Problem RunHostCheck()
        {
            if (update == null || !update.EnforceHomogeneity())
            {
                return(null);
            }

            //If mixed pool, skip the precheck and issue warning, because the update may not be compatible to all servers.
            if (!pool.IsPoolFullyUpgraded())
            {
                return(new MixedPoolServerSelectionWarning(this, pool));
            }

            if (pool.Connection.Cache.Hosts.Any(h => !update.AppliedOn(h) && !selectedServers.Contains(h)))
            {
                return(new ServerSelectionProblem(this, pool));
            }

            return(null);
        }
Example #5
0
        protected override void Run()
        {
            SafeToExit = false;

            if (update.AppliedOn(host))
            {
                return;
            }

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

            var poolUpdates = new List <Pool_update>(Connection.Cache.Pool_updates);
            var poolUpdate  = poolUpdates.FirstOrDefault(u => u != null && string.Equals(u.uuid, update.uuid, StringComparison.OrdinalIgnoreCase));

            if (poolUpdate == null)
            {
                throw new Failure(Failure.INTERNAL_ERROR, Messages.POOL_UPDATE_GONE);
            }

            if (poolUpdate.AppliedOn(host))
            {
                Description = string.Format(Messages.PATCH_APPLIED_ALREADY, update.Name(), host.Name());
                return;
            }

            try
            {
                RelatedTask = Pool_update.async_apply(Session, poolUpdate.opaque_ref, host.opaque_ref);
                PollToCompletion();
                Description = string.Format(Messages.PATCH_APPLIED, update.Name(), host.Name());
            }
            catch (Failure f)
            {
                log.ErrorFormat("Failed to apply update '{0}' on server '{1}': '{2}'",
                                update.Name(), host.Name(), string.Join(", ", f.ErrorDescription)); //CA-339237
                throw;
            }
        }
        protected virtual List <CheckGroup> GenerateChecks(Pool_update update)
        {
            List <Host> applicableServers = update != null?SelectedServers.Where(h => !update.AppliedOn(h)).ToList() : SelectedServers;

            var groups = GenerateCommonChecks(applicableServers);

            //Update Homogeneity check for InvernessOrGreater
            if (update != null)
            {
                var homogeneityChecks = new List <Check>();
                foreach (var pool in SelectedPools.Where(pool => Helpers.InvernessOrGreater(pool.Connection)))
                {
                    homogeneityChecks.Add(new ServerSelectionCheck(pool, update, SelectedServers));
                }

                if (homogeneityChecks.Count > 0)
                {
                    groups.Add(new CheckGroup(Messages.CHECKING_SERVER_SELECTION, homogeneityChecks));
                }
            }

            //Checking other things
            if (update != null)
            {
                var serverChecks = new List <Check>();
                foreach (Host host in SelectedServers)
                {
                    var updates            = new List <Pool_update>(host.Connection.Cache.Pool_updates);
                    var poolUpdateFromHost = updates.Find(p => string.Equals(p.uuid, update.uuid, StringComparison.OrdinalIgnoreCase));

                    SR uploadSr = null;
                    if (SrUploadedUpdates != null && poolUpdateFromHost != null &&
                        SrUploadedUpdates.ContainsKey(poolUpdateFromHost) && SrUploadedUpdates[poolUpdateFromHost].ContainsKey(host))
                    {
                        uploadSr = SrUploadedUpdates[poolUpdateFromHost][host];
                    }

                    serverChecks.Add(new PatchPrecheckCheck(host, poolUpdateFromHost, LivePatchCodesByHost, uploadSr));
                }
                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     = update != null
                    ? update.after_apply_guidance
                    : new List <update_after_apply_guidance> {
                    update_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
            if (WizardMode == WizardMode.SingleUpdate && (update == null || update.after_apply_guidance.Contains(update_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, update == null ? null : update.uuid));
            }
            groups.Add(new CheckGroup(Messages.CHECKING_FOR_PENDING_RESTART, restartChecks));

            return(groups);
        }
        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));
            }
        }
Example #8
0
        public static string ModeRetailPatch(List <Host> servers, Pool_update update, Dictionary <string, livepatch_status> LivePatchCodesByHost, out bool someHostMayRequireRestart)
        {
            var guidances = GetAfterApplyGuidancesFromUpdate(update);

            return(Build(servers.Where(h => update != null && !update.AppliedOn(h)).ToList(), update != null ? guidances : new List <after_apply_guidance>(), LivePatchCodesByHost, out someHostMayRequireRestart));
        }
Example #9
0
        protected virtual List <KeyValuePair <string, List <Check> > > GenerateChecks(Pool_update update)
        {
            List <Host> applicableServers = update != null?SelectedServers.Where(h => !update.AppliedOn(h)).ToList() : SelectedServers;

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

            //Checking other things
            if (update != 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_update> updates            = new List <Pool_update>(host.Connection.Cache.Pool_updates);
                    Pool_update        poolUpdateFromHost = updates.Find(otherPatch => string.Equals(otherPatch.uuid, update.uuid, StringComparison.OrdinalIgnoreCase));
                    checkGroup.Add(new PatchPrecheckCheck(host, poolUpdateFromHost, 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 = update != null
                    ? update.after_apply_guidance
                    : new List <update_after_apply_guidance> {
                    update_after_apply_guidance.restartHost
                };
                foreach (var host in applicableServers)
                {
                    checkGroup.Add(new HostNeedsRebootCheck(host, guidance, LivePatchCodesByHost));
                }
            }

            //Checking can evacuate host
            if (update == null || update.after_apply_guidance.Contains(update_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);
        }
Example #10
0
        protected virtual List <KeyValuePair <string, List <Check> > > GenerateChecks(Pool_update update)
        {
            List <Host> applicableServers = update != null?SelectedServers.Where(h => !update.AppliedOn(h)).ToList() : SelectedServers;

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

            //Update Homogeneity check for InvernessOrGreater
            if (update != null)
            {
                var homogeneityChecks = new List <Check>();
                foreach (var pool in SelectedPools.Where(pool => Helpers.InvernessOrGreater(pool.Connection)))
                {
                    homogeneityChecks.Add(new ServerSelectionCheck(pool, update, SelectedServers));
                }

                if (homogeneityChecks.Count > 0)
                {
                    checks.Add(new KeyValuePair <string, List <Check> >(Messages.CHECKING_SERVER_SELECTION, homogeneityChecks));
                }
            }

            //Checking other things
            if (update != 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_update> updates            = new List <Pool_update>(host.Connection.Cache.Pool_updates);
                    Pool_update        poolUpdateFromHost = updates.Find(otherPatch => string.Equals(otherPatch.uuid, update.uuid, StringComparison.OrdinalIgnoreCase));
                    checkGroup.Add(new PatchPrecheckCheck(host, poolUpdateFromHost, LivePatchCodesByHost));
                }
            }

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

            //Checking can evacuate host
            if (update == null || update.after_apply_guidance.Contains(update_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));
                }
            }

            if (update != null || WizardMode == WizardMode.AutomatedUpdates)
            {
                checks.Add(new KeyValuePair <string, List <Check> >(Messages.CHECKING_FOR_PENDING_RESTART, new List <Check>()));
                checkGroup = checks[checks.Count - 1].Value;

                foreach (var pool in SelectedPools)
                {
                    checkGroup.Add(new RestartHostOrToolstackPendingOnMasterCheck(pool, WizardMode == WizardMode.AutomatedUpdates ? null : update.uuid));
                }
            }

            return(checks);
        }