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_default_node_mem_scaling(self):
62 config = self.load_config()
63 self.assertEqual(0.95, config.getfloat('Daemon', 'node_mem_scaling'))
65 def test_shutdown_windows(self):
66 config = self.load_config()
67 self.assertEqual([52, 6, 2], config.shutdown_windows())
69 def test_log_levels(self):
70 config = self.load_config()
71 self.assertEqual({'level': logging.DEBUG,
72 'testlogger': logging.INFO},
75 def check_dispatch_classes(self, config, module):
76 setup, shutdown, update, monitor = config.dispatch_classes()
77 self.assertIs(setup, module.ComputeNodeSetupActor)
78 self.assertIs(shutdown, module.ComputeNodeShutdownActor)
79 self.assertIs(update, module.ComputeNodeUpdateActor)
80 self.assertIs(monitor, module.ComputeNodeMonitorActor)
82 def test_default_dispatch(self):
83 config = self.load_config()
84 self.check_dispatch_classes(config, dispatch)
86 def test_custom_dispatch(self):
87 config = self.load_config(
88 config_str=self.TEST_CONFIG + "[Daemon]\ndispatcher=slurm\n")
89 self.check_dispatch_classes(config, slurm_dispatch)