public void TestAlertWithConnectionAndHosts() { XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), ""); XenServerPatchAlert alert = new XenServerPatchAlert(p); alert.IncludeConnection(connA.Object); alert.IncludeConnection(connB.Object); alert.IncludeHosts(new List <Host> { hostA.Object, hostB.Object }); IUnitTestVerifier validator = new VerifyGetters(alert); validator.Verify(new AlertClassUnitTestData { AppliesTo = "HostAName, HostBName, ConnAName, ConnBName", FixLinkText = "Go to Web Page", HelpID = "XenServerPatchAlert", Description = "My description", HelpLinkText = "Help", Title = "New Update Available - name", Priority = "Priority2" }); Assert.IsFalse(alert.CanIgnore); VerifyConnExpectations(Times.Once); VerifyHostsExpectations(Times.Once); }
public void TestAlertWithConnectionAndNoHosts() { XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", string.Empty, "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), "0", "", ""); XenServerPatchAlert alert = new XenServerPatchAlert(p); alert.IncludeConnection(connA.Object); alert.IncludeConnection(connB.Object); ClassVerifiers.VerifyGetters(alert, new AlertClassUnitTestData { AppliesTo = "ConnAName, ConnBName", FixLinkText = "Go to Web Page", HelpID = "XenServerPatchAlert", Description = "My description", HelpLinkText = "Help", Title = "New Update Available - name", Priority = "Unknown" }); Assert.IsFalse(alert.CanIgnore); VerifyConnExpectations(Times.Once); VerifyHostsExpectations(Times.Never); }
public static List <XenServerPatchAlert> NewXenServerPatchAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches) { if (Helpers.CommonCriteriaCertificationRelease) { return(null); } var alerts = new List <XenServerPatchAlert>(); var xenServerVersionsAsUpdates = xenServerVersions.Where(v => v.IsVersionAvailableAsAnUpdate); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } var serverVersions = new List <XenServerVersion>(); foreach (Host host in hosts) { var serverVersion = GetServerVersions(host, xenServerVersions); serverVersions.AddRange(serverVersion); } serverVersions = serverVersions.Distinct().ToList(); if (serverVersions.Count == 0) { continue; } foreach (XenServerVersion xenServerVersion in serverVersions) { XenServerVersion version = xenServerVersion; List <XenServerPatch> patches = xenServerPatches.FindAll(patch => version.Patches.Contains(patch)); if (patches.Count == 0) { continue; } foreach (XenServerPatch xenServerPatch in patches) { XenServerVersion newServerVersion = xenServerVersionsAsUpdates.FirstOrDefault(newVersion => newVersion.PatchUuid.Equals(xenServerPatch.Uuid, StringComparison.OrdinalIgnoreCase)); var alert = new XenServerPatchAlert(xenServerPatch, newServerVersion); var existingAlert = alerts.Find(al => al.Equals(alert)); if (existingAlert != null) { alert = existingAlert; } else { alerts.Add(alert); } if (!xenConnection.IsConnected) { continue; } XenServerPatch serverPatch = xenServerPatch; var noPatchHosts = hosts.Where(host => PatchCanBeInstalledOnHost(serverPatch, host, version)); if (noPatchHosts.Count() == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }
public static List <XenServerPatchAlert> NewXenServerPatchAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches) { if (Helpers.CommonCriteriaCertificationRelease) { return(null); } var alerts = new List <XenServerPatchAlert>(); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } var serverVersions = xenServerVersions.FindAll(version => { if (version.BuildNumber != string.Empty) { return(master.BuildNumberRaw == version.BuildNumber); } return(Helpers.HostProductVersionWithOEM(master) == version.VersionAndOEM || (version.Oem != null && Helpers.OEMName(master).StartsWith(version.Oem) && Helpers.HostProductVersion(master) == version.Version.ToString())); }); if (serverVersions.Count == 0) { continue; } foreach (XenServerVersion xenServerVersion in serverVersions) { XenServerVersion version = xenServerVersion; List <XenServerPatch> patches = xenServerPatches.FindAll(patch => version.Patches.Contains(patch)); if (patches.Count == 0) { continue; } foreach (XenServerPatch xenServerPatch in patches) { var alert = new XenServerPatchAlert(xenServerPatch); var existingAlert = alerts.Find(al => al.Equals(alert)); if (existingAlert != null) { alert = existingAlert; } else { alerts.Add(alert); } if (!xenConnection.IsConnected) { continue; } XenServerPatch serverPatch = xenServerPatch; // A patch can be installed on a host if: // 1. it is not already installed and // 2. the host has all the required patches installed and // 3. the host doesn't have any of the conflicting patches installed var noPatchHosts = hosts.Where(host => { var appliedPatches = host.AppliedPatches(); // 1. patch is not already installed if (appliedPatches.Any(patch => patch.uuid == serverPatch.Uuid)) { return(false); } // 2. the host has all the required patches installed if (serverPatch.RequiredPatches != null && serverPatch.RequiredPatches.Count > 0 && !serverPatch.RequiredPatches.All(requiredPatchUuid => appliedPatches.Any(patch => patch.uuid == requiredPatchUuid))) { return(false); } // 3. the host doesn't have any of the conflicting patches installed if (serverPatch.ConflictingPatches != null && serverPatch.ConflictingPatches.Count > 0 && serverPatch.ConflictingPatches.Any(conflictingPatchUuid => appliedPatches.Any(patch => patch.uuid == conflictingPatchUuid))) { return(false); } return(true); }); if (noPatchHosts.Count() == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }
private static List <XenServerPatchAlert> GetServerPatchesAlerts(List <XenServerVersion> xenServerVersions, List <XenServerPatch> xenServerPatches, bool checkAlertIsAlreadyDismissed) { List <XenServerPatchAlert> alerts = new List <XenServerPatchAlert>(); foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy) { Host master = Helpers.GetMaster(xenConnection); Pool pool = Helpers.GetPoolOfOne(xenConnection); List <Host> hosts = xenConnection.Cache.Hosts.ToList(); if (master == null || pool == null) { continue; } List <XenServerVersion> serverVersions = xenServerVersions.FindAll(version => { if (version.BuildNumber != string.Empty) { return(master.BuildNumberRaw == version.BuildNumber); } return(Helpers.HostProductVersionWithOEM(master) == version.VersionAndOEM || (version.Oem != null && Helpers.OEMName(master).StartsWith(version.Oem) && Helpers.HostProductVersion(master) == version.Version.ToString())); }); if (serverVersions.Count == 0) { continue; } foreach (XenServerVersion xenServerVersion in serverVersions) { XenServerVersion version = xenServerVersion; List <XenServerPatch> patches = xenServerPatches.FindAll(patch => version.Patches.Contains(patch)); if (patches.Count == 0) { continue; } foreach (XenServerPatch xenServerPatch in patches) { XenServerPatchAlert alert = GetServerPatchAlert(alerts, xenServerPatch); if (checkAlertIsAlreadyDismissed && pool.other_config.ContainsKey(IgnorePatchAction.IgnorePatchKey)) { List <string> ignorelist = new List <string>(pool.other_config[IgnorePatchAction.IgnorePatchKey].Split(',')); if (ignorelist.Contains(xenServerPatch.Uuid)) { // we dont want to show the alert continue; } } XenServerPatch serverPatch = xenServerPatch; List <Host> noPatchHosts = hosts.Where(host => !host.AppliedPatches().Any(patch => patch.uuid == serverPatch.Uuid)).ToList(); if (noPatchHosts.Count == hosts.Count) { alert.IncludeConnection(xenConnection); } else { alert.IncludeHosts(noPatchHosts); } } } } return(alerts); }