"""`get_log_sources`: which logs the node writes, and which service writes each. pveproxy, pvedaemon, the Ceph daemons and a backup server's proxy write to journald and to files under ``/var/log``. The command and its parse are napalm-device-types'; the driver only carries the command over its exec path, which already runs as root (NetOrk/netork#2049). """ from __future__ import annotations from unittest.mock import patch from napalm_device_types import LogSourcesMixin from napalm_proxmox.backup_driver import ProxmoxBackupDriver from napalm_proxmox.driver import ProxmoxDriver WIRE = ( "LOGS_BEGIN\n[journald]\npveproxy.service\n" "[open]\n/proc/2101/fd/7 /var/log/pveproxy/access.log\n" "[stat]\n/proc/2101/fd/7 4096 1762250200\n" "[cgroups]\n2101 0::/system.slice/pveproxy.service\n" "[comm]\n2101 pveproxy worker\n" "LOGS_END\n" ) def test_both_drivers_declare_the_contract(): assert issubclass(ProxmoxDriver, LogSourcesMixin) assert issubclass(ProxmoxBackupDriver, LogSourcesMixin) def test_it_reads_as_root_over_the_exec_path(driver): with patch.object(driver, "_exec_ssh_command", return_value=WIRE) as exec_: reading = driver.get_log_sources() [command] = [c.args[0] for c in exec_.call_args_list] assert command.startswith("sh -c '") assert reading["attributed"] is True access = [s for s in reading["sources"] if s["kind"] == "file"] assert [(s["path"], s["unit"]) for s in access] == [ ("/var/log/pveproxy/access.log", "pveproxy") ]