def ui_entry_api(board_info, scenario_info, launch_info):

    err_dic = {}
    arg_list = [
        'board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info,
        '--launch', launch_info, '--uosid', '0'
    ]

    err_dic = launch_cfg_lib.prepare()
    if err_dic:
        return err_dic

    err_dic = main(arg_list)
    return err_dic
예제 #2
0
def ui_entry_api(board_info, scenario_info, launch_info, enable_commit=False):

    err_dic = {}
    git_env_check = False
    arg_list = ['board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info, '--launch', launch_info, '--uosid', '0']

    if enable_commit:
        arg_list.append('--enable_commit')
        git_env_check = True

    err_dic = launch_cfg_lib.prepare(git_env_check)
    if err_dic:
        return err_dic

    err_dic = main(arg_list)
    return err_dic
예제 #3
0
def main(args):
    """
    This is main function to start generate launch script
    :param args: it is a command line args for the script
    """
    config_srcs = []

    # get parameters
    (err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th, enable_commit) = launch_cfg_lib.get_param(args)
    if err_dic:
        return err_dic

    # check env
    err_dic = launch_cfg_lib.prepare(enable_commit)
    if err_dic:
        return err_dic

    # vm_th =[0..post_vm_max]
    # 0: generate all launch script for all post vm launch script
    # 1: generate launch script for 1st post vm launch script
    # 2: generate launch script for 2nd post vm launch script

    launch_cfg_lib.BOARD_INFO_FILE = board_info_file
    launch_cfg_lib.SCENARIO_INFO_FILE = scenario_info_file
    launch_cfg_lib.LAUNCH_INFO_FILE = launch_info_file

    # get post vm dic
    post_num_list = launch_cfg_lib.get_post_num_list()

    # get toatl post vm number and total vm in launch config file
    (launch_vm_count, post_vm_count) = launch_cfg_lib.get_post_vm_cnt()
    if vm_th < 0 or vm_th > post_vm_count:
        err_dic['uosid err:'] = "--uosid shoudl be positive and less than total post vm count in scenario"
    if vm_th and vm_th not in post_num_list:
        err_dic['uosid err:'] = "--uosid generate the {} post vm, but this vm's config not in launch xml".format(vm_th)
    if launch_vm_count > post_vm_count:
        err_dic['xm config err:'] = "too many vms config than scenario"

    for post_num in post_num_list:
        if post_num > post_vm_count:
            err_dic['xm config err:'] = "launch xml uos id config is bigger than scenario post vm count"

    if err_dic:
        return err_dic

    # validate launch config file
    (err_dic, pt_sel, virt_io, dm) = validate_launch_setting(board_info_file, scenario_info_file, launch_info_file)
    if err_dic:
        return err_dic

    # check if this is the scenario config which matched board info
    (err_dic, status) = launch_cfg_lib.is_config_file_match()
    if not status:
        return err_dic

    (err_dic, names) = get_names()
    if err_dic:
        return err_dic

    # create output directory
    board_name = names['board_name']
    output = XML_PATH + '/' + board_name + '/output/'
    if not os.path.exists(output):
        os.makedirs(output)

    # generate launch script
    if vm_th:
        script_name = "launch_uos_id{}.sh".format(vm_th)
        commit_msg = script_name
        launch_script_file = output + script_name
        config_srcs.append(launch_script_file)
        with open(launch_script_file, mode = 'w', newline=None, encoding='utf-8') as config:
            err_dic = generate_script_file(names, pt_sel, virt_io.dev, dm.args, vm_th, config)
            if err_dic:
                return err_dic
    else:
        for post_vm_i in post_num_list:
            script_name = "launch_uos_id{}.sh".format(post_vm_i)
            launch_script_file = output + script_name
            config_srcs.append(launch_script_file)
            with open(launch_script_file, mode = 'w', newline='\n', encoding='utf-8') as config:
                err_dic = generate_script_file(names, pt_sel, virt_io.dev, dm.args, post_vm_i, config)
                if err_dic:
                    return err_dic

        commit_msg = "launch_uos_id{}.sh".format(launch_vm_count)

    config_str = 'Config files'
    gen_str = 'generated'
    # move changes to patch, and apply to the source code
    if enable_commit:
        err_dic = launch_cfg_lib.gen_patch(config_srcs, commit_msg)
        config_str = 'Config patch'
        gen_str = 'committed'

    if not err_dic:
        print("{} for {} is {} successfully!".format(config_str, commit_msg, gen_str))
    else:
        print("{} for {} is failed".format(config_str, commit_msg))

    return err_dic
                      newline='\n',
                      encoding='utf-8') as config:
                generate_script_file(names, pt_sel, dm.args, post_vm_i, config)

        commit_msg = "launch_uos_id{}.sh".format(launch_vm_count)

    # move changes to patch, and apply to the source code
    err_dic = launch_cfg_lib.gen_patch(config_srcs, commit_msg)
    if not err_dic:
        print("Config patch for {} is committed successfully!".format(
            commit_msg))
    else:
        print("Config patch for {} is failed".format(commit_msg))

    return err_dic


