Esempio n. 1
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
Esempio n. 2
0
def main(args):
    """
    This is main function to start generate launch script
    :param args: it is a command line args for the script
    """
    # 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

    # check env
    err_dic = common.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

    common.BOARD_INFO_FILE = board_info_file
    common.SCENARIO_INFO_FILE = scenario_info_file
    common.LAUNCH_INFO_FILE = launch_info_file
    common.get_vm_types()

    # 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']
    if output_folder:
        if os.path.isabs(output_folder):
            output = os.path.join(output_folder + '/' + board_name, 'output/')
        else:
            output = os.path.join(ACRN_PATH + output_folder + '/' + board_name,
                                  'output/')
    else:
        output = os.path.join(ACRN_CONFIG_DEF + board_name, 'output/')
    common.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
def main(args):
    """
    This is main function to start generate launch script
    :param args: it is a command line args for the script
    """
    # 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

    # check env
    err_dic = common.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

    common.BOARD_INFO_FILE = board_info_file
    common.SCENARIO_INFO_FILE = scenario_info_file
    common.LAUNCH_INFO_FILE = launch_info_file
    common.get_vm_types()

    # 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[
            'user_vmid err:'] = "--user_vmid 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[
            'user_vmid err:'] = "--user_vmid 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 user vmid config is bigger than scenario post vm count"

    # validate vm_names
    scenario_names = common.get_leaf_tag_map(scenario_info_file,
                                             "name").values()
    for user_vm_id, vm_name in launch_cfg_lib.get_user_vm_names().items():
        if not re.match(r"^\S{1,15}$", vm_name):
            err_name = 'user_vm id="{}" name error:'.format(user_vm_id)
            err_dic[err_name] = 'vm_name only allowed 1-15 characters with letters, numbers & symbols ' \
                                '(not include space)'
        if vm_name not in scenario_names:
            err_name = 'user_vm id="{}" name not found error:'.format(
                user_vm_id)
            err_dic[
                err_name] = 'user_vm id="{}" vm_name not found in it scenario file:'.format(
                    user_vm_id)

    if err_dic:
        return err_dic

    # validate launch config file
    (err_dic, pt_sel, virt_io, dm,
     sriov) = 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']
    if output_folder:
        if os.path.isabs(output_folder):
            output = os.path.join(output_folder, board_name, 'output')
        else:
            output = os.path.join(ACRN_PATH, output_folder, board_name,
                                  'output')
    else:
        output = os.path.join(ACRN_CONFIG_DEF, board_name, 'output')
    output = os.path.abspath(output)
    common.mkdir(output)

    # generate launch script
    if vm_th:
        script_name = "launch_user_vm_id{}.sh".format(vm_th)
        launch_script_file = os.path.join(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,
                                           sriov.dev, vm_th, config)
            if err_dic:
                return err_dic
    else:
        for post_vm_i in post_num_list:
            script_name = "launch_user_vm_id{}.sh".format(post_vm_i)
            launch_script_file = os.path.join(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, sriov.dev, 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