-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import os | ||
|
||
os.environ["NO_COLOR"] = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from unittest.mock import patch | ||
from pvecontrol.cluster import PVECluster | ||
from pvecontrol.sanitycheck.tests.vm_backups import VmBackups | ||
from pvecontrol.sanitycheck import SanityCheck | ||
from pvecontrol.sanitycheck.checks import CheckCode | ||
from tests.fixtures.api import mock_api_requests, node, vm, backup_job, backup | ||
from datetime import datetime, timedelta | ||
|
||
|
||
@patch("proxmoxer.backends.https.ProxmoxHTTPAuth") | ||
@patch("proxmoxer.backends.https.ProxmoxHttpSession.request") | ||
def test_sanitycheck_vm_backups(request, _proxmox_http_auth): | ||
nodes = [ | ||
node(1, True), | ||
node(2, True), | ||
] | ||
vms = [ | ||
vm(100, nodes[0]), | ||
vm(101, nodes[0]), | ||
vm(102, nodes[1]), | ||
vm(103, nodes[1]), | ||
] | ||
backup_jobs = [ | ||
backup_job(1, "100"), | ||
backup_job(2, "101"), | ||
backup_job(3, "102"), | ||
] | ||
storages_contents = [ | ||
backup("s3", 100, datetime.now() - timedelta(minutes=110)), | ||
backup("s3", 101, datetime.now() - timedelta(minutes=90)), | ||
] | ||
|
||
request.side_effect = mock_api_requests(nodes, vms, backup_jobs, storages_contents) | ||
|
||
proxmox = PVECluster( | ||
"name", | ||
"host", | ||
"username", | ||
"password", | ||
config={ | ||
"node": { | ||
"cpufactor": 2.5, | ||
"memoryminimum": 81928589934592, | ||
}, | ||
"sanitycheck": { | ||
VmBackups.id: { | ||
"max_last_backup_in_minutes": 100, | ||
}, | ||
}, | ||
}, | ||
timeout=1, | ||
) | ||
|
||
vm_backups_check = VmBackups(proxmox) | ||
vm_backups_check.run() | ||
|
||
def assert_message(message, expected_code, *message_contains): | ||
assert message.code == expected_code | ||
for string in message_contains: | ||
assert string in message.message | ||
|
||
sc = SanityCheck(proxmox) | ||
with patch.object(sc, "_checks", new=[vm_backups_check]): | ||
exitcode = sc.get_exit_code() | ||
sc.display() | ||
|
||
assert exitcode == 1 | ||
assert len(vm_backups_check.messages) == 7 | ||
assert_message(vm_backups_check.messages[0], CheckCode.OK, "vm-100", "is associated") | ||
assert_message(vm_backups_check.messages[1], CheckCode.OK, "vm-101", "is associated") | ||
assert_message(vm_backups_check.messages[2], CheckCode.OK, "vm-102", "is associated") | ||
assert_message(vm_backups_check.messages[3], CheckCode.CRIT, "vm-103", "not associated") | ||
assert_message(vm_backups_check.messages[4], CheckCode.WARN, "vm-100", "more than") | ||
assert_message(vm_backups_check.messages[5], CheckCode.OK, "vm-101", "less than") | ||
assert_message(vm_backups_check.messages[6], CheckCode.WARN, "vm-102", "never") |