Ejemplo n.º 1
0
 def test_skte_t1023_t1030_share_and_cancel_files_in_bulk(self):
     target = config.ceph_path  # 上传路径
     filename1 = 'iris.csv'  # 上传文件名称
     file1 = '{}{}'.format(config.file_url, filename1)  # 源文件及其路径
     filePath1 = '{}{}'.format(target, filename1)  # 上传后文件及其路径
     filename2 = 'iris.txt'
     file2 = '{}{}'.format(config.file_url, filename2)
     filePath2 = '{}{}'.format(target, filename2)
     paths = []
     paths.append(filePath1)
     paths.append(filePath2)
     # 上传文件用于共享/取消共享操作
     send_file_m_req.upload_file(self.token, file1, target)
     send_file_m_req.upload_file(self.token, file2, target)
     # 共享文件给用户
     uuid = get_uuid_from_token(self.token)  # 文件所有者的uuid,同时也是文件共享者的uuid
     shareuser_token = send_user_m_req.get_token_simple(
         config.user_name_b, config.user_passwd_b)  # 被共享用户的token
     sharer_uuid = get_uuid_from_token(shareuser_token)  # 被共享用户的uuid
     share_uuid = send_file_m_req.share_files_batch(self.token,
                                                    sharePaths=paths,
                                                    owner_id=uuid,
                                                    share_id=uuid,
                                                    users=[sharer_uuid])
     # 验证文件共享结果: 1)共享用户在“我的共享”文件夹下可看到共享文件 2)被共享用户在“接收的共享”文件夹下可看到被共享文件
     my_share_file = send_file_m_req.get_shared_file_list(
         self.token, owner_id=uuid)  # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表
     if filename1 and filename2 not in my_share_file:
         logger.log_error(
             'user {} cannot find shared file {} and {}'.format(
                 config.user_name_a, filename1, filename2))
         assert False
     share_file_list = send_file_m_req.get_shared_file_list(
         shareuser_token,
         user_id=sharer_uuid)  # 被共享用户查看"接收的共享",返回其下可查看到的文件列表
     if filename1 and filename2 not in share_file_list:
         logger.log_error(
             'user {} cannot find shared file {} and {}'.format(
                 config.user_name_b, filename1, filename2))
         assert False
     # 取消共享文件
     send_file_m_req.cancel_shared_file(self.token, share_uuid)
     # 验证文件共享结果: 1)共享用户的“我的共享”文件夹下已移除共享文件 2)被共享用户已在“接收的共享”文件夹下移除被共享文件
     my_share_file = send_file_m_req.get_shared_file_list(
         self.token, owner_id=uuid)  # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表
     if filename1 and filename2 in my_share_file:
         logger.log_error(
             'user {} should not find unshared file {} and {}'.format(
                 config.user_name_a, filename1, filename2))
         assert False
     share_file_list = send_file_m_req.get_shared_file_list(
         shareuser_token,
         user_id=sharer_uuid)  # 被共享用户查看"接收的共享",返回其下可查看到的文件列表
     if filename1 and filename2 in share_file_list:
         logger.log_error(
             'user {} should not find unshared file {} and {}'.format(
                 config.user_name_b, filename1, filename2))
         assert False
     # 删除文件
     send_file_m_req.delete_files_and_folders(self.token, paths)
Ejemplo n.º 2
0
 def test_skte_t1014_t1029_share_and_cancel_file(self):
     filename = config.file_name  # 上传文件名称
     file = '{}{}'.format(config.file_url, filename)  # 源文件及其路径
     target = config.ceph_path  # 上传路径
     filePath = '{}{}'.format(target, filename)  # 上传后文件及其路径
     # 上传文件用于共享/取消共享操作
     send_file_m_req.upload_file(self.token, file, target)
     # 共享文件给全局
     uuid = get_uuid_from_token(self.token)  # 文件所有者的uuid,同时也是文件共享者的uuid
     share_uuid = send_file_m_req.share_file(self.token,
                                             owner_uuid=uuid,
                                             sharePath=filePath,
                                             isGlobal=True)
     # 验证文件共享结果: 1)共享用户在“我的共享”文件夹下可看到共享文件 2)被共享用户在“接收的共享”文件夹下可看到被共享文件
     my_share_file = send_file_m_req.get_shared_file_list(
         self.token, owner_id=uuid)  # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表
     if filename not in my_share_file:
         logger.log_error('user {} cannot find shared file {}'.format(
             config.user_name_a, filename))
         assert False
     shareuser_token = send_user_m_req.get_token_simple(
         config.user_name_b, config.user_passwd_b)  # 被共享用户的token
     sharer_uuid = get_uuid_from_token(shareuser_token)  # 被共享用户的uuid
     share_file_list = send_file_m_req.get_shared_file_list(
         shareuser_token,
         user_id=sharer_uuid)  # 被共享用户查看"接收的共享",返回其下可查看到的文件列表
     if filename not in share_file_list:
         logger.log_error('user {} cannot find shared file {}'.format(
             config.user_name_b, filename))
         assert False
     # 取消共享文件
     send_file_m_req.cancel_shared_file(self.token, share_uuid)
     # 验证文件共享结果: 1)共享用户的“我的共享”文件夹下已移除共享文件 2)被共享用户已在“接收的共享”文件夹下移除被共享文件
     my_share_file = send_file_m_req.get_shared_file_list(
         self.token, owner_id=uuid)  # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表
     if filename in my_share_file:
         logger.log_error('user {} should not find unshared file {}'.format(
             config.user_name_a, filename))
         assert False
     share_file_list = send_file_m_req.get_shared_file_list(
         shareuser_token,
         user_id=sharer_uuid)  # 被共享用户查看"接收的共享",返回其下可查看到的文件列表
     if filename in share_file_list:
         logger.log_error('user {} should not find unshared file {}'.format(
             config.user_name_b, filename))
         assert False
     # 删除文件
     paths = []
     paths.append(filePath)
     send_file_m_req.delete_files_and_folders(self.token, paths)
