35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
"""Offline checks for sandbox verification parsing."""
|
|
import importlib.util
|
|
import subprocess
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
spec = importlib.util.spec_from_file_location('sandbox_verify', ROOT / 'scripts/network-sandbox-verify-host.py')
|
|
verify = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(verify)
|
|
|
|
|
|
class SandboxVerifyTests(unittest.TestCase):
|
|
def test_vlan_output(self):
|
|
output = 'port vlan ids\ntap9100i1 1 PVID Egress Untagged\n 10\n 20\n'
|
|
self.assertEqual(verify.vlan_ids(output), {1, 10, 20})
|
|
|
|
def test_expected_client_address(self):
|
|
output = '2: eth0: <UP>\n inet 172.29.210.101/24 scope global eth0\n'
|
|
self.assertEqual(verify.address_from_output(output, '172.29.210.0/24'), '172.29.210.101')
|
|
with self.assertRaises(RuntimeError):
|
|
verify.address_from_output(output, '172.29.220.0/24')
|
|
|
|
def test_ping_failure_explains_why_check_is_inconclusive(self):
|
|
result = subprocess.CompletedProcess([], 1, stdout='', stderr='permission denied')
|
|
with patch.object(verify.subprocess, 'run', return_value=result):
|
|
message = verify.peer_probe(9110, '172.29.210.146', '172.29.220.107')
|
|
self.assertIn('inconclusive', message)
|
|
self.assertIn('permission denied', message)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|