| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Unit test for CLI.Config""" |
| 5 |
|
| 6 |
import resource |
| 7 |
import os.path |
| 8 |
import shutil |
| 9 |
import tempfile |
| 10 |
from textwrap import dedent |
| 11 |
import unittest |
| 12 |
|
| 13 |
from .TLib import * |
| 14 |
|
| 15 |
from ClusterShell.CLI.Clush import set_fdlimit |
| 16 |
from ClusterShell.CLI.Config import ClushConfig, ClushConfigError |
| 17 |
from ClusterShell.CLI.Display import * |
| 18 |
from ClusterShell.CLI.OptionParser import OptionParser |
| 19 |
|
| 20 |
|
| 21 |
class CLIClushConfigTest(unittest.TestCase): |
| 22 |
"""This test case performs a complete CLI.Config.ClushConfig |
| 23 |
verification. Also CLI.OptionParser is used and some parts are |
| 24 |
verified btw. |
| 25 |
""" |
| 26 |
def testClushConfigEmpty(self): |
| 27 |
"""test CLI.Config.ClushConfig (empty)""" |
| 28 |
|
| 29 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 30 |
f.write(b"\n") |
| 31 |
|
| 32 |
parser = OptionParser("dummy") |
| 33 |
parser.install_clush_config_options() |
| 34 |
parser.install_display_options(verbose_options=True) |
| 35 |
parser.install_connector_options() |
| 36 |
options, _ = parser.parse_args([]) |
| 37 |
config = ClushConfig(options, filename=f.name) |
| 38 |
self.assertEqual(config.color, THREE_CHOICES[0]) |
| 39 |
self.assertEqual(config.verbosity, VERB_STD) |
| 40 |
self.assertEqual(config.fanout, 64) |
| 41 |
self.assertEqual(config.maxrc, False) |
| 42 |
self.assertEqual(config.node_count, True) |
| 43 |
self.assertEqual(config.connect_timeout, 10) |
| 44 |
self.assertEqual(config.command_timeout, 0) |
| 45 |
self.assertEqual(config.ssh_user, None) |
| 46 |
self.assertEqual(config.ssh_path, None) |
| 47 |
self.assertEqual(config.ssh_options, None) |
| 48 |
f.close() |
| 49 |
|
| 50 |
def testClushConfigAlmostEmpty(self): |
| 51 |
"""test CLI.Config.ClushConfig (almost empty)""" |
| 52 |
|
| 53 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 54 |
f.write("[Main]\n".encode()) |
| 55 |
|
| 56 |
parser = OptionParser("dummy") |
| 57 |
parser.install_clush_config_options() |
| 58 |
parser.install_display_options(verbose_options=True) |
| 59 |
parser.install_connector_options() |
| 60 |
options, _ = parser.parse_args([]) |
| 61 |
config = ClushConfig(options, filename=f.name) |
| 62 |
self.assertEqual(config.color, THREE_CHOICES[0]) |
| 63 |
self.assertEqual(config.verbosity, VERB_STD) |
| 64 |
self.assertEqual(config.maxrc, False) |
| 65 |
self.assertEqual(config.node_count, True) |
| 66 |
self.assertEqual(config.fanout, 64) |
| 67 |
self.assertEqual(config.connect_timeout, 10) |
| 68 |
self.assertEqual(config.command_timeout, 0) |
| 69 |
self.assertEqual(config.ssh_user, None) |
| 70 |
self.assertEqual(config.ssh_path, None) |
| 71 |
self.assertEqual(config.ssh_options, None) |
| 72 |
f.close() |
| 73 |
|
| 74 |
def testClushConfigDefault(self): |
| 75 |
"""test CLI.Config.ClushConfig (default)""" |
| 76 |
|
| 77 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 78 |
f.write(dedent(""" |
| 79 |
[Main] |
| 80 |
fanout: 42 |
| 81 |
connect_timeout: 14 |
| 82 |
command_timeout: 0 |
| 83 |
history_size: 100 |
| 84 |
color: auto |
| 85 |
verbosity: 1 |
| 86 |
#ssh_user: root |
| 87 |
#ssh_path: /usr/bin/ssh |
| 88 |
#ssh_options: -oStrictHostKeyChecking=no""").encode()) |
| 89 |
f.flush() |
| 90 |
parser = OptionParser("dummy") |
| 91 |
parser.install_clush_config_options() |
| 92 |
parser.install_display_options(verbose_options=True) |
| 93 |
parser.install_connector_options() |
| 94 |
options, _ = parser.parse_args([]) |
| 95 |
config = ClushConfig(options, filename=f.name) |
| 96 |
display = Display(options, config) |
| 97 |
display.vprint(VERB_STD, "test") |
| 98 |
display.vprint(VERB_DEBUG, "shouldn't see this") |
| 99 |
self.assertEqual(config.color, THREE_CHOICES[-1]) |
| 100 |
self.assertEqual(config.verbosity, VERB_STD) |
| 101 |
self.assertEqual(config.maxrc, False) |
| 102 |
self.assertEqual(config.node_count, True) |
| 103 |
self.assertEqual(config.fanout, 42) |
| 104 |
self.assertEqual(config.connect_timeout, 14) |
| 105 |
self.assertEqual(config.command_timeout, 0) |
| 106 |
self.assertEqual(config.ssh_user, None) |
| 107 |
self.assertEqual(config.ssh_path, None) |
| 108 |
self.assertEqual(config.ssh_options, None) |
| 109 |
f.close() |
| 110 |
|
| 111 |
def testClushConfigFull(self): |
| 112 |
"""test CLI.Config.ClushConfig (full)""" |
| 113 |
|
| 114 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 115 |
f.write(dedent(""" |
| 116 |
[Main] |
| 117 |
fanout: 42 |
| 118 |
connect_timeout: 14 |
| 119 |
command_timeout: 0 |
| 120 |
history_size: 100 |
| 121 |
color: auto |
| 122 |
maxrc: yes |
| 123 |
node_count: yes |
| 124 |
verbosity: 1 |
| 125 |
ssh_user: root |
| 126 |
ssh_path: /usr/bin/ssh |
| 127 |
ssh_options: -oStrictHostKeyChecking=no |
| 128 |
""").encode()) |
| 129 |
|
| 130 |
f.flush() |
| 131 |
parser = OptionParser("dummy") |
| 132 |
parser.install_clush_config_options() |
| 133 |
parser.install_display_options(verbose_options=True) |
| 134 |
parser.install_connector_options() |
| 135 |
options, _ = parser.parse_args([]) |
| 136 |
config = ClushConfig(options, filename=f.name) |
| 137 |
self.assertEqual(config.color, THREE_CHOICES[-1]) |
| 138 |
self.assertEqual(config.verbosity, VERB_STD) |
| 139 |
self.assertEqual(config.maxrc, True) |
| 140 |
self.assertEqual(config.node_count, True) |
| 141 |
self.assertEqual(config.fanout, 42) |
| 142 |
self.assertEqual(config.connect_timeout, 14) |
| 143 |
self.assertEqual(config.command_timeout, 0) |
| 144 |
self.assertEqual(config.ssh_user, "root") |
| 145 |
self.assertEqual(config.ssh_path, "/usr/bin/ssh") |
| 146 |
self.assertEqual(config.ssh_options, "-oStrictHostKeyChecking=no") |
| 147 |
f.close() |
| 148 |
|
| 149 |
def testClushConfigError(self): |
| 150 |
"""test CLI.Config.ClushConfig (error)""" |
| 151 |
|
| 152 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 153 |
f.write(dedent(""" |
| 154 |
[Main] |
| 155 |
fanout: 3.2 |
| 156 |
connect_timeout: foo |
| 157 |
command_timeout: bar |
| 158 |
history_size: 100 |
| 159 |
color: maybe |
| 160 |
node_count: 3 |
| 161 |
verbosity: bar |
| 162 |
ssh_user: root |
| 163 |
ssh_path: /usr/bin/ssh |
| 164 |
ssh_options: -oStrictHostKeyChecking=no |
| 165 |
""").encode()) |
| 166 |
|
| 167 |
f.flush() |
| 168 |
parser = OptionParser("dummy") |
| 169 |
parser.install_clush_config_options() |
| 170 |
parser.install_display_options(verbose_options=True) |
| 171 |
parser.install_connector_options() |
| 172 |
options, _ = parser.parse_args([]) |
| 173 |
config = ClushConfig(options, filename=f.name) |
| 174 |
try: |
| 175 |
c = config.color |
| 176 |
self.fail("Exception ClushConfigError not raised (color)") |
| 177 |
except ClushConfigError: |
| 178 |
pass |
| 179 |
self.assertEqual(config.verbosity, 0) |
| 180 |
try: |
| 181 |
f = config.fanout |
| 182 |
self.fail("Exception ClushConfigError not raised (fanout)") |
| 183 |
except ClushConfigError: |
| 184 |
pass |
| 185 |
try: |
| 186 |
f = config.node_count |
| 187 |
self.fail("Exception ClushConfigError not raised (node_count)") |
| 188 |
except ClushConfigError: |
| 189 |
pass |
| 190 |
try: |
| 191 |
f = config.fanout |
| 192 |
except ClushConfigError as e: |
| 193 |
self.assertEqual(str(e)[0:20], "(Config Main.fanout)") |
| 194 |
|
| 195 |
try: |
| 196 |
t = config.connect_timeout |
| 197 |
self.fail("Exception ClushConfigError not raised (connect_timeout)") |
| 198 |
except ClushConfigError: |
| 199 |
pass |
| 200 |
try: |
| 201 |
m = config.command_timeout |
| 202 |
self.fail("Exception ClushConfigError not raised (command_timeout)") |
| 203 |
except ClushConfigError: |
| 204 |
pass |
| 205 |
f.close() |
| 206 |
|
| 207 |
def testClushConfigSetRlimit(self): |
| 208 |
"""test CLI.Config.ClushConfig (setrlimit)""" |
| 209 |
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 210 |
hard2 = min(32768, hard) |
| 211 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 212 |
f.write(dedent(""" |
| 213 |
[Main] |
| 214 |
fanout: 42 |
| 215 |
connect_timeout: 14 |
| 216 |
command_timeout: 0 |
| 217 |
history_size: 100 |
| 218 |
color: auto |
| 219 |
fd_max: %d |
| 220 |
verbosity: 1 |
| 221 |
""" % hard2).encode()) |
| 222 |
f.flush() |
| 223 |
parser = OptionParser("dummy") |
| 224 |
parser.install_clush_config_options() |
| 225 |
parser.install_display_options(verbose_options=True) |
| 226 |
parser.install_connector_options() |
| 227 |
options, _ = parser.parse_args([]) |
| 228 |
config = ClushConfig(options, filename=f.name) |
| 229 |
display = Display(options, config) |
| 230 |
|
| 231 |
|
| 232 |
resource.setrlimit(resource.RLIMIT_NOFILE, (hard2//2, hard)) |
| 233 |
|
| 234 |
set_fdlimit(config.fd_max, display) |
| 235 |
|
| 236 |
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 237 |
self.assertEqual(soft, hard2) |
| 238 |
f.close() |
| 239 |
|
| 240 |
def testClushConfigSetRlimitValueError(self): |
| 241 |
"""test CLI.Config.ClushConfig (setrlimit ValueError)""" |
| 242 |
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 243 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 244 |
f.write(dedent(""" |
| 245 |
[Main] |
| 246 |
fanout: 42 |
| 247 |
connect_timeout: 14 |
| 248 |
command_timeout: 0 |
| 249 |
history_size: 100 |
| 250 |
color: auto |
| 251 |
# Use wrong fd_max value to generate ValueError |
| 252 |
fd_max: -1 |
| 253 |
verbosity: 1""").encode()) |
| 254 |
f.flush() |
| 255 |
parser = OptionParser("dummy") |
| 256 |
parser.install_clush_config_options() |
| 257 |
parser.install_display_options(verbose_options=True) |
| 258 |
parser.install_connector_options() |
| 259 |
options, _ = parser.parse_args([]) |
| 260 |
config = ClushConfig(options, filename=f.name) |
| 261 |
f.close() |
| 262 |
display = Display(options, config) |
| 263 |
|
| 264 |
class TestException(Exception): pass |
| 265 |
|
| 266 |
def mock_vprint_err(level, message): |
| 267 |
if message.startswith('Warning: Failed to set max open files'): |
| 268 |
raise TestException() |
| 269 |
|
| 270 |
display.vprint_err = mock_vprint_err |
| 271 |
self.assertRaises(TestException, set_fdlimit, config.fd_max, display) |
| 272 |
|
| 273 |
soft2, _ = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 274 |
self.assertEqual(soft, soft2) |
| 275 |
|
| 276 |
def testClushConfigDefaultWithOptions(self): |
| 277 |
"""test CLI.Config.ClushConfig (default with options)""" |
| 278 |
|
| 279 |
f = tempfile.NamedTemporaryFile(prefix='testclushconfig') |
| 280 |
f.write(dedent(""" |
| 281 |
[Main] |
| 282 |
fanout: 42 |
| 283 |
connect_timeout: 14 |
| 284 |
command_timeout: 0 |
| 285 |
history_size: 100 |
| 286 |
color: auto |
| 287 |
verbosity: 1""").encode()) |
| 288 |
f.flush() |
| 289 |
parser = OptionParser("dummy") |
| 290 |
parser.install_clush_config_options() |
| 291 |
parser.install_display_options(verbose_options=True) |
| 292 |
parser.install_connector_options() |
| 293 |
options, _ = parser.parse_args(["-f", "36", "-u", "3", "-t", "7", |
| 294 |
"--user", "foobar", "--color", |
| 295 |
"always", "-d", "-v", "-q", "-o", |
| 296 |
"-oSomething"]) |
| 297 |
config = ClushConfig(options, filename=f.name) |
| 298 |
display = Display(options, config) |
| 299 |
display.vprint(VERB_STD, "test") |
| 300 |
display.vprint(VERB_DEBUG, "test") |
| 301 |
self.assertEqual(config.color, THREE_CHOICES[2]) |
| 302 |
self.assertEqual(config.verbosity, VERB_DEBUG) |
| 303 |
self.assertEqual(config.fanout, 36) |
| 304 |
self.assertEqual(config.connect_timeout, 7) |
| 305 |
self.assertEqual(config.command_timeout, 3) |
| 306 |
self.assertEqual(config.ssh_user, "foobar") |
| 307 |
self.assertEqual(config.ssh_path, None) |
| 308 |
self.assertEqual(config.ssh_options, "-oSomething") |
| 309 |
f.close() |
| 310 |
|
| 311 |
def testClushConfigWithInstalledConfig(self): |
| 312 |
"""test CLI.Config.ClushConfig (installed config required)""" |
| 313 |
|
| 314 |
|
| 315 |
parser = OptionParser("dummy") |
| 316 |
parser.install_clush_config_options() |
| 317 |
parser.install_display_options(verbose_options=True) |
| 318 |
parser.install_connector_options() |
| 319 |
options, _ = parser.parse_args([]) |
| 320 |
config = ClushConfig(options) |
| 321 |
|
| 322 |
def testClushConfigCustomGlobal(self): |
| 323 |
"""test CLI.Config.ClushConfig (CLUSTERSHELL_CFGDIR global custom config) |
| 324 |
""" |
| 325 |
|
| 326 |
|
| 327 |
custom_config_save = os.environ.get('CLUSTERSHELL_CFGDIR') |
| 328 |
|
| 329 |
|
| 330 |
custom_cfg_dir = make_temp_dir() |
| 331 |
|
| 332 |
try: |
| 333 |
os.environ['CLUSTERSHELL_CFGDIR'] = custom_cfg_dir.name |
| 334 |
|
| 335 |
cfgfile = open(os.path.join(custom_cfg_dir.name, 'clush.conf'), 'w') |
| 336 |
cfgfile.write(dedent(""" |
| 337 |
[Main] |
| 338 |
fanout: 42 |
| 339 |
connect_timeout: 14 |
| 340 |
command_timeout: 0 |
| 341 |
history_size: 100 |
| 342 |
color: never |
| 343 |
verbosity: 2 |
| 344 |
ssh_user: joebar |
| 345 |
ssh_path: ~/bin/ssh |
| 346 |
ssh_options: -oSomeDummyUserOption=yes |
| 347 |
""")) |
| 348 |
|
| 349 |
cfgfile.flush() |
| 350 |
parser = OptionParser("dummy") |
| 351 |
parser.install_clush_config_options() |
| 352 |
parser.install_display_options(verbose_options=True) |
| 353 |
parser.install_connector_options() |
| 354 |
options, _ = parser.parse_args([]) |
| 355 |
config = ClushConfig(options) |
| 356 |
self.assertEqual(config.color, THREE_CHOICES[1]) |
| 357 |
self.assertEqual(config.verbosity, VERB_VERB) |
| 358 |
self.assertEqual(config.fanout, 42) |
| 359 |
self.assertEqual(config.connect_timeout, 14) |
| 360 |
self.assertEqual(config.command_timeout, 0) |
| 361 |
self.assertEqual(config.ssh_user, 'joebar') |
| 362 |
self.assertEqual(config.ssh_path, '~/bin/ssh') |
| 363 |
self.assertEqual(config.ssh_options, '-oSomeDummyUserOption=yes') |
| 364 |
cfgfile.close() |
| 365 |
|
| 366 |
finally: |
| 367 |
if custom_config_save: |
| 368 |
os.environ['CLUSTERSHELL_CFGDIR'] = custom_config_save |
| 369 |
else: |
| 370 |
del os.environ['CLUSTERSHELL_CFGDIR'] |
| 371 |
custom_cfg_dir.cleanup() |
| 372 |
|
| 373 |
|
| 374 |
def testClushConfigUserOverride(self): |
| 375 |
"""test CLI.Config.ClushConfig (XDG_CONFIG_HOME user config)""" |
| 376 |
|
| 377 |
xdg_config_home_save = os.environ.get('XDG_CONFIG_HOME') |
| 378 |
|
| 379 |
|
| 380 |
tdir = make_temp_dir() |
| 381 |
try: |
| 382 |
os.environ['XDG_CONFIG_HOME'] = tdir.name |
| 383 |
|
| 384 |
|
| 385 |
usercfgdir = os.path.join(tdir.name, 'clustershell') |
| 386 |
os.mkdir(usercfgdir) |
| 387 |
cfgfile = open(os.path.join(usercfgdir, 'clush.conf'), 'w') |
| 388 |
cfgfile.write(dedent(""" |
| 389 |
[Main] |
| 390 |
fanout: 42 |
| 391 |
connect_timeout: 14 |
| 392 |
command_timeout: 0 |
| 393 |
history_size: 100 |
| 394 |
color: never |
| 395 |
verbosity: 2 |
| 396 |
ssh_user: trump |
| 397 |
ssh_path: ~/bin/ssh |
| 398 |
ssh_options: -oSomeDummyUserOption=yes |
| 399 |
""")) |
| 400 |
|
| 401 |
cfgfile.flush() |
| 402 |
parser = OptionParser("dummy") |
| 403 |
parser.install_clush_config_options() |
| 404 |
parser.install_display_options(verbose_options=True) |
| 405 |
parser.install_connector_options() |
| 406 |
options, _ = parser.parse_args([]) |
| 407 |
config = ClushConfig(options) |
| 408 |
self.assertEqual(config.color, THREE_CHOICES[1]) |
| 409 |
self.assertEqual(config.verbosity, VERB_VERB) |
| 410 |
self.assertEqual(config.fanout, 42) |
| 411 |
self.assertEqual(config.connect_timeout, 14) |
| 412 |
self.assertEqual(config.command_timeout, 0) |
| 413 |
self.assertEqual(config.ssh_user, 'trump') |
| 414 |
self.assertEqual(config.ssh_path, '~/bin/ssh') |
| 415 |
self.assertEqual(config.ssh_options, '-oSomeDummyUserOption=yes') |
| 416 |
cfgfile.close() |
| 417 |
|
| 418 |
finally: |
| 419 |
if xdg_config_home_save: |
| 420 |
os.environ['XDG_CONFIG_HOME'] = xdg_config_home_save |
| 421 |
else: |
| 422 |
del os.environ['XDG_CONFIG_HOME'] |
| 423 |
tdir.cleanup() |
| 424 |
|
| 425 |
def testClushConfigConfDirModesEmpty(self): |
| 426 |
"""test CLI.Config.ClushConfig (confdir with no modes)""" |
| 427 |
tdir1 = make_temp_dir() |
| 428 |
dname1 = tdir1.name |
| 429 |
tdir2 = make_temp_dir() |
| 430 |
dname2 = tdir2.name |
| 431 |
f = make_temp_file(dedent(""" |
| 432 |
[Main] |
| 433 |
fanout: 42 |
| 434 |
connect_timeout: 14 |
| 435 |
command_timeout: 0 |
| 436 |
history_size: 100 |
| 437 |
color: auto |
| 438 |
maxrc: yes |
| 439 |
node_count: yes |
| 440 |
verbosity: 1 |
| 441 |
confdir: %s "%s" %s |
| 442 |
""" % (dname1, dname2, dname1)).encode()) |
| 443 |
|
| 444 |
try: |
| 445 |
parser = OptionParser("dummy") |
| 446 |
parser.install_clush_config_options() |
| 447 |
parser.install_display_options(verbose_options=True) |
| 448 |
parser.install_connector_options() |
| 449 |
options, _ = parser.parse_args([]) |
| 450 |
config = ClushConfig(options, filename=f.name) |
| 451 |
self.assertEqual(config.color, THREE_CHOICES[-1]) |
| 452 |
self.assertEqual(config.verbosity, VERB_STD) |
| 453 |
self.assertTrue(config.maxrc) |
| 454 |
self.assertTrue(config.node_count) |
| 455 |
self.assertEqual(config.fanout, 42) |
| 456 |
self.assertEqual(config.connect_timeout, 14) |
| 457 |
self.assertEqual(config.command_timeout, 0) |
| 458 |
self.assertEqual(config.ssh_user, None) |
| 459 |
self.assertEqual(config.ssh_path, None) |
| 460 |
self.assertEqual(config.ssh_options, None) |
| 461 |
self.assertEqual(config.command_prefix, "") |
| 462 |
self.assertFalse(config.command_prefix) |
| 463 |
self.assertFalse(config.password_prompt) |
| 464 |
|
| 465 |
self.assertEqual(len(set(config.modes())), 0) |
| 466 |
|
| 467 |
self.assertRaises(ClushConfigError, config.set_mode, "sshpass") |
| 468 |
finally: |
| 469 |
f.close() |
| 470 |
tdir2.cleanup() |
| 471 |
tdir1.cleanup() |
| 472 |
|
| 473 |
|
| 474 |
def testClushConfigConfDirModes(self): |
| 475 |
"""test CLI.Config.ClushConfig (confdir and modes)""" |
| 476 |
tdir1 = make_temp_dir() |
| 477 |
dname1 = tdir1.name |
| 478 |
tdir2 = make_temp_dir() |
| 479 |
dname2 = tdir2.name |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
f = make_temp_file(dedent(""" |
| 485 |
[Main] |
| 486 |
fanout: 42 |
| 487 |
connect_timeout: 14 |
| 488 |
command_timeout: 0 |
| 489 |
history_size: 100 |
| 490 |
color: auto |
| 491 |
maxrc: yes |
| 492 |
node_count: yes |
| 493 |
verbosity: 1 |
| 494 |
ssh_user: root |
| 495 |
ssh_path: /usr/bin/ssh |
| 496 |
ssh_options: -oStrictHostKeyChecking=no |
| 497 |
confdir: %s "%s" %s |
| 498 |
""" % (dname1, dname2, dname1)).encode()) |
| 499 |
|
| 500 |
f1 = make_temp_file(dedent(""" |
| 501 |
[mode:sshpass] |
| 502 |
password_prompt: yes |
| 503 |
ssh_path: /usr/bin/sshpass /usr/bin/ssh |
| 504 |
scp_path: /usr/bin/sshpass /usr/bin/scp |
| 505 |
ssh_options: -oBatchMode=no |
| 506 |
""").encode(), suffix=".conf", dir=dname1) |
| 507 |
|
| 508 |
f2 = make_temp_file(dedent(""" |
| 509 |
[mode:sudo] |
| 510 |
password_prompt: yes |
| 511 |
command_prefix: /usr/bin/sudo -S -p "''" |
| 512 |
""").encode(), suffix=".conf", dir=dname2) |
| 513 |
|
| 514 |
f3 = make_temp_file(dedent(""" |
| 515 |
[mode:test] |
| 516 |
fanout: 100 |
| 517 |
connect_timeout: 6 |
| 518 |
command_timeout: 5 |
| 519 |
history_size: 200 |
| 520 |
color: always |
| 521 |
maxrc: no |
| 522 |
node_count: no |
| 523 |
verbosity: 0 |
| 524 |
ssh_user: nobody |
| 525 |
ssh_path: /some/other/ssh |
| 526 |
ssh_options: |
| 527 |
""").encode(), suffix=".conf", dir=dname2) |
| 528 |
|
| 529 |
try: |
| 530 |
parser = OptionParser("dummy") |
| 531 |
parser.install_clush_config_options() |
| 532 |
parser.install_display_options(verbose_options=True) |
| 533 |
parser.install_connector_options() |
| 534 |
options, _ = parser.parse_args([]) |
| 535 |
config = ClushConfig(options, filename=f.name) |
| 536 |
self.assertEqual(config.color, THREE_CHOICES[-1]) |
| 537 |
self.assertEqual(config.verbosity, VERB_STD) |
| 538 |
self.assertTrue(config.maxrc) |
| 539 |
self.assertTrue(config.node_count) |
| 540 |
self.assertEqual(config.fanout, 42) |
| 541 |
self.assertEqual(config.connect_timeout, 14) |
| 542 |
self.assertEqual(config.command_timeout, 0) |
| 543 |
self.assertEqual(config.ssh_user, "root") |
| 544 |
self.assertEqual(config.ssh_path, "/usr/bin/ssh") |
| 545 |
self.assertEqual(config.ssh_options, "-oStrictHostKeyChecking=no") |
| 546 |
self.assertEqual(config.command_prefix, "") |
| 547 |
self.assertFalse(config.command_prefix) |
| 548 |
self.assertFalse(config.password_prompt) |
| 549 |
|
| 550 |
self.assertEqual(set(config.modes()), {'sshpass', 'sudo', 'test'}) |
| 551 |
|
| 552 |
config.set_mode("sshpass") |
| 553 |
self.assertEqual(config.color, THREE_CHOICES[-1]) |
| 554 |
self.assertEqual(config.verbosity, VERB_STD) |
| 555 |
self.assertTrue(config.maxrc) |
| 556 |
self.assertTrue(config.node_count) |
| 557 |
self.assertEqual(config.fanout, 42) |
| 558 |
self.assertEqual(config.connect_timeout, 14) |
| 559 |
self.assertEqual(config.command_timeout, 0) |
| 560 |
self.assertEqual(config.ssh_user, "root") |
| 561 |
self.assertEqual(config.ssh_path, "/usr/bin/sshpass /usr/bin/ssh") |
| 562 |
self.assertEqual(config.ssh_options, "-oBatchMode=no") |
| 563 |
self.assertEqual(config.command_prefix, "") |
| 564 |
self.assertFalse(config.command_prefix) |
| 565 |
self.assertTrue(config.password_prompt) |
| 566 |
|
| 567 |
config.set_mode("sudo") |
| 568 |
self.assertEqual(config.color, THREE_CHOICES[-1]) |
| 569 |
self.assertEqual(config.verbosity, VERB_STD) |
| 570 |
self.assertTrue(config.maxrc) |
| 571 |
self.assertTrue(config.node_count) |
| 572 |
self.assertEqual(config.fanout, 42) |
| 573 |
self.assertEqual(config.connect_timeout, 14) |
| 574 |
self.assertEqual(config.command_timeout, 0) |
| 575 |
self.assertEqual(config.ssh_user, "root") |
| 576 |
self.assertEqual(config.ssh_path, "/usr/bin/ssh") |
| 577 |
self.assertEqual(config.ssh_options, "-oStrictHostKeyChecking=no") |
| 578 |
self.assertEqual(config.command_prefix, '/usr/bin/sudo -S -p "\'\'"') |
| 579 |
self.assertTrue(config.command_prefix) |
| 580 |
self.assertTrue(config.password_prompt) |
| 581 |
|
| 582 |
config.set_mode("test") |
| 583 |
self.assertEqual(config.color, THREE_CHOICES[2]) |
| 584 |
self.assertEqual(config.verbosity, VERB_STD) |
| 585 |
self.assertFalse(config.maxrc) |
| 586 |
self.assertFalse(config.node_count) |
| 587 |
self.assertEqual(config.fanout, 100) |
| 588 |
self.assertEqual(config.connect_timeout, 6) |
| 589 |
self.assertEqual(config.command_timeout, 5) |
| 590 |
self.assertEqual(config.ssh_user, "nobody") |
| 591 |
self.assertEqual(config.ssh_path, "/some/other/ssh") |
| 592 |
self.assertEqual(config.ssh_options, "") |
| 593 |
self.assertEqual(config.command_prefix, "") |
| 594 |
self.assertFalse(config.command_prefix) |
| 595 |
self.assertFalse(config.password_prompt) |
| 596 |
finally: |
| 597 |
f3.close() |
| 598 |
f2.close() |
| 599 |
f1.close() |
| 600 |
f.close() |
| 601 |
tdir2.cleanup() |
| 602 |
tdir1.cleanup() |