mirror of
https://github.com/thegeeklab/prometheus-pve-sd.git
synced 2024-11-28 12:20:35 +00:00
fix: ensure that label values are strings (#166)
This commit is contained in:
parent
ba10c5467c
commit
264976c2e4
@ -6,17 +6,17 @@ class Host:
|
|||||||
"""Represents a virtual machine or container in PVE."""
|
"""Represents a virtual machine or container in PVE."""
|
||||||
|
|
||||||
def __init__(self, vmid, hostname, ipv4_address, ipv6_address, pve_type):
|
def __init__(self, vmid, hostname, ipv4_address, ipv6_address, pve_type):
|
||||||
self.hostname = hostname
|
self.hostname = str(hostname)
|
||||||
self.ipv4_address = ipv4_address
|
self.ipv4_address = str(ipv4_address)
|
||||||
self.ipv6_address = ipv6_address
|
self.ipv6_address = str(ipv6_address)
|
||||||
self.vmid = vmid
|
self.vmid = str(vmid)
|
||||||
self.pve_type = pve_type
|
self.pve_type = str(pve_type)
|
||||||
self.labels = {}
|
self.labels = {}
|
||||||
self.labels["__meta_pve_ipv4"] = ipv4_address
|
self.add_label("ipv4", ipv4_address)
|
||||||
self.labels["__meta_pve_ipv6"] = ipv6_address
|
self.add_label("ipv6", ipv6_address)
|
||||||
self.labels["__meta_pve_name"] = hostname
|
self.add_label("name", hostname)
|
||||||
self.labels["__meta_pve_type"] = pve_type
|
self.add_label("type", pve_type)
|
||||||
self.labels["__meta_pve_vmid"] = str(vmid)
|
self.add_label("vmid", vmid)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.hostname}({self.vmid}): {self.pve_type} \
|
return f"{self.hostname}({self.vmid}): {self.pve_type} \
|
||||||
|
50
prometheuspvesd/test/unit/test_model.py
Normal file
50
prometheuspvesd/test/unit/test_model.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
"""Test Host class."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from prometheuspvesd.model import Host
|
||||||
|
|
||||||
|
pytest_plugins = [
|
||||||
|
"prometheuspvesd.test.fixtures.fixtures",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"testinput,expected", [
|
||||||
|
({
|
||||||
|
"vmid": 101,
|
||||||
|
"hostname": "host1",
|
||||||
|
"ipv4_address": False,
|
||||||
|
"ipv6_address": False,
|
||||||
|
"pve_type": "qemu",
|
||||||
|
}, {
|
||||||
|
"__meta_pve_vmid": "101",
|
||||||
|
"__meta_pve_name": "host1",
|
||||||
|
"__meta_pve_ipv4": "False",
|
||||||
|
"__meta_pve_ipv6": "False",
|
||||||
|
"__meta_pve_type": "qemu",
|
||||||
|
}),
|
||||||
|
({
|
||||||
|
"vmid": "202",
|
||||||
|
"hostname": "host2",
|
||||||
|
"ipv4_address": "129.168.0.1",
|
||||||
|
"ipv6_address": "2001:db8:3333:4444:5555:6666:7777:8888",
|
||||||
|
"pve_type": "qemu",
|
||||||
|
}, {
|
||||||
|
"__meta_pve_vmid": "202",
|
||||||
|
"__meta_pve_name": "host2",
|
||||||
|
"__meta_pve_ipv4": "129.168.0.1",
|
||||||
|
"__meta_pve_ipv6": "2001:db8:3333:4444:5555:6666:7777:8888",
|
||||||
|
"__meta_pve_type": "qemu",
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_host(mocker, testinput, expected):
|
||||||
|
host = Host(
|
||||||
|
testinput["vmid"],
|
||||||
|
testinput["hostname"],
|
||||||
|
testinput["ipv4_address"],
|
||||||
|
testinput["ipv6_address"],
|
||||||
|
testinput["pve_type"],
|
||||||
|
)
|
||||||
|
|
||||||
|
assert host.labels == expected
|
Loading…
Reference in New Issue
Block a user