if __name__ == '__main__':

    err_dic = launch_cfg_lib.prepare()
    if err_dic:
        for err_k, err_v in err_dic.items():
            launch_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True)
        sys.exit(1)

    ARGS = sys.argv
    err_dic = main(ARGS)
    if err_dic:
        for err_k, err_v in err_dic.items():
            launch_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True)
예제 #5
0
def main(args):
    """
    This is main function to start generate launch script
    :param args: it is a command line args for the script
    """
    global ACRN_CONFIG_TARGET
    # get parameters
    (err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th,
     output_folder) = launch_cfg_lib.get_param(args)
    if err_dic:
        return err_dic

    if output_folder:
        ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/'

    # check env
    err_dic = launch_cfg_lib.prepare()
    if err_dic:
        return err_dic

    # vm_th =[0..post_vm_max]
    # 0: generate all launch script for all post vm launch script
    # 1: generate launch script for 1st post vm launch script
    # 2: generate launch script for 2nd post vm launch script

    launch_cfg_lib.BOARD_INFO_FILE = board_info_file
    launch_cfg_lib.SCENARIO_INFO_FILE = scenario_info_file
    launch_cfg_lib.LAUNCH_INFO_FILE = launch_info_file

    # get post vm dic
    post_num_list = launch_cfg_lib.get_post_num_list()

    # get toatl post vm number and total vm in launch config file
    (launch_vm_count, post_vm_count) = launch_cfg_lib.get_post_vm_cnt()
    if vm_th < 0 or vm_th > post_vm_count:
        err_dic[
            'uosid err:'] = "--uosid shoudl be positive and less than total post vm count in scenario"
    if vm_th and vm_th not in post_num_list:
        err_dic[
            'uosid err:'] = "--uosid generate the {} post vm, but this vm's config not in launch xml".format(
                vm_th)
    if launch_vm_count > post_vm_count:
        err_dic['xm config err:'] = "too many vms config than scenario"

    for post_num in post_num_list:
        if post_num > post_vm_count:
            err_dic[
                'xm config err:'] = "launch xml uos id config is bigger than scenario post vm count"

    if err_dic:
        return err_dic

    # validate launch config file
    (err_dic, pt_sel, virt_io,
     dm) = validate_launch_setting(board_info_file, scenario_info_file,
                                   launch_info_file)
    if err_dic:
        return err_dic

    # check if this is the scenario config which matched board info
    (err_dic, status) = launch_cfg_lib.is_config_file_match()
    if not status:
        return err_dic

    (err_dic, names) = get_names()
    if err_dic:
        return err_dic

    # create output directory
    board_name = names['board_name']
    output = ACRN_CONFIG_TARGET + '/' + board_name + '/output/'
    launch_cfg_lib.mkdir(output)

    # generate launch script
    if vm_th:
        script_name = "launch_uos_id{}.sh".format(vm_th)
        launch_script_file = output + script_name
        with open(launch_script_file, mode='w', newline=None,
                  encoding='utf-8') as config:
            err_dic = generate_script_file(names, pt_sel, virt_io.dev, dm.args,
                                           vm_th, config)
            if err_dic:
                return err_dic
    else:
        for post_vm_i in post_num_list:
            script_name = "launch_uos_id{}.sh".format(post_vm_i)
            launch_script_file = output + script_name
            with open(launch_script_file,
                      mode='w',
                      newline='\n',
                      encoding='utf-8') as config:
                err_dic = generate_script_file(names, pt_sel, virt_io.dev,
                                               dm.args, post_vm_i, config)
                if err_dic:
                    return err_dic

    if not err_dic:
        print("Launch files in {} is generated successfully!".format(output))
    else:
        print("Launch files generate failed".format(output))

    return err_dic