3 from __future__ import absolute_import, print_function
9 import arvnodeman.computenode.dispatch as dispatch
10 import arvnodeman.computenode.dispatch.slurm as slurm_dispatch
11 import arvnodeman.config as nmconfig
13 class NodeManagerConfigTestCase(unittest.TestCase):
17 shutdown_windows = 52, 6, 2
34 def load_config(self, config=None, config_str=None):
36 config = nmconfig.NodeManagerConfig()
37 if config_str is None:
38 config_str = self.TEST_CONFIG
39 with io.StringIO(config_str) as config_fp:
40 config.readfp(config_fp)
43 def test_seeded_defaults(self):
44 config = nmconfig.NodeManagerConfig()
45 sec_names = set(config.sections())
46 self.assertIn('Arvados', sec_names)
47 self.assertIn('Daemon', sec_names)
48 self.assertFalse(any(name.startswith('Size ') for name in sec_names))
50 def test_list_sizes(self):
51 config = self.load_config()
52 client = config.new_cloud_client()
53 sizes = config.node_sizes(client.list_sizes())
54 self.assertEqual(1, len(sizes))
55 size, kwargs = sizes[0]
56 self.assertEqual('Small', size.name)
57 self.assertEqual(1, kwargs['cores'])
59 def test_shutdown_windows(self):
60 config = self.load_config()
61 self.assertEqual([52, 6, 2], config.shutdown_windows())
63 def test_log_levels(self):
64 config = self.load_config()
65 self.assertEqual({'level': logging.DEBUG,
66 'testlogger': logging.INFO},
69 def check_dispatch_classes(self, config, module):
70 setup, shutdown, update, monitor = config.dispatch_classes()
71 self.assertIs(setup, module.ComputeNodeSetupActor)
72 self.assertIs(shutdown, module.ComputeNodeShutdownActor)
73 self.assertIs(update, module.ComputeNodeUpdateActor)
74 self.assertIs(monitor, module.ComputeNodeMonitorActor)
76 def test_default_dispatch(self):
77 config = self.load_config()
78 self.check_dispatch_classes(config, dispatch)
80 def test_custom_dispatch(self):
81 config = self.load_config(
82 config_str=self.TEST_CONFIG + "[Daemon]\ndispatcher=slurm\n")
83 self.check_dispatch_classes(config, slurm_dispatch)