2022-02-26 15:45:02 +00:00
|
|
|
"""Global pytest fixtures."""
|
|
|
|
|
2022-03-06 12:48:40 +00:00
|
|
|
import environs
|
2022-02-26 15:45:02 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-01-24 11:50:39 +00:00
|
|
|
from prometheuspvesd.model import Host, HostList
|
2022-03-28 21:10:38 +00:00
|
|
|
|
2022-02-26 15:45:02 +00:00
|
|
|
|
2022-03-06 12:48:40 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def builtins():
|
|
|
|
return {
|
|
|
|
"metrics.enabled": {
|
|
|
|
"default": True,
|
|
|
|
"env": "METRICS_ENABLED",
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().bool,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"metrics.address": {
|
|
|
|
"default": "127.0.0.1",
|
|
|
|
"env": "METRICS_ADDRESS",
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
2024-01-24 11:50:39 +00:00
|
|
|
"metrics.port": {"default": 8000, "env": "METRICS_PORT", "type": environs.Env().int},
|
|
|
|
"config_file": {"default": "", "env": "CONFIG_FILE", "type": environs.Env().str},
|
2022-03-06 12:48:40 +00:00
|
|
|
"logging.level": {
|
|
|
|
"default": "WARNING",
|
|
|
|
"env": "LOG_LEVEL",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"logging.format": {
|
|
|
|
"default": "console",
|
|
|
|
"env": "LOG_FORMAT",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"output_file": {
|
|
|
|
"default": "dummy",
|
|
|
|
"env": "OUTPUT_FILE",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
2022-03-27 11:36:26 +00:00
|
|
|
"output_file_mode": {
|
|
|
|
"default": "0640",
|
|
|
|
"env": "OUTPUT_FILE_MODE",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-27 11:36:26 +00:00
|
|
|
},
|
2022-03-06 12:48:40 +00:00
|
|
|
"loop_delay": {
|
|
|
|
"default": 300,
|
|
|
|
"env": "LOOP_DELAY",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().int,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
2024-01-24 11:50:39 +00:00
|
|
|
"service": {"default": False, "env": "SERVICE", "file": True, "type": environs.Env().bool},
|
2022-03-06 12:48:40 +00:00
|
|
|
"exclude_state": {
|
|
|
|
"default": [],
|
|
|
|
"env": "EXCLUDE_STATE",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().list,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"exclude_vmid": {
|
|
|
|
"default": [],
|
|
|
|
"env": "EXCLUDE_VMID",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().list,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"exclude_tags": {
|
|
|
|
"default": [],
|
|
|
|
"env": "EXCLUDE_TAGS",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().list,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
2022-03-30 18:48:39 +00:00
|
|
|
"include_vmid": {
|
|
|
|
"default": [],
|
|
|
|
"env": "INCLUDE_VMID",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().list,
|
2022-03-30 18:48:39 +00:00
|
|
|
},
|
|
|
|
"include_tags": {
|
|
|
|
"default": [],
|
|
|
|
"env": "INCLUDE_TAGS",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().list,
|
2022-03-30 18:48:39 +00:00
|
|
|
},
|
2022-03-06 12:48:40 +00:00
|
|
|
"pve.server": {
|
|
|
|
"default": "dummyserver",
|
|
|
|
"env": "PVE_SERVER",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"pve.user": {
|
|
|
|
"default": "dummyuser",
|
|
|
|
"env": "PVE_USER",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"pve.password": {
|
|
|
|
"default": "dummypass",
|
|
|
|
"env": "PVE_PASSWORD",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
2023-09-19 07:00:30 +00:00
|
|
|
"pve.token_name": {
|
|
|
|
"default": "dummyname",
|
|
|
|
"env": "PVE_TOKEN_NAME",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2023-09-19 07:00:30 +00:00
|
|
|
},
|
|
|
|
"pve.token_value": {
|
|
|
|
"default": "dummyvalue",
|
|
|
|
"env": "PVE_TOKEN_VALUE",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().str,
|
2023-09-19 07:00:30 +00:00
|
|
|
},
|
2022-03-06 12:48:40 +00:00
|
|
|
"pve.auth_timeout": {
|
|
|
|
"default": 5,
|
|
|
|
"env": "PVE_AUTH_TIMEOUT",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().int,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"pve.verify_ssl": {
|
|
|
|
"default": True,
|
|
|
|
"env": "PVE_VERIFY_SSL",
|
|
|
|
"file": True,
|
2024-01-24 11:50:39 +00:00
|
|
|
"type": environs.Env().bool,
|
|
|
|
},
|
2022-03-06 12:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def defaults():
|
|
|
|
return {
|
|
|
|
"exclude_state": [],
|
|
|
|
"exclude_tags": [],
|
|
|
|
"exclude_vmid": [],
|
2022-03-30 18:48:39 +00:00
|
|
|
"include_tags": [],
|
|
|
|
"include_vmid": [],
|
2024-01-24 11:50:39 +00:00
|
|
|
"logging": {"format": "console", "level": "WARNING"},
|
2022-03-06 12:48:40 +00:00
|
|
|
"loop_delay": 300,
|
2024-01-24 11:50:39 +00:00
|
|
|
"metrics": {"address": "127.0.0.1", "enabled": True, "port": 8000},
|
2022-03-06 12:48:40 +00:00
|
|
|
"output_file": "dummy",
|
2022-03-27 11:36:26 +00:00
|
|
|
"output_file_mode": "0640",
|
2022-03-06 12:48:40 +00:00
|
|
|
"pve": {
|
|
|
|
"auth_timeout": 5,
|
2022-03-06 22:18:55 +00:00
|
|
|
"password": "",
|
|
|
|
"server": "",
|
|
|
|
"user": "",
|
2023-09-19 07:00:30 +00:00
|
|
|
"token_name": "",
|
|
|
|
"token_value": "",
|
2024-01-24 11:50:39 +00:00
|
|
|
"verify_ssl": True,
|
2022-03-06 12:48:40 +00:00
|
|
|
},
|
|
|
|
"service": True,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-04 20:43:00 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def nodes():
|
2024-01-24 11:50:39 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"level": "",
|
|
|
|
"id": "node/example-node",
|
|
|
|
"disk": 4783488,
|
|
|
|
"cpu": 0.0935113631167406,
|
|
|
|
"maxcpu": 24,
|
|
|
|
"maxmem": 142073272990,
|
|
|
|
"mem": 135884478304,
|
|
|
|
"node": "example-node",
|
|
|
|
"type": "node",
|
|
|
|
"status": "online",
|
|
|
|
"maxdisk": 504209920,
|
|
|
|
"uptime": 200,
|
|
|
|
}
|
|
|
|
]
|
2022-04-04 20:43:00 +00:00
|
|
|
|
|
|
|
|
2022-02-26 15:45:02 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def qemus():
|
2022-02-27 16:56:08 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"diskwrite": 0,
|
|
|
|
"vmid": "100",
|
|
|
|
"name": "100.example.com",
|
|
|
|
"cpu": 0.0202130478509556,
|
|
|
|
"diskread": 0,
|
|
|
|
"template": "",
|
|
|
|
"uptime": 3101505,
|
|
|
|
"maxdisk": 26843545600,
|
|
|
|
"maxmem": 1073741824,
|
|
|
|
"pid": "1765",
|
|
|
|
"cpus": 1,
|
|
|
|
"netin": 2856071643,
|
|
|
|
"disk": 0,
|
|
|
|
"status": "running",
|
|
|
|
"netout": 12159205236,
|
2022-03-03 08:08:27 +00:00
|
|
|
"mem": 496179157,
|
2024-01-24 11:50:39 +00:00
|
|
|
"tags": "unmonitored;excluded;postgres",
|
2022-02-27 16:56:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"diskwrite": 0,
|
|
|
|
"vmid": "101",
|
|
|
|
"name": "101.example.com",
|
|
|
|
"cpu": 0.0202130478509556,
|
|
|
|
"diskread": 0,
|
|
|
|
"template": "",
|
|
|
|
"uptime": 3101505,
|
|
|
|
"maxdisk": 26843545600,
|
|
|
|
"maxmem": 1073741824,
|
|
|
|
"pid": "1765",
|
|
|
|
"cpus": 1,
|
|
|
|
"netin": 2856071643,
|
|
|
|
"disk": 0,
|
|
|
|
"status": "running",
|
|
|
|
"netout": 12159205236,
|
2024-01-24 11:50:39 +00:00
|
|
|
"mem": 496179157,
|
2022-02-27 16:56:08 +00:00
|
|
|
},
|
2022-03-03 08:08:27 +00:00
|
|
|
{
|
|
|
|
"diskwrite": 0,
|
|
|
|
"vmid": "102",
|
|
|
|
"name": "102.example.com",
|
|
|
|
"cpu": 0.0202130478509556,
|
|
|
|
"diskread": 0,
|
|
|
|
"template": "",
|
|
|
|
"uptime": 3101505,
|
|
|
|
"maxdisk": 26843545600,
|
|
|
|
"maxmem": 1073741824,
|
|
|
|
"pid": "1765",
|
|
|
|
"cpus": 1,
|
|
|
|
"netin": 2856071643,
|
|
|
|
"disk": 0,
|
|
|
|
"status": "prelaunch",
|
|
|
|
"netout": 12159205236,
|
|
|
|
"mem": 496179157,
|
2024-01-24 11:50:39 +00:00
|
|
|
"tags": "monitored",
|
2022-03-03 08:08:27 +00:00
|
|
|
},
|
2022-02-27 16:56:08 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-04-04 20:43:00 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def instance_config():
|
|
|
|
return {
|
|
|
|
"name": "102.example.com",
|
|
|
|
"description": '{"groups": "test-group"}',
|
|
|
|
"net0": "virtio=D8-85-75-47-2E-8D,bridge=vmbr122,ip=192.0.2.25,ip=2001:db8::666:77:8888",
|
|
|
|
"cpu": 2,
|
2024-01-24 11:50:39 +00:00
|
|
|
"cores": 2,
|
2022-04-04 20:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def agent_info():
|
|
|
|
return {
|
2024-01-24 11:50:39 +00:00
|
|
|
"supported_commands": [
|
|
|
|
{"name": "guest-network-get-interfaces", "enabled": True, "success-response": True}
|
|
|
|
],
|
|
|
|
"version": "5.2.0",
|
2022-04-04 20:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-27 16:56:08 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def addresses():
|
|
|
|
return {
|
|
|
|
"ipv4_valid": [
|
2022-04-04 20:43:00 +00:00
|
|
|
"192.0.2.1",
|
|
|
|
"198.51.100.1",
|
2022-02-27 16:56:08 +00:00
|
|
|
],
|
|
|
|
"ipv4_invalid": [
|
|
|
|
"127.0.0.1",
|
|
|
|
"169.254.1.1",
|
|
|
|
],
|
|
|
|
"ipv6_valid": [
|
|
|
|
"2001:db8:3333:4444:5555:6666:7777:8888",
|
|
|
|
"2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF",
|
|
|
|
"::",
|
|
|
|
"2001:db8::",
|
|
|
|
"::1234:5678",
|
|
|
|
"2001:db8::1234:5678",
|
|
|
|
"2001:0db8:0001:0000:0000:0ab9:C0A8:0102",
|
|
|
|
],
|
|
|
|
"ipv6_invalid": [
|
|
|
|
"::1",
|
|
|
|
"fe80::903a:1c1a:e802:11e4",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def networks():
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
"hardware-address": "00:00:00:00:00:00",
|
|
|
|
"ip-addresses": [
|
2024-01-24 11:50:39 +00:00
|
|
|
{"ip-address": "127.0.0.1", "ip-address-type": "ipv4", "prefix": 8},
|
|
|
|
{"ip-address": "::1", "ip-address-type": "ipv6", "prefix": 128},
|
2022-02-27 16:56:08 +00:00
|
|
|
],
|
|
|
|
"name": "lo",
|
|
|
|
"statistics": {
|
|
|
|
"rx-bytes": 9280,
|
|
|
|
"rx-dropped": 0,
|
|
|
|
"rx-errs": 0,
|
|
|
|
"rx-packets": 92,
|
|
|
|
"tx-bytes": 9280,
|
|
|
|
"tx-dropped": 0,
|
|
|
|
"tx-errs": 0,
|
2024-01-24 11:50:39 +00:00
|
|
|
"tx-packets": 92,
|
|
|
|
},
|
2022-02-27 16:56:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"hardware-address": "92:0b:bd:c1:f8:39",
|
|
|
|
"ip-addresses": [
|
2024-01-24 11:50:39 +00:00
|
|
|
{"ip-address": "192.0.2.1", "ip-address-type": "ipv4", "prefix": 32},
|
|
|
|
{"ip-address": "192.0.2.4", "ip-address-type": "ipv4", "prefix": 32},
|
2022-02-27 16:56:08 +00:00
|
|
|
{
|
2022-04-04 20:43:00 +00:00
|
|
|
"ip-address": "2001:db8:3333:4444:5555:6666:7777:8888",
|
2022-02-27 16:56:08 +00:00
|
|
|
"ip-address-type": "ipv6",
|
2024-01-24 11:50:39 +00:00
|
|
|
"prefix": 64,
|
2022-02-27 16:56:08 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
"name": "eth0",
|
|
|
|
"statistics": {
|
|
|
|
"rx-bytes": 2861070337,
|
|
|
|
"rx-dropped": 0,
|
|
|
|
"rx-errs": 0,
|
|
|
|
"rx-packets": 18065580,
|
|
|
|
"tx-bytes": 12185866619,
|
|
|
|
"tx-dropped": 0,
|
|
|
|
"tx-errs": 0,
|
2024-01-24 11:50:39 +00:00
|
|
|
"tx-packets": 14423878,
|
|
|
|
},
|
2022-04-06 08:10:29 +00:00
|
|
|
},
|
2024-01-24 11:50:39 +00:00
|
|
|
{"hardware-address": "ba:97:85:bd:9a:a5", "name": "eth1"},
|
2022-02-27 16:56:08 +00:00
|
|
|
]
|
2022-03-28 21:10:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def inventory():
|
|
|
|
hostlist = HostList()
|
2022-04-04 20:43:00 +00:00
|
|
|
hostlist.add_host(Host("100", "100.example.com", "192.0.2.1", False, "qemu"))
|
|
|
|
hostlist.add_host(Host("101", "101.example.com", "192.0.2.2", False, "qemu"))
|
|
|
|
hostlist.add_host(Host("102", "102.example.com", "192.0.2.3", False, "qemu"))
|
2022-03-28 21:10:38 +00:00
|
|
|
|
|
|
|
return hostlist
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def labels():
|
2024-01-24 11:50:39 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"targets": ["100.example.com"],
|
|
|
|
"labels": {
|
|
|
|
"__meta_pve_ipv4": "192.0.2.1",
|
|
|
|
"__meta_pve_ipv6": "False",
|
|
|
|
"__meta_pve_name": "100.example.com",
|
|
|
|
"__meta_pve_type": "qemu",
|
|
|
|
"__meta_pve_vmid": "100",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": ["101.example.com"],
|
|
|
|
"labels": {
|
|
|
|
"__meta_pve_ipv4": "192.0.2.2",
|
|
|
|
"__meta_pve_ipv6": "False",
|
|
|
|
"__meta_pve_name": "101.example.com",
|
|
|
|
"__meta_pve_type": "qemu",
|
|
|
|
"__meta_pve_vmid": "101",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": ["102.example.com"],
|
|
|
|
"labels": {
|
|
|
|
"__meta_pve_ipv4": "192.0.2.3",
|
|
|
|
"__meta_pve_ipv6": "False",
|
|
|
|
"__meta_pve_name": "102.example.com",
|
|
|
|
"__meta_pve_type": "qemu",
|
|
|
|
"__meta_pve_vmid": "102",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|