mirror of
https://github.com/thegeeklab/prometheus-pve-sd.git
synced 2024-11-22 01:10:39 +00:00
fix: replace deprecated ruamel.yaml.safe_load (#161)
This commit is contained in:
parent
c6b63909d0
commit
5963668dfa
@ -34,7 +34,7 @@ exclude_tags: []
|
|||||||
pve:
|
pve:
|
||||||
server:
|
server:
|
||||||
user:
|
user:
|
||||||
password
|
password:
|
||||||
auth_timeout: 5
|
auth_timeout: 5
|
||||||
verify_ssl: true
|
verify_ssl: true
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ class Config():
|
|||||||
with open(config, "r", encoding="utf8") as stream:
|
with open(config, "r", encoding="utf8") as stream:
|
||||||
s = stream.read()
|
s = stream.read()
|
||||||
try:
|
try:
|
||||||
file_dict = ruamel.yaml.safe_load(s)
|
file_dict = ruamel.yaml.YAML(typ="safe", pure=True).load(s)
|
||||||
except (
|
except (
|
||||||
ruamel.yaml.composer.ComposerError, ruamel.yaml.scanner.ScannerError
|
ruamel.yaml.composer.ComposerError, ruamel.yaml.scanner.ScannerError
|
||||||
) as e:
|
) as e:
|
||||||
|
24
prometheuspvesd/test/data/config.yml
Normal file
24
prometheuspvesd/test/data/config.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
logging:
|
||||||
|
level: warning
|
||||||
|
format: console
|
||||||
|
|
||||||
|
metrics:
|
||||||
|
enabled: true
|
||||||
|
address: "127.0.0.1"
|
||||||
|
port: 8000
|
||||||
|
|
||||||
|
output_file: dummy
|
||||||
|
loop_delay: 300
|
||||||
|
service: true
|
||||||
|
|
||||||
|
exclude_state: []
|
||||||
|
exclude_vmid: []
|
||||||
|
exclude_tags: []
|
||||||
|
|
||||||
|
pve:
|
||||||
|
server: proxmox.example.com
|
||||||
|
user: root
|
||||||
|
password: secure
|
||||||
|
auth_timeout: 5
|
||||||
|
verify_ssl: true
|
@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
exclude_vmid:
|
|
||||||
- 100
|
|
||||||
- "101"
|
|
6
prometheuspvesd/test/fixtures/fixtures.py
vendored
6
prometheuspvesd/test/fixtures/fixtures.py
vendored
@ -127,9 +127,9 @@ def defaults():
|
|||||||
"output_file": "dummy",
|
"output_file": "dummy",
|
||||||
"pve": {
|
"pve": {
|
||||||
"auth_timeout": 5,
|
"auth_timeout": 5,
|
||||||
"password": "dummypass",
|
"password": "",
|
||||||
"server": "dummyserver",
|
"server": "",
|
||||||
"user": "dummyuser",
|
"user": "",
|
||||||
"verify_ssl": True
|
"verify_ssl": True
|
||||||
},
|
},
|
||||||
"service": True,
|
"service": True,
|
||||||
|
35
prometheuspvesd/test/unit/test_config.py
Normal file
35
prometheuspvesd/test/unit/test_config.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
"""Test Config class."""
|
||||||
|
import pytest
|
||||||
|
import ruamel.yaml
|
||||||
|
|
||||||
|
import prometheuspvesd.exception
|
||||||
|
from prometheuspvesd.config import Config
|
||||||
|
|
||||||
|
pytest_plugins = [
|
||||||
|
"prometheuspvesd.test.fixtures.fixtures",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_yaml_config(mocker, defaults):
|
||||||
|
mocker.patch(
|
||||||
|
"prometheuspvesd.config.default_config_file", "./prometheuspvesd/test/data/config.yml"
|
||||||
|
)
|
||||||
|
config = Config()
|
||||||
|
|
||||||
|
defaults["pve"]["user"] = "root"
|
||||||
|
defaults["pve"]["password"] = "secure"
|
||||||
|
defaults["pve"]["server"] = "proxmox.example.com"
|
||||||
|
|
||||||
|
assert config.config == defaults
|
||||||
|
|
||||||
|
|
||||||
|
def test_yaml_config_error(mocker, capsys):
|
||||||
|
mocker.patch(
|
||||||
|
"prometheuspvesd.config.default_config_file", "./prometheuspvesd/test/data/config.yml"
|
||||||
|
)
|
||||||
|
mocker.patch.object(ruamel.yaml.YAML, "load", side_effect=ruamel.yaml.composer.ComposerError)
|
||||||
|
|
||||||
|
with pytest.raises(prometheuspvesd.exception.ConfigError) as e:
|
||||||
|
Config()
|
||||||
|
|
||||||
|
assert "Unable to read config file ./prometheuspvesd/test/data/config.yml" in str(e.value)
|
Loading…
Reference in New Issue
Block a user