def get_user_volume_id_req(token):
    uuid = get_uuid_from_token(token)
    req = ApiTemplate()
    sub_path = "storage-manager/api/v1/volumes"
    req.url = urljoin(config.base_url, sub_path)
    req.method = 'get'
    req.headers = {"Authorization": token, "Content-Type": ""}
    req.param = {'type': 'user', 'ownerId': uuid}
    return req
Ejemplo n.º 4
0
def get_rename_file_folder_req(token, sourcepath, newname):
    # 获取用户uuid
    uuid = get_uuid_from_token(token)
    # 构造重命名文件或文件夹请求
    path = 'file-manager/api/v1/files/rename'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'post'
    req.headers = {
        "Authorization": token,
    }
    req.body = {"ownerId": uuid, "path": sourcepath, "newName": newname}
    return req
Ejemplo n.º 5
0
def get_extract_file_req(token, file_path, target_path):
    # 获取用户uuid
    uuid = get_uuid_from_token(token)
    # 构造解压文件请求
    path = 'file-manager/api/v1/files/extract'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'post'
    req.headers = {
        "Authorization": token,
    }
    req.body = {"ownerId": uuid, "path": file_path, "targetPath": target_path}
    return req
Ejemplo n.º 6
0
def get_create_folder_req(token, target, folder):
    # 获取用户uuid
    uuid = get_uuid_from_token(token)
    # 构造创建文件夹请求
    path = 'file-manager/api/v1/files'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'post'
    req.headers = {
        "Authorization": token
        # "Content-Type": "application/json"
    }
    req.body = {"ownerId": uuid, "path": '{}/{}'.format(target, folder)}
    return req
Ejemplo n.º 7
0
def get_delete_files_and_folder_req(token, paths):
    # 获取用户uuid
    uuid = get_uuid_from_token(token)
    # 构造删除文件和文件夹名称列表请求
    path = 'file-manager/api/v1/files/delete'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'post'
    req.headers = {
        "Authorization": token
        # "Content-Type": "application/json"
    }
    req.body = {"ownerId": uuid, "paths": paths}
    return req
Ejemplo n.º 8
0
def get_download_file_req(token, filename, target):
    # 获取用户uuid
    uuid = get_uuid_from_token(token)
    # 构造下载文件请求
    path = 'file-manager/api/v1/files/download'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'get'
    req.param = {"ownerId": uuid, "path": '{}{}'.format(target, filename)}
    req.headers = {
        "Authorization": token
        # "Content-Type": "application/json"
    }
    return req
Ejemplo n.º 9
0
def get_move_file_req(token, sourcePaths, targetPath):
    # 获取用户uuid
    uuid = get_uuid_from_token(token)
    # 构造移动文件/文件夹请求
    path = 'file-manager/api/v1/files/move'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'post'
    req.headers = {"Authorization": token}
    req.body = {
        "ownerId": uuid,
        "sourcePaths": sourcePaths,
        "targetPath": targetPath
    }
    return req
Ejemplo n.º 10
0
def get_upload_file_req(token, file, target):
    # 获取用户uuid
    uuid = get_uuid_from_token(token)
    # 构造上传文件请求
    path = 'file-manager/api/v1/files/upload'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'post'
    req.headers = {
        "Authorization": token,
        # "Content-Type": "multipart/form-data"
    }
    req.body = {"ownerId": uuid, "path": target}
    # 将文件转化为二进制格式,通过files参数post上传
    req.files = {"files": open(r'{}'.format(file), "rb")}
    return req
