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
44 def load_config(self, config=None, config_str=None):
46 config = nmconfig.NodeManagerConfig()
47 if config_str is None:
48 config_str = self.TEST_CONFIG
49 with io.StringIO(config_str) as config_fp:
50 config.readfp(config_fp)
53 def test_seeded_defaults(self):
54 config = nmconfig.NodeManagerConfig()
55 sec_names = set(config.sections())
56 self.assertIn('Arvados', sec_names)
57 self.assertIn('Daemon', sec_names)
58 self.assertFalse(any(name.startswith('Size ') for name in sec_names))
60 def test_list_sizes(self):
61 config = self.load_config()
62 sizes = config.node_sizes()
63 self.assertEqual(2, len(sizes))
64 size, kwargs = sizes[0]
65 self.assertEqual('Small', size.name)
66 self.assertEqual(1, kwargs['cores'])
67 self.assertEqual(0.8, kwargs['price'])
68 # preemptible is False by default
69 self.assertEqual(False, kwargs['preemptible'])
70 # instance_type == arvados node size id by default
71 self.assertEqual(kwargs['id'], kwargs['instance_type'])
72 # Now retrieve the preemptible version
73 size, kwargs = sizes[1]
74 self.assertEqual('Small', size.name)
75 self.assertEqual('1.preemptible', kwargs['id'])
76 self.assertEqual(1, kwargs['cores'])
77 self.assertEqual(0.8, kwargs['price'])
78 self.assertEqual(True, kwargs['preemptible'])
79 self.assertEqual('1', kwargs['instance_type'])
82 def test_default_node_mem_scaling(self):
83 config = self.load_config()
84 self.assertEqual(0.95, config.getfloat('Daemon', 'node_mem_scaling'))
86 def test_shutdown_windows(self):
87 config = self.load_config()
88 self.assertEqual([52, 6, 2], config.shutdown_windows())
90 def test_log_levels(self):
91 config = self.load_config()
92 self.assertEqual({'level': logging.DEBUG,
93 'testlogger': logging.INFO},
96 def check_dispatch_classes(self, config, module):
97 setup, shutdown, update, monitor = config.dispatch_classes()
98 self.assertIs(setup, module.ComputeNodeSetupActor)
99 self.assertIs(shutdown, module.ComputeNodeShutdownActor)
100 self.assertIs(update, module.ComputeNodeUpdateActor)
101 self.assertIs(monitor, module.ComputeNodeMonitorActor)
103 def test_default_dispatch(self):
104 config = self.load_config()
105 self.check_dispatch_classes(config, dispatch)
107 def test_custom_dispatch(self):
108 config = self.load_config(
109 config_str=self.TEST_CONFIG + "[Daemon]\ndispatcher=slurm\n")
110 self.check_dispatch_classes(config, slurm_dispatch)