Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions tests/browser/updates_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

The page lists available updates, checks for and installs them on request
while following the run's log, shows a failed run's errors (an unreachable
archive must not be silent), says whether a restart is needed and why, and
restarts only after the operator confirms.
archive must not be silent), says when a failed install has since been
superseded by successful unattended upgrades and when an install succeeded
although a package source couldn't be refreshed, says whether a restart is
needed and why, and restarts only after the operator confirms.
"""
import json
import os
Expand All @@ -18,6 +20,7 @@
base = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:5173"
REASON = "smoothfs 0.3.2 is installed; running 0.3.1"
RESOLVE_ERR = "Err:5 https://updates.rakuensoftware.com/public common InRelease: Temporary failure resolving 'updates.rakuensoftware.com'"
BCACHEFS_ERR = "Err:4 https://apt.bcachefs.org/trixie bcachefs-tools-release InRelease: Could not connect to apt.bcachefs.org:443 (5.161.236.196). - connect (111: Connection refused)"
LOG = "== smoothnas-update start install 2026-10-29T18:10:00Z\nSetting up smoothfs-dkms (0.3.2-1) ...\n"


Expand All @@ -34,6 +37,23 @@ def status(scenario, state):
"last_run": {"action": "install", "started_at": "t0", "finished_at": "t1", "exit_code": 0, "errors": []}}
return {"running": False, "available": [], "reboot": no_reboot,
"last_run": {"action": "check", "started_at": "t0", "finished_at": "2026-10-29T18:00:00Z", "exit_code": 0, "errors": []}}
# The WTR Max on 2026-11-02: an install started here failed on Nov 1
# because apt.bcachefs.org was down; unattended upgrades have succeeded
# since. That failure is history, not an error.
if scenario == "install_failed_superseded":
return {"running": False, "available": [], "reboot": no_reboot,
"last_run": {"action": "install", "started_at": "2026-11-01T15:36:21Z", "finished_at": "2026-11-01T15:36:28Z",
"exit_code": 100, "errors": [BCACHEFS_ERR], "superseded_at": "2026-11-02T13:38:27Z"}}
# Negative control: the same failure, nothing has succeeded since.
if scenario == "install_failed":
return {"running": False, "available": [], "reboot": no_reboot,
"last_run": {"action": "install", "started_at": "2026-11-01T15:36:21Z", "finished_at": "2026-11-01T15:36:28Z",
"exit_code": 100, "errors": [BCACHEFS_ERR]}}
# A source was down, but the install went ahead and succeeded.
if scenario == "installed_refresh_failed":
return {"running": False, "available": [], "reboot": no_reboot,
"last_run": {"action": "install", "started_at": "t0", "finished_at": "2026-11-02T15:00:00Z",
"exit_code": 0, "refresh_failed": True, "errors": [BCACHEFS_ERR]}}
if scenario == "check_failed":
return {"running": False, "available": [], "reboot": no_reboot,
"last_run": {"action": "check", "started_at": "t0", "finished_at": "t1", "exit_code": 100, "errors": [RESOLVE_ERR]}}
Expand All @@ -50,7 +70,8 @@ def status(scenario, state):
if os.environ.get("CHROMIUM_PATH"):
options["executable_path"] = os.environ["CHROMIUM_PATH"]
browser = playwright.chromium.launch(**options)
for scenario in ("restart_needed", "up_to_date", "check_failed", "available"):
for scenario in ("restart_needed", "up_to_date", "check_failed", "install_failed_superseded",
"install_failed", "installed_refresh_failed", "available"):
context = browser.new_context(ignore_https_errors=os.environ.get("ALLOW_INSECURE_TLS") == "1")
context.add_init_script("localStorage.setItem('sn_session','true'); localStorage.setItem('sn_user','qa');")
reboots = []
Expand Down Expand Up @@ -107,6 +128,19 @@ def respond(route):
page.get_by_role("button", name="Check for updates", exact=True).click()
expect(page.get_by_text("Checking for updates…", exact=True)).to_be_visible()
assert page.get_by_text("Installing updates…", exact=False).count() == 0, "a check was labelled as an install"
elif scenario == "install_failed_superseded":
expect(page.get_by_text("SmoothNAS is up to date.", exact=False)).to_be_visible()
expect(page.get_by_text("automatic updates have installed successfully since (2026-11-02T13:38:27Z)", exact=False)).to_be_visible()
assert page.get_by_text("Installing updates failed", exact=False).count() == 0, "a superseded failure is shown as current"
assert page.locator(".error-msg").count() == 0, "a superseded failure is shown as an error"
elif scenario == "install_failed":
expect(page.get_by_text("Installing updates failed (2026-11-01T15:36:28Z).", exact=True)).to_be_visible()
expect(page.get_by_text(BCACHEFS_ERR, exact=True)).to_be_visible()
assert page.get_by_text("automatic updates have installed", exact=False).count() == 0
elif scenario == "installed_refresh_failed":
expect(page.get_by_text("Updates were installed (2026-11-02T15:00:00Z), but these package sources could not be refreshed:", exact=True)).to_be_visible()
expect(page.get_by_text(BCACHEFS_ERR, exact=True)).to_be_visible()
assert page.get_by_text("Installing updates failed", exact=False).count() == 0, "a successful install is shown as failed"
elif scenario == "check_failed":
expect(page.get_by_text("Checking for updates failed", exact=False)).to_be_visible()
expect(page.get_by_text(RESOLVE_ERR, exact=True)).to_be_visible()
Expand Down
2 changes: 2 additions & 0 deletions tierd-ui/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,8 @@ const en: LanguageTranslations = {
'updates.label.installing': 'Installing updates… This continues even if you leave this page.',
'updates.label.checkFailed': 'Checking for updates failed ({time}).',
'updates.label.installFailed': 'Installing updates failed ({time}).',
'updates.label.installFailedSuperseded': 'An update started here failed ({failed}); automatic updates have installed successfully since ({time}).',
'updates.label.installedRefreshFailed': 'Updates were installed ({time}), but these package sources could not be refreshed:',
'updates.label.upToDate': 'SmoothNAS is up to date.',
'updates.label.lastChecked': '(last checked {time})',
'updates.label.available': '{count} update(s) available',
Expand Down
2 changes: 2 additions & 0 deletions tierd-ui/src/i18n/locales/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,8 @@ const nl: LanguageTranslations = {
'updates.label.installing': 'Updates worden geïnstalleerd… Dit gaat door, ook als je deze pagina verlaat.',
'updates.label.checkFailed': 'Zoeken naar updates mislukt ({time}).',
'updates.label.installFailed': 'Installeren van updates mislukt ({time}).',
'updates.label.installFailedSuperseded': 'Een hier gestarte update is mislukt ({failed}); automatische updates zijn sindsdien wel geslaagd ({time}).',
'updates.label.installedRefreshFailed': 'Updates zijn geïnstalleerd ({time}), maar deze pakketbronnen konden niet worden vernieuwd:',
'updates.label.upToDate': 'SmoothNAS is up-to-date.',
'updates.label.lastChecked': '(laatst gecontroleerd {time})',
'updates.label.available': '{count} update(s) beschikbaar',
Expand Down
23 changes: 21 additions & 2 deletions tierd-ui/src/pages/Updates/Updates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ interface UpdateStatus {
finished_at?: string;
exit_code?: number;
errors: string[];
// An install whose package-list refresh failed for some source; the
// install still ran and exit_code is its result.
refresh_failed?: boolean;
// A failed install that unattended upgrades have since succeeded past.
superseded_at?: string;
} | null;
reboot: RebootStatus;
}
Expand Down Expand Up @@ -119,7 +124,9 @@ export default function Updates() {

const last = status?.last_run;
const runningAction = (last?.finished_at ? null : last?.action) || startedAction;
const lastFailed = !!last && !status?.running && last.exit_code !== undefined && last.exit_code !== 0;
const lastFailed = !!last && !status?.running && last.exit_code !== undefined && last.exit_code !== 0 && !last.superseded_at;
const refreshFailed = !!last && !status?.running && last.exit_code === 0 && !!last.refresh_failed;
const superseded = !!last && !status?.running && !!last.superseded_at;
const available = status?.available ?? [];

return (
Expand Down Expand Up @@ -150,12 +157,24 @@ export default function Updates() {
</ul>
)}
</div>
) : refreshFailed ? (
<div style={{ background: '#fef3c7', borderRadius: 8, padding: 16, marginBottom: 12 }}>
<strong>{t('updates.label.installedRefreshFailed', { time: last!.finished_at || last!.started_at })}</strong>
<ul style={{ margin: '8px 0 0' }}>
{last!.errors.map((e, i) => <li key={i} style={{ fontFamily: 'monospace', fontSize: 12 }}>{e}</li>)}
</ul>
</div>
) : available.length === 0 ? (
<p style={{ color: '#16a34a', marginBottom: 12 }}>
{t('updates.label.upToDate')}
{last?.finished_at && <span style={{ color: '#666' }}> {t('updates.label.lastChecked', { time: last.finished_at })}</span>}
{last?.finished_at && !superseded && <span style={{ color: '#666' }}> {t('updates.label.lastChecked', { time: last.finished_at })}</span>}
</p>
) : null}
{superseded && (
<p style={{ fontSize: 13, color: '#666', marginBottom: 12 }}>
{t('updates.label.installFailedSuperseded', { failed: last!.finished_at || last!.started_at, time: last!.superseded_at! })}
</p>
)}

{available.length > 0 && !status.running && (
<div style={{ marginBottom: 12 }}>
Expand Down
51 changes: 48 additions & 3 deletions tierd/internal/updater/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
)

// Operator-started update runs. unattended-upgrades keeps the NAS current on
Expand All @@ -25,6 +26,10 @@ const runUnit = "smoothnas-update"
var (
runLogPath = "/var/log/smoothnas/update.log"

// apt.systemd.daily touches this only when unattended-upgrade exits 0, so
// its time is when updates last installed without an error.
upgradeStampPath = "/var/lib/apt/periodic/upgrade-stamp"

// systemctl and systemd-run are vars so tests can fake them.
unitActive = func() bool {
return exec.Command("systemctl", "is-active", "--quiet", runUnit).Run() == nil
Expand Down Expand Up @@ -61,6 +66,14 @@ const aptRepair = "{ dpkg --configure -a || true; } && " +
"apt-get -o DPkg::Lock::Timeout=600 -o Dpkg::Options::=--force-confdef " +
"-o Dpkg::Options::=--force-confold -y --fix-broken install"

// installCmd refreshes the package lists, then installs whatever they offer.
// A source that can't be refreshed (a third-party archive that is down) must
// not stop SmoothNAS's own updates from installing: the refresh result is
// recorded on its own line and reported, and the install still runs, from
// the lists as of the last successful refresh for that source.
const installCmd = aptUpdate + "; refresh=$?; echo \"" + refreshMarker + " $refresh\"; " +
aptRepair + " && " + aptUpgrade

// Run actions.
const (
ActionCheck = "check"
Expand All @@ -80,7 +93,7 @@ func Start(action string) error {
case ActionCheck:
script = runScript(ActionCheck, aptUpdate, runLogPath)
case ActionInstall:
script = runScript(ActionInstall, aptUpdate+" && "+aptRepair+" && "+aptUpgrade, runLogPath)
script = runScript(ActionInstall, installCmd, runLogPath)
default:
return fmt.Errorf("unknown update action %q", action)
}
Expand All @@ -102,8 +115,9 @@ func runScript(action, cmd, logPath string) string {
}

const (
startMarker = "== smoothnas-update start"
endMarker = "== smoothnas-update exit"
startMarker = "== smoothnas-update start"
endMarker = "== smoothnas-update exit"
refreshMarker = "== smoothnas-update refresh-exit"
)

// Package is an update available for an installed package.
Expand All @@ -120,6 +134,13 @@ type LastRun struct {
FinishedAt string `json:"finished_at,omitempty"`
ExitCode *int `json:"exit_code,omitempty"`
Errors []string `json:"errors"`
// RefreshFailed: an install whose package-list refresh failed for some
// source; the install itself still ran, and ExitCode is its result.
RefreshFailed bool `json:"refresh_failed,omitempty"`
// SupersededAt: this failed install is older than a later unattended
// run that installed updates without an error, at this time. The
// failure is history, not the NAS's current state.
SupersededAt string `json:"superseded_at,omitempty"`
}

// UpdateStatus is what the Updates page shows.
Expand All @@ -141,9 +162,29 @@ func GetUpdateStatus() UpdateStatus {
st.LastRun = parseRunLog(f)
f.Close()
}
markSuperseded(st.LastRun)
return st
}

// markSuperseded sets SupersededAt on a failed install that unattended
// upgrades have since succeeded past. A failed check is left alone: the
// unattended refresh runs in apt's default mode, which exits 0 even when an
// archive is unreachable, so it can't show that a check would now pass.
func markSuperseded(run *LastRun) {
if run == nil || run.Action != ActionInstall || run.ExitCode == nil || *run.ExitCode == 0 {
return
}
failed, err := time.Parse(time.RFC3339, run.FinishedAt)
if err != nil {
return
}
info, err := os.Stat(upgradeStampPath)
if err != nil || !info.ModTime().After(failed) {
return
}
run.SupersededAt = info.ModTime().UTC().Format(time.RFC3339)
}

// ReadLog returns the run log from byte offset on, and the offset to read
// from next. A run truncates the log, so an offset past the end restarts at 0.
func ReadLog(offset int64) (string, int64, error) {
Expand Down Expand Up @@ -211,6 +252,10 @@ func parseRunLog(r io.Reader) *LastRun {
if len(f) > 1 {
run.StartedAt = f[1]
}
case run != nil && strings.HasPrefix(line, refreshMarker+" "):
if code, err := strconv.Atoi(strings.TrimSpace(strings.TrimPrefix(line, refreshMarker+" "))); err == nil {
run.RefreshFailed = code != 0
}
case run != nil && strings.HasPrefix(line, endMarker+" "):
f := strings.Fields(strings.TrimPrefix(line, endMarker+" "))
if len(f) > 0 {
Expand Down
Loading
Loading