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
35 def load_config(self, config=None, config_str=None):
37 config = nmconfig.NodeManagerConfig()
38 if config_str is None:
39 config_str = self.TEST_CONFIG
40 with io.StringIO(config_str) as config_fp:
41 config.readfp(config_fp)
44 def test_seeded_defaults(self):
45 config = nmconfig.NodeManagerConfig()
46 sec_names = set(config.sections())
47 self.assertIn('Arvados', sec_names)
48 self.assertIn('Daemon', sec_names)
49 self.assertFalse(any(name.startswith('Size ') for name in sec_names))
51 def test_list_sizes(self):
52 config = self.load_config()
53 client = config.new_cloud_client()
54 sizes = config.node_sizes(client.list_sizes())
55 self.assertEqual(1, len(sizes))
56 size, kwargs = sizes[0]
57 self.assertEqual('Small', size.name)
58 self.assertEqual(1, kwargs['cores'])
59 self.assertEqual(0.8, kwargs['price'])
61 def test_shutdown_windows(self):
62 config = self.load_config()
63 self.assertEqual([52, 6, 2], config.shutdown_windows())
65 def test_log_levels(self):
66 config = self.load_config()
67 self.assertEqual({'level': logging.DEBUG,
68 'testlogger': logging.INFO},
71 def check_dispatch_classes(self, config, module):
72 setup, shutdown, update, monitor = config.dispatch_classes()
73 self.assertIs(setup, module.ComputeNodeSetupActor)
74 self.assertIs(shutdown, module.ComputeNodeShutdownActor)
75 self.assertIs(update, module.ComputeNodeUpdateActor)
76 self.assertIs(monitor, module.ComputeNodeMonitorActor)
78 def test_default_dispatch(self):
79 config = self.load_config()
80 self.check_dispatch_classes(config, dispatch)
82 def test_custom_dispatch(self):
83 config = self.load_config(
84 config_str=self.TEST_CONFIG + "[Daemon]\ndispatcher=slurm\n")
85 self.check_dispatch_classes(config, slurm_dispatch)