47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""Keep a narrow node-access update from replacing unrelated recovery settings."""
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
import yaml
|
|
|
|
spec = importlib.util.spec_from_file_location('node_access_config',
|
|
Path(__file__).resolve().parents[2] / 'scripts/configure_ananke_node_access.py')
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
|
|
|
|
class AccessConfigTests(unittest.TestCase):
|
|
def test_unrelated_settings_and_comments_survive(self):
|
|
original = '''# operator comment
|
|
ssh_node_users:
|
|
titan-24: atlas
|
|
titan-12: atlas
|
|
workers:
|
|
- titan-12
|
|
startup:
|
|
host_sudo_secret_namespace: old
|
|
bounded_recovery: true
|
|
timeout: 45
|
|
power:
|
|
shutdown: false
|
|
'''
|
|
result = module.updated_config(original)
|
|
after = yaml.safe_load(result)
|
|
self.assertIn('# operator comment', result)
|
|
self.assertEqual(after['power'], {'shutdown': False})
|
|
self.assertEqual(after['startup']['timeout'], 45)
|
|
self.assertTrue(after['startup']['bounded_recovery'])
|
|
self.assertEqual(after['ssh_node_users']['titan-12'], 'atlas')
|
|
self.assertEqual(after['ssh_node_users']['titan-24'], 'tethys')
|
|
self.assertEqual(after['startup']['host_sudo_secret_namespace'], 'maintenance')
|
|
self.assertEqual(module.updated_config(result), result)
|
|
|
|
def test_unexpected_structure_fails_before_write(self):
|
|
with self.assertRaisesRegex(ValueError, 'unexpected_config_structure'):
|
|
module.updated_config('startup: {}\nssh_node_users: {}\n')
|
|
|
|
def test_missing_peer_override_is_added(self):
|
|
source = '\nssh_node_users:\n titan-12: atlas\nworkers: []\nstartup:\n timeout: 45\n'
|
|
result = yaml.safe_load(module.updated_config(source))
|
|
self.assertEqual(result['ssh_node_users'], {'titan-12': 'atlas', 'titan-24': 'tethys'})
|