feat: show Ubuntu phased updates apart and leave them out of pending counts
apt lists phased updates as upgradable while an upgrade defers them until Ubuntu selects the host, so a freshly patched server kept reporting pending updates. The agent now flags them; the server stores the flag and leaves them out of patch run counts, and the server page shows them in their own section.
This commit is contained in:
@@ -83,7 +83,7 @@ func serverBootTime(ctx context.Context, instanceID, serverID string) *time.Time
|
||||
}
|
||||
|
||||
func newServerRun(s models.Server, now time.Time) models.PatchServerRun {
|
||||
r := models.PatchServerRun{ServerID: s.ServerID, Hostname: s.Hostname, Status: models.PatchSrvQueued, PendingBefore: len(s.AvailableUpdates)}
|
||||
r := models.PatchServerRun{ServerID: s.ServerID, Hostname: s.Hostname, Status: models.PatchSrvQueued, PendingBefore: InstallableUpdateCount(s.AvailableUpdates)}
|
||||
if !patchrun.AgentSupportsPatchResults(s.AgentVersion) {
|
||||
v := s.AgentVersion
|
||||
if v == "" {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package services
|
||||
|
||||
import "gitea.hostxtra.co.uk/mrhid6/vantage/server/internal/models"
|
||||
|
||||
// InstallableUpdateCount is the number of pending updates an upgrade would
|
||||
// install now. Ubuntu phased updates are listed by apt but deferred until the
|
||||
// host's phase comes up, so they are not counted: counting them made a patch
|
||||
// run look as if it installed less than it did.
|
||||
func InstallableUpdateCount(ups []models.PackageUpdate) int {
|
||||
n := 0
|
||||
for _, u := range ups {
|
||||
if !u.Phased {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.hostxtra.co.uk/mrhid6/vantage/server/internal/models"
|
||||
)
|
||||
|
||||
// Phased updates are listed but not installable yet, so they never count as
|
||||
// pending: they must not lower "updates installed" on a patch run.
|
||||
func TestInstallableUpdateCount(t *testing.T) {
|
||||
ups := []models.PackageUpdate{
|
||||
{Name: "curl"},
|
||||
{Name: "netplan.io", Phased: true},
|
||||
{Name: "openssl"},
|
||||
}
|
||||
if got := InstallableUpdateCount(ups); got != 2 {
|
||||
t.Fatalf("got %d, want 2", got)
|
||||
}
|
||||
if got := InstallableUpdateCount(nil); got != 0 {
|
||||
t.Fatalf("got %d for nil, want 0", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user