2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 from __future__ import absolute_import, print_function
12 import arvnodeman.computenode.dispatch as dispatch
13 import arvnodeman.computenode.dispatch.slurm as slurm_dispatch
14 import arvnodeman.config as nmconfig
16 class NodeManagerConfigTestCase(unittest.TestCase):
20 shutdown_windows = 52, 6, 2
38 def load_config(self, config=None, config_str=None):
40 config = nmconfig.NodeManagerConfig()
41 if config_str is None:
42 config_str = self.TEST_CONFIG
43 with io.StringIO(config_str) as config_fp:
44 config.readfp(config_fp)
47 def test_seeded_defaults(self):
48 config = nmconfig.NodeManagerConfig()
49 sec_names = set(config.sections())
50 self.assertIn('Arvados', sec_names)
51 self.assertIn('Daemon', sec_names)
52 self.assertFalse(any(name.startswith('Size ') for name in sec_names))
54 def test_list_sizes(self):
55 config = self.load_config()
56 client = config.new_cloud_client()
57 sizes = config.node_sizes(client.list_sizes())
58 self.assertEqual(1, len(sizes))
59 size, kwargs = sizes[0]
60 self.assertEqual('Small', size.name)
61 self.assertEqual(1, kwargs['cores'])
62 self.assertEqual(0.8, kwargs['price'])
64 def test_default_node_mem_scaling(self):
65 config = self.load_config()
66 self.assertEqual(0.95, config.getfloat('Daemon', 'node_mem_scaling'))
68 def test_shutdown_windows(self):
69 config = self.load_config()
70 self.assertEqual([52, 6, 2], config.shutdown_windows())
72 def test_log_levels(self):
73 config = self.load_config()
74 self.assertEqual({'level': logging.DEBUG,
75 'testlogger': logging.INFO},
78 def check_dispatch_classes(self, config, module):
79 setup, shutdown, update, monitor = config.dispatch_classes()
80 self.assertIs(setup, module.ComputeNodeSetupActor)
81 self.assertIs(shutdown, module.ComputeNodeShutdownActor)
82 self.assertIs(update, module.ComputeNodeUpdateActor)
83 self.assertIs(monitor, module.ComputeNodeMonitorActor)
85 def test_default_dispatch(self):
86 config = self.load_config()
87 self.check_dispatch_classes(config, dispatch)
89 def test_custom_dispatch(self):
90 config = self.load_config(
91 config_str=self.TEST_CONFIG + "[Daemon]\ndispatcher=slurm\n")
92 self.check_dispatch_classes(config, slurm_dispatch)