From patchwork Thu Dec 3 21:20:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Kanavin X-Patchwork-Id: 107227 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.3769.1796332863993996433 for ; Thu, 03 Dec 2026 13:21:04 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=aarrLRwl; spf=pass (domain: gmail.com, ip: 209.85.128.53, mailfrom: alex.kanavin@gmail.com) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4a2153c8525so1478845e9.3 for ; Thu, 03 Dec 2026 13:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796332862; x=1796937662; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=va2p8Q71onOV8TNHMFI51XaNViEYDRwiwvnfSyBGAcU=; b=aarrLRwlLO/9AbXxxTjFTL9PlLQ8slJwhhZRguhSyRm6ef6xGNshFhBgFyPxAdZmxL RzjC00KtaoxbY5ODpdHAss0VEWytlSxUAbPlzuxtwb2vIyKct7y3ZvdNnx1x2o6Xb6g9 GhyZToXPEsWZ75qQfNXL7v149wCb2yc1qm7DpO94MNkSMdwZ/fwUe3jAni/bVI5FtE9D xujHNvrZFyBJXxOgkH0zP4L2BrNE8H5cqu8oIc2oDD4sCQx0HWWXRkI3XAEOX3BLUDIE yDfI809MyG7EQVs1+XtGJa50tmOhMhuVc/jaissFo4M7DOCzBe+wVFVaNn3dCGoY+PpE KGEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796332862; x=1796937662; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=va2p8Q71onOV8TNHMFI51XaNViEYDRwiwvnfSyBGAcU=; b=KrJWBhSmfE/e0DPyM876dQxs9SRHtKAcy7bkunbvH0CBT0PD8MCVqIe3Z251PTEcjC j41iiaGl7HXjIPgZcKJHCsKer4Ir1Qb0S8SeuJiRaTi9F9VhcCXcCynoFf+DXsHa2Efz gJ8e8hx0Wz8hDz61Rw8aEnWn8m1jWi4xM7jsRGkErX1PRQPOhrD/KcbbfVLKfhqrcNqb clLuKjHRyQqp89ouTkkYZ75JV8v108PrpPEr8mnHeJbHBbSU/QT4TlfiyAe2HG5SuRIH STsUeHyAXw8z9UpagjcxlyOksyMcSW4B3sbDhaus5Eb/9nOofz24A65BKh+2C3Se6SBn anEQ== X-Gm-Message-State: APuU4Z/vLzql1BnsQMZsn16iu3Grba/bdNDxaDUylGQKkx5RyqqWuoV7 rSZGFpJb4dFFv5SggapgY0vst6wUm22Gp4/pX5IZ1rMYgEiujCnx/Z7QZ802iQ== X-Gm-Gg: AZFdTZef2NL/2ZpIARPILlm9t9FEYWApvEe91b8KmH2NijH5OjKbJZKq610GvY1R1Xq tx1xv1Uvv/E76Xwkd/xNNhsb+dHPZ0d+kZLr2IVhs62EQYEwH8hl95jEmJt1zo+WVM4+eea2OeB R1vUbTnkOdFSnOkSgo7oYZA9WoY1ZXu7RkODpcDc97ADcykvBWmiL+9LKKuV+CuTadiKXktDrH3 5rezsqUCQX7vgKv9/sWC14zl5tb8mY7v46KkkEe7baAc76cj30duHpd4Pl6+zck3AQDEeBtWGg4 WT64jJGmqp0wJpp5zY6KwTLQwk+UBHWK9m/YyL68em08BraQX321DClUXhv0NkTXrfVFCsjwSxU /y4avEv80kQnQX3KmTuVAsZzqGdI5O+NQqB/QubaJ7yldq2N8HLN9u0nym0UTWtACf8sX249oAM nThs2V2cHm6r0ZgEST8jek4pwCj35f1BRteyyqJWIK/1mewSN8BVcssoyg7EDBixG/fs2Mhew9m c6V2ujJH1RoeAVmbMEFfhDGlDP+jnbhLLoJJZpz/vctA9y2c/OjhBYjaIc097uLKDgYfjl26jMw Mutwi9ItYUqBhCW+4vnLtW0tjy3GeVhRid0CUgmq2KhpcGHeqqcMSHqzAnB1JZf+ X-Received: by 2002:a05:600c:848d:b0:4ac:86c9:b09c with SMTP id 5b1f17b1804b1-4bb88811da9mr906392815e9.13.1796332862298; Thu, 03 Dec 2026 13:21:02 -0800 (PST) Return-Path: Received: from Zen2.lab.linutronix.de. (drugstore.linutronix.de. [80.153.143.164]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1724ad3a5sm1860126f8f.9.2026.12.03.13.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 13:21:01 -0800 (PST) From: Alexander Kanavin X-Google-Original-From: Alexander Kanavin To: yocto-patches@lists.yoctoproject.org Cc: daniel.turull@ericsson.com, Alexander Kanavin Subject: [auh][PATCH v2 1/3] modules/state: rework state to include both original and updated version Date: Thu, 3 Dec 2026 22:20:48 +0100 Message-ID: <20261203212050.799982-1-alex@linutronix.de> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Thu, 03 Dec 2026 21:21:06 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/5664 The state information in incremental mode did not keep the original versions that recipes were updated from, only the new versions. This is problematic when upstreams release new versions in quick succession: if a layer updates a recipe to an intermediate version after AUH produced an update from the original version to latest version, AUH will not re-roll the update from an intermediate to latest because it doesn't track the original versions, and the update will only be retried after a retry period (typically 30 days) expires. Additionally, it would be useful to know when the original version, or the latest version was first seen by AUH; if either period grows too much, that means the AUH upgrade attempts are being ignored, the recipe isn't being updated, and the situation needs to be looked at. The patch reworks the state format from being a dict of recipes containing a dict of (latest) versions to a flat dict of recipes that contains the original version, the new version, when either was first seen, and when an AUH did the update. The rest of the code is adapted to that; it's difficult to test all the corner cases, but I confirmed that at least the update and the skipping after work as they should. Note that AUH will not try to migrate the v1 state to v2 state. It will simply detect that the state is not usable, and re-run the full update cycle to repopulate state. AI-Generated: Claude Sonnet 5.5 Signed-off-by: Alexander Kanavin --- modules/state.py | 77 +++++++++++++++++++++-------------------------- upgrade-helper.py | 8 ++--- 2 files changed, 39 insertions(+), 46 deletions(-) diff --git a/modules/state.py b/modules/state.py index d70972b..9a10d32 100644 --- a/modules/state.py +++ b/modules/state.py @@ -32,7 +32,7 @@ RESULT_SUCCESS = "success" RESULT_FAILURE = "failure" STATE_FILENAME = "auh-state.json" -STATE_VERSION = 1 +STATE_VERSION = 2 SECONDS_PER_DAY = 86400 DEFAULT_RETRY_SAME_VERSION_DAYS = 30 @@ -41,7 +41,9 @@ DEFAULT_SUCCESS_MAX_AGE_DAYS = 30 class State: - """Tracks upgrade attempts as {recipe: {version: {timestamp, result}}}.""" + """Tracks upgrade attempts as a flat dict, one entry per recipe: + {recipe: {oldversion, oldversion_firstseen, newversion, newversion_firstseen, + timestamp, result}}.""" def __init__(self, state_dir, retry_same_version_days=DEFAULT_RETRY_SAME_VERSION_DAYS, @@ -53,10 +55,9 @@ class State: self.success_max_age = success_max_age_days * SECONDS_PER_DAY self.retry_any_version = retry_any_version_days * SECONDS_PER_DAY self.any_version_recipes = set(retry_any_version_recipes or []) - self.data = self._load() - self._prune() + self.data = self._load_state_file() - def _load(self): + def _load_state_file(self): if os.path.exists(self.path): try: with open(self.path) as f: @@ -76,38 +77,46 @@ class State: json.dump({"version": STATE_VERSION, "recipes": self.data}, f, indent=2) - def record(self, pn, version, result): - entry = {"timestamp": time.time(), "result": result} - if pn not in self.data: - self.data[pn] = {} - self.data[pn][version] = entry - - def should_skip(self, pn, version): - """Return True if this recipe/version should not be attempted.""" - return self.check(pn, version)['skip'] - - def skip_reason(self, pn, version): - """Return a human-readable string explaining why pn/version is being skipped.""" - return self.check(pn, version)['reason'] - - def check(self, pn, version): + def record(self, pn, old_version, new_version, result): + current_time = time.time() + oldversion_firstseen = current_time + newversion_firstseen = current_time + + if pn in self.data: + if self.data[pn]['oldversion'] == old_version: + oldversion_firstseen = self.data[pn]['oldversion_firstseen'] + if self.data[pn]['newversion'] == new_version: + newversion_firstseen = self.data[pn]['newversion_firstseen'] + + self.data[pn] = {"timestamp": current_time, + "result": result, + "oldversion": old_version, + "oldversion_firstseen": oldversion_firstseen, + "newversion": new_version, + "newversion_firstseen": newversion_firstseen, + } + + def check(self, pn, old_version, new_version): """Return {'skip': bool, 'reason': str} for a recipe/version pair. For any_version_recipes, any recent attempt (any version) causes a skip. - For normal recipes, only a matching version entry causes a skip. + For normal recipes, only an entry for the same old and new version + causes a skip. """ + + entry = self.data.get(pn, {}) + + if not entry: + return {'skip': False, 'reason': ''} + if pn in self.any_version_recipes: - entry = self._newest_entry(pn) max_age = self.retry_any_version else: - entry = self.data.get(pn, {}).get(version) - if entry is None: - return {'skip': False, 'reason': ''} max_age = self.success_max_age \ if entry.get("result") == RESULT_SUCCESS \ else self.retry_same_version - if not entry: + if pn not in self.any_version_recipes and (entry['oldversion'] != old_version or entry['newversion'] != new_version): return {'skip': False, 'reason': ''} ts = entry.get("timestamp", 0) @@ -122,19 +131,3 @@ class State: return {'skip': True, 'reason': "%slast attempt %s result=%s; will retry in %d day(s)" % (prefix, when, result, retry_in)} - - def _newest_entry(self, pn): - """Return the most recent entry for a recipe across all versions.""" - versions = self.data.get(pn, {}) - return max(versions.values(), key=lambda e: e.get("timestamp", 0), - default={}) - - def _prune(self): - """Remove entries that check() would no longer skip.""" - for pn in list(self.data): - versions = self.data[pn] - for ver in list(versions): - if not self.check(pn, ver)['skip']: - del versions[ver] - if not versions: - del self.data[pn] diff --git a/upgrade-helper.py b/upgrade-helper.py index 56b1f02..8e47e40 100755 --- a/upgrade-helper.py +++ b/upgrade-helper.py @@ -498,10 +498,10 @@ class Updater(object): if self.state: kept = [] for g in pkggroups_ctx: - pn, npv = g['pkgs'][0]['PN'], g['pkgs'][0]['NPV'] - r = self.state.check(pn, npv) + pn, opv, npv = g['pkgs'][0]['PN'], g['pkgs'][0]['PV'], g['pkgs'][0]['NPV'] + r = self.state.check(pn, opv, npv) if r['skip']: - I(" %s %s: skipping (%s)" % (pn, npv, r['reason'])) + I(" %s %s -> %s: skipping (%s)" % (pn, opv, npv, r['reason'])) self.statistics.skip(g, r['reason']) else: kept.append(g) @@ -579,7 +579,7 @@ class Updater(object): # upgrades them atomically; individual outcomes are not tracked. for pkg_ctx in g['pkgs']: I(" %s %s: recording result=%s" % (pkg_ctx['PN'], pkg_ctx['NPV'], result)) - self.state.record(pkg_ctx['PN'], pkg_ctx['NPV'], result) + self.state.record(pkg_ctx['PN'], pkg_ctx['PV'], pkg_ctx['NPV'], result) if self.state: self.state.save() From patchwork Thu Dec 3 21:20:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Kanavin X-Patchwork-Id: 107228 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.3771.1796332864791262957 for ; Thu, 03 Dec 2026 13:21:05 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=FBheX8kC; spf=pass (domain: gmail.com, ip: 209.85.128.47, mailfrom: alex.kanavin@gmail.com) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4b467581b98so1658545e9.0 for ; Thu, 03 Dec 2026 13:21:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796332863; x=1796937663; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fkmvZxdmu1SULs31+gzELlCgt8krGDRh3utcVwKRJPE=; b=FBheX8kCpJBMVLmI6SIkEQsW5TuyjoXTYCfltxQuR4s+M7FslYrkS504sKYhPrwXBl eea5ZQt6XFcDlekYDnfRhyQQJx5oC5FLNdopi2VzwSEZXr0xbcWIyyiv+c7WPcxM3rm+ kY0yKTlzeIvo5gDMFYnJvZiYEZygdIDG/ys2PQmuTWWzegGkJZ98Dkfd5OIfjlSnkf/l TqU/sDw0ZtoKx+nzoRZ2E/yjzVxbDwkTBM12vbswhjpy2fOTC3w0jQ8ijLp5LI71hSzs gxFz9a4b+Yms1sXdtarGsT/U1sCmT4AwLmKWy0PyDWU1Zo96OL3O0CqaeoKL/UOahP2T H9BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796332863; x=1796937663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fkmvZxdmu1SULs31+gzELlCgt8krGDRh3utcVwKRJPE=; b=ok5/uennoRI+nLikCliyglyafQiZPGYY7+yJ8F7+ZOMrZJBsqfd2YIW0saqHb/dcVk b5drbltIreQI4yuJNYuBrVfzTOZWDdlNisxCBeXGjEyr9+wNM0qt6TxdS/CE0ra0TpzF JHlVbT7kl/Ee74XT43KkLxtgQuxMR2ay8cYYDtbiKHyuPgV/X20wrQ/loBfyTti3I6es IOHJOrSJj0sDNSAoEfyRUvnJiIQh1YWUPXZzX2yRJtDr3lRW6uUmmdO3gykmI9FQtD8Z XzSjU2HkaXH5n//zUoX0/aEzLUmZGNFf8ki5H6NxCzTuqMpcEZQg1midlFyiWY4C2UvR 3d9g== X-Gm-Message-State: APuU4Z82HJfSsMZQ3PJXZ1APZHdx6r/1VYpd3I0g1Xwp7nY80HTY518i xd7BU0iI2cMGJLCBoSMVKBJ3u2tJ0x4ND4IyjXvR3Fy5+KnKSff+sSI+tqVHSA== X-Gm-Gg: AZFdTZcH4X24wS0jyFL2jTCiuI6LWGuCOnA0MXosOi3e6BP7w6CSgrKPFvxzWh/ZT7w qlHvpuPv93+1iFHgJcvLA5XP3Q85qMGtLEMrQUsHez15qLugpA7H8RBclMpsP7EsMpwwM289ZXP 1Y6ki+DekIMjGsJaXDuMepCNOtK0kkQLCk5Ufq3pF/wx/bqUJUJBdNODc9iFzYFM9ToHmatiHAZ delRxZTwLhtn1aUKisdZNs/pkp1ieWu7bxMndIijAEXfcH7WBTFpQa6gYiYd0fJjHJYdX/oWBhl cWOPjkHxKSupiqAgzDQVHHDTw+tBLWLH7rKNQX37yIlAaGDYIKhAkwfxaJ16rOuIjbJ0ApdmhWO x9NvbV+gV/l4vRLh0fiArexEUo2DtHqRHrINXPHLd/sYUsd8qmODt12VCdl+GZSE0AEiMBKNIzx r95ZUjqIvwSmhP0ExffUYPVdvb8O0r8pwl6luT96X6MIf5WU5W0E+HlpR99f5qZIRaOgeZpPE98 T/QzmDPvXUd7k759frbpEjVQA5YMVGm6E6jTdTWLkrP6scOfJP70ZqDk1Qe544ku0JcfH2fh5V5 9UxPm28PgCby4Sr891cLdYW+U8nI3pKBsnlvSDGZmAkL2p7LM9WMXQY0oE3pZMA+ X-Received: by 2002:a05:600c:8b11:b0:4a2:a9:ed5a with SMTP id 5b1f17b1804b1-4bb88826835mr885487945e9.8.1796332863076; Thu, 03 Dec 2026 13:21:03 -0800 (PST) Return-Path: Received: from Zen2.lab.linutronix.de. (drugstore.linutronix.de. [80.153.143.164]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1724ad3a5sm1860126f8f.9.2026.12.03.13.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 13:21:02 -0800 (PST) From: Alexander Kanavin X-Google-Original-From: Alexander Kanavin To: yocto-patches@lists.yoctoproject.org Cc: daniel.turull@ericsson.com, Alexander Kanavin Subject: [auh][PATCH v2 2/3] modules/statistics.py: rework and include first-seen statistics in status reports Date: Thu, 3 Dec 2026 22:20:49 +0100 Message-ID: <20261203212050.799982-2-alex@linutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203212050.799982-1-alex@linutronix.de> References: <20261203212050.799982-1-alex@linutronix.de> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Thu, 03 Dec 2026 21:21:06 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/5665 This module's code quality wasn't great (non-pythonic code, excessive amount of unneeded class data, producing a not particularly useful per-maintainer report), so I took the opportunity to clean it all up. Per-maintainer section of the report is dropped altogether. The status report now includes information about how long ago the current and new versions were first seen. This helps identify recipes which are falling behind upstream development: if either the current or new version was first seen many days ago, then updating that recipe should be prioritized: INFO: Recipe upgrade statistics: * Succeeded: 1 gpgme, 2.2.0 (first seen 117 day(s) ago) -> 2.3.1 (first seen 117 day(s) ago), Unassigned AI-Generated: Claude Sonnet 5.5 Signed-off-by: Alexander Kanavin --- modules/state.py | 14 +++++ modules/statistics.py | 116 +++++++++++++++++++++--------------------- upgrade-helper.py | 2 +- 3 files changed, 72 insertions(+), 60 deletions(-) diff --git a/modules/state.py b/modules/state.py index 9a10d32..1f3aebf 100644 --- a/modules/state.py +++ b/modules/state.py @@ -131,3 +131,17 @@ class State: return {'skip': True, 'reason': "%slast attempt %s result=%s; will retry in %d day(s)" % (prefix, when, result, retry_in)} + + def _firstseen_days(self, pn, field, version): + """Days since 'version' was first seen in 'field' (oldversion or + newversion); 0 if there is no matching state entry.""" + entry = self.data.get(pn) + if not entry or entry.get(field) != version: + return 0 + return int((time.time() - entry[field + '_firstseen']) / SECONDS_PER_DAY) + + def get_oldver_firstseen_days(self, pn, version): + return self._firstseen_days(pn, 'oldversion', version) + + def get_newver_firstseen_days(self, pn, version): + return self._firstseen_days(pn, 'newversion', version) diff --git a/modules/statistics.py b/modules/statistics.py index 5126a39..6174cec 100644 --- a/modules/statistics.py +++ b/modules/statistics.py @@ -25,16 +25,10 @@ class Statistics(object): def __init__(self): - self.succeeded = dict() - self.failed = dict() - self.succeeded["total"] = 0 - self.failed["total"] = 0 self.upgrade_stats = dict() - self.maintainers = set() - self.total_attempted = 0 self.skipped = [] - def _update(self, pn, new_ver, maintainer, error): + def _update(self, p, error): if error is None: status = "Succeeded" else: @@ -43,85 +37,89 @@ class Statistics(object): if not status in self.upgrade_stats: self.upgrade_stats[status] = [] - self.upgrade_stats[status].append((pn, new_ver, maintainer)) - - # add maintainer to the set of unique maintainers - self.maintainers.add(maintainer) - - if not maintainer in self.succeeded: - self.succeeded[maintainer] = 0 - if not maintainer in self.failed: - self.failed[maintainer] = 0 - - if status == "Succeeded": - self.succeeded["total"] += 1 - self.succeeded[maintainer] += 1 - else: - self.failed["total"] += 1 - self.failed[maintainer] += 1 - - self.total_attempted += 1 + self.upgrade_stats[status].append(p) def update(self, group): for p in group['pkgs']: - self._update(p['PN'],p['NPV'],p['MAINTAINER'],group['error']) + self._update(p, group['error']) def skip(self, group, reason): for p in group['pkgs']: - self.skipped.append((p['PN'],p['NPV'],p['MAINTAINER'],reason)) - - def _pkg_stats(self): + self.skipped.append((p, reason)) + + @property + def total_attempted(self): + return sum(len(v) for v in self.upgrade_stats.values()) + + @staticmethod + def _firstseen_days(state, p): + """(old version, new version) days since first seen; (0, 0) without state.""" + if state is None: + return (0, 0) + return (state.get_oldver_firstseen_days(p['PN'], p['PV']), + state.get_newver_firstseen_days(p['PN'], p['NPV'])) + + @staticmethod + def _pkg_line(p, old_days, new_days, state, reason=None): + """One report line; first-seen ages are only shown when state is in use.""" + if state is None: + line = "{}, {} -> {}".format(p['PN'], p['PV'], p['NPV']) + else: + line = "{}, {} (first seen {} day(s) ago) -> {} (first seen {} day(s) ago)".format( + p['PN'], p['PV'], old_days, p['NPV'], new_days) + if reason: + line += ", " + reason + if p['MAINTAINER']: + line += ", " + p['MAINTAINER'] + return " " + line + "\n" + + def _pkg_stats(self, state): stat_msg = "Recipe upgrade statistics:\n\n" for status in self.upgrade_stats: list_len = len(self.upgrade_stats[status]) if list_len > 0: - stat_msg += " * " + status + ": " + str(list_len) + "\n" + stat_msg += " * {}: {}\n".format(status, list_len) - for pkg, new_ver, maintainer in self.upgrade_stats[status]: - stat_msg += " " + pkg + ", " + new_ver - if maintainer: - stat_msg += ", " + maintainer - stat_msg += "\n" + for p in self.upgrade_stats[status]: + old_days, new_days = self._firstseen_days(state, p) + stat_msg += self._pkg_line(p, old_days, new_days, state) if self.skipped: stat_msg += " * Skipped: {}\n".format(len(self.skipped)) - for (pkg, new_ver, maintainer, reason) in self.skipped: - stat_msg += " {}, {}, {}, {}\n".format(pkg, new_ver, reason, maintainer) - if self.total_attempted == 0: - percent_succeded = 0 + skipped = [(p, reason) + self._firstseen_days(state, p) + for (p, reason) in self.skipped] + # Longest outstanding first + skipped.sort(key=lambda item: max(item[2], item[3]), reverse=True) + + for (p, reason, old_days, new_days) in skipped: + stat_msg += self._pkg_line(p, old_days, new_days, state, reason) + + attempted = self.total_attempted + succeeded = len(self.upgrade_stats.get('Succeeded', [])) + failed = attempted - succeeded + + if attempted == 0: + percent_succeeded = 0 percent_failed = 0 else: - percent_succeded = self.succeeded["total"] * 100.0 / self.total_attempted - percent_failed = self.failed["total"] * 100.0 / self.total_attempted + percent_succeeded = succeeded * 100.0 / attempted + percent_failed = failed * 100.0 / attempted stat_msg += "\n TOTAL: attempted=%d succeeded=%d(%.2f%%) failed=%d(%.2f%%)\n\n" % \ - (self.total_attempted, self.succeeded["total"], - percent_succeded, - self.failed["total"], + (attempted, succeeded, + percent_succeeded, + failed, percent_failed) return stat_msg - def _maintainer_stats(self): - stat_msg = "Recipe upgrade statistics per Maintainer:\n\n" - for m in self.maintainers: - attempted = self.succeeded[m] + self.failed[m] - stat_msg += " %s: attempted=%d succeeded=%d(%.2f%%) failed=%d(%.2f%%)\n" % \ - (m.split("@")[0] if m else "Maintainerless", attempted, self.succeeded[m], - self.succeeded[m] * 100.0 / attempted, - self.failed[m], - self.failed[m] * 100.0 / attempted) - - return stat_msg - - def get_summary(self, publish_work_url, workdir): + def get_summary(self, publish_work_url, workdir, state): msg = '' if publish_work_url: msg += "AUH finished upgrade batch the result patches/logs can be found at:\n" \ "%s/%s, next are the statistics:\n\n" % (publish_work_url, workdir) - msg += self._pkg_stats() - msg += self._maintainer_stats() + msg += self._pkg_stats(state) return msg diff --git a/upgrade-helper.py b/upgrade-helper.py index 8e47e40..6997e89 100755 --- a/upgrade-helper.py +++ b/upgrade-helper.py @@ -622,7 +622,7 @@ class Updater(object): attach_tarball = False statistics_summary = self.statistics.get_summary( - publish_work_url, os.path.basename(self.uh_work_dir)) + publish_work_url, os.path.basename(self.uh_work_dir), self.state) statistics_file = os.path.join(self.uh_work_dir, "statistics_summary") From patchwork Thu Dec 3 21:20:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Kanavin X-Patchwork-Id: 107229 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.3752.1796332865504429075 for ; Thu, 03 Dec 2026 13:21:05 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=Ltssp98J; spf=pass (domain: gmail.com, ip: 209.85.221.51, mailfrom: alex.kanavin@gmail.com) Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-490d59c3edaso159611f8f.1 for ; Thu, 03 Dec 2026 13:21:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796332864; x=1796937664; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PqOxCHfLw0wOuqDeJZ2dxMAtu1ZyptOGEF5/jTb+FEc=; b=Ltssp98JxykFDMMWbm0Bii8oJcITBqM6tllrmB9EEfYaBd5fIUwU/oxDaQ6zHQXZaF ioDpqbQtD0N8NbBqrg8Rg8h32q3rrbKbo1++rg3wr1oE9bgtkHTnAfrVRwuRq7/oQbaa pjPDPYvggy/Ipup2AQPf+H1eaMtPyuDNc1GDgoxMwDfzs0wq+vB/K0iDkg67vPhaHBlv hi4kOcuTSRCIUydtbfaZ+EsBGfUNjKcr04GJWHhl3XIS5MpWOnqVdADIx5k78baCIF6H mYgEuKxkrpPuPn2DrAtH+rL5WHTIBCnIylo8X4ctiPvyT7mf4b4wkZX+n1fsWunCrjR7 0deg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796332864; x=1796937664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=PqOxCHfLw0wOuqDeJZ2dxMAtu1ZyptOGEF5/jTb+FEc=; b=LH2VZBAZFk+6ONvyyCiL9iSpoiK8SQWjkJm7YMBUN3wuDYTVxpSu47oPNrcl09oQRd omfrI+m8NTzWUpLuXTNSjxcNHdRRz7uqtGBY9eOYrv14ODX55vRxaJzBa2QM0Cblk2jl vvBypsnrnjjr86ntCdfV+D3ePGgUhrQ/N7jWgulSHNzNCn3pCwdVvEBnlTUroW353WI3 8C1B/XebVMXtph7c7ydkRs2j7vO+UMT2FYIq6g/g/n6FH2IQM11kAUEgdnsdfGQY1DLi J0HUHGOf/BYvafULlqZBg7vLYQCqkvyq6PrDhyPHywARNVmpq6GG3frPp4l5FkA+wekp by3A== X-Gm-Message-State: APuU4Z9N5PkqeBizdESczBJ5xqblAtBfmjH99Upf3oCbh0sl5cxx39ea 5Qf92QR+ccWXfOgzkrK32I9ZIMsLAk92wLwzp1Va5l4I+j3MqUFOUJ5fj1y/FA== X-Gm-Gg: AZFdTZcMAm6OkZt2n3/Ii0SafIuPpyEihmp42xfqx8pXQBfYYJRbgnUfGilpzeCRtBD RKWh24e3uQAbD7xvq6KNYx4PsxSN7g2Yjuro0m4qunVkOaay/AfeugjGRxTmSiTQ5RIXJvaFpjQ ZVxo3nYUdjZ+TK4Wx4M7b12E0AbMhNz4HXp3ul5SA2augMyqEs2U+Cw2AAID1OFi7t8IwLHjIKF Nv1+Qc6/kDB1Q82k+3v4f0VKmadWE50jtum7B2+8ydLXpjD/e7THYukvxzfOVr0stypq4bSk0wp kCsxUX15U6ZM3qBtfB2rHeQWowsEo4+QVkgYJflNX/xS6I7pf9I8XOD7PwPxA1YDvpgPdHZ1jwk axpbzycUETotOLZ5MtLP0+kFazsk9LpcoA8rBJ0nLHxHYc2yijuqcp8LkyxfygaZbr0oTLdnol1 q/IgFuRFdlmTNJhwp+W0LVlgnGtOHnBx3MXacQlP8e52dkcDxPh/T12tIjaw6wnlMX6L/wrKluk di2tKrWOTFPmFtaFAVxU592Ey6t+cuWMHjMGWY8EpC9FR06xjn9HorrHJ+9K5e5eX5BcAWl02kn VjW6Vu+Re49nbPn0TNQO7O6d/tmfLjbg8pk1QolyQgbvd6HnjU0IfkGo5Ci4eVcT X-Received: by 2002:a05:6000:2909:b0:492:2b36:a149 with SMTP id ffacd0b85a97d-4cf4bb393b1mr7093593f8f.25.1796332863809; Thu, 03 Dec 2026 13:21:03 -0800 (PST) Return-Path: Received: from Zen2.lab.linutronix.de. (drugstore.linutronix.de. [80.153.143.164]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1724ad3a5sm1860126f8f.9.2026.12.03.13.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 13:21:03 -0800 (PST) From: Alexander Kanavin X-Google-Original-From: Alexander Kanavin To: yocto-patches@lists.yoctoproject.org Cc: daniel.turull@ericsson.com, Alexander Kanavin Subject: [auh][PATCH v2 3/3] tests: add unit tests for modules/state.py and modules/statistics.py Date: Thu, 3 Dec 2026 22:20:50 +0100 Message-ID: <20261203212050.799982-3-alex@linutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203212050.799982-1-alex@linutronix.de> References: <20261203212050.799982-1-alex@linutronix.de> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Thu, 03 Dec 2026 21:21:06 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/5666 AUH has no built-in tests, and corner cases are only hit in production autobuilder runs. State and statistics are pure logic, so cover the version-change, expiry, state-less (non --incremental) and partial-run cases with stdlib unittest. Run from the top of the tree: python3 -m unittest discover -s tests -v AI-Generated: Claude Sonnet 5.5 Signed-off-by: Alexander Kanavin --- tests/test_state_statistics.py | 218 +++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 tests/test_state_statistics.py diff --git a/tests/test_state_statistics.py b/tests/test_state_statistics.py new file mode 100644 index 0000000..73a3517 --- /dev/null +++ b/tests/test_state_statistics.py @@ -0,0 +1,218 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Unit tests for modules/state.py and modules/statistics.py. +# Run from the top of the tree with: +# python3 -m unittest discover -s tests -v + +import json +import os +import sys +import tempfile +import time +import unittest + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) + +from modules import state as state_mod +from modules.state import State, STATE_FILENAME, SECONDS_PER_DAY +from modules.statistics import Statistics + + +def pkg(pn, pv="1.0", npv="1.1", maintainer="a@b.c"): + return {"PN": pn, "PV": pv, "NPV": npv, "MAINTAINER": maintainer} + + +def group(*pkgs, error=None): + return {"name": ",".join(p["PN"] for p in pkgs), "pkgs": list(pkgs), + "error": error} + + +class StateTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.dir = self.tmp.name + + def tearDown(self): + self.tmp.cleanup() + + def age(self, st, pn, days): + """Pretend the last attempt on pn was 'days' days ago.""" + st.data[pn]["timestamp"] = time.time() - days * SECONDS_PER_DAY + + def test_no_state_file(self): + self.assertEqual(State(self.dir).data, {}) + + def test_v1_state_is_ignored(self): + with open(os.path.join(self.dir, STATE_FILENAME), "w") as f: + json.dump({"version": 1, "recipes": { + "a": {"1.1": {"timestamp": time.time(), "result": "success"}}}}, f) + self.assertEqual(State(self.dir).data, {}) + + def test_corrupt_state_is_ignored(self): + with open(os.path.join(self.dir, STATE_FILENAME), "w") as f: + f.write("{not json") + self.assertEqual(State(self.dir).data, {}) + + def test_save_and_reload(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_SUCCESS) + st.save() + self.assertEqual(State(self.dir).data, st.data) + + def test_save_keeps_entries_not_in_current_run(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_SUCCESS) + st.record("b", "1.0", "1.1", state_mod.RESULT_FAILURE) + st.save() + st = State(self.dir) # a later run that only touches 'a' + st.record("a", "1.0", "1.1", state_mod.RESULT_SUCCESS) + st.save() + self.assertEqual(set(State(self.dir).data), {"a", "b"}) + + def test_record_keeps_firstseen_when_versions_unchanged(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + st.data["a"]["oldversion_firstseen"] -= 10 * SECONDS_PER_DAY + st.data["a"]["newversion_firstseen"] -= 20 * SECONDS_PER_DAY + old, new = (st.data["a"]["oldversion_firstseen"], + st.data["a"]["newversion_firstseen"]) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + self.assertEqual(st.data["a"]["oldversion_firstseen"], old) + self.assertEqual(st.data["a"]["newversion_firstseen"], new) + + def test_record_resets_only_the_changed_side(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + st.data["a"]["oldversion_firstseen"] -= 10 * SECONDS_PER_DAY + st.data["a"]["newversion_firstseen"] -= 10 * SECONDS_PER_DAY + old, new = (st.data["a"]["oldversion_firstseen"], + st.data["a"]["newversion_firstseen"]) + st.record("a", "1.0", "1.2", state_mod.RESULT_FAILURE) # new changed + self.assertEqual(st.data["a"]["oldversion_firstseen"], old) + self.assertGreater(st.data["a"]["newversion_firstseen"], new) + old = st.data["a"]["oldversion_firstseen"] + st.data["a"]["oldversion_firstseen"] -= 5 * SECONDS_PER_DAY + old = st.data["a"]["oldversion_firstseen"] + st.record("a", "1.0.1", "1.2", state_mod.RESULT_FAILURE) # old changed + self.assertGreater(st.data["a"]["oldversion_firstseen"], old) + + def test_check_skips_same_pair_within_window(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + self.assertTrue(st.check("a", "1.0", "1.1")["skip"]) + + def test_check_unknown_recipe(self): + self.assertFalse(State(self.dir).check("a", "1.0", "1.1")["skip"]) + + def test_check_rerolls_when_old_version_changed(self): + # Layer moved the recipe to an intermediate version after our attempt. + st = State(self.dir) + st.record("a", "1.0", "1.3", state_mod.RESULT_SUCCESS) + self.assertFalse(st.check("a", "1.1", "1.3")["skip"]) + + def test_check_retries_when_new_version_changed(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + self.assertFalse(st.check("a", "1.0", "1.2")["skip"]) + + def test_check_windows_expire(self): + st = State(self.dir, retry_same_version_days=30, success_max_age_days=10) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + st.record("b", "1.0", "1.1", state_mod.RESULT_SUCCESS) + self.age(st, "a", 20) + self.age(st, "b", 20) + self.assertTrue(st.check("a", "1.0", "1.1")["skip"]) # 20 < 30 + self.assertFalse(st.check("b", "1.0", "1.1")["skip"]) # 20 > 10 + + def test_check_any_version_recipe_ignores_versions(self): + st = State(self.dir, retry_any_version_days=7, + retry_any_version_recipes=["a"]) + st.record("a", "1.0", "1.1", state_mod.RESULT_SUCCESS) + self.assertTrue(st.check("a", "1.5", "1.6")["skip"]) + self.age(st, "a", 8) + self.assertFalse(st.check("a", "1.5", "1.6")["skip"]) + + def test_firstseen_days(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + st.data["a"]["oldversion_firstseen"] -= 3 * SECONDS_PER_DAY + 60 + st.data["a"]["newversion_firstseen"] -= 1 * SECONDS_PER_DAY + 60 + self.assertEqual(st.get_oldver_firstseen_days("a", "1.0"), 3) + self.assertEqual(st.get_newver_firstseen_days("a", "1.1"), 1) + + def test_firstseen_days_missing_or_mismatched(self): + st = State(self.dir) + st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + self.assertEqual(st.get_oldver_firstseen_days("nope", "1.0"), 0) + self.assertEqual(st.get_newver_firstseen_days("nope", "1.1"), 0) + self.assertEqual(st.get_oldver_firstseen_days("a", "9.9"), 0) + self.assertEqual(st.get_newver_firstseen_days("a", "9.9"), 0) + + +class StatisticsTests(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.st = State(self.tmp.name) + + def tearDown(self): + self.tmp.cleanup() + + def test_total_attempted(self): + s = Statistics() + self.assertFalse(s.total_attempted) # used by send_status_mail() + s.update(group(pkg("a"), pkg("b"))) + s.update(group(pkg("c"), error=Exception("boom"))) + self.assertEqual(s.total_attempted, 3) + + def test_summary_without_state(self): + # state is None unless --incremental is given + s = Statistics() + s.update(group(pkg("a"))) + s.update(group(pkg("b"), error=Exception("boom"))) + out = s.get_summary("", "w", None) + self.assertIn("a, 1.0 -> 1.1, a@b.c", out) + self.assertNotIn("first seen", out) + self.assertIn("attempted=2 succeeded=1(50.00%) failed=1(50.00%)", out) + + def test_summary_with_state(self): + self.st.record("a", "1.0", "1.1", state_mod.RESULT_SUCCESS) + self.st.data["a"]["oldversion_firstseen"] -= 5 * SECONDS_PER_DAY + 60 + s = Statistics() + s.update(group(pkg("a"))) + out = s.get_summary("", "w", self.st) + self.assertIn("a, 1.0 (first seen 5 day(s) ago) -> " + "1.1 (first seen 0 day(s) ago), a@b.c", out) + + def test_skipped_sorted_longest_outstanding_first(self): + for pn, days in (("young", 1), ("old", 40), ("mid", 10)): + self.st.record(pn, "1.0", "1.1", state_mod.RESULT_FAILURE) + self.st.data[pn]["newversion_firstseen"] -= days * SECONDS_PER_DAY + 60 + s = Statistics() + for pn in ("young", "old", "mid"): + s.skip(group(pkg(pn)), "reason") + out = s.get_summary("", "w", self.st) + self.assertLess(out.index("old,"), out.index("mid,")) + self.assertLess(out.index("mid,"), out.index("young,")) + self.assertIn("* Skipped: 3", out) + + def test_skipped_group_member_without_state_entry(self): + # Group membership changed since the last run: only 'a' has an entry. + self.st.record("a", "1.0", "1.1", state_mod.RESULT_FAILURE) + s = Statistics() + s.skip(group(pkg("a"), pkg("c")), "reason") + out = s.get_summary("", "w", self.st) + self.assertIn("c, 1.0 (first seen 0 day(s) ago)", out) + + def test_empty_maintainer(self): + s = Statistics() + s.update(group(pkg("a", maintainer=""))) + out = s.get_summary("", "w", None) + self.assertIn("a, 1.0 -> 1.1\n", out) + + def test_nothing_attempted(self): + out = Statistics().get_summary("", "w", None) + self.assertIn("attempted=0 succeeded=0(0.00%) failed=0(0.00%)", out) + + +if __name__ == "__main__": + unittest.main()