Пример #1
0
def take_user_input():
    sal_input = input(
        "Do you want to build(b),clean(c),run(r),test(t),[do_nothing(n)] sal, "
        "Enter one or more action chars in appropriate order i.e. cbr?")

    if 'n' in sal_input or not sal_input:
        # In case user give nasty input like cbrn
        # User meant do nothing in such cases
        return

    

    for action_char in sal_input:
        if action_char == 'c':
            set_sal_env()
            clean_sal()
        elif action_char == 'r' and get_selected_profile_name() in [
                constants.sal_hw_profile_name,
                constants.sal_sim_profile_name]:
            # Additional checks are for if user selected stratum profile
            # Then there is no need to run sal.
            run_sal()
        elif action_char == 't':
            test_sal()
        elif action_char == 'b':
            set_sal_env()
            build_sal()
            prepare_sal_release()
        else:
            print(
                "Unrecognised action {0} or action doesn't fit with selected profile {1}.".format(
                    action_char, get_selected_profile_name()))
Пример #2
0
def execute_user_action(sal_input):
    rc = True
    for action_char in sal_input:
        if action_char == 'c':
            rc &= set_sal_env()
            rc &= clean_sal()
        elif action_char == 'r':
            rc &= run_sal()
        elif action_char == 't':
            print('Running SAL tests from AOT are currently not supported, '
                  'Should run from within SAL package only')
            # rc &= test_sal()
        elif action_char == 'b':
            rc &= set_sal_env()
            rc &= build_sal()
            rc &= prepare_sal_release()
        elif action_char == 'i':
            if get_from_advance_setting_dict(constants.sal_sw_attr_node,
                                             constants.build_third_party_node):
                rc &= install_sal_thirdparty_deps()
            else:
                print(
                    'But choose not to build thirdparty SW. Check settings.yaml'
                )
        else:
            print(
                "Invalid action {0} or action doesn't fit with selected profile {1}."
                .format(action_char, get_selected_profile_name()))
            return False
    return rc
Пример #3
0
def take_user_input():
    sal_input = input(
        "SAL : build(b),clean(c),run(r),test(t),install_deps(i),[do_nothing(n)], "
        "Enter one or more action chars in appropriate order i.e. cbr?")

    if 'n' in sal_input or not sal_input:
        # In case user give nasty input like cbrn
        # User meant do nothing in such cases
        return

    for action_char in sal_input:
        if action_char == 'c':
            set_sal_env()
            clean_sal()
        elif action_char == 'r':
            run_sal()
        elif action_char == 't':
            test_sal()
        elif action_char == 'b':
            set_sal_env()
            build_sal()
            prepare_sal_release()
        elif action_char == 'i':
            if get_from_setting_dict(constants.sal_sw_attr_node,
                                     constants.build_third_party_node):
                install_sal_thirdparty_deps()
            else:
                print(
                    'But choose not to build thirdparty SW. Check settings.yaml'
                )
        else:
            print(
                "Invalid action {0} or action doesn't fit with selected profile {1}."
                .format(action_char, get_selected_profile_name()))
Пример #4
0
def get_stratum_profile_dict():
    if get_selected_profile_name() in [constants.stratum_hw_profile_name,
                                       constants.stratum_sim_profile_name]:
        return get_selected_profile_dict()
    else:
        # Currently there is no difference btwn stratum hw or sw profile
        return settings_dict.get(constants.build_profiles_node).get(
            constants.stratum_hw_profile)
Пример #5
0
def load_bf_sde_profile():
    ask_user_for_building_sde()
    ask_user_for_building_bsp()
    prepare_sde_release()
    # SDE to be started only in case of SDE profiles
    # Else SDE will be started by SAL or STRATUM
    if get_selected_profile_name() in [
            constants.sde_hw_profile_name, constants.sde_sim_profile_name
    ]:
        ask_user_for_starting_sde()
Пример #6
0
def do_basic_path_validation(profile_name):
    # Do basic path verification.
    print('Selected build profile is {}.'.format(profile_name))
    print('Switch model : {}'.format(get_switch_model_from_settings()))
    validate_path_existence(get_sde_pkg_abs_path(), 'Barefoot SDE')
    if not is_sim_profile_selected():
        validate_path_existence(get_bsp_pkg_abs_path(), 'BSP')
    if get_selected_profile_name() in [constants.stratum_sim_profile_name,
                                       constants.stratum_hw_profile_name]:
        validate_path_existence(get_stratum_home_absolute(),'Stratum')
