コード例 #1
0
ファイル: task.py プロジェクト: bitvismk/krem
def run(task):

    result = rc.PASS
    # Init test project
    shell_return = f.shell_run(p.KREM_CMD + p.CMD_INIT + " " +
                               p.CMD_INIT_OPTION_PROJECT + " " +
                               p.TEMP_PROJECT_PATH)

    print(p.TEMP_PROJECT_PATH)
    if shell_return[0] != 0:
        result = rc.FAIL

    # Copy job and task to test project
    if result == rc.PASS:
        shell_return = f.shell_run(
            "cp -r " + os.path.join(p.TEST_PROJECT_TASKS_DIR, p.SIMPLE_TASK) +
            " " + os.path.join(p.TEMP_PROJECT_PATH, p.TASKS_DIR_NAME))
        if shell_return[0] != 0:
            result = rc.FAIL

    if result == rc.PASS:
        shell_return = f.shell_run(
            "cp -r " + os.path.join(p.TEST_PROJECT_JOBS_DIR, p.SIMPLE_JOB) +
            " " + os.path.join(p.TEMP_PROJECT_PATH, p.JOBS_DIR_NAME))
        if shell_return[0] != 0:
            result = rc.FAIL

    return result
コード例 #2
0
ファイル: task.py プロジェクト: bitvismk/krem
def test_call_order(task):
    start_directory = os.getcwd()
    result = execute_with_target_setup(p.TEMP_PROJECT_PATH, "setup_test_call_order.py", "test_job")
    if result == rc.PASS:
        if not os.path.isfile(os.path.join("output", "call_order_ok")):
            print("ERROR: Failed to verify call order")
            result = rc.FAIL
        else:
            print("Call order verified")
        f.shell_run("cat output/test_job/latest/1_test_task__run__test_func_1/task.log")
    os.chdir(start_directory)
    print("Changed directory to " + str(start_directory))
    return result
コード例 #3
0
ファイル: task.py プロジェクト: bitvismk/krem
def run(task):
    result = rc.PASS
    temp_task_created = False
    temp_task_path = os.path.join(p.TEST_PROJECT_TASKS_DIR, p.TEMP_TASK_NAME)

    # Init job
    shell_return = f.shell_run(p.KREM_CMD + p.CMD_INIT + " " +
                               p.CMD_INIT_OPTION_TASK + " " + p.TEMP_TASK_NAME)
    if shell_return[0] != 0:
        result = rc.FAIL
    else:
        temp_task_created = True

    if result == rc.PASS:
        if not os.path.isfile(os.path.join(temp_task_path, p.TASK_SCRIPT)):
            result = rc.FAIL
            print("ERROR: Failed to deploy task template file: " +
                  p.TASK_SCRIPT)

    if temp_task_created:
        try:
            shutil.rmtree(temp_task_path)
            print("Directory removed: " + str(temp_task_path))
        except Exception:
            print("WARNING: Failed to remove temporary task '" +
                  p.TEMP_TASK_NAME + "'")
            result = rc.UNSTABLE

    return result
コード例 #4
0
ファイル: task.py プロジェクト: bitvismk/krem
def run_with_syntax_error(task):

    result = rc.PASS
    start_directory = os.getcwd()

    # Navigate to temp project dir and run
    try:
        os.chdir(p.TEMP_PROJECT_PATH)
    except Exception:
        result = rc.FAIL
        print("ERROR: Failed to change current directory to: '" +
              p.TEMP_PROJECT_PATH + "'")

    result = mv_files_to_temp_krem_project(p.TEMP_PROJECT_PATH)

    if result == rc.PASS:
        print("Changed directory to " + str(p.TEMP_PROJECT_PATH))
        shell_return = f.shell_run(p.KREM_CMD + p.CMD_RUN + " " +
                                   p.CMD_RUN_OPTION_JOB + " " +
                                   "test_syntax_error_job")

        #we expect the above command to fail since we are running a job with a task with syntax error
        #so failed job means that this test pass
        if shell_return[0] == 1:
            result = rc.PASS
        else:
            result = rc.FAIL

    os.chdir(start_directory)
    print("Changed directory to " + str(start_directory))

    return (result)
コード例 #5
0
def run(task):

    result = rc.PASS

    tasks_in_dir = []
    listed_tasks = []
    missing_from_list = []
    missing_from_tasks_dir = []

    shell_return = f.shell_run(p.KREM_CMD + p.CMD_LIST + " " +
                               p.CMD_LIST_OPTION_TASK)
    if shell_return[0] != 0:
        result = rc.FAIL

    if result == rc.PASS:
        # Get list of tasks
        print("tasks listed:")

        taskprint = re.findall(p.LIST_ID_REGEX + '.*', shell_return[1])
        for task in taskprint:
            m = re.search(p.LIST_ID_REGEX, task)
            if m:
                task = task.replace(m.group(), '')
                task = task.strip()
                listed_tasks.append(task)
                print(task)

        # Get tasks in task directory
        tasks_dir = os.listdir(p.TEST_PROJECT_TASKS_DIR)
        print("\nTasks present in tasks directory:")
        for task in tasks_dir:
            if task != "__pycache__":
                if os.path.isdir(os.path.join(p.TEST_PROJECT_TASKS_DIR, task)):
                    print(task)
                    tasks_in_dir.append(task)

    # compile results
    if result == rc.PASS:
        missing_from_list = f.compare_lists(listed_tasks, tasks_in_dir)
        missing_from_tasks_dir = f.compare_lists(tasks_in_dir, listed_tasks)

        if len(missing_from_list) > 0:
            print("\nERROR: Files present in tasks dir that was not listed: " +
                  str(missing_from_list))
            result = rc.FAIL
        if len(missing_from_tasks_dir):
            print("\nERROR: Files listed that are not present in tasks dir: " +
                  str(missing_from_tasks_dir))
            result = rc.FAIL

    return (result)
