Proxmox Backup Server speaks the same REST dialect, logs in the same way and runs on Debian too, so what a second driver needs moves out of ProxmoxDriver first: - napalm_proxmox._base: the connection (proxmoxer service PVE or PBS, each with its port), the token split, the SSH session, run_command, the node helpers and the DMI read. - napalm_proxmox.host_mixin: packages and APT updates, the subscription, restart and shutdown through the API, root file writes and the transports of the host readers (kernel, listening sockets, identity, systemd, host status, apt's proxy). The PVE driver behaves as before; what it hands proxmoxer is pinned by tests first, and it now names service="PVE" explicitly. get_packages is split so the dpkg line parser stands alone; get_facts and get_packages leave the quality baseline.
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""What the PVE driver hands proxmoxer, pinned before the connection moved into a
|
|
base it shares with the Proxmox Backup Server driver (#52)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from napalm_proxmox.driver import ProxmoxDriver
|
|
from tests.conftest import _build_mock_api
|
|
|
|
|
|
def _kwargs(username: str = "root", password: str = "secret", **optional_args) -> dict:
|
|
drv = ProxmoxDriver("pve1", username, password, optional_args=optional_args)
|
|
with patch("napalm_proxmox.driver.ProxmoxAPI", return_value=_build_mock_api()) as api:
|
|
drv.open()
|
|
return api.call_args.kwargs
|
|
|
|
|
|
def test_password_login_on_the_pve_port():
|
|
assert _kwargs() == {
|
|
"host": "pve1",
|
|
"user": "root@pam",
|
|
"password": "secret",
|
|
"port": 8006,
|
|
"verify_ssl": True,
|
|
"backend": "https",
|
|
"service": "PVE",
|
|
}
|
|
|
|
|
|
def test_port_and_realm_from_the_arguments():
|
|
kwargs = _kwargs(port=443, realm="pve")
|
|
assert (kwargs["port"], kwargs["user"]) == (443, "root@pve")
|
|
|
|
|
|
def test_a_username_with_a_realm_keeps_it():
|
|
assert _kwargs("admin@ldap")["user"] == "admin@ldap"
|
|
|
|
|
|
@pytest.mark.parametrize("arg", ["verify_ssl", "ssl_verify", "verify"])
|
|
def test_tls_verification_under_each_name(arg):
|
|
assert _kwargs(**{arg: False})["verify_ssl"] is False
|
|
|
|
|
|
def test_token_without_a_user_part_is_passed_as_given():
|
|
kwargs = _kwargs(token_name="mytoken", token_value="s3cret")
|
|
assert (kwargs["user"], kwargs["token_name"], kwargs["token_value"]) == (
|
|
"root@pam",
|
|
"mytoken",
|
|
"s3cret",
|
|
)
|
|
assert "password" not in kwargs
|