Exemple #1
0
        def test_multiple_files(self):
            test_dir_path = os.path.join(os.getcwd(),
                                         'testdir_%s' % uuid.uuid1())
            os.makedirs(test_dir_path)
            test_file_paths = []
            for i in range(10):
                test_file_path = os.path.join(test_dir_path,
                                              'testfile_%s.txt' % i)
                with open(test_file_path, 'w') as file:
                    file.write(1000 * 'a')

                if i % 2 == 0:  #only transfer half the files in the directory
                    test_file_paths.append(test_file_path)

            try:
                cp = ltacp.LtaCp('localhost', test_file_paths,
                                 'srm://fake_surl')
                md5cs, a32cs, fs = cp.transfer()
            except Exception as e:
                self.assertTrue(False,
                                'Unexpected exception in transfer: %s' % e)
            finally:
                for f in os.listdir(test_dir_path):
                    os.remove(os.path.join(test_dir_path, f))
                os.removedirs(test_dir_path)
Exemple #2
0
        def test_path_mounted(self):
            #first test with a valid path, the current working dir + some random dir + file
            test_file_path = os.path.join(os.getcwd(), str(uuid.uuid1()),
                                          'testfile.txt')
            cp = ltacp.LtaCp('localhost', test_file_path, 'srm://fake_surl')

            #the path should not exists, but it should be mounted
            self.assertFalse(cp.source_exists())
            self.assertTrue(cp.source_mounted())

            #let's try to transfer this file, should not succeed, but raise an exception
            try:
                cp = ltacp.LtaCp('localhost', test_file_path,
                                 'srm://fake_surl')
                cp.transfer()
            except ltacp.LtacpException as e:
                logger.info('caught expected LtacpException: %s', e.value)
                self.assertTrue('source path' in e.value
                                and 'does not exist' in e.value)
            except Exception as e:
                self.assertTrue(False,
                                'Unexpected exception in transfer: %s' % e)

            #repeat same test, but now with a non-mounted disk
            test_file_path = '/non-existing-root-dir/dir1/dir2/file.txt'
            cp = ltacp.LtaCp('localhost', test_file_path, 'srm://fake_surl')
            self.assertFalse(cp.source_mounted())

            #let's try to transfer this file, should not succeed, but raise an exception
            try:
                cp = ltacp.LtaCp('localhost', test_file_path,
                                 'srm://fake_surl')
                cp.transfer()
            except ltacp.LtacpException as e:
                logger.info('caught expected LtacpException: %s', e.value)
                self.assertTrue('the disk of source path' in e.value
                                and 'does not seem to be mounted' in e.value)
            except Exception as e:
                self.assertTrue(False,
                                'Unexpected exception in transfer: %s' % e)
Exemple #3
0
        def test_path_exists(self):
            test_file_path = os.path.join(os.getcwd(), str(uuid.uuid1()),
                                          'testfile.txt')
            os.makedirs(os.path.dirname(test_file_path))
            with open(test_file_path, 'w') as file:
                file.write(1000 * 'a')

            try:
                cp = ltacp.LtaCp('localhost', test_file_path,
                                 'srm://fake_surl')
                self.assertTrue(cp.source_exists())
            except Exception as e:
                self.assertTrue(False,
                                'Unexpected exception in transfer: %s' % e)
            finally:
                os.remove(test_file_path)
Exemple #4
0
        def test_single_file(self):
            test_file_path = os.path.join(os.getcwd(), str(uuid.uuid1()),
                                          'testfile.txt')
            os.makedirs(os.path.dirname(test_file_path))
            with open(test_file_path, 'w') as file:
                file.write(1000 * 'a')

            try:
                cp = ltacp.LtaCp('localhost', test_file_path,
                                 'srm://fake_surl')
                md5cs, a32cs, fs = cp.transfer()
                #it suffices to check only the filesize as transfer result
                #if the checksums whould have been different between source, local, and/or 'lta'
                #then an exception would have been raised, and that is asserted below
                self.assertEqual(1000, int(fs))
            except Exception as e:
                logger.exception(e)
                self.assertTrue(False,
                                'Unexpected exception in transfer: %s' % e)
            finally:
                os.remove(test_file_path)