4233: bug fix - rounding errors were causing us to miss maxima scrolling off the...
[arvados.git] / services / nodemanager / tests / test_config.py
1 #!/usr/bin/env python
2
3 from __future__ import absolute_import, print_function
4
5 import io
6 import logging
7 import unittest
8
9 import arvnodeman.config as nmconfig
10
11 class NodeManagerConfigTestCase(unittest.TestCase):
12     TEST_CONFIG = u"""
13 [Cloud]
14 provider = dummy
15 shutdown_windows = 52, 6, 2
16
17 [Cloud Credentials]
18 creds = dummy_creds
19
20 [Cloud List]
21 [Cloud Create]
22
23 [Size 1]
24 cores = 1
25
26 [Logging]
27 file = /dev/null
28 level = DEBUG
29 testlogger = INFO
30 """
31
32     def load_config(self, config=None, config_str=None):
33         if config is None:
34             config = nmconfig.NodeManagerConfig()
35         if config_str is None:
36             config_str = self.TEST_CONFIG
37         with io.StringIO(config_str) as config_fp:
38             config.readfp(config_fp)
39         return config
40
41     def test_seeded_defaults(self):
42         config = nmconfig.NodeManagerConfig()
43         sec_names = set(config.sections())
44         self.assertIn('Arvados', sec_names)
45         self.assertIn('Daemon', sec_names)
46         self.assertFalse(any(name.startswith('Size ') for name in sec_names))
47
48     def test_list_sizes(self):
49         config = self.load_config()
50         client = config.new_cloud_client()
51         sizes = config.node_sizes(client.list_sizes())
52         self.assertEqual(1, len(sizes))
53         size, kwargs = sizes[0]
54         self.assertEqual('Small', size.name)
55         self.assertEqual(1, kwargs['cores'])
56
57     def test_shutdown_windows(self):
58         config = self.load_config()
59         self.assertEqual([52, 6, 2], config.shutdown_windows())
60
61     def test_log_levels(self):
62         config = self.load_config()
63         self.assertEqual({'level': logging.DEBUG,
64                           'testlogger': logging.INFO},
65                          config.log_levels())