feat!: report hosts and licenses as facts, not warnings (0.2.0)
CI / test (3.10) (push) Successful in 27s
CI / test (3.11) (push) Successful in 25s
CI / test (3.12) (push) Successful in 27s
CI / test (3.10) (pull_request) Successful in 27s
CI / test (3.11) (pull_request) Successful in 24s
CI / test (3.12) (pull_request) Successful in 26s

get_device_warnings is gone; netOrk names the warnings from facts
(netOrk #1111). get_hypervisor_hosts() reports each host's connection
state, maintenance mode, configuration issues and managing vCenter;
get_licenses() the assigned licenses with the edition key as edition,
never the key itself.

The reach stays: the ESXi driver reports connected as None (a
disconnected host could not have answered), and managed_by only for a
host it reached directly. parse/warnings.py is replaced by
parse/hosts.py and parse/licenses.py.
This commit is contained in:
Christian Manivong committed 2026-10-17 09:41:47 +02:00
1 parent 276276bd9f
commit 990dfe2f3c
10 files changed
+154 -100

No files matched your search

+50 -33
View File
@@ -1,13 +1,14 @@
"""Datastores, sensors/utilisation, CDP/LLDP neighbours and raw device warnings."""
"""Datastores, sensors/utilisation, CDP/LLDP neighbours, host and license facts."""
from __future__ import annotations
import pytest
from napalm_vmware.parse.environment import environment
from napalm_vmware.parse.hosts import hypervisor_hosts
from napalm_vmware.parse.licenses import license_list
from napalm_vmware.parse.lldp import lldp_neighbors
from napalm_vmware.parse.storage import storage_pools
from napalm_vmware.parse.warnings import host_warnings
class TestStoragePools:
@@ -125,60 +126,76 @@ class TestLldpNeighbors:
assert lldp_neighbors([]) == {}
class TestHostWarnings:
class TestHypervisorHosts:
"""Facts only (netOrk #1111): which of them is a warning is the caller's call."""
def test_healthy_vcsim_host(self, esxi_host):
assert host_warnings([esxi_host], [], standalone=True) == []
assert hypervisor_hosts([esxi_host], standalone=True) == [
{
"name": "localhost.localdomain",
"connected": None,
"maintenance": False,
"config_issues": [],
"managed_by": None,
}
]
def test_maintenance_mode(self, esxi_host):
esxi_host["runtime.inMaintenanceMode"] = True
assert host_warnings([esxi_host], [], standalone=True) == [
{"code": "vmware_host_maintenance_mode", "meta": {"host": "localhost.localdomain"}}
]
assert hypervisor_hosts([esxi_host], standalone=True)[0]["maintenance"] is True
@pytest.mark.parametrize("state", ["disconnected", "notResponding"])
def test_disconnected_host_under_vcenter(self, esxi_host, state):
esxi_host["runtime.connectionState"] = state
assert host_warnings([esxi_host], [], standalone=False) == [
{
"code": "vmware_host_disconnected",
"meta": {"host": "localhost.localdomain", "state": state},
}
]
assert hypervisor_hosts([esxi_host], standalone=False)[0]["connected"] is False
def test_connected_host_under_vcenter(self, esxi_host):
assert hypervisor_hosts([esxi_host], standalone=False)[0]["connected"] is True
def test_a_standalone_host_cannot_tell(self, esxi_host):
"""A disconnected host could not have answered the ESXi driver."""
esxi_host["runtime.connectionState"] = "disconnected"
assert hypervisor_hosts([esxi_host], standalone=True)[0]["connected"] is None
def test_config_issues(self, esxi_host):
esxi_host["configIssue"] = [
{"fullFormattedMessage": "SSH for the host has been enabled"},
{"fullFormattedMessage": ""},
]
assert host_warnings([esxi_host], [], standalone=True) == [
{
"code": "vmware_host_config_issue",
"meta": {
"host": "localhost.localdomain",
"issues": ["SSH for the host has been enabled"],
},
}
assert hypervisor_hosts([esxi_host], standalone=True)[0]["config_issues"] == [
"SSH for the host has been enabled"
]
def test_standalone_driver_on_a_vcenter_managed_host(self, esxi_host):
esxi_host["summary.managementServerIp"] = "192.0.2.5"
assert host_warnings([esxi_host], [], standalone=True) == [
{"code": "vmware_host_managed_by_vcenter", "meta": {"vcenter": "192.0.2.5"}}
]
assert hypervisor_hosts([esxi_host], standalone=True)[0]["managed_by"] == "192.0.2.5"
@pytest.mark.parametrize("ip", ["", "0.0.0.0", None])
def test_unmanaged(self, esxi_host, ip):
esxi_host["summary.managementServerIp"] = ip
assert hypervisor_hosts([esxi_host], standalone=True)[0]["managed_by"] is None
def test_vcenter_driver_does_not_report_its_own_management(self, esxi_host):
esxi_host["summary.managementServerIp"] = "192.0.2.5"
assert host_warnings([esxi_host], [], standalone=False) == []
assert hypervisor_hosts([esxi_host], standalone=False)[0]["managed_by"] is None
def test_free_license_makes_the_api_read_only(self, esxi_host):
licenses = [{"editionKey": "esxBasic", "name": "VMware vSphere 8 Hypervisor"}]
assert host_warnings([esxi_host], licenses, standalone=True) == [
class TestLicenseList:
def test_the_edition_key_is_the_edition(self):
licenses = [
{
"code": "vmware_api_read_only",
"meta": {"edition": "VMware vSphere 8 Hypervisor"},
"editionKey": "esxBasic",
"name": "VMware vSphere 8 Hypervisor",
"licenseKey": "AAAAA-BBBBB-CCCCC-DDDDD-EEEEE",
}
]
assert license_list(licenses) == [
{"name": "VMware vSphere 8 Hypervisor", "status": "active", "edition": "esxBasic"}
]
def test_evaluation_license_is_not_read_only(self, esxi_host):
licenses = [{"editionKey": "eval", "name": "Evaluation Mode"}]
assert host_warnings([esxi_host], licenses, standalone=True) == []
def test_the_key_is_never_reported(self):
licenses = [{"editionKey": "eval", "name": "Evaluation Mode", "licenseKey": "00000"}]
assert "00000" not in str(license_list(licenses))
def test_none(self):
assert license_list([]) == []