@@ -288,181 +288,181 @@ def test_pssh_client_retries(self):
288288# for cmd in cmds:
289289# self.assertRaises(ConnectionErrorException, cmd.get)
290290
291- def test_pssh_copy_file (self ):
292- """Test parallel copy file"""
293- test_file_data = 'test'
294- local_filename = 'test_file'
295- remote_test_dir , remote_filename = 'remote_test_dir' , 'test_file_copy'
296- remote_filename = os .path .sep .join ([remote_test_dir , remote_filename ])
297- remote_file_abspath = os .path .expanduser ('~/' + remote_filename )
298- remote_test_dir_abspath = os .path .expanduser ('~/' + remote_test_dir )
299- test_file = open (local_filename , 'w' )
300- test_file .writelines ([test_file_data + os .linesep ])
301- test_file .close ()
302- cmds = self .client .copy_file (local_filename , remote_filename )
303- cmds [0 ].get ()
304- try :
305- self .assertTrue (os .path .isdir (remote_test_dir_abspath ))
306- self .assertTrue (os .path .isfile (remote_file_abspath ))
307- remote_file_data = open (remote_file_abspath , 'r' ).readlines ()
308- self .assertEqual (remote_file_data [0 ].strip (), test_file_data )
309- except Exception :
310- raise
311- finally :
312- for filepath in [local_filename , remote_file_abspath ]:
313- os .unlink (filepath )
314- shutil .rmtree (remote_test_dir_abspath )
315-
316- def test_pssh_client_directory (self ):
317- """Tests copying multiple directories with SSH client. Copy all the files from
318- local directory to server, then make sure they are all present."""
319- test_file_data = 'test'
320- local_test_path = 'directory_test'
321- remote_test_path = 'directory_test_copied'
322- dir_name = os .path .dirname (__file__ )
323- remote_test_path_abs = os .sep .join (
324- (dir_name , remote_test_path ))
325- for path in [local_test_path , remote_test_path_abs ]:
326- try :
327- shutil .rmtree (path )
328- except OSError :
329- pass
330- os .mkdir (local_test_path )
331- remote_file_paths = []
332- for i in range (0 , 10 ):
333- local_file_path_dir = os .path .join (
334- local_test_path , 'sub_dir1' , 'sub_dir2' , 'dir_foo' + str (i ))
335- os .makedirs (local_file_path_dir )
336- local_file_path = os .path .join (local_file_path_dir , 'foo' + str (i ))
337- remote_file_path = os .path .join (
338- remote_test_path , 'sub_dir1' , 'sub_dir2' , 'dir_foo' + str (i ), 'foo' + str (i ))
339- remote_file_paths .append (
340- os .sep .join ((os .path .dirname (__file__ ), remote_file_path )))
341- test_file = open (local_file_path , 'w' )
342- test_file .write (test_file_data )
343- test_file .close ()
344- cmds = self .client .copy_file (local_test_path , remote_test_path_abs , recurse = True )
345- gevent .joinall (cmds , raise_error = True )
346- for path in remote_file_paths :
347- self .assertTrue (os .path .isfile (path ))
348- shutil .rmtree (local_test_path )
349- shutil .rmtree (os .sep .join ((os .path .dirname (__file__ ), remote_test_path )))
350-
351- def test_pssh_client_copy_file_failure (self ):
352- """Test failure scenarios of file copy"""
353- test_file_data = 'test'
354- local_test_path = 'directory_test'
355- remote_test_path = 'directory_test_copied'
356- dir_name = os .path .dirname (__file__ )
357- remote_test_path_abs = os .sep .join ((dir_name , remote_test_path ))
358- for path in [local_test_path , remote_test_path_abs ]:
359- mask = int ('0700' ) if sys .version_info <= (2 ,) else 0o700
360- if os .path .isdir (path ):
361- os .chmod (path , mask )
362- for root , dirs , files in os .walk (path ):
363- os .chmod (root , mask )
364- for _path in files + dirs :
365- os .chmod (os .path .join (root , _path ), mask )
366- try :
367- shutil .rmtree (path )
368- except OSError :
369- pass
370- os .mkdir (local_test_path )
371- os .mkdir (remote_test_path_abs )
372- local_file_path = os .path .join (local_test_path , 'test_file' )
373- remote_file_path = os .path .join (remote_test_path , 'test_file' )
374- remote_test_path_abs = os .sep .join ((dir_name , remote_test_path ))
375- test_file = open (local_file_path , 'w' )
376- test_file .write ('testing\n ' )
377- test_file .close ()
378- # Permission errors on writing into dir
379- mask = int ('0111' ) if sys .version_info <= (2 ,) else 0o111
380- os .chmod (remote_test_path_abs , mask )
381- cmds = self .client .copy_file (local_test_path , remote_test_path_abs , recurse = True )
382- try :
383- gevent .joinall (cmds , raise_error = True )
384- raise Exception ("Expected SFTPError exception" )
385- except SFTPError :
386- pass
387- self .assertFalse (os .path .isfile (remote_test_path_abs ))
388- # Create directory tree failure test
389- local_file_path = os .path .join (local_test_path , 'test_file' )
390- remote_file_path = os .path .join (remote_test_path , 'test_dir' , 'test_file' )
391- remote_test_path_abs = os .sep .join ((dir_name , remote_test_path ))
392- cmds = self .client .copy_file (local_file_path , remote_test_path_abs , recurse = True )
393- try :
394- gevent .joinall (cmds , raise_error = True )
395- raise Exception ("Expected SFTPError exception on creating remote "
396- "directory" )
397- except SFTPError :
398- pass
399- self .assertFalse (os .path .isfile (remote_test_path_abs ))
400- mask = int ('0600' ) if sys .version_info <= (2 ,) else 0o600
401- os .chmod (remote_test_path_abs , mask )
402- for path in [local_test_path , remote_test_path_abs ]:
403- shutil .rmtree (path )
404-
405- def test_pssh_copy_remote_file_failure (self ):
406- cmds = self .client .copy_remote_file (
407- 'fakey fakey fake fake' , 'equally fake' )
408- self .assertRaises (SFTPIOError , cmds [0 ].get )
409-
410- def test_pssh_copy_remote_file (self ):
411- """Test parallel copy file to local host"""
412- test_file_data = 'test'
413- dir_name = os .path .dirname (__file__ )
414- local_test_path = os .sep .join ((dir_name , 'directory_test_local_remote_copied' ))
415- remote_test_path = 'directory_test_remote_copy'
416- remote_test_path_abs = os .sep .join ((dir_name , remote_test_path ))
417- local_copied_dir = '_' .join ([local_test_path , self .host ])
418- new_local_copied_dir = '.' .join ([local_test_path , self .host ])
419- for path in [local_test_path , remote_test_path_abs , local_copied_dir ,
420- new_local_copied_dir ]:
421- try :
422- shutil .rmtree (path )
423- except OSError :
424- try :
425- os .unlink (path )
426- except Exception :
427- pass
428- pass
429- os .mkdir (remote_test_path_abs )
430- local_file_paths = []
431- for i in range (0 , 10 ):
432- remote_file_path_dir = os .path .join (
433- remote_test_path_abs , 'sub_dir' , 'dir_foo' + str (i ))
434- os .makedirs (remote_file_path_dir )
435- remote_file_path = os .path .join (remote_file_path_dir , 'foo' + str (i ))
436- local_file_path = os .path .join (
437- local_copied_dir , 'sub_dir' , 'dir_foo' + str (i ), 'foo' + str (i ))
438- local_file_paths .append (local_file_path )
439- test_file = open (remote_file_path , 'w' )
440- test_file .write (test_file_data )
441- test_file .close ()
442- cmds = self .client .copy_remote_file (remote_test_path_abs , local_test_path )
443- self .assertRaises (ValueError , gevent .joinall , cmds , raise_error = True )
444- cmds = self .client .copy_remote_file (remote_test_path_abs , local_test_path ,
445- recurse = True )
446- gevent .joinall (cmds , raise_error = True )
447- try :
448- self .assertTrue (os .path .isdir (local_copied_dir ))
449- for path in local_file_paths :
450- self .assertTrue (os .path .isfile (path ))
451- except Exception :
452- shutil .rmtree (remote_test_path_abs )
453- finally :
454- shutil .rmtree (local_copied_dir )
455- cmds = self .client .copy_remote_file (remote_test_path_abs , local_test_path ,
456- suffix_separator = '.' , recurse = True )
457- gevent .joinall (cmds , raise_error = True )
458- new_local_copied_dir = '.' .join ([local_test_path , self .host ])
459- try :
460- for path in local_file_paths :
461- path = path .replace (local_copied_dir , new_local_copied_dir )
462- self .assertTrue (os .path .isfile (path ))
463- finally :
464- shutil .rmtree (new_local_copied_dir )
465- shutil .rmtree (remote_test_path_abs )
291+ # def test_pssh_copy_file(self):
292+ # """Test parallel copy file"""
293+ # test_file_data = 'test'
294+ # local_filename = 'test_file'
295+ # remote_test_dir, remote_filename = 'remote_test_dir', 'test_file_copy'
296+ # remote_filename = os.path.sep.join([remote_test_dir, remote_filename])
297+ # remote_file_abspath = os.path.expanduser('~/' + remote_filename)
298+ # remote_test_dir_abspath = os.path.expanduser('~/' + remote_test_dir)
299+ # test_file = open(local_filename, 'w')
300+ # test_file.writelines([test_file_data + os.linesep])
301+ # test_file.close()
302+ # cmds = self.client.copy_file(local_filename, remote_filename)
303+ # cmds[0].get()
304+ # try:
305+ # self.assertTrue(os.path.isdir(remote_test_dir_abspath))
306+ # self.assertTrue(os.path.isfile(remote_file_abspath))
307+ # remote_file_data = open(remote_file_abspath, 'r').readlines()
308+ # self.assertEqual(remote_file_data[0].strip(), test_file_data)
309+ # except Exception:
310+ # raise
311+ # finally:
312+ # for filepath in [local_filename, remote_file_abspath]:
313+ # os.unlink(filepath)
314+ # shutil.rmtree(remote_test_dir_abspath)
315+
316+ # def test_pssh_client_directory(self):
317+ # """Tests copying multiple directories with SSH client. Copy all the files from
318+ # local directory to server, then make sure they are all present."""
319+ # test_file_data = 'test'
320+ # local_test_path = 'directory_test'
321+ # remote_test_path = 'directory_test_copied'
322+ # dir_name = os.path.dirname(__file__)
323+ # remote_test_path_abs = os.sep.join(
324+ # (dir_name, remote_test_path))
325+ # for path in [local_test_path, remote_test_path_abs]:
326+ # try:
327+ # shutil.rmtree(path)
328+ # except OSError:
329+ # pass
330+ # os.mkdir(local_test_path)
331+ # remote_file_paths = []
332+ # for i in range(0, 10):
333+ # local_file_path_dir = os.path.join(
334+ # local_test_path, 'sub_dir1', 'sub_dir2', 'dir_foo' + str(i))
335+ # os.makedirs(local_file_path_dir)
336+ # local_file_path = os.path.join(local_file_path_dir, 'foo' + str(i))
337+ # remote_file_path = os.path.join(
338+ # remote_test_path, 'sub_dir1', 'sub_dir2', 'dir_foo' + str(i), 'foo' + str(i))
339+ # remote_file_paths.append(
340+ # os.sep.join((os.path.dirname(__file__), remote_file_path)))
341+ # test_file = open(local_file_path, 'w')
342+ # test_file.write(test_file_data)
343+ # test_file.close()
344+ # cmds = self.client.copy_file(local_test_path, remote_test_path_abs, recurse=True)
345+ # gevent.joinall(cmds, raise_error=True)
346+ # for path in remote_file_paths:
347+ # self.assertTrue(os.path.isfile(path))
348+ # shutil.rmtree(local_test_path)
349+ # shutil.rmtree(os.sep.join((os.path.dirname(__file__), remote_test_path)))
350+
351+ # def test_pssh_client_copy_file_failure(self):
352+ # """Test failure scenarios of file copy"""
353+ # test_file_data = 'test'
354+ # local_test_path = 'directory_test'
355+ # remote_test_path = 'directory_test_copied'
356+ # dir_name = os.path.dirname(__file__)
357+ # remote_test_path_abs = os.sep.join((dir_name, remote_test_path))
358+ # for path in [local_test_path, remote_test_path_abs]:
359+ # mask = int('0700') if sys.version_info <= (2,) else 0o700
360+ # if os.path.isdir(path):
361+ # os.chmod(path, mask)
362+ # for root, dirs, files in os.walk(path):
363+ # os.chmod(root, mask)
364+ # for _path in files + dirs:
365+ # os.chmod(os.path.join(root, _path), mask)
366+ # try:
367+ # shutil.rmtree(path)
368+ # except OSError:
369+ # pass
370+ # os.mkdir(local_test_path)
371+ # os.mkdir(remote_test_path_abs)
372+ # local_file_path = os.path.join(local_test_path, 'test_file')
373+ # remote_file_path = os.path.join(remote_test_path, 'test_file')
374+ # remote_test_path_abs = os.sep.join((dir_name, remote_test_path))
375+ # test_file = open(local_file_path, 'w')
376+ # test_file.write('testing\n')
377+ # test_file.close()
378+ # # Permission errors on writing into dir
379+ # mask = int('0111') if sys.version_info <= (2,) else 0o111
380+ # os.chmod(remote_test_path_abs, mask)
381+ # cmds = self.client.copy_file(local_test_path, remote_test_path_abs, recurse=True)
382+ # try:
383+ # gevent.joinall(cmds, raise_error=True)
384+ # raise Exception("Expected SFTPError exception")
385+ # except SFTPError:
386+ # pass
387+ # self.assertFalse(os.path.isfile(remote_test_path_abs))
388+ # # Create directory tree failure test
389+ # local_file_path = os.path.join(local_test_path, 'test_file')
390+ # remote_file_path = os.path.join(remote_test_path, 'test_dir', 'test_file')
391+ # remote_test_path_abs = os.sep.join((dir_name, remote_test_path))
392+ # cmds = self.client.copy_file(local_file_path, remote_test_path_abs, recurse=True)
393+ # try:
394+ # gevent.joinall(cmds, raise_error=True)
395+ # raise Exception("Expected SFTPError exception on creating remote "
396+ # "directory")
397+ # except SFTPError:
398+ # pass
399+ # self.assertFalse(os.path.isfile(remote_test_path_abs))
400+ # mask = int('0600') if sys.version_info <= (2,) else 0o600
401+ # os.chmod(remote_test_path_abs, mask)
402+ # for path in [local_test_path, remote_test_path_abs]:
403+ # shutil.rmtree(path)
404+
405+ # def test_pssh_copy_remote_file_failure(self):
406+ # cmds = self.client.copy_remote_file(
407+ # 'fakey fakey fake fake', 'equally fake')
408+ # self.assertRaises(SFTPIOError, cmds[0].get)
409+
410+ # def test_pssh_copy_remote_file(self):
411+ # """Test parallel copy file to local host"""
412+ # test_file_data = 'test'
413+ # dir_name = os.path.dirname(__file__)
414+ # local_test_path = os.sep.join((dir_name, 'directory_test_local_remote_copied'))
415+ # remote_test_path = 'directory_test_remote_copy'
416+ # remote_test_path_abs = os.sep.join((dir_name, remote_test_path))
417+ # local_copied_dir = '_'.join([local_test_path, self.host])
418+ # new_local_copied_dir = '.'.join([local_test_path, self.host])
419+ # for path in [local_test_path, remote_test_path_abs, local_copied_dir,
420+ # new_local_copied_dir]:
421+ # try:
422+ # shutil.rmtree(path)
423+ # except OSError:
424+ # try:
425+ # os.unlink(path)
426+ # except Exception:
427+ # pass
428+ # pass
429+ # os.mkdir(remote_test_path_abs)
430+ # local_file_paths = []
431+ # for i in range(0, 10):
432+ # remote_file_path_dir = os.path.join(
433+ # remote_test_path_abs, 'sub_dir', 'dir_foo' + str(i))
434+ # os.makedirs(remote_file_path_dir)
435+ # remote_file_path = os.path.join(remote_file_path_dir, 'foo' + str(i))
436+ # local_file_path = os.path.join(
437+ # local_copied_dir, 'sub_dir', 'dir_foo' + str(i), 'foo' + str(i))
438+ # local_file_paths.append(local_file_path)
439+ # test_file = open(remote_file_path, 'w')
440+ # test_file.write(test_file_data)
441+ # test_file.close()
442+ # cmds = self.client.copy_remote_file(remote_test_path_abs, local_test_path)
443+ # self.assertRaises(ValueError, gevent.joinall, cmds, raise_error=True)
444+ # cmds = self.client.copy_remote_file(remote_test_path_abs, local_test_path,
445+ # recurse=True)
446+ # gevent.joinall(cmds, raise_error=True)
447+ # try:
448+ # self.assertTrue(os.path.isdir(local_copied_dir))
449+ # for path in local_file_paths:
450+ # self.assertTrue(os.path.isfile(path))
451+ # except Exception:
452+ # shutil.rmtree(remote_test_path_abs)
453+ # finally:
454+ # shutil.rmtree(local_copied_dir)
455+ # cmds = self.client.copy_remote_file(remote_test_path_abs, local_test_path,
456+ # suffix_separator='.', recurse=True)
457+ # gevent.joinall(cmds, raise_error=True)
458+ # new_local_copied_dir = '.'.join([local_test_path, self.host])
459+ # try:
460+ # for path in local_file_paths:
461+ # path = path.replace(local_copied_dir, new_local_copied_dir)
462+ # self.assertTrue(os.path.isfile(path))
463+ # finally:
464+ # shutil.rmtree(new_local_copied_dir)
465+ # shutil.rmtree(remote_test_path_abs)
466466
467467 def test_pssh_pool_size (self ):
468468 """Test setting pool size to non default values"""
0 commit comments