def tearDownClass(cls):
        """rsync (RSE/PROTOCOLS): Removing created directories and files"""
        rse_id, prefix, hostname, port, sshuser = cls.get_rse_info()
        shutil.rmtree(prefix)
        shutil.rmtree(cls.tmpdir)

        clean_raw = '%s/data.raw' % prefix
        list_files_cmd_user = '******' % (sshuser, hostname, prefix, cls.user)
        clean_files = str(execute(list_files_cmd_user)[1]).split('\n')
        list_files_cmd_group = 'ssh %s@%s find %s/group/%s' % (sshuser, hostname, prefix, cls.user)
        clean_files += str(execute(list_files_cmd_group)[1]).split('\n')
        clean_files.append(clean_raw)
        for files in clean_files:
            clean_cmd = 'ssh %s@%s rm %s' % (sshuser, hostname, files)

        list_directory = 'ssh %s@%s find %s/user/%s' % (sshuser, hostname, prefix, cls.user)
        clean_directory = str(execute(list_directory)[1]).split('\n')
        list_directory_group = 'ssh %s@%s find %s/group/%s' % (sshuser, hostname, prefix, cls.user)
        clean_directory += str(execute(list_directory_group)[1]).split('\n')
        for directory in clean_directory:
            clean_cmd = 'ssh %s@%s rm -r %s' % (sshuser, hostname, directory)
            execute(clean_cmd)

        set_preferred_checksum(cls.original_prefchecksum)
        cmd = 'ssh-keygen -R %s' % (hostname)
        execute(cmd)
示例#2
0
    def setUpClass(cls):
        """SSH (RSE/PROTOCOLS): Creating necessary directories and files """

        # Getting info for the test environment
        rse_id, prefix, hostname, port, sshuser = cls.get_rse_info()

        try:
            os.mkdir(prefix)
        except Exception as e:
            print(e)

        # Creating local files
        cls.tmpdir = tempfile.mkdtemp()
        cls.user = uuid()

        set_preferred_checksum('md5')
        cmd = 'ssh-keygen -R %s' % (cls.hostname)
        execute(cmd)
        cmd = 'ssh-keyscan %s  >> /root/.ssh/known_hosts' % (cls.hostname)
        execute(cmd)

        with open("%s/data.raw" % cls.tmpdir, "wb") as out:
            out.seek((1024 * 1024) - 1)  # 1 MB
            out.write(b'\0')
        for f in MgrTestCases.files_local:
            shutil.copy('%s/data.raw' % cls.tmpdir, '%s/%s' % (cls.tmpdir, f))

        protocol = rsemanager.create_protocol(rsemanager.get_rse_info(rse_id),
                                              'write')
        protocol.connect()

        os.system('dd if=/dev/urandom of=%s/data.raw bs=1024 count=1024' %
                  prefix)
        cls.static_file = '%s@%s:/%s/data.raw' % (sshuser, hostname, prefix)
        pathdir = os.path.dirname(prefix)
        cmd = 'ssh %s@%s "mkdir -p %s" && scp %s/data.raw %s' % (
            sshuser, hostname, str(pathdir), prefix, cls.static_file)
        execute(cmd)

        for f in MgrTestCases.files_remote:
            path = str(prefix + protocol._get_path('user.%s' % cls.user, f))
            pathdir = os.path.dirname(path)
            cmd = 'ssh %s@%s "mkdir -p %s" && scp %s/data.raw %s@%s:%s' % (
                sshuser, hostname, str(pathdir), prefix, sshuser, hostname,
                path)
            execute(cmd)

        for f in MgrTestCases.files_local_and_remote:
            shutil.copy('%s/data.raw' % cls.tmpdir, '%s/%s' % (cls.tmpdir, f))
            path = str(prefix + protocol._get_path('user.%s' % cls.user, f))
            pathdir = os.path.dirname(path)
            cmd = 'ssh {0}@{1} "mkdir -p {2}" && scp {3}/{4} {5}@{6}:{7}'.format(
                sshuser, hostname, str(pathdir), str(cls.tmpdir), str(f),
                sshuser, hostname, path)
            execute(cmd)
示例#3
0
    def tearDownClass(cls):
        """rclone (RSE/PROTOCOLS): Removing created directories and files"""
        rse_id, prefix, hostname = cls.get_rse_info()
        shutil.rmtree(prefix)
        shutil.rmtree(cls.tmpdir)

        clean_raw = 'rclone delete %s/data.raw' % prefix
        execute(clean_raw)
        list_files_cmd_user = '******' % (hostname, prefix,
                                                              cls.user)
        execute(list_files_cmd_user)
        list_files_cmd_group = 'rclone purge %s:%s/group/%s' % (
            hostname, prefix, cls.user)
        execute(list_files_cmd_group)

        set_preferred_checksum(cls.original_prefchecksum)
        cmd = 'ssh-keygen -R %s' % (hostname)
        execute(cmd)