feat: AptProxyMixin, what apt fetches through and pointing it at a proxy (NetOrk/netork#1397) #53

Merged
christianmanivong merged 2 commits from feat/apt-proxy-verify into main 2026-10-23 10:01:41 +00:00
Owner

apt reads apt.conf.d in order and apt.conf last, and the last value wins. Reading 00proxy alone missed a proxy the Debian or Ubuntu installer wrote, and a fix that wrote 00proxy and read it back reported success while apt fetched elsewhere (NetOrk/netork#1397).

AptProxyMixin (napalm_device_types.apt_proxy) is PackageProxyMixin for a Debian-family host. Its form follows HostStatusMixin: the command and the parse live here, and a driver supplies _run_apt_command, _run_apt_root_command and _write_apt_file.

  • get_package_proxy_report(): the proxy from apt-config dump, per-host overrides and auto-detect, every line that sets it in apt's reading order (editable or inside a block, files apt skips left out), and the http and https sources.
  • check_package_proxy(url, expect): a fetch with apt-helper download-file, past any proxy. An HTTP error counts as an answer. The caller names the text the page should contain, so no product name lives here.
  • configure_package_proxy(url): the steps configure → conflicts (other lines commented out with sed -i by line number, only where the line still sets the proxy) → verify (apt-config again) → fetch (the InRelease of an http source that is not DIRECT).
  • same_proxy_url(): scheme, host and port, a trailing slash aside.

62 new tests: fixtures from real apt-helper output, sh -n on the commands, and one run against this host's apt. Version 4.22.0.

apt reads `apt.conf.d` in order and `apt.conf` last, and the last value wins. Reading `00proxy` alone missed a proxy the Debian or Ubuntu installer wrote, and a fix that wrote `00proxy` and read it back reported success while apt fetched elsewhere (NetOrk/netork#1397). `AptProxyMixin` (`napalm_device_types.apt_proxy`) is `PackageProxyMixin` for a Debian-family host. Its form follows `HostStatusMixin`: the command and the parse live here, and a driver supplies `_run_apt_command`, `_run_apt_root_command` and `_write_apt_file`. - `get_package_proxy_report()`: the proxy from `apt-config dump`, per-host overrides and auto-detect, every line that sets it in apt's reading order (editable or inside a block, files apt skips left out), and the http and https sources. - `check_package_proxy(url, expect)`: a fetch with `apt-helper download-file`, past any proxy. An HTTP error counts as an answer. The caller names the text the page should contain, so no product name lives here. - `configure_package_proxy(url)`: the steps configure → conflicts (other lines commented out with `sed -i` by line number, only where the line still sets the proxy) → verify (`apt-config` again) → fetch (the `InRelease` of an http source that is not `DIRECT`). - `same_proxy_url()`: scheme, host and port, a trailing slash aside. 62 new tests: fixtures from real `apt-helper` output, `sh -n` on the commands, and one run against this host's apt. Version 4.22.0.
christianmanivong added 1 commit 2026-10-22 17:17:02 +00:00
feat: AptProxyMixin, what apt fetches through and pointing it at a proxy (NetOrk/netork#1397)
CI / test (3.10) (push) Successful in 31s
CI / test (3.11) (push) Successful in 30s
CI / test (3.12) (push) Successful in 30s
CI / test (3.13) (push) Successful in 33s
CI / test (3.10) (pull_request) Successful in 30s
CI / test (3.11) (pull_request) Successful in 28s
CI / test (3.12) (pull_request) Successful in 29s
CI / test (3.13) (pull_request) Successful in 29s
d7ec558933
apt reads apt.conf.d in order and apt.conf last; the last value wins. The
Debian installer writes its proxy into apt.conf, Ubuntu's into
90curtin-aptproxy: reading 00proxy alone missed both, and a fix that wrote
00proxy and read it back reported success while apt fetched elsewhere.

- get_package_proxy_report(): apt-config dump's proxy, per-host overrides,
  auto-detect, every line of apt's files that sets it (in reading order,
  editable or inside a block), the http and https sources.
- check_package_proxy(url, expect): a fetch with apt-helper, past any proxy;
  an HTTP error counts as an answer.
- configure_package_proxy(url): write 00proxy, comment out other proxy
  lines, read apt's proxy back, fetch one InRelease through it.
- same_proxy_url(): scheme, host and port, a trailing slash aside.

A driver supplies _run_apt_command, _run_apt_root_command and
_write_apt_file. Version 4.22.0.
christianmanivong added 1 commit 2026-10-22 22:15:00 +00:00
Merge branch 'main' into feat/apt-proxy-verify
driver / standard (pull_request) Successful in 13s
driver / lint (pull_request) Successful in 1m24s
driver / types (pull_request) Successful in 44s
driver / test (3.10) (pull_request) Successful in 50s
driver / test (3.11) (pull_request) Successful in 48s
driver / test (3.12) (pull_request) Successful in 48s
driver / test (3.13) (pull_request) Successful in 41s
driver / lowest (pull_request) Successful in 24s
driver / security (pull_request) Successful in 46s
driver / build (pull_request) Successful in 23s
CI / driver (pull_request) Successful in 7m2s
driver / publish (pull_request) Skipped
a07ced2df6
The NAPALM driver standard landed on main (#52, 4.21.1). apt_proxy follows
it: builtin generics, strict mypy, complexity 10 at most (parse_apt_proxy,
same_proxy_url and the comment-out step split into helpers), 100 % covered.
Its TypedDicts live in apt_proxy.py, since models.py is over 1000 lines and
may not grow. Version 4.22.0 with its CHANGELOG section.
christianmanivong merged commit 87dbdfac66 into main 2026-10-23 10:01:41 +00:00
christianmanivong deleted branch feat/apt-proxy-verify 2026-10-23 10:01:41 +00:00
Sign in to join this conversation.