コード例 #6
0
ファイル: task.py プロジェクト: ipfarher/krem
def run(task):

    result = rc.PASS

    jobs_in_dir = []
    listed_jobs = []
    missing_from_list = []
    missing_from_jobs_dir = []

    shell_return = f.shell_run(p.KREM_CMD + "list " + p.CMD_LIST_OPTION_JOB)
    if shell_return[0] != 0:
        result = rc.FAIL

    if not result:
        # Get list of jobs
        print("Jobs listed:")

        jobprint = re.findall(p.LIST_ID_REGEX + '.*', shell_return[1])
        for job in jobprint:
            m = re.search(p.LIST_ID_REGEX, job)
            if m:
                job = job.replace(m.group(), '')
                job = job.strip()
                listed_jobs.append(job)
                print(job)

        # Get jobs in job directory
        jobs_dir = os.listdir(p.TEST_PROJECT_JOBS_DIR)
        print("\nJobs present in jobs directory:")
        for job in jobs_dir:
            if os.path.isdir(os.path.join(p.TEST_PROJECT_JOBS_DIR, job)):
                print(job)
                jobs_in_dir.append(job)

    # compile results
    if not result:
        missing_from_list = f.compare_lists(listed_jobs, jobs_in_dir)
        missing_from_jobs_dir = f.compare_lists(jobs_in_dir, listed_jobs)

        if len(missing_from_list) > 0:
            print("\nERROR: Files present in jobs dir that was not listed: " +
                  str(missing_from_list))
            result = rc.FAIL
        if len(missing_from_jobs_dir):
            print("\nERROR: Files listed that are not present in jobs dir: " +
                  str(missing_from_jobs_dir))
            result = rc.FAIL

    return (result)
コード例 #7
0
ファイル: task.py プロジェクト: bitvismk/krem
def run_and_check(cmd, expected):
    result = rc.PASS
    shell_return = f.shell_run(cmd)
    if shell_return[0] != 0:
        print("[ERROR]: Failed to run command: " + str(cmd))
        result = rc.FAIL

    if result == rc.PASS:
        for exp in expected:
            if exp not in shell_return[1]:
                print("[ERROR]: Unexpected command error. Expected '" +
                      str(expected) + "'. Got '" + str(shell_return[1]) + "'")
                result = rc.FAIL

    return result
コード例 #8
0
ファイル: task.py プロジェクト: bitvismk/krem
def execute_with_target_setup(path, target, test_job):
    result = rc.PASS
    setup_path = os.path.join(p.CONFIG_DIR_NAME, "setup_files")

    # Navigate to temp project dir and run
    try:
        os.chdir(path)
    except Exception:
        result = rc.FAIL
        print("ERROR: Failed to change current directory to: '" + path + "'")


    # Rename target setup file to "setup.py"
    if result == rc.PASS:
        print("Changed directory to " + str(path))

        try:
            shutil.move(os.path.join(setup_path, target), os.path.join(setup_path, "setup.py"))
            print("Using setup file: " + target)
        except Exception as e:
            print("Error: Failed to set target setup file: " + target)
            result = rc.FAIL

        #remove setup.pyc
        if os.path.isfile(os.path.join(setup_path, "setup.pyc")):
            os.remove(os.path.join(setup_path, "setup.pyc"))

    # execute job
    if result == rc.PASS:
        shell_return = f.shell_run("krem run -j " + test_job)
        if shell_return[0] != 0:
            result = rc.FAIL

    #rename test file to original name
    try:
        shutil.move(os.path.join(setup_path, "setup.py"), os.path.join(setup_path, target))    
    except Exception as e:
        print("WARNING: Failed to rename setup script back to original name")
        result = rc.UNSTABLE

    return(result)
コード例 #9
0
ファイル: task.py プロジェクト: ipfarher/krem
def run(task, path):

    path = os.path.abspath(path)
    result = rc.PASS
    start_directory = os.getcwd()

    # Navigate to temp project dir and run
    try:
        os.chdir(path)
    except Exception:
        result = rc.FAIL
        print("ERROR: Failed to change current directory to: '" + path + "'")
        
    if not result:
        print("Changed directory to " + str(path))
        shell_return = f.shell_run(p.KREM_CMD +  p.CMD_RUN + " " + p.CMD_RUN_OPTION_JOB + " " + p.SIMPLE_JOB)
        if shell_return[0] != 0:
            result = rc.FAIL   

    os.chdir(start_directory)
    print("Changed directory to " + str(start_directory))
    
    return(result)
コード例 #10
0
def run(task):

    result = rc.PASS
    start_directory = os.getcwd()

    # Navigate to temp project dir and run
    try:
        os.chdir(p.TEMP_PROJECT_PATH)
    except Exception:
        result = rc.FAIL
        print("ERROR: Failed to change current directory to: '" +
              p.TEMP_PROJECT_PATH + "'")

    if result == rc.PASS:
        print("Changed directory to " + str(p.TEMP_PROJECT_PATH))
        shell_return = f.shell_run(p.KREM_CMD + p.CMD_RUN + " " +
                                   p.CMD_RUN_OPTION_JOB + " " + p.SIMPLE_JOB)
        if shell_return[0] != 0:
            result = rc.FAIL

    os.chdir(start_directory)
    print("Changed directory to " + str(start_directory))

    return (result)