|
33 | 33 | import os
|
34 | 34 | import warnings
|
35 | 35 | import shutil
|
| 36 | +import sys |
| 37 | + |
36 | 38 |
|
37 | 39 | PKEY_FILENAME = os.path.sep.join([os.path.dirname(__file__), 'test_client_private_key'])
|
38 | 40 | USER_KEY = paramiko.RSAKey.from_private_key_file(PKEY_FILENAME)
|
@@ -390,6 +392,60 @@ def test_pssh_client_directory(self):
|
390 | 392 | self.assertTrue(os.path.isfile(path))
|
391 | 393 | shutil.rmtree(local_test_path)
|
392 | 394 | shutil.rmtree(remote_test_path)
|
| 395 | + |
| 396 | + def test_pssh_client_copy_file_failure(self): |
| 397 | + """Test failure scenarios of file copy""" |
| 398 | + test_file_data = 'test' |
| 399 | + local_test_path = 'directory_test' |
| 400 | + remote_test_path = 'directory_test_copied' |
| 401 | + for path in [local_test_path, remote_test_path]: |
| 402 | + mask = int('0700') if sys.version_info <= (2,) else 0o700 |
| 403 | + if os.path.isdir(path): |
| 404 | + os.chmod(path, mask) |
| 405 | + for root, dirs, files in os.walk(path): |
| 406 | + os.chmod(root, mask) |
| 407 | + for _path in files + dirs: |
| 408 | + os.chmod(os.path.join(root, _path), mask) |
| 409 | + try: |
| 410 | + shutil.rmtree(path) |
| 411 | + except OSError: |
| 412 | + pass |
| 413 | + os.mkdir(local_test_path) |
| 414 | + os.mkdir(remote_test_path) |
| 415 | + local_file_path = os.path.join(local_test_path, 'test_file') |
| 416 | + remote_file_path = os.path.join(remote_test_path, 'test_file') |
| 417 | + test_file = open(local_file_path, 'w') |
| 418 | + test_file.write('testing\n') |
| 419 | + test_file.close() |
| 420 | + # Permission errors on writing into dir |
| 421 | + mask = 0111 if sys.version_info <= (2,) else 0o111 |
| 422 | + os.chmod(remote_test_path, mask) |
| 423 | + client = ParallelSSHClient([self.host], port=self.listen_port, |
| 424 | + pkey=self.user_key) |
| 425 | + cmds = client.copy_file(local_test_path, remote_test_path, recurse=True) |
| 426 | + for cmd in cmds: |
| 427 | + try: |
| 428 | + cmd.get() |
| 429 | + raise Exception("Expected IOError exception, got none") |
| 430 | + except IOError: |
| 431 | + pass |
| 432 | + self.assertFalse(os.path.isfile(remote_file_path)) |
| 433 | + # Create directory tree failure test |
| 434 | + local_file_path = os.path.join(local_test_path, 'test_file') |
| 435 | + remote_file_path = os.path.join(remote_test_path, 'test_dir', 'test_file') |
| 436 | + cmds = client.copy_file(local_file_path, remote_file_path, recurse=True) |
| 437 | + for cmd in cmds: |
| 438 | + try: |
| 439 | + cmd.get() |
| 440 | + raise Exception("Expected IOError exception on creating remote " |
| 441 | + "directory, got none") |
| 442 | + except IOError: |
| 443 | + pass |
| 444 | + self.assertFalse(os.path.isfile(remote_file_path)) |
| 445 | + mask = int('0600') if sys.version_info <= (2,) else 0o600 |
| 446 | + os.chmod(remote_test_path, mask) |
| 447 | + for path in [local_test_path, remote_test_path]: |
| 448 | + shutil.rmtree(path) |
393 | 449 |
|
394 | 450 | def test_pssh_pool_size(self):
|
395 | 451 | """Test setting pool size to non default values"""
|
|
0 commit comments