def get_file_list(token, path):
    '''
    根据path查询路径下存在的文件/文件夹,并返回文件/文件夹名称列表
    :param token:
    :param ownerid:
    :param path:
    :return:
    '''
    ownerid = get_uuid_from_token(token)
    req = api_compose.get_compose_file_list_req(token=token, owner_id=ownerid, file_path=path)
    res = send_req.send_request(req)
    filename = []
    elements = res['children']
    for i in range(len(elements)):
        filename.append(elements[i]['name'])
    return filename
    def test_skte_t1007_delete_folder(self):
        # Title: 删除文件夹
        # Owner:qingzhen
        # PreCondition:创建测试目录T1007,上传iris.csv文件到该目录成功,并检查宿主机上对应user volumn下文件夹存在
        target = config.ceph_path
        file = '{}{}'.format(config.file_url, config.file_name)
        send_file_m_req.create_folder(self.token, target, 'T1007')
        send_file_m_req.upload_file(self.token, file, target + 'T1007')
        user_uuid = get_uuid_from_token(self.token)
        volume_id = send_file_m_req.get_volume_id_by_user_uuid(user_uuid)

        # 1. 删除文件夹
        send_file_m_req.delete_files_and_folders(self.token,
                                                 paths=[target + 'T1007'])
        time.sleep(2)

        # 2. 在对应user volume下检查文件夹删除成功
        foler_check = '/SkyDiscovery/cephfs/data/user/volume_{}/T1007'.format(
            volume_id)
        assert check_files_folders_exist(input_path_list=[foler_check],
                                         isExistCheck=False)
Ejemplo n.º 13
0
def get_share_file_req(token,
                       owner_uuid,
                       sharePath,
                       isGlobal=False,
                       users=None,
                       groups=None):
    # 获取用户uuid
    share_uuid = get_uuid_from_token(token)
    # 构造共享文件/文件夹请求
    path = 'file-manager/api/v1/file_shares'
    req = ApiTemplate()
    req.url = urljoin(config.base_url, path)
    req.method = 'post'
    req.headers = {"Authorization": token}
    req.body = {
        "ownerId": owner_uuid,
        "sharerId": share_uuid,
        "path": sharePath,
        "isGlobal": isGlobal,
        "users": [] if users is None else users,
        "groups": [] if groups is None else groups
    }
    return req
    def test_skte_t1008_delete_multi_files_folders(self):
        # Title: 删除多个文件或文件夹
        # Owner:qingzhen
        # PreCondition:创建测试目录T1008,上传iris_folder文件夹到该目录成功
        target = config.ceph_path
        # iris_folder文件结构:
        # iris_folder
        #   iris0(iris0_1.csv+iris0_2.csv+iris0_3.csv)
        #   iris1(iris1.csv)
        #   iris2(iris2_1.csv+iris2_2.csv)
        #   iris3.csv
        #   iris4.csv
        #   iris5.csv
        folder = '{}{}'.format(config.file_url, config.folder_name)
        send_file_m_req.create_folder(self.token, target, 'T1008')
        send_file_m_req.upload_file(self.token, folder + '/iris3.csv',
                                    target + 'T1008/' + config.folder_name)
        send_file_m_req.upload_file(self.token, folder + '/iris4.csv',
                                    target + 'T1008/' + config.folder_name)
        send_file_m_req.upload_file(self.token, folder + '/iris5.csv',
                                    target + 'T1008/' + config.folder_name)
        send_file_m_req.upload_file(
            self.token, folder + '/iris0/iris0_1.csv',
            target + 'T1008/' + config.folder_name + '/iris0')
        send_file_m_req.upload_file(
            self.token, folder + '/iris0/iris0_2.csv',
            target + 'T1008/' + config.folder_name + '/iris0')
        send_file_m_req.upload_file(
            self.token, folder + '/iris0/iris0_3.csv',
            target + 'T1008/' + config.folder_name + '/iris0')
        send_file_m_req.upload_file(
            self.token, folder + '/iris1/iris1.csv',
            target + 'T1008/' + config.folder_name + '/iris1')
        send_file_m_req.upload_file(
            self.token, folder + '/iris2/iris2_1.csv',
            target + 'T1008/' + config.folder_name + '/iris2')
        send_file_m_req.upload_file(
            self.token, folder + '/iris2/iris2_2.csv',
            target + 'T1008/' + config.folder_name + '/iris2')

        user_uuid = get_uuid_from_token(self.token)
        volume_id = send_file_m_req.get_volume_id_by_user_uuid(user_uuid)

        # 1. 删除文件夹和文件夹
        delete_paths = [
            target + 'T1008/' + config.folder_name + '/iris0',
            target + 'T1008/' + config.folder_name + '/iris2',
            target + 'T1008/' + config.folder_name + '/iris3.csv',
            target + 'T1008/' + config.folder_name + '/iris5.csv'
        ]
        send_file_m_req.delete_files_and_folders(self.token,
                                                 paths=delete_paths)
        time.sleep(2)

        # 2.在对应user volume下检查文件夹和文件夹删除成功
        user_volume_path = '/SkyDiscovery/cephfs/data/user/volume_{}/'.format(
            volume_id)
        delete_paths_check = [
            user_volume_path + 'T1008/' + config.folder_name + '/iris0',
            user_volume_path + 'T1008/' + config.folder_name + '/iris2',
            user_volume_path + 'T1008/' + config.folder_name + '/iris3.csv',
            user_volume_path + 'T1008/' + config.folder_name + '/iris5.csv'
        ]

        assert check_files_folders_exist(input_path_list=delete_paths_check,
                                         isExistCheck=False)

        # Reset: 删除目录 T1008
        send_file_m_req.delete_files_and_folders(self.token,
                                                 paths=[target + 'T1008'])