feat: Proxmox VE 9.3 API additions (NetOrk/netork#2728)
On a node running 9.3: HA maintenance over PUT /nodes/{node}/maintenance
(the target node's version decides, SSH below it), the guest uid in
get_vms, the cluster-id as ClusterDict.id, sync-time-on-resume on resume.
get_credential_expiry reads the expiry of the token or account the driver
logged in with; get_update_history lists the node's APT transactions.
Needs napalm-device-types 4.44.0.
This commit is contained in:
1 parent
c2d9d7e75e
commit
fddf8af680
17 files changed
+718
-17
No files matched your search
@@ -0,0 +1,124 @@
|
||||
"""The node's past APT transactions (``UpdateMixin.get_update_history``, NetOrk/netork#2728).
|
||||
|
||||
PVE 9.3 reads apt's history log for ``GET /nodes/{node}/apt/history``, newest
|
||||
first. The payload below follows its schema: a transaction is identified by
|
||||
``start-time`` with ``start-index`` (default 0) among those that started in the
|
||||
same second; ``end-time`` is missing while it runs or after it was interrupted.
|
||||
An older node has no such endpoint, and the driver parses no log over SSH.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
HISTORY = [
|
||||
{
|
||||
"start-time": 1764158400,
|
||||
"start-index": 1,
|
||||
"end-time": 1764158460,
|
||||
"command-line": "apt-get -y dist-upgrade",
|
||||
"requested-by": "admin",
|
||||
"requested-by-uid": 1000,
|
||||
"packages": [
|
||||
{
|
||||
"package": "openssh-server",
|
||||
"action": "upgrade",
|
||||
"arch": "amd64",
|
||||
"old-version": "1:10.0p1-7",
|
||||
"new-version": "1:10.0p1-7+deb13u1",
|
||||
},
|
||||
{
|
||||
"package": "proxmox-kernel-6.17.2-1-pve-signed",
|
||||
"action": "install",
|
||||
"new-version": "6.17.2-1",
|
||||
"automatic": 1,
|
||||
},
|
||||
{"package": "ifupdown", "action": "purge", "old-version": "0.8.44"},
|
||||
],
|
||||
},
|
||||
{
|
||||
# unattended-upgrades, interrupted: no end, no user, the error dpkg left.
|
||||
"start-time": 1764072000,
|
||||
"packages": [
|
||||
{
|
||||
"package": "libssl3t64",
|
||||
"action": "upgrade",
|
||||
"old-version": "3.5.1-1",
|
||||
"new-version": "3.5.1-1+deb13u1",
|
||||
}
|
||||
],
|
||||
"error": "Sub-process /usr/bin/dpkg returned an error code (1)",
|
||||
"running": 0,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def history(driver) -> MagicMock:
|
||||
driver._api.version.get.return_value = {"version": "9.3.0", "release": "9.3"}
|
||||
getter = driver._node_api().apt.history.get
|
||||
getter.return_value = HISTORY
|
||||
return getter
|
||||
|
||||
|
||||
class TestUpdateHistory:
|
||||
def test_transactions_newest_first(self, driver, history):
|
||||
newest, older = driver.get_update_history()
|
||||
assert newest == {
|
||||
"id": "1764158400-1",
|
||||
"start": 1764158400,
|
||||
"end": 1764158460,
|
||||
"packages": [
|
||||
{
|
||||
"name": "openssh-server",
|
||||
"action": "upgrade",
|
||||
"old_version": "1:10.0p1-7",
|
||||
"new_version": "1:10.0p1-7+deb13u1",
|
||||
},
|
||||
{
|
||||
"name": "proxmox-kernel-6.17.2-1-pve-signed",
|
||||
"action": "install",
|
||||
"old_version": None,
|
||||
"new_version": "6.17.2-1",
|
||||
},
|
||||
{
|
||||
"name": "ifupdown",
|
||||
"action": "purge",
|
||||
"old_version": "0.8.44",
|
||||
"new_version": None,
|
||||
},
|
||||
],
|
||||
"requested_by": "admin",
|
||||
"command": "apt-get -y dist-upgrade",
|
||||
"error": None,
|
||||
}
|
||||
assert older["id"] == "1764072000-0"
|
||||
history.assert_called_once_with()
|
||||
|
||||
def test_what_the_log_does_not_keep_is_none(self, driver, history):
|
||||
older = driver.get_update_history()[1]
|
||||
assert older["end"] is None
|
||||
assert older["requested_by"] is None
|
||||
assert older["command"] is None
|
||||
assert older["error"] == "Sub-process /usr/bin/dpkg returned an error code (1)"
|
||||
|
||||
def test_since_is_passed_on(self, driver, history):
|
||||
driver.get_update_history(since=1764100000)
|
||||
history.assert_called_once_with(since=1764100000)
|
||||
|
||||
def test_no_transaction_is_an_empty_list(self, driver, history):
|
||||
history.return_value = []
|
||||
assert driver.get_update_history() == []
|
||||
|
||||
def test_a_failed_read_raises(self, driver, history):
|
||||
history.side_effect = Exception("596 Connection timed out")
|
||||
with pytest.raises(RuntimeError, match="timed out"):
|
||||
driver.get_update_history()
|
||||
|
||||
def test_an_older_node_has_no_history(self, driver, history):
|
||||
driver._api.version.get.return_value = {"version": "9.2.4", "release": "9.2"}
|
||||
with pytest.raises(NotImplementedError):
|
||||
driver.get_update_history()
|
||||
history.assert_not_called()
|
||||
Reference in new issue
Block a user