feat: apt's proxy on a Proxmox VE node (NetOrk/netork#1397)
CI / test (3.10) (push) Failing after 19s
CI / test (3.11) (push) Failing after 17s
CI / test (3.12) (push) Failing after 20s
CI / test (3.10) (pull_request) Failing after 18s
CI / test (3.11) (pull_request) Failing after 20s
CI / test (3.12) (pull_request) Failing after 19s
CI / test (3.10) (push) Failing after 19s
CI / test (3.11) (push) Failing after 17s
CI / test (3.12) (push) Failing after 20s
CI / test (3.10) (pull_request) Failing after 18s
CI / test (3.11) (pull_request) Failing after 20s
CI / test (3.12) (pull_request) Failing after 19s
The node is Debian: AptProxyMixin gives it get_package_proxy(), get_package_proxy_report(), check_package_proxy() and the fix configure_package_proxy(), as on any Debian host. Logged in as root, the transports are the exec path; the file is written without an exit inside _rc's braces, which would end the shell before the status (see #30). Requires napalm-device-types 4.22.0; version 0.7.0.
This commit is contained in:
1 parent
03c7cdfa02
commit
7776bb904a
5 files changed
+99
-2
No files matched your search
@@ -116,3 +116,77 @@ class TestPackages:
|
||||
def test_the_old_actions_are_gone():
|
||||
for name in ("run_device_action", "_action_fix_snmp", "_action_install_lldpd"):
|
||||
assert not hasattr(ProxmoxDriver, name), name
|
||||
|
||||
|
||||
_APT_REPORT = (
|
||||
"APROXY_BEGIN\n[dump]\n{dump}[parts]\n{parts}[main]\n[sources]\n"
|
||||
"http://download.proxmox.com/debian/pve/dists/trixie/\nAPROXY_END\n"
|
||||
)
|
||||
|
||||
|
||||
class _AptNode(_Node):
|
||||
"""A node that answers apt's proxy report and a fetch."""
|
||||
|
||||
def __init__(self, proxy="", parts=""):
|
||||
super().__init__()
|
||||
self.proxy = proxy
|
||||
self.parts = parts
|
||||
|
||||
def __call__(self, command: str) -> str:
|
||||
if "apt-config dump" in command:
|
||||
self.ran.append(command)
|
||||
dump = f'Acquire::http::Proxy "{self.proxy}";\n' if self.proxy else ""
|
||||
return _APT_REPORT.format(dump=dump, parts=self.parts)
|
||||
if "apt-helper" in command:
|
||||
self.ran.append(command)
|
||||
return "APROXY_BEGIN\n[fetch]\nGet:1 x\n[rc]\n0\n[match]\n2\nAPROXY_END\n"
|
||||
return super().__call__(command)
|
||||
|
||||
|
||||
class TestPackageProxy:
|
||||
"""Proxmox VE is Debian: apt's proxy is set and read as on any Debian host (netOrk #1397)."""
|
||||
|
||||
def test_it_takes_the_fix(self):
|
||||
assert callable(getattr(ProxmoxDriver, "configure_package_proxy", None))
|
||||
|
||||
def test_the_fact(self):
|
||||
d = ProxmoxDriver("pve", "root@pam", "pw")
|
||||
d._exec_ssh_command = _AptNode(proxy="http://c:3142")
|
||||
|
||||
assert d.get_package_proxy() == "http://c:3142"
|
||||
|
||||
def test_written_as_root_read_back_and_fetched_through(self):
|
||||
node = _AptNode(proxy="http://c:3142")
|
||||
d = ProxmoxDriver("pve", "root@pam", "pw")
|
||||
d._exec_ssh_command = node
|
||||
|
||||
result = d.configure_package_proxy("http://c:3142")
|
||||
|
||||
assert result["success"] is True, result["output"]
|
||||
write = next(c for c in node.ran if "/etc/apt/apt.conf.d/00proxy" in c)
|
||||
assert "install -m 644" in write
|
||||
b64 = re.search(r"echo ([A-Za-z0-9+/=]+) \| base64 -d", write).group(1)
|
||||
import base64
|
||||
|
||||
assert base64.b64decode(b64).decode() == 'Acquire::http::Proxy "http://c:3142";\n'
|
||||
assert any("dists/trixie/InRelease" in c for c in node.ran)
|
||||
|
||||
def test_another_proxy_is_commented_out(self):
|
||||
node = _AptNode(
|
||||
proxy="http://c:3142",
|
||||
parts='/etc/apt/apt.conf.d/90curtin-aptproxy:1:Acquire::http::Proxy "http://old:3128";\n',
|
||||
)
|
||||
d = ProxmoxDriver("pve", "root@pam", "pw")
|
||||
d._exec_ssh_command = node
|
||||
|
||||
d.configure_package_proxy("http://c:3142")
|
||||
|
||||
assert any(c.startswith("{ sed -i -e '1{") for c in node.ran)
|
||||
|
||||
def test_the_proxy_answers(self):
|
||||
d = ProxmoxDriver("pve", "root@pam", "pw")
|
||||
d._exec_ssh_command = _AptNode()
|
||||
|
||||
result = d.check_package_proxy("http://c:3142/acng-report.html", expect="Cache")
|
||||
|
||||
assert result == {"reachable": True, "expected": True, "error": ""}
|
||||
Reference in new issue
Block a user