Пример #7
0
def build_sde():
    install_sde_deps()
    sde_tar = tarfile.open(get_sde_pkg_abs_path())
    sde_home_absolute = get_sde_home_absolute()
    sde_build_flags = get_sde_build_flags()

    # Deletion is required otherwise moving the directories
    # in further steps might create issues.
    # And delete only when user have opted for not to resume build
    if sde_build_flags is not None and '-rb' not in sde_build_flags:
        try:
            print("Deleting previous installation at {}.".format(
                sde_home_absolute))
            os.system('sudo rm -rf {}'.format(sde_home_absolute))
        except FileNotFoundError:
            print('{} already deleted.'.format(sde_home_absolute))

    # Extract tar here i.e. in APS one touch directory
    sde_tar.extractall()
    # In case SDE home is configured in yaml other than this directory,
    # If both paths are same following line doesn't cause any problem.
    if not os.path.exists(sde_home_absolute):
        shutil.move(get_sde_dir_name_in_tar(), sde_home_absolute)
    sde_tar.close()
    os.chdir(sde_home_absolute)
    build_opt = "-up"
    p4studio_build_profile = get_p4_studio_build_profile_name()

    if get_selected_profile_name() in [
            constants.stratum_hw_profile_name,
            constants.stratum_sim_profile_name
    ]:
        p4studio_build_profile = stratum_profile

    if p4studio_build_profile == "" or p4studio_build_profile is None:
        build_opt = ""
        p4studio_build_profile = ""

    sde_install_cmd = "{0}/p4studio_build/p4studio_build.py {1} {2}".format(
        sde_home_absolute, build_opt, p4studio_build_profile)

    if sde_build_flags is not None:
        for flag in sde_build_flags:
            if flag:
                sde_install_cmd += ' ' + flag
    else:
        print('No build flag will be used for BF_SDE build.')
    os.environ[
        constants.path_env_var_name] += os.pathsep + sde_home_absolute + \
                                        '/install/bin/'
    print('Building sde with command {}'.format(sde_install_cmd))
    os.system(sde_install_cmd)
    return True
Пример #8
0
def get_sal_profile_dict():
    selected_profile = get_selected_profile_dict()
    selected_profile_name = get_selected_profile_name()
    if selected_profile_name in [constants.sal_hw_profile_name,
                                 constants.sal_sim_profile_name]:
        return selected_profile
    elif selected_profile_name == constants.stratum_sim_profile_name:
        return common.settings_dict.get(constants.build_profiles_node).get(
            constants.sal_sim_profile_node)
    elif selected_profile_name == constants.stratum_hw_profile_name:
        return common.settings_dict.get(constants.build_profiles_node).get(
            constants.sal_hw_profile_node)
    else:
        logging.error('There is no selected or associated SAL profile')
Пример #9
0
def run_sal():
    print('Starting SAL reference application...')
    if get_selected_profile_name() == constants.sal_hw_profile_name and not load_and_verify_kernel_modules():
        print("ERROR:Some kernel modules are not loaded.")
        exit(0)

    #os.environ['TCMALLOC_LARGE_ALLOC_REPORT_THRESHOLD'] = '64077925800531312640'
    set_env_var(constants.sal_home_env_var_name, sal_rel_dir)

    sal_executable = sal_rel_dir + '/build/salRefApp'
    sal_run_cmd='sudo -E LD_LIBRARY_PATH={0}:{1} {2}'.format(
        sal_rel_dir + '/lib',
        get_sde_home_absolute() + '/install/lib', sal_executable)
    print('Running SAL with command: {}'.format(sal_run_cmd))
    os.system(sal_run_cmd)
Пример #10
0
def run_sal():
    print('Starting SAL reference application...')
    set_sal_runtime_env()
    if get_selected_profile_name(
    ) == constants.sal_hw_profile_name and not load_and_verify_kernel_modules(
    ):
        print("ERROR:Some kernel modules are not loaded.")
        exit(0)

    sal_executable = sal_rel_dir + '/build/salRefApp'
    sal_run_cmd = 'sudo -E LD_LIBRARY_PATH={0}:{1}:{2} {3}'.format(
        sal_rel_dir + '/build', sal_rel_dir + '/lib',
        get_sde_home_absolute() + '/install/lib', sal_executable)
    print('Running SAL with command: {}'.format(sal_run_cmd))
    os.system(sal_run_cmd)
