feat(clusters): name the backup server behind a pbs storage (#55)
driver / lint (pull_request) Successful in 1m25s
driver / standard (pull_request) Successful in 1m26s
driver / types (pull_request) Successful in 2m17s
driver / test (3.13) (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m15s
driver / lowest (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m4s
driver / build (pull_request) Successful in 50s
CI / driver (pull_request) Successful in 3m31s
driver / publish (pull_request) Skipped

get_clusters() lists a pbs storage like any other, so nothing told an
application which Proxmox Backup Server and datastore it writes to.
Each pbs storage now carries ClusterStorageDict.backup_server
(napalm-device-types 4.25.0): server, port, datastore, namespace and
fingerprint from /storage, never the password or encryption key. An
unreadable /storage leaves it None; other storages carry no such key.

This was step 6 of #52 and was left out there.
This commit is contained in:
Christian Manivong committed 2026-11-03 04:26:09 +01:00
1 parent 983553cf11
commit 44b260b2c4
3 files changed
+97

No files matched your search

+59
View File
@@ -226,6 +226,7 @@ def _api(
api.cluster.ha.status.current.get.return_value = []
api.cluster.ha.rules.get.return_value = []
api.cluster.backup.get.return_value = []
api.storage.get.return_value = []
return api
@@ -505,3 +506,61 @@ class TestCreateOnAnotherNode:
api.cluster.nextid.get.assert_not_called()
for res in [api.nodes(n) for n in ("pve1", "pve2")]:
assert not [c for c in res.mock_calls if "post" in c[0]]
# /storage: what a pbs storage writes to (napalm-device-types 4.25, #55). The password
# and the encryption key are never in this answer's use.
PBS_ROW = _storage_row("pve1", "pbs-01", "pbs", 1, "backup", 1000 * GIB, 30 * GIB)
STORAGE_CONFIG = [
{"storage": "local", "type": "dir", "path": "/var/lib/vz", "content": "iso,backup"},
{
"storage": "pbs-01",
"type": "pbs",
"server": "192.0.2.80",
"port": 8007,
"datastore": "backup",
"namespace": "lab",
"fingerprint": "aa:bb",
"username": "root@pam",
"content": "backup",
},
]
class TestBackupServerRef:
def _storages(self, config):
api = _api(resources=[*CLUSTER_RESOURCES, PBS_ROW])
if isinstance(config, Exception):
api.storage.get.side_effect = config
else:
api.storage.get.return_value = config
return _by_name(_driver(api).get_clusters()[0]["storages"])
def test_a_pbs_storage_names_its_server(self):
assert self._storages(STORAGE_CONFIG)["pbs-01"]["backup_server"] == {
"server": "192.0.2.80",
"port": 8007,
"datastore": "backup",
"namespace": "lab",
"fingerprint": "aa:bb",
}
def test_what_it_does_not_set_is_none(self):
bare = [{"storage": "pbs-01", "type": "pbs", "server": "pbs.example.com", "datastore": "b"}]
assert self._storages(bare)["pbs-01"]["backup_server"] == {
"server": "pbs.example.com",
"port": None,
"datastore": "b",
"namespace": None,
"fingerprint": None,
}
def test_other_storages_carry_no_reference(self):
storages = self._storages(STORAGE_CONFIG)
assert "backup_server" not in storages["local-lvm"]
assert "backup_server" not in storages["ceph-vm"]
def test_an_unreadable_storage_config_says_none(self):
storages = self._storages(PermissionError("403 Forbidden"))
assert storages["pbs-01"]["backup_server"] is None
assert "backup_server" not in storages["local-lvm"]