fix(hostname): refuse to rename a clustered node
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m20s
driver / test (3.12) (pull_request) Successful in 1m26s
driver / lowest (pull_request) Successful in 43s
driver / test (3.13) (pull_request) Successful in 1m21s
driver / build (pull_request) Successful in 38s
driver / security (pull_request) Successful in 1m20s
CI / driver (pull_request) Successful in 3m12s
driver / publish (pull_request) Skipped

The rename moves /etc/pve/nodes/<old> while the node still runs as <old>,
which Proxmox does not support for a cluster member. set_hostname now
checks for a corosync.conf first and raises before touching anything on
a member, or when the check cannot be read; a single node renames as
before.

The check is the file, not `pvecm status`: pvecm decides membership by
/etc/pve/corosync.conf itself, and its status also fails on a member
whose corosync is down. /etc/corosync/corosync.conf covers a member
whose /etc/pve is not mounted.

Closes #21
This commit is contained in:
Christian Manivong committed 2026-11-01 22:08:54 +01:00
1 parent 9c7b64ba64
commit 8ef880b73b
3 files changed
+66 -8

No files matched your search

+37 -2
View File
@@ -1,4 +1,5 @@
"""set_hostname: what it writes to /etc/hosts (napalm-proxmox#21)."""
"""set_hostname: what it writes to /etc/hosts, and that it leaves a clustered node alone
(napalm-proxmox#21)."""
from __future__ import annotations
@@ -6,6 +7,7 @@ import base64
import re
import pytest
from napalm.base.exceptions import CommandErrorException
from napalm_proxmox import ProxmoxDriver
@@ -18,13 +20,20 @@ HOSTS = """\
class _Node:
"""The node's shell: /etc/hostname reads "pve", /etc/hosts reads HOSTS."""
"""The node's shell: /etc/hostname reads "pve", /etc/hosts reads HOSTS.
*cluster_check* is what the test for a corosync.conf prints: exit status 1
(no corosync.conf, a single node) unless a test says otherwise.
"""
def __init__(self) -> None:
self.ran: list[str] = []
self.cluster_check = "__PVE_RC=1"
def __call__(self, command: str) -> str:
self.ran.append(command)
if "corosync.conf" in command:
return self.cluster_check
if command.startswith("cat /etc/hostname"):
return "pve\n"
if command.startswith("cat /etc/hosts"):
@@ -70,3 +79,29 @@ def test_the_same_name_leaves_hosts_alone(driver, node):
driver.set_hostname("pve")
assert not any("/etc/hosts" in c and "base64 -d" in c for c in node.ran)
def test_a_clustered_node_is_refused_before_anything_changes(driver, node):
node.cluster_check = "__PVE_RC=0"
with pytest.raises(CommandErrorException, match="part of a cluster"):
driver.set_hostname("new")
assert [c for c in node.ran if "corosync.conf" not in c] == []
def test_the_cluster_check_looks_at_both_corosync_confs(driver, node):
driver.set_hostname("new")
check = next(c for c in node.ran if "corosync.conf" in c)
assert "/etc/pve/corosync.conf" in check
assert "/etc/corosync/corosync.conf" in check
def test_an_unreadable_cluster_check_refuses_too(driver, node):
node.cluster_check = ""
with pytest.raises(CommandErrorException, match="could not tell"):
driver.set_hostname("new")
assert [c for c in node.ran if "corosync.conf" not in c] == []