Пример #11
0
def build_sde():
    sde_tar = tarfile.open(get_sde_pkg_name())
    sde_home_absolute = get_sde_home_absolute()
    sde_build_flags = get_sde_build_flags()

    # Deletion is required otherwise moving the directories
    # in further steps might create issues.
    # And delete only when user have opted for not to resume build
    if '-rb' not in sde_build_flags:
        try:
            print("Deleting previous installation at {}.".format(
                sde_home_absolute))
            os.system('sudo rm -rf {}'.format(sde_home_absolute))
        except FileNotFoundError as e:
            print('{} already deleted.'.format(sde_home_absolute))

    # Extract tar here i.e. in APS one touch directory
    sde_tar.extractall()
    # In case SDE home is configured in yaml other than this directory,
    # If both paths are same following line doesn't cause any problem.
    if not os.path.exists(sde_home_absolute):
        shutil.move(get_sde_dir_name_in_tar(), sde_home_absolute)
    sde_tar.close()
    os.chdir(sde_home_absolute)
    build_opt = "-up"
    p4studio_build_profile = get_from_setting_dict('BF SDE',
                                                   'p4studio_build_profile')

    if get_selected_profile_name() in [
            constants.stratum_hw_profile_name,
            constants.stratum_sim_profile_name
    ]:
        p4studio_build_profile = 'stratum_profile'

    if p4studio_build_profile == "":
        build_opt = ""

    sde_install_cmd = "./p4studio_build/p4studio_build.py {} {}".format(
        build_opt, p4studio_build_profile)

    for flag in sde_build_flags:
        if flag:
            sde_install_cmd += ' ' + flag

    print('Building sde with command {}'.format(sde_install_cmd))
    os.system(sde_install_cmd)
Пример #12
0
def run_sal():
    print('Starting SAL reference application...')
    if get_selected_profile_name(
    ) == constants.sal_hw_profile_name and not load_and_verify_kernel_modules(
    ):
        print("ERROR:Some kernel modules are not loaded.")
        exit(0)
    sal_home = get_env_var(constants.sal_home_env_var_name)
    sal_executable = sal_home + '/build/salRefApp'
    sal_run_cmd = 'sudo -E LD_LIBRARY_PATH={0}:{1}:{2}:{3} {4}'.format(
        sal_home + '/build', sal_home + '/lib',
        get_env_var(constants.tp_install_env_var_name) + '/lib',
        get_env_var(constants.sal_home_env_var_name) + '/install/lib',
        sal_executable)
    print('Running SAL with command: {}'.format(sal_run_cmd))
    execute_cmd(sal_run_cmd)
    return True
Пример #13
0
def do_basic_path_validation(prof_name):
    # Do basic path verification.
    print('Selected build profile is {}.'.format(prof_name))
    print('Switch model : {}'.format(get_switch_model()))
    validate_path_existence(get_sde_pkg_abs_path(), 'Barefoot SDE')
    if not is_sim_profile_selected():
        validate_path_existence(get_ref_bsp_abs_path(), 'BF BSP')
    if get_selected_profile_name() in [
            constants.stratum_sim_profile_name,
            constants.stratum_hw_profile_name
    ]:
        validate_path_existence(get_stratum_home_absolute(), 'Stratum')


if __name__ == '__main__':
    profile_name = get_selected_profile_name()

    do_basic_path_validation(profile_name)

    if profile_name in [
            constants.stratum_hw_profile_name,
            constants.stratum_sim_profile_name
    ]:
        load_stratum_profile()
    elif profile_name in [
            constants.sde_sim_profile_name, constants.sde_hw_profile_name
    ]:
        load_bf_sde_profile()
    elif profile_name in [
            constants.sal_sim_profile_name, constants.sal_hw_profile_name
    ]:
Пример #14
0
def get_stratum_profile_dict():
    if get_selected_profile_name() in [
            constants.stratum_hw_profile_name,
            constants.stratum_sim_profile_name
    ]:
        return get_selected_profile_dict()