fix: update node validation error descriptions
Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
1 file changed
+6
-6
@@ -49,22 +49,22 @@ def _validate_distribution(distribution: str) -> None:
|
|||||||
|
|
||||||
def _validate_node(node: dict, node_cidr: str, distribution: str) -> None:
|
def _validate_node(node: dict, node_cidr: str, distribution: str) -> None:
|
||||||
if not node.get("name"):
|
if not node.get("name"):
|
||||||
raise ValueError(f"Node {node.get('name')} is missing a name")
|
raise ValueError(f"A node is missing a name")
|
||||||
if not node.get("username") and distribution not in ["k0s", "k3s"]:
|
if not node.get("username") and distribution not in ["k0s", "k3s"]:
|
||||||
raise ValueError(f"Node {node.get('username')} is missing a username")
|
raise ValueError(f"Node {node.get('name')} is missing a username")
|
||||||
if not node.get("diskSerial") and distribution in ["talos"]:
|
if not node.get("diskSerial") and distribution in ["talos"]:
|
||||||
raise ValueError(f"Node {node.get('diskSerial')} is missing a disk serial")
|
raise ValueError(f"Node {node.get('name')} is missing a disk serial")
|
||||||
if not re.match(r"^[a-z0-9-\.]+$", node.get('name')):
|
if not re.match(r"^[a-z0-9-\.]+$", node.get('name')):
|
||||||
raise ValueError(f"Invalid node name {node.get('name')}")
|
raise ValueError(f"Node {node.get('name')} has an invalid name")
|
||||||
ip = _validate_ip(node.get("address"))
|
ip = _validate_ip(node.get("address"))
|
||||||
if netaddr.IPAddress(ip, 4) not in netaddr.IPNetwork(node_cidr):
|
if netaddr.IPAddress(ip, 4) not in netaddr.IPNetwork(node_cidr):
|
||||||
raise ValueError(f"Node {node.get('address')} is not in the node CIDR {node_cidr}")
|
raise ValueError(f"Node {node.get('name')} is not in the node CIDR {node_cidr}")
|
||||||
port = 50000 if distribution == "talos" else 22
|
port = 50000 if distribution == "talos" else 22
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
sock.settimeout(5)
|
sock.settimeout(5)
|
||||||
result = sock.connect_ex((ip, port))
|
result = sock.connect_ex((ip, port))
|
||||||
if result != 0:
|
if result != 0:
|
||||||
raise ValueError(f"Node {ip} port {port} is not open")
|
raise ValueError(f"Node {node.get('name')} port {port} is not open")
|
||||||
|
|
||||||
def validate_python_version() -> None:
|
def validate_python_version() -> None:
|
||||||
required_version = (3, 11, 0)
|
required_version = (3, 11, 0)
|
||||||
|
|||||||
Reference in new issue
Block a user