forked from cea-hpc/clustershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultsTest.py
274 lines (243 loc) · 10.1 KB
/
DefaultsTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# ClusterShell.Defaults test suite
# Written by S. Thiell
"""Unit test for ClusterShell.Defaults"""
import os
import sys
import shutil
from textwrap import dedent
import unittest
from TLib import make_temp_file, make_temp_dir
from ClusterShell.Defaults import Defaults, _task_print_debug
from ClusterShell.Task import task_self, task_terminate
from ClusterShell.Worker.Pdsh import WorkerPdsh
from ClusterShell.Worker.Ssh import WorkerSsh
class Defaults000NoConfigTest(unittest.TestCase):
def setUp(self):
"""setup test - initialize Defaults instance"""
self.defaults = Defaults([])
def test_000_initial(self):
"""test Defaults initial values"""
# nodeset
self.assertEqual(self.defaults.fold_axis, ())
# task_default
self.assertFalse(self.defaults.stderr)
self.assertTrue(self.defaults.stdout_msgtree)
self.assertTrue(self.defaults.stderr_msgtree)
self.assertEqual(self.defaults.engine, 'auto')
self.assertEqual(self.defaults.port_qlimit, 100)
self.assertTrue(self.defaults.auto_tree)
self.assertEqual(self.defaults.local_workername, 'exec')
self.assertEqual(self.defaults.distant_workername, 'ssh')
# task_info
self.assertFalse(self.defaults.debug)
self.assertEqual(self.defaults.print_debug, _task_print_debug)
self.assertFalse(self.defaults.print_debug is None)
self.assertEqual(self.defaults.fanout, 64)
self.assertEqual(self.defaults.grooming_delay, 0.25)
self.assertEqual(self.defaults.connect_timeout, 10)
self.assertEqual(self.defaults.command_timeout, 0)
def test_001_setattr(self):
"""test Defaults setattr"""
# nodeset
self.defaults.fold_axis = (0, 2)
self.assertEqual(self.defaults.fold_axis, (0, 2))
# task_default
self.defaults.stderr = True
self.assertTrue(self.defaults.stderr)
self.defaults.stdout_msgtree = False
self.assertFalse(self.defaults.stdout_msgtree)
self.defaults.stderr_msgtree = False
self.assertFalse(self.defaults.stderr_msgtree)
self.defaults.engine = 'select'
self.assertEqual(self.defaults.engine, 'select')
self.defaults.port_qlimit = 1000
self.assertEqual(self.defaults.port_qlimit, 1000)
self.defaults.auto_tree = False
self.assertFalse(self.defaults.auto_tree)
self.defaults.local_workername = 'none'
self.assertEqual(self.defaults.local_workername, 'none')
self.defaults.distant_workername = 'pdsh'
self.assertEqual(self.defaults.distant_workername, 'pdsh')
# task_info
self.defaults.debug = True
self.assertTrue(self.defaults.debug)
self.defaults.print_debug = None
self.assertEqual(self.defaults.print_debug, None)
self.defaults.fanout = 256
self.assertEqual(self.defaults.fanout, 256)
self.defaults.grooming_delay = 0.5
self.assertEqual(self.defaults.grooming_delay, 0.5)
self.defaults.connect_timeout = 12.5
self.assertEqual(self.defaults.connect_timeout, 12.5)
self.defaults.connect_timeout = 30.5
def test_002_reinit_defaults(self):
"""Test Defaults manual reinit"""
# For testing purposes only
self.defaults.__init__(filenames=[])
self.test_000_initial()
def test_004_workerclass(self):
"""test Defaults workerclass"""
self.defaults.distant_workername = 'pdsh'
task_terminate()
task = task_self(self.defaults)
self.assertTrue(task.default("distant_worker") is WorkerPdsh)
self.defaults.distant_workername = 'ssh'
self.assertTrue(task.default("distant_worker") is WorkerPdsh)
task_terminate()
task = task_self(self.defaults)
self.assertTrue(task.default("distant_worker") is WorkerSsh)
task_terminate()
tdir = make_temp_dir()
modfile = open(os.path.join(tdir.name, 'OutOfTree.py'), 'w')
modfile.write(dedent("""
class OutOfTreeWorker(object):
pass
WORKER_CLASS = OutOfTreeWorker"""))
modfile.flush()
modfile.close()
sys.path.append(tdir.name)
self.defaults.distant_workername = 'OutOfTree'
task = task_self(self.defaults)
self.assertEqual(task.default("distant_worker").__name__, 'OutOfTreeWorker')
task_terminate()
tdir.cleanup()
def test_005_misc_value_errors(self):
"""test Defaults misc value errors"""
task_terminate()
self.defaults.local_workername = 'dummy1'
self.assertRaises(ImportError, task_self, self.defaults)
self.defaults.local_workername = 'exec'
self.defaults.distant_workername = 'dummy2'
self.assertRaises(ImportError, task_self, self.defaults)
self.defaults.distant_workername = 'ssh'
self.defaults.engine = 'unknown'
self.assertRaises(KeyError, task_self, self.defaults)
self.defaults.engine = 'auto'
task = task_self(self.defaults)
self.assertEqual(task.default('engine'), 'auto')
task_terminate()
class Defaults001ConfigTest(unittest.TestCase):
def setUp(self):
self.defaults = None
def _assert_default_values(self):
# nodeset
self.assertEqual(self.defaults.fold_axis, ())
# task_default
self.assertFalse(self.defaults.stderr)
self.assertTrue(self.defaults.stdout_msgtree)
self.assertTrue(self.defaults.stderr_msgtree)
self.assertEqual(self.defaults.engine, 'auto')
self.assertEqual(self.defaults.port_qlimit, 100)
self.assertTrue(self.defaults.auto_tree)
self.assertEqual(self.defaults.local_workername, 'exec')
self.assertEqual(self.defaults.distant_workername, 'ssh')
# task_info
self.assertFalse(self.defaults.debug)
self.assertEqual(self.defaults.print_debug, _task_print_debug)
self.assertFalse(self.defaults.print_debug is None)
self.assertEqual(self.defaults.fanout, 64)
self.assertEqual(self.defaults.grooming_delay, 0.25)
self.assertEqual(self.defaults.connect_timeout, 10)
self.assertEqual(self.defaults.command_timeout, 0)
def test_000_empty(self):
"""test Defaults config file (empty)"""
conf_test = make_temp_file(b'')
self.defaults = Defaults(filenames=[conf_test.name])
self._assert_default_values()
def test_001_defaults(self):
"""test Defaults config file (defaults)"""
conf_test = make_temp_file(dedent("""
[nodeset]
fold_axis:
[task.default]
stderr: false
stdout_msgtree: true
stderr_msgtree: true
engine: auto
port_qlimit: 100
auto_tree: true
local_workername: exec
distant_workername: ssh
[task.info]
debug: false
fanout: 64
grooming_delay: 0.25
connect_timeout: 10
command_timeout: 0""").encode('ascii'))
self.defaults = Defaults(filenames=[conf_test.name])
self._assert_default_values()
def test_002_changed(self):
"""test Defaults config file (changed)"""
conf_test = make_temp_file(dedent("""
[nodeset]
fold_axis: -1
[task.default]
stderr: true
stdout_msgtree: false
stderr_msgtree: false
engine: select
port_qlimit: 1000
auto_tree: false
local_workername: none
distant_workername: pdsh
[task.info]
debug: true
fanout: 256
grooming_delay: 0.5
connect_timeout: 12.5
command_timeout: 30.5""").encode('ascii'))
self.defaults = Defaults(filenames=[conf_test.name])
# nodeset
self.assertEqual(self.defaults.fold_axis, (-1,))
# task_default
self.assertTrue(self.defaults.stderr)
self.assertFalse(self.defaults.stdout_msgtree)
self.assertFalse(self.defaults.stderr_msgtree)
self.assertEqual(self.defaults.engine, 'select')
self.assertEqual(self.defaults.port_qlimit, 1000) # 1.8 compat
self.assertFalse(self.defaults.auto_tree)
self.assertEqual(self.defaults.local_workername, 'none')
self.assertEqual(self.defaults.distant_workername, 'pdsh')
# task_info
self.assertTrue(self.defaults.debug)
self.assertEqual(self.defaults.fanout, 256)
self.assertEqual(self.defaults.grooming_delay, 0.5)
self.assertEqual(self.defaults.connect_timeout, 12.5)
def test_003_engine(self):
"""test Defaults config file (engine section)"""
conf_test = make_temp_file(dedent("""
[nodeset]
fold_axis: -1
[task.default]
stderr: true
stdout_msgtree: false
stderr_msgtree: false
engine: select
auto_tree: false
local_workername: none
distant_workername: pdsh
[task.info]
debug: true
fanout: 256
grooming_delay: 0.5
connect_timeout: 12.5
command_timeout: 30.5
[engine]
port_qlimit: 1000""").encode('ascii'))
self.defaults = Defaults(filenames=[conf_test.name])
# nodeset
self.assertEqual(self.defaults.fold_axis, (-1,))
# task_default
self.assertTrue(self.defaults.stderr)
self.assertFalse(self.defaults.stdout_msgtree)
self.assertFalse(self.defaults.stderr_msgtree)
self.assertEqual(self.defaults.engine, 'select')
self.assertEqual(self.defaults.port_qlimit, 1000)
self.assertFalse(self.defaults.auto_tree)
self.assertEqual(self.defaults.local_workername, 'none')
self.assertEqual(self.defaults.distant_workername, 'pdsh')
# task_info
self.assertTrue(self.defaults.debug)
self.assertEqual(self.defaults.fanout, 256)
self.assertEqual(self.defaults.grooming_delay, 0.5)
self.assertEqual(self.defaults.connect_timeout, 12.5)