Beispiel #1
0
def clean_environment(users_path):
    print "\nCleaning environment"
    read_users_info(users_path)

    for i, user_id in enumerate(users_dict):
        user = users_dict[user_id]
        is_ss_provider = user.provider == "SS"
        response = list_content(user.oauth, user.shared_folder_id, is_ss_provider)
        if response.status_code == 200:
            json_data = response.json()
            content_root = json_data["contents"]
            print i, " ", user_id
            for line in content_root:
                try:
                    print_seq_dots()
                    name = line["filename"]
                    server_id = line["id"]
                    is_folder = line["is_folder"]
                    if name.isdigit():
                        response = unlink(user.oauth, server_id, is_folder, is_ss_provider)
                        if response.status_code != 200:
                            print response, response.text, response.content
                except KeyError:
                    pass
        else:
            print i, user_id, response, response.text, response.content
        print
Beispiel #2
0
    def process_delete(self, event_args, ops_counter):
        process_debug_log("Count %d ProcessUnlink node_id %d of user_id %s" % (ops_counter,
                                                                               int(event_args[
                                                                                       TraceProcessor.csv_node_id]),
                                                                               int(event_args[
                                                                                       TraceProcessor.csv_user_id])))

        user_id = int(event_args[TraceProcessor.csv_user_id])
        node_id = int(event_args[TraceProcessor.csv_node_id])
        is_folder = event_args[TraceProcessor.csv_node_type] == "Directory"
        friend_id = int(event_args[TraceProcessor.csv_friend_id])

        friend = TraceProcessor.all_users_dict[friend_id]
        oauth = friend.oauth
        is_ss_provider = friend.provider == "SS"

        fake_delete = False
        server_id = None
        url = "NULL"

        start = time.time()
        try:
            server_id = None
            if node_id in friend.node_server_id_dict:
                server_id = friend.node_server_id_dict[node_id]

            if is_folder:
                if server_id not in friend.workspace_folders:
                    if len(friend.workspace_folders) > 0:
                        server_id = random.sample(friend.workspace_folders, 1)[0]
                    else:
                        server_id = friend.shared_folder_id
                        fake_delete = True
            else:
                if server_id not in friend.workspace_files:
                    if len(friend.workspace_files) > 0:
                        server_id = random.sample(friend.workspace_files, 1)[0]
                    else:
                        server_id = friend.file0_id
                        fake_delete = True

            if not fake_delete:
                start = time.time()
                response = unlink(oauth, server_id, is_folder, is_ss_provider)
                end = time.time()
                url = response.url

                if response.status_code == 200:
                    if is_folder:
                        friend.workspace_folders.remove(server_id)
                    else:
                        friend.workspace_files.remove(server_id)
                    for k in friend.node_server_id_dict:
                        if friend.node_server_id_dict[k] == server_id:
                            friend.node_server_id_dict.pop(k)
                            break

                    elapsed = end - start

                    process_log(str(ops_counter), str(repr(start)), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                                str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                                str(event_args[TraceProcessor.csv_req_type]),
                                str(TraceProcessor.all_users_dict[user_id].provider),
                                str(TraceProcessor.all_users_dict[friend_id].provider), str(friend_id),
                                str(server_id),
                                str(event_args[TraceProcessor.csv_node_type]), str(event_args[TraceProcessor.csv_size]),
                                str(elapsed),
                                str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)), url=str(url))
                else:
                    raise ValueError(
                        "Error on response with status_code %d and text %s" % (response.status_code, response.text))
            else:
                elapsed = "0.725152481329475"
                has_error = "0"
                error_msg = "fake_delete"

                process_log(str(ops_counter), str(repr(time.time())), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                            str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                            str(event_args[TraceProcessor.csv_req_type]),
                            str(TraceProcessor.all_users_dict[user_id].provider),
                            str(TraceProcessor.all_users_dict[friend_id].provider),
                            str(friend_id), str(server_id), str(event_args[TraceProcessor.csv_node_type]),
                            str(event_args[TraceProcessor.csv_size]), str(elapsed),
                            str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)),
                            has_error=str(has_error), error_msg=str(error_msg), url=str(url))
            return 0
        except Exception as e:
            trace = event_args
            exception = type(e)
            error_msg = e.message
            args = e.args
            size = "NULL"
            level = "ERROR"
            if server_id is None:
                server_id = node_id

            elapsed = time.time() - start
            process_log(str(ops_counter), str(repr(start)), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                        str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                        str(event_args[TraceProcessor.csv_req_type]),
                        str(TraceProcessor.all_users_dict[user_id].provider),
                        str(TraceProcessor.all_users_dict[friend_id].provider), str(friend_id), str(server_id),
                        str(event_args[TraceProcessor.csv_node_type]), str(size), str(elapsed),
                        str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)),
                        str(TraceProcessor.has_error_code), str(trace), str(exception), str(error_msg), str(args),
                        str(level), url=str(url))
            return TraceProcessor.has_error_code
Beispiel #3
0
def test_api(current_path):
    is_ss_provider = False
    create_test_user(is_ss_provider)

    user = users_dict.popitem()[1]
    root = user.shared_folder_id

    oauth = user.oauth
    file_name = "file5"
    folder_name = "folder5"
    is_folder = True

    start = time.time()
    response = make(oauth, folder_name, parent_id=root, is_folder=is_folder, is_ss_provider=is_ss_provider)
    end = time.time()
    print "MAKE folder elapsed;", (end - start)
    if response.status_code == 201:
        json_data = json.loads(response.text)
        folder_id = str(json_data["id"])
    elif (response.status_code == 400 or response.status_code == 403) and "already" in response.text:
        response = list_content(oauth, parent_id=root, is_ss_provider=is_ss_provider)
        json_data = response.json()
        content_root = json_data["contents"]
        folder_id = None
        for tuppla in content_root:
            try:
                name = tuppla["filename"]
                is_response_folder = tuppla["is_folder"]
                if name == folder_name and is_folder == is_response_folder:
                    folder_id = tuppla["id"]
                    break
            except KeyError:
                raise ValueError("ERROR MAKE Folder: Failed to extract folder_id form get_content at %s" % (response.url))
    else:
        raise ValueError(
            "ERROR MAKE Folder: response with status_code %d and text {%s}" % (response.status_code, response.text))
    print "Folder_id=", folder_id

    is_folder = False
    start = time.time()
    response = make(oauth, file_name, parent_id=folder_id, is_folder=is_folder, is_ss_provider=is_ss_provider)
    end = time.time()
    print "MAKE file elapsed;", (end - start)
    if response.status_code == 201:
        json_data = json.loads(response.text)
        server_id = str(json_data["id"])
    elif (response.status_code == 400 or response.status_code == 403) and "already" in response.text:
        response = list_content(oauth, parent_id=root, is_ss_provider=is_ss_provider)
        json_data = response.json()
        content_root = json_data["contents"]
        server_id = None
        for tuppla in content_root:
            try:
                name = tuppla["filename"]
                is_response_folder = tuppla["is_folder"]
                if name == folder_name and is_folder == is_response_folder:
                    server_id = tuppla["id"]
                    break
            except KeyError:
                raise ValueError("ERROR MAKE File: Failed to extract file_id form get_content at %s" % (response.url))
    else:
        raise ValueError(
            "ERROR MAKE File: response with status_code %d and text {%s}" % (response.status_code, response.text))
    print "File_id", server_id

    file_path = current_path + "/../README.md"
    start = time.time()
    response = put_content(oauth, server_id, file_path, is_ss_provider=is_ss_provider)
    end = time.time()
    print "PUT file elapsed;", (end - start)
    if not (response.status_code == 200 or response.status_code == 201):
        raise ValueError(
            "ERROR PUT File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = get_content(oauth, server_id, is_ss_provider=is_ss_provider)
    end = time.time()
    print "GET file elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR GET File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = unlink(oauth, server_id, is_folder=False, is_ss_provider=is_ss_provider)
    end = time.time()
    print "DELETE file elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR DELETE File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = unlink(oauth, folder_id, is_folder=True, is_ss_provider=is_ss_provider)
    end = time.time()
    print "DELETE folder elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR DELETE Folder: response with status_code %d and text {%s}" % (response.status_code, response.text))