diff --git a/fork-kit/desk/tests/windows.test.py b/fork-kit/desk/tests/windows.test.py index ca65aa9765188..cf704146d1b2e 100644 --- a/fork-kit/desk/tests/windows.test.py +++ b/fork-kit/desk/tests/windows.test.py @@ -389,6 +389,12 @@ def test_the_memory_cap_kept_is_one_wsl_reads_within_its_bounds(self): ('memory=16777216TB', 30, '8GB', 8388608, '[wsl2] memory: 16777216TB -> 8GB'), # WSL: 0, its default ('memory=26 GB', 30, '8GB', 8388608, '[wsl2] memory: 26 GB -> 8GB'), # WSL rejects these two ('memory=30720mb', 30, '8GB', 8388608, '[wsl2] memory: 30720mb -> 8GB'), + ('memory=26Gb', 30, '8GB', 8388608, '[wsl2] memory: 26Gb -> 8GB'), # the unit is case-sensitive + # WSL trims only space and tab: a non-breaking space (pasted from a web page) or a form feed after + # the unit stays in its value, and it rejects that (#321) + ('memory=26GB\u00a0', 30, '8GB', 8388608, '[wsl2] memory: 26GB\u00a0 -> 8GB'), + ('memory=26GB\f', 30, '8GB', 8388608, '[wsl2] memory: 26GB\f -> 8GB'), + ('memory=\u00a026GB', 30, '8GB', 8388608, '[wsl2] memory: \u00a026GB -> 8GB'), ('memory=4GB', 30, '8GB', 8388608, '[wsl2] memory: 4GB -> 8GB'), # below: raised ('memory=8191MB', 30, '8GB', 8388608, '[wsl2] memory: 8191MB -> 8GB'), ('memory=lots', 30, '8GB', 8388608, '[wsl2] memory: lots -> 8GB'), diff --git a/fork-kit/desk/windows/start-desk.ps1 b/fork-kit/desk/windows/start-desk.ps1 index 018a97b4c001d..d1bf095f42c19 100644 --- a/fork-kit/desk/windows/start-desk.ps1 +++ b/fork-kit/desk/windows/start-desk.ps1 @@ -121,11 +121,13 @@ function Read-WslConfig([string]$path) { # networkingMode and dnsTunneling were [experimental] keys before WSL 2.0; an old line there can still win over # [wsl2], so Merge-WslConfig removes them there (the [wsl2] ones are what the desk needs) and the check FAILs on them. $Experimental = @('networkingMode', 'dnsTunneling') +# A key=value line, trimmed of space and tab only, as WSL's config parser does: a non-breaking space or a form feed +# stays in the value (WSL then rejects a memory= value, so it is rewritten), where .NET's \s would drop it. function SectionKeys([string[]]$lines, [string]$section) { # the keys of one section only $keys = @{}; $sec = '' foreach ($l in $lines) { if ($l -match '^\s*\[(.+)\]\s*$') { $sec = $Matches[1].Trim().ToLower(); continue } - if ($sec -eq $section -and $l -match '^\s*([^=#;\s]+)\s*=\s*(.*?)\s*$') { $keys[$Matches[1]] = $Matches[2] } + if ($sec -eq $section -and $l -match '^[ \t]*([^=#; \t]+)[ \t]*=[ \t]*(.*?)[ \t]*$') { $keys[$Matches[1]] = $Matches[2] } } $keys } @@ -138,13 +140,13 @@ function MergeLines([string[]]$lines, $want) { function AddMissing { foreach ($k in $want.Keys) { if (-not $done[$k]) { $out.Add("$k=$($want[$k])"); $done[$k] = 1; $notes.Add(" [wsl2] ${k}: (not set) -> $($want[$k])") } } } foreach ($l in $lines) { if ($l -match '^\s*\[(.+)\]\s*$') { if ($sec -eq 'wsl2') { AddMissing }; $sec = $Matches[1].Trim().ToLower(); $out.Add($l); continue } - if ($sec -eq 'wsl2' -and $l -match '^\s*([^=#;\s]+)\s*=\s*(.*?)\s*$' -and $want.Contains($Matches[1])) { + if ($sec -eq 'wsl2' -and $l -match '^[ \t]*([^=#; \t]+)[ \t]*=[ \t]*(.*?)[ \t]*$' -and $want.Contains($Matches[1])) { $k = $Matches[1]; $v = $Matches[2] if ($done[$k]) { $notes.Add(" [wsl2] $k=${v}: a repeated line, removed"); continue } $done[$k] = 1 if ($v -eq $want[$k]) { $out.Add($l) } else { $out.Add("$k=$($want[$k])"); $notes.Add(" [wsl2] ${k}: $v -> $($want[$k])") } continue } - if ($sec -eq 'experimental' -and $l -match '^\s*([^=#;\s]+)\s*=\s*(.*?)\s*$' -and $Matches[1] -in $Experimental) { + if ($sec -eq 'experimental' -and $l -match '^[ \t]*([^=#; \t]+)[ \t]*=[ \t]*(.*?)[ \t]*$' -and $Matches[1] -in $Experimental) { $notes.Add(" [experimental] $($Matches[1])=$($Matches[2]): removed (the [wsl2] one is used)"); continue } $out.Add($l) } @@ -166,7 +168,7 @@ function Merge-WslConfig([string]$path, $want, [scriptblock]$before = {}) { # # (ParseMemorySize) takes a number and B, K, KB, M, MB, G, GB, T or TB exactly: no space before the unit, upper case # (`26 GB` or `26gb` makes it warn and run on half the RAM). function CapKb([string]$v) { - if ($v -cnotmatch '^\s*([0-9]{1,13})([KMGT]?)B?\s*$') { return [long]-1 } + if ($v -cnotmatch '^([0-9]{1,13})([KMGT]?)B?$') { return [long]-1 } [long][math]::Min(1e15, [math]::Floor([double]$Matches[1] * [math]::Pow(1024, ' KMGT'.IndexOf($Matches[2])) / 1024)) } # The memory cap to want: $gb GB, or the one already in .wslconfig, kept as it is written (neither lowered nor a FAIL, diff --git a/fork-kit/pc-agents/README.md b/fork-kit/pc-agents/README.md index 2dae0c05e223a..3bbdb8d5d9775 100644 --- a/fork-kit/pc-agents/README.md +++ b/fork-kit/pc-agents/README.md @@ -87,7 +87,8 @@ The kit reads the `pc-agents` section of the machine file `/etc/fork-kit/machine `t3Version` must be 0.1.7 or newer: older releases have no managed policy, so they would run with none of the kit's locks and with updates on. A 0.1.7 pre-release counts as older (some 0.1.7 nightlies were built before the policy), -and a pre-release of a later version as that version. Setup and `check` refuse them, naming the key. (`t3 pair`, +and a pre-release of a later version as that version. This fork's stable build of a release (`0.1.7-fork.1`) counts +as that release, its nightlies as pre-releases. Setup and `check` refuse the older ones, naming the key. (`t3 pair`, step 10, came earlier.) Every T3 setting can be locked through `lockedSettings`, the fork's own settings (`agentSlots`, `usagePacingGate`, @@ -235,12 +236,15 @@ allowed (connection tracking). - **Packages:** setup installs `nftables`, `libatomic1` and `unzip` when `dpkg` does not list one as installed (held counts as installed; a distro set up by an older kit gets the two new ones at its next run; no T3 restart for them). It installs them after it writes its files, so `apt-get` resolves through the machine file's `nameservers` - as they are now, and before it loads the firewall. A package install stopped half-way is finished first - (`dpkg --configure -a`). Nothing asks a question: a changed config file is kept, debconf takes its defaults, and - `apt-get` waits up to 5 minutes for a lock (apt-daily on a new distro). A failed step stops setup, naming the - command to run; the files it wrote stay, and when one of them changed what T3 runs with, the walls check's - `restart` wall fails (and the 2-minute check stops T3) until setup runs again to the end, as after a failed T3 - download. + as they are now, and before it loads the firewall. A package install stopped half-way (`dpkg --audit` names it) is + finished first (`dpkg --configure -a`, run only then). Nothing asks a question: a changed config file is kept and + debconf takes its defaults. A lock another `apt-get` or `dpkg` holds (apt-daily on a new distro) is waited for, up + to 5 minutes a step: `apt-get` waits for dpkg's lock itself, and setup runs `dpkg`, `apt-get update` and + `apt-get install` again while they fail on the locks they take without a wait. A failed step stops setup, naming + the command to run (for a lock still held, to wait for the other one); the files it wrote stay, and when one of them + changed what T3 runs with, the walls check's `restart` wall fails (and the 2-minute check stops T3) until setup runs + again to the end, as after a failed T3 download. A distro restart in between starts T3 again with the new files and + firewall, without the packages. - **A distro that is not fresh:** refused before anything is written, with the reasons: another login user, an `agent` with another uid or in another group, a file the kit would write that it did not write (or that was edited since, for example a hand-written `wsl.conf` or `policy.json`), a cron, at or ssh unit where the kit masks diff --git a/fork-kit/pc-agents/lib/pc_agents.py b/fork-kit/pc-agents/lib/pc_agents.py index eb5dd564c6e93..261c323ff749b 100644 --- a/fork-kit/pc-agents/lib/pc_agents.py +++ b/fork-kit/pc-agents/lib/pc_agents.py @@ -19,6 +19,7 @@ BOOT_ID = '/proc/sys/kernel/random/boot_id' # the marker holds this boot's id and CLOCK_MONOTONIC, like systemd's AS_AGENT = 'pc-agents-as-agent' # name prefix of `pc-agents as-agent`'s transient units (check --enforce stops them) SETTLE, SETTLE_STEP = 15, 1 # after a (re)start, setup watches T3 this many seconds, every SETTLE_STEP, before done +LOCK_WAIT, LOCK_STEP = 300, 5 # setup retries a dpkg or apt-get step that found a lock held this long, every LOCK_STEP LOADED = '/run/pc-agents/firewall.loaded' # sha256 of the firewall file and `nft list` of it, saved when loaded T3 = OPT + '/t3' # T3's runtime, installed by root (T3CODE_HOME of scripts/install.sh): the agent cannot change it UNIT, WALLS = 't3code-agents.service', 'pc-agents-walls' @@ -98,10 +99,11 @@ def is_ip_list(value, net, glob=False, most=64): def new_enough(version): - """Whether VERSION version is OLDEST_T3 or newer, in semver order: a pre-release ranks below its release.""" + """Whether VERSION version is OLDEST_T3 or newer, in semver order: a pre-release ranks below its release. The + fork's stable build of a release (`-fork.`, fork-release.yml) is that release; its nightlies are pre-releases.""" m = VERSION.fullmatch(version) numbers = tuple(map(int, m.groups()[:3])) - return numbers > OLDEST_T3 or numbers == OLDEST_T3 and not m[4] + return numbers > OLDEST_T3 or numbers == OLDEST_T3 and (not m[4] or bool(re.fullmatch(r'-fork\.[1-9]\d*', m[4]))) def port_range(text): diff --git a/fork-kit/pc-agents/sbin/pc-agents b/fork-kit/pc-agents/sbin/pc-agents index 14cc472cd5024..d160dbfb97fca 100755 --- a/fork-kit/pc-agents/sbin/pc-agents +++ b/fork-kit/pc-agents/sbin/pc-agents @@ -192,10 +192,27 @@ def install_t3(c, version, done): return None +# What dpkg and apt-get say when another one (apt-daily, unattended-upgrades) holds a lock they take without a wait +LOCKED = re.compile(r'could not get lock|unable to lock|(is|was) locked by another process', re.I) + + +def run_locked(argv, env): + """k.run(argv), tried again every k.LOCK_STEP s for up to k.LOCK_WAIT s while it fails on a lock another apt-get + or dpkg holds. apt-get's DPkg::Lock::Timeout waits only for dpkg's frontend lock: `update` takes the lists lock and + `install` the archives lock without a wait, and so does dpkg its own.""" + end = time.monotonic() + k.LOCK_WAIT + while True: + r = k.run(argv, timeout=900, env=env) + if not r.returncode or not LOCKED.search(r.stderr) or time.monotonic() >= end: + return r + time.sleep(k.LOCK_STEP) + + def install_packages(): """Install the k.PACKAGES that are not (fully) installed; held counts as installed. A dpkg run stopped half-way - is finished first (apt-get refuses until it is). Nothing asks a question (stdin is /dev/null): a changed config - file is kept, debconf takes its defaults, and apt-get waits for a lock apt-daily holds. Returns why not, or None.""" + (`dpkg --audit` names a package) is finished first (apt-get refuses until it is). Nothing asks a question (stdin + is /dev/null): a changed config file is kept, debconf takes its defaults, and a lock apt-daily holds is waited + for (run_locked). Returns why not, or None.""" r = k.run(['/usr/bin/dpkg-query', '-W', '-f=${Package}\t${Status}\n', *k.PACKAGES]) have = {p for p, _, status in (line.partition('\t') for line in r.stdout.splitlines()) if status.endswith(' ok installed')} @@ -204,20 +221,24 @@ def install_packages(): return None say('installing ' + ' '.join(missing)) quiet = {'DEBIAN_FRONTEND': 'noninteractive'} - r = k.run(['/usr/bin/dpkg', '--force-confdef', '--force-confold', '--configure', '-a'], timeout=900, env=quiet) - if r.returncode: - return (f'cannot install {" ".join(missing)}: dpkg --configure -a failed ({r.stderr.strip()[-300:]}). If ' - 'another apt-get or dpkg still runs (apt-daily, on a new distro), wait for it to end; then run ' - '`dpkg --configure -a` as root, and setup again') + busy = (' Another apt-get or dpkg still runs (apt-daily, on a new distro) after 5 minutes: ' + 'wait for it to end, then run setup again') + r = k.run(['/usr/bin/dpkg', '--audit']) # reads only: no lock + if r.returncode or r.stdout.strip(): + r = run_locked(['/usr/bin/dpkg', '--force-confdef', '--force-confold', '--configure', '-a'], quiet) + if r.returncode: + return (f'cannot install {" ".join(missing)}: dpkg --configure -a failed ({r.stderr.strip()[-300:]}).' + + (busy if LOCKED.search(r.stderr) else ' Run `dpkg --configure -a` as root, then setup again')) apt = ['/usr/bin/apt-get', '-o', 'Dpkg::Options::=--force-confdef', '-o', 'Dpkg::Options::=--force-confold', '-o', 'DPkg::Lock::Timeout=300'] for argv in (apt + ['update'], apt + ['install', '-y', *missing]): - r = k.run(argv, timeout=900, env=quiet) + r = run_locked(argv, quiet) if r.returncode: return (f'cannot install {" ".join(missing)}: apt-get {argv[len(apt)]} failed ({r.stderr.strip()[-300:]}).' - ' Fix the distro\'s network (the machine file\'s nameservers are in /etc/resolv.conf now) or ' - f'package sources, run `apt-get update && apt-get install -y {" ".join(missing)}` as root, then ' - 'setup again') + + (busy if LOCKED.search(r.stderr) else + ' Fix the distro\'s network (the machine file\'s nameservers are in /etc/resolv.conf now) or ' + f'package sources, run `apt-get update && apt-get install -y {" ".join(missing)}` as root, ' + 'then setup again')) return None diff --git a/fork-kit/pc-agents/tests/fake_distro.py b/fork-kit/pc-agents/tests/fake_distro.py index 442d5ab8d19df..2a1a3a0b75e75 100644 --- a/fork-kit/pc-agents/tests/fake_distro.py +++ b/fork-kit/pc-agents/tests/fake_distro.py @@ -79,12 +79,19 @@ ' [ -e "$S/$u.status" ] && { echo "ExecMainCode=$(cat "$S/$u.code")"; echo "ExecMainStatus=$(cat "$S/$u.status")"; }\n' ' echo "ExecMainStartTimestampMonotonic=$(cat "$S/$u.start" 2>/dev/null || echo 0)";;\n' 'esac\n', - # apt-get [-o OPTION]... update|install -y PKG...: logs the rest; installs each package in /log/packages (nftables - # brings the fake nft kept in /log/nft-package). As real apt-get: refuses while a package is unpacked (dpkg was - # interrupted). /log/apt-fail makes it fail; /log/dns holds the resolv.conf line `update` needs to reach the - # mirror; with /log/questions it fails unless noninteractive and keeping changed config files. + # apt-get [-o OPTION]... update|install -y PKG...: logs the rest (and the options, in /log/apt-get-options); + # installs each package in /log/packages (nftables brings the fake nft kept in /log/nft-package). As real apt-get: + # refuses while a package is unpacked (dpkg was interrupted). /log/apt-locked-update (or -install) holds how many + # more runs find the lists (or archives) lock held, as while apt-daily runs: real apt-get does not wait for those. + # /log/apt-fail makes it fail; /log/dns holds the resolv.conf line `update` needs to reach the mirror; with + # /log/questions it fails unless noninteractive and keeping changed config files. 'usr/bin/apt-get': 'R="${0%/usr/bin/apt-get}"; o=; while [ "$1" = -o ]; do o="$o $2"; shift 2; done\n' - 'echo "$*" >>"$R/log/apt-get"\n' + 'echo "$*" >>"$R/log/apt-get"; echo "${o# }" >>"$R/log/apt-get-options"\n' + 'n=$(cat "$R/log/apt-locked-$1" 2>/dev/null || echo 0); if [ "$n" -gt 0 ]; then\n' + ' echo $((n - 1)) >"$R/log/apt-locked-$1"; [ "$1" = update ] && d=/var/lib/apt/lists || ' + 'd=/var/cache/apt/archives\n' + ' echo "E: Could not get lock $d/lock. It is held by process 4242 (apt-get) (test)" >&2\n' + ' echo "E: Unable to lock directory $d/" >&2; exit 100; fi\n' '[ -e "$R/log/apt-fail" ] && { echo "E: no network (test)" >&2; exit 100; }\n' 'grep -qs unpacked "$R"/log/packages/* && { echo "E: dpkg was interrupted, you must manually ' 'run \'dpkg --configure -a\' to correct the problem." >&2; exit 100; }\n' @@ -100,11 +107,19 @@ 'usr/bin/dpkg-query': 'R="${0%/usr/bin/dpkg-query}"; echo "$*" >>"$R/log/dpkg-query"; shift 2; rc=0\n' 'for p; do if [ -e "$R/log/packages/$p" ]; then printf "%s\\t%s\\n" "$p" "$(cat "$R/log/packages/$p")"\n' ' else echo "dpkg-query: no packages found matching $p" >&2; rc=1; fi; done; exit $rc\n', - # dpkg [--force-...]... --configure -a: finishes what an apt-get stopped half-way left unpacked. /log/dpkg-fail - # makes it fail as with apt-daily holding the lock; /log/questions as for apt-get. + # dpkg --audit: names each package an apt-get stopped half-way left unpacked (no lock: it only reads). + # dpkg [--force-...]... --configure -a: finishes them. /log/dpkg-locked holds how many more runs find the lock + # held (real dpkg does not wait); /log/questions as for apt-get. 'usr/bin/dpkg': 'R="${0%/usr/bin/dpkg}"; echo "$*" >>"$R/log/dpkg"\n' - '[ -e "$R/log/dpkg-fail" ] && { echo "dpkg: error: dpkg frontend lock was locked by another process ' - '(test)" >&2; exit 2; }\n' + 'if [ "$1" = --audit ]; then rc=0; for f in "$R"/log/packages/*; do grep -qs unpacked "$f" || ' + 'continue\n' + ' [ $rc = 1 ] || echo "The following packages have been unpacked but not yet configured:"\n' + ' echo " ${f##*/}"; rc=1; done; exit $rc; fi\n' + 'n=$(cat "$R/log/dpkg-locked" 2>/dev/null || echo 0); if [ "$n" -gt 0 ]; then\n' + ' echo $((n - 1)) >"$R/log/dpkg-locked"\n' + ' echo "dpkg: error: dpkg frontend lock was locked by another process with pid 4242 (test)" >&2\n' + ' exit 2; fi\n' + '[ ! -e "$R/log/questions" ] || { [ "$DEBIAN_FRONTEND" = noninteractive ] && case "$*" in ' '*--force-confold*) :;; *) false;; esac; } || ' '{ echo "dpkg: error: end of file on stdin at conffile prompt (test)" >&2; exit 1; }\n' @@ -139,6 +154,7 @@ class Case(unittest.TestCase): def setUp(self): k.SETTLE, k.SETTLE_STEP = self.settle, 0.05 + k.LOCK_WAIT, k.LOCK_STEP = 0.3, 0.01 # 300 s and 5 s on a machine # No power cut in a fake root, so when a write reaches the disk is not tested here: fsync only costs time. fsync = mock.patch.object(os, 'fsync', lambda fd: None) fsync.start() diff --git a/fork-kit/pc-agents/tests/setup.test.py b/fork-kit/pc-agents/tests/setup.test.py index 1614425aa1ea5..a7a38cdd7d9f3 100644 --- a/fork-kit/pc-agents/tests/setup.test.py +++ b/fork-kit/pc-agents/tests/setup.test.py @@ -12,6 +12,8 @@ from fake_distro import CONFIG, KIT, REPO, SHA1, SHA2, Case, blob, cli, k # noqa: E402 DPKG = '--force-confdef --force-confold --configure -a' # how setup runs dpkg: no config-file question +# apt-get's options: no config-file question, and a wait for dpkg's lock (apt-get's own locks are retried by setup) +APT = 'Dpkg::Options::=--force-confdef Dpkg::Options::=--force-confold DPkg::Lock::Timeout=300' class Setup(Case): @@ -338,7 +340,7 @@ def test_libatomic1_and_unzip_are_installed_once(self): self.write('/log/packages/unzip', 'install ok unpacked') # an apt-get stopped half-way code, out = self.setup_run() self.assertEqual(code, 0, out) - self.assertEqual(self.log('dpkg'), [DPKG]) # first: apt-get refuses while dpkg was interrupted + self.assertEqual(self.log('dpkg'), ['--audit', DPKG]) # first: apt-get refuses while dpkg was interrupted self.assertEqual(self.log('apt-get'), ['update', 'install -y unzip']) self.assertFalse([line for line in self.log() if line.startswith('restart')]) # no T3 restart for a package @@ -364,6 +366,7 @@ def test_packages_are_installed_after_the_kits_own_resolv_conf(self): code, out = self.setup_run() self.assertEqual(code, 1, out) self.assertIn('nameserver 8.8.8.8\n', self.read('/etc/resolv.conf')) # written before apt-get + self.assertEqual(self.check()[0], 1) # between the two runs: the files changed, T3 did not restart (#321) os.unlink(self.path('/log/apt-fail')) code, out = self.setup_run() self.assertEqual(code, 0, out) @@ -380,20 +383,51 @@ def test_dpkg_and_apt_get_ask_nothing(self): code, out = self.setup_run() self.assertEqual(code, 0, out) self.assertEqual(self.read('/log/packages/unzip'), 'install ok installed\n') + self.assertEqual(set(self.log('apt-get-options')), {APT}) # every apt-get run, every option (#321) - def test_a_dpkg_that_fails_is_named_with_its_own_fix(self): - """apt-daily holding dpkg's lock on a new distro: the advice is dpkg's, not an apt-get that fails too.""" + def test_dpkg_configure_runs_only_when_something_is_half_installed(self): + """`dpkg --configure -a` takes dpkg's lock without waiting: on a fresh distro with nothing half-installed + it is not run, so unattended-upgrades holding that lock is left to apt-get's own wait (#321).""" self.ready() - self.write('/log/packages/unzip', 'install ok unpacked') - self.write('/log/dpkg-fail', '') - code, out = self.setup_run() - self.assertEqual(code, 1, out) - self.assertIn('dpkg --configure -a failed', out) - self.assertIn('another apt-get or dpkg', out) - self.assertNotIn('apt-get update && apt-get install', out) - os.unlink(self.path('/log/dpkg-fail')) - code, out = self.setup_run() - self.assertEqual(code, 0, out) + self.assertEqual(self.log('dpkg'), ['--audit']) + self.assertEqual(self.log('apt-get'), ['update', 'install -y libatomic1 unzip']) + + def test_a_lock_apt_daily_holds_is_waited_for(self): + """A new distro where apt-daily runs: apt-get update's lists lock, install's archives lock and dpkg's own + lock are taken without a wait (only DPkg::Lock::Timeout's frontend lock waits), so setup tries again (#321).""" + self.write('/log/packages/unzip', 'install ok unpacked') # an upgrade stopped half-way + for name in ('dpkg-locked', 'apt-locked-update', 'apt-locked-install'): + self.write('/log/' + name, '2') + self.ready() + self.assertEqual(self.log('dpkg'), ['--audit'] + [DPKG] * 3) + self.assertEqual(self.log('apt-get'), ['update'] * 3 + ['install -y libatomic1 unzip'] * 3) + self.assertEqual(self.read('/log/packages/libatomic1'), 'install ok installed\n') + self.assertEqual(self.check()[0], 0) + + def test_a_lock_held_past_the_wait_is_named_with_its_own_fix(self): + """A lock still held after the wait (5 minutes on a machine): the advice is to wait for the other apt-get or + dpkg, not to fix the network; nothing is installed, and the next run goes on.""" + for name, failed in (('dpkg-locked', 'dpkg --configure -a failed'), + ('apt-locked-update', 'apt-get update failed'), + ('apt-locked-install', 'apt-get install failed')): + with self.subTest(lock=name): + self.ready() + os.unlink(self.path('/log/packages/libatomic1')) + self.write('/log/packages/unzip', 'install ok unpacked') + self.write('/log/' + name, '1000000') + code, out = self.setup_run() + self.assertEqual(code, 1, out) + self.assertIn(failed, out) + self.assertIn('Could not get lock' if 'apt' in name else 'locked by another process', out) + self.assertIn('Another apt-get or dpkg still runs', out) + self.assertNotIn('network', out) + self.assertFalse(os.path.exists(self.path('/log/packages/libatomic1'))) + os.unlink(self.path('/log/' + name)) + code, out = self.setup_run() + self.assertEqual(code, 0, out) + self.assertEqual(self.read('/log/packages/libatomic1'), 'install ok installed\n') + shutil.rmtree(self.root) + self.setUp() def test_t3_that_does_not_start_is_reported(self): self.ready() @@ -780,6 +814,8 @@ def test_bad_config(self): ({'t3Version': '0.0.30-fork.1'}, '0.1.7 or newer'), # built before 0.1.7 had the managed policy: a pre-release is older than its release ({'t3Version': '0.1.7-nightly.20261031.3991'}, '0.1.7 or newer'), + ({'t3Version': '0.1.7-nightly.20261031.3991.fork.1'}, '0.1.7 or newer'), # the fork's + ({'t3Version': '0.1.7-fork.1.rc.1'}, '0.1.7 or newer'), ({'maxRuntimeMode': 'root'}, 'one of')): self.machine({**CONFIG, **change}) code, out = self.setup_run() @@ -789,8 +825,10 @@ def test_bad_config(self): def test_versions_from_0_1_7_on_are_accepted(self): - """Compared as numbers, the release itself included: a string compare would refuse 0.1.10 (#296).""" - for v in ('0.1.7', '0.1.8-rc.1', '0.1.10', '0.1.10-nightly.20261114.4682.fork.1', '0.2.0', '1.0.0'): + """Compared as numbers, the release itself included: a string compare would refuse 0.1.10 (#296). The fork's + stable build of a release (`v-fork.`, fork-release.yml) is that release (#321).""" + for v in ('0.1.7', '0.1.7-fork.1', '0.1.7-fork.12', '0.1.8-rc.1', '0.1.10', + '0.1.10-nightly.20261114.4682.fork.1', '0.2.0', '1.0.0'): self.machine({**CONFIG, 't3Version': v}) self.assertEqual(k.config()['t3Version'], v)