Esempio n. 1
0
def main():

    #------------------------------------------
    # Usage tool option
    #------------------------------------------
    def usage():
        print " \n"
        print "  :: Command line USAGE options for Copying SBE FW files for compilation :: \n"
        print "  sbeDistribute.py -s <Sandbox Name> -i <file1,file2...>"

        print " \n"
        print "   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        print "   |       By default NO argument is needed as an input .                            |"
        print "   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        print " \n  ***** Options Supported  *****"
        print " \t  -p,--patch     = [ Optional ] Patch Simics related files on Sandbox "
        print " \t  -s,--sb        = [ Optional ] Sandbox base name"
        print " \t                                By default it picks up the ppe Repo test_sb sandbox"
        print " \t                                but if you have created a sandbox of your own manually "
        print " \t                                and you want to compile, use this option then only"
        print " \t  -i,--files     = [ Optional ] Firmware Files coma ',' separated input file1,file2"
        print " \t                                Only the pre-define listed files bellow:"
        print " \t                                sbe_sp_intf.H,simics.tar,"
        print " \t                                sbe_seeprom_DD1.bin/sbe_seeprom_DD2.bin"
        print " \t  -r,--rc_file   = [ Optional ] The RC file for the sandbox (with absolute path)"
        print " \t  -n,--no_build  = [ Optional ] Flag to determine if sbei component should be compiled"
        print " \t  -h,--help      = Help"
        print "  ------------------------------------------------------------------------------------"

    #------------------------------------------
    # Exit from this Main
    #------------------------------------------
    def exit_main(rc):
        if rc == errorcode.HELP_EXIT:
           print "  [ HELP DOCUMENTATION ]\n"
           sys.exit(0)

        if rc == errorcode.ERROR_BUILD_FAILED:
            print "  Compilation Failed .. Error "

        if rc == errorcode.SUCCESS_DEV_EXIT:
           print "  [ Files Copy done! ]\n"
           sys.exit(0)

        if rc:
           print "\n  [ ERROR - MAIN ] Exiting with error code = ", rc
           sys.exit(rc)
        else:
           print "\n  Fips Sandbox compilation and simics patching completed [ OK ] "
           sys.exit(0)

    #------------------------------------------
    # Local var place name holder's
    #------------------------------------------
    sim_patch    = "None"
    sandbox_name = "None"
    path_name    = "None" # PPE Repo
    file_name    = "None"
    rc_file      = "None"
    build        = "1"
    ddlevel      = "None"

    #----------------------------
    # Read command line args
    #----------------------------
    opts, args = getopt.getopt(sys.argv[1:],"p:s:i:hr:nl:",['patch=', 'sb=', 'files=', 'help', 'rc_file=', 'no_build', 'level='])
    for opt, arg in opts:
       if opt in ('-h', '--help'):
           usage()
           exit_main(errorcode.HELP_EXIT)
       elif opt in ('-p', '--patch'):
           sim_patch = arg
       elif opt in ('-s', '--sb'):
           sandbox_name = arg
       elif opt in ('-i', '--files'):
           file_name = arg
       elif opt in ('-r', '--rc_file'):
           rc_file = arg
       elif opt in ('--no_build'):
           build = "0"
       elif opt in ('-l', '--level'):
           ddlevel = arg
       else:
           usage()
           exit_main(errorcode.ERROR_EXIT)

    #------------------------------------------------------
    # Make sure that it has passed atleast one arg with it
    #------------------------------------------------------
    if len(sys.argv)<1:
        usage()
        exit_main(errorcode.ERROR_SYS_EXIT)

    #---------------------------------------------
    # Callling the Func defs in order
    #---------------------------------------------

    #------------------------------
    # 1) User input params/ Check ENV
    #------------------------------
    print "\n [ Checking SBE user ENV Pre-req ] "
    # Get it from ENV
    if path_name == "None":
        # Get the PPE path
        l_ppe_path = utilcode.utilppeSbENV("SBEROOT")
        if l_ppe_path == "None":
            print "\n  Couldn't find PPE repo info from ENV currently set... "
            print "  [ ERROR ] PPE Repo ENV Setting Path  : %s " % l_ppe_path
            exit_main(errorcode.ERROR_SETTING)
        else:
            print "  PPE Repo path Setting\t :  %s "% l_ppe_path
            path_name = l_ppe_path

    #-----------------------------------
    # 2) Get the Sanbox and repo paths
    #-----------------------------------
    # Get the base path of the fips sandbox
    if sandbox_name == "None":
        # Find the sanbox name and base from ENV
        # User must have done workon fips sandbox to work
        sandbox_path = utilcode.utilFind_ENV_string("SANDBOXBASE").rstrip('\n')
    else:
        sandbox_path = utilcode.utilFind_sb_base(sandbox_name).rstrip('\n')
    print "  Fips Sandbox path\t : ",sandbox_path

    #-----------------------------------
    # 3) Get the Sanbox root path
    #-----------------------------------
    if sandbox_name == "None":
        sandbox_root = utilcode.utilFind_ENV_string("SANDBOXROOT").rstrip('\n')
    else:
#        sandbox_root = utilcode.utilFind_ENV_string("SANDBOXRC").rstrip('\n')
        sandbox_root = utilcode.utilFind_sb_rc(sandbox_name).rstrip('\n')

    if sandbox_root == "None":
        print "  ** [ ERROR ] Something Fishy about the ENV set -OR- Option used.. Please check manually ** "
        usage()
        exit_main(errorcode.ERROR_SETTING)
    else:
        print "  Sandbox root path\t : ",sandbox_root

    #---------------------------------------------
    # sim setup if user initiates
    #---------------------------------------------
    if sim_patch != "None":
        #---------------------------------------------
        # Create sandbox for simics
        #---------------------------------------------
        rc_sb = utilpatch.utilExecuteShell(path_name,"None","sandbox-create")
        if rc_sb == errorcode.SUCCESS_EXIT:
            print "  Sandbox Created.. [ OK ] \n"
        else:
            print "  Sandbox Create.. [ ERROR ]",rc_sb
            exit_main(rc_sb)

        #----------------------------------------
        # Patch up the simics patches files
        #----------------------------------------

        print "\n  *** Update Simics patches onto Sandbox *** \n "
        # Pre sim setup
        rc_shell = utilpatch.utilExecuteShell(path_name,sandbox_path,"workarounds.presimsetup")
        if rc_shell == errorcode.SUCCESS_EXIT:
            print "  presimsetup [ OK ]\n"
        else:
            print "  presimsetup [ ERROR ] : ",rc_shell
            exit_main(rc_shell)

        # Patch the simics files
        rc_sim = utilpatch.utilPatchSimics(sandbox_path,sandbox_root)
        if rc_sim != errorcode.SUCCESS_EXIT:
            exit_main(rc_sim)
        else:
            print "  Patch the simics files on Sandbox [ OK ] \n"

        # Post sim setup
        rc_shell = utilpatch.utilExecuteShell(path_name,sandbox_path,"workarounds.postsimsetup")
        if rc_shell == errorcode.SUCCESS_EXIT:
            print "  postsimsetup [ OK ]\n"
            # Clean exit Get out from here
            exit_main(errorcode.SUCCESS_EXIT)
        else:
            print "  postsimsetup [ ERROR ] : ",rc_shell
            exit_main(rc_shell)

    # Files to copy for sbe prime
    # TODO via RTC:168436 - remove sbe_seeprom.bin
    if ddlevel == "None":
        PRIME_FILE_LIST  ="sbe_sp_intf.H,simics.tar,sbe_seeprom.bin,sbe_seeprom_DD1.bin,sbe_seeprom_DD2.bin"
    else:
        PRIME_FILE_LIST  ="sbe_sp_intf.H,simics.tar,sbe_seeprom.bin,sbe_seeprom_"+ddlevel+".bin"

    #----------------------------------------
    # 4) Copy the files from repo to sandbox
    #----------------------------------------
    # Find the files and copy to the sanbox dir
    # Just take a quick check if the Sandbox exist or not

    if sim_patch == "None":
        file_name = PRIME_FILE_LIST
    if sandbox_path != "None":
        if os.path.isdir(sandbox_path) == True:
           rc_copy = utilcode.utilCopyFileToSandbox(path_name,sandbox_path,file_name)
           if rc_copy == errorcode.SUCCESS_DEV_EXIT:
               print "  Files Copied to Fips Sandbox : [ OK ]"
           else:
               exit_main(rc_copy)
        else:
            print "  Sandbox : %s [ Either doesn't exist or do workon to fips sb to load the ENV.. ]" % os.path.basename(sandbox_path)
            print "               - OR - "
            print "  [ Optional ] You can specify your sandbox name as input as well"
            print "               -s <fips_sandbox Name >"
            usage()
            exit_main(errorcode.ERROR_SANDBOX_EXIST)
    else:
        print "  Please Check your fips Sandbox and retry"
        exit_main(errorcode.ERROR_SANDBOX_EXIST)

    sb_name=os.path.basename(sandbox_path)
    print "\n  Sandbox :",sb_name

    if build == "1":
        #----------------------------------------
        # 5) Wite the hook file into shell file
        #----------------------------------------
        # Write the compile shell hook on the fips sandbox location
        hook_file = utilcode.utilWriteShell_hooks(sandbox_path)

        #----------------------------------------
        # 6) Compile the code
        #----------------------------------------
        # Use the hook script to compile the code
        if sandbox_name == "None":
            compile_cmd="workon -m ppc  " + sb_name + " -c " + hook_file + " -rc " + sandbox_root +"/sbesandboxrc"
        else:
            if rc_file == "None":
                compile_cmd="workon -m ppc  " + sb_name + " -c " + hook_file + " -rc " + sandbox_root +"/.sandboxrc"
            else:
                print " getting rc file from user \n"
                compile_cmd="workon -m ppc  " + sb_name + " -c " + hook_file + " -rc " + rc_file
        print "\n  [ COMPILE ] Executing :%s \n"%compile_cmd
        rc = os.system(compile_cmd)

        print "  Compilation returned rc :",rc
        if rc != 0:
            exit_main(errorcode.ERROR_BUILD_FAILED)

    # Clean exit
    exit_main(errorcode.SUCCESS_EXIT)
Esempio n. 2
0
def main():

    #------------------------------------------
    # Usage tool option
    #------------------------------------------
    def usage():
        print "  ---------------------------------------------------------------------------------------------------"
        print "  :: Command line USAGE options for Uploading FW SBE image to CMVC :: \n"
        print "  CommitSbeImageToCMVC.py -d <cmvc defect/feature id> -r <fips release> -p <SBE repo Path> -i <file1,file2.file3>"

        print " \n"
        print "   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        print "   |       By default user MUST pass CMVC/Release/Path input.                        |"
        print "   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        print " \n  ***** Options Supported  *****"
        print " \t  -d,--defect       = Defect CMVC number"
        print " \t  -f,--feature      = Feature CMVC number"
        print " \t  -r,--release      = FW fips release string EX: fips910"
        print " \t  -p,--path         = Absolute path of the SBE repo"
        print " \t  -i,--input        = [ Optional ] List of image or file to upload"
        print " \t  -b,--bvt          = BVT xml file for CI"
        print " \t  -h,--help         = Help"
        print "  ------------------------------------------------------------------------------------"

    #------------------------------------------
    # Exit from this Main
    #------------------------------------------
    def exit_main(rc):
        if rc == errorcode.HELP_EXIT:
            print "  [ HELP DOCUMENTATION ]\n"
            sys.exit(0)

        if rc:
            print "\n  [ ERROR - MAIN ] Exiting with error code = ", rc
            sys.exit(rc)
        else:
            print "\n  SBE Image Upload to CMVC completed [ OK ] "
            sys.exit(0)

    #------------------------------------------
    # Local var place name holder's
    #------------------------------------------
    defect_num = "None"
    feature_num = "None"
    release_name = "None"
    path_name = "None"
    file_name = "None"
    bvt = "None"

    #----------------------------
    # Read command line args
    #----------------------------
    opts, args = getopt.getopt(
        sys.argv[1:], "d:f:r:p:i:b:h",
        ['defect=', 'feature=', 'release=', 'path=', 'input=', 'bvt=', 'help'])
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage()
            exit_main(errorcode.HELP_EXIT)
        elif opt in ('-d', '--defect'):
            defect_num = arg
        elif opt in ('-f', '--feature'):
            feature_num = arg
        elif opt in ('-r', '--release'):
            release_name = arg
        elif opt in ('-p', '--path'):
            path_name = arg
        elif opt in ('-i', '--input'):
            file_name = arg
        elif opt in ('-b', '--bvt'):
            bvt = arg
        else:
            usage()
            exit_main(errorcode.ERROR_EXIT)

    #----------------------------------
    # Preping the data for Image Upload
    #----------------------------------
    print " \n"
    print "  ******************************************************"
    print "  ******  Stagging PPE image Files Upload to CMVC ******"
    print "  ******************************************************"

    #------------------------------------------------------
    # Make sure that it has passed atleast one arg with it
    #------------------------------------------------------
    if len(sys.argv) < 2:
        usage()
        exit_main(errorcode.ERROR_SYS_EXIT)

    #-------------------------------------------------------------
    # Check user inputs and display
    #-------------------------------------------------------------
    def input_setting():
        print "  ---------------------------------------------------------------------------------"
        print "           [ Display User Inputs ]"
        print "  ---------------------------------------------------------------------------------"
        # Look elsewhere for the name instead of assigning to it locally.
        # This is now gloabal var
        global g_cmvc_num
        if (defect_num != "None") or (feature_num != "None"):
            if not defect_num == "None":
                g_cmvc_num = 'D' + defect_num  #D1234
                print " [ CMVC Defect ]  \t\t#Number\t = %s" % (g_cmvc_num)
            else:
                g_cmvc_num = 'F' + feature_num  # F1234
                print " [ CMVC Feature ]  \t\t#Number\t = %s" % (g_cmvc_num)
        else:
            print " [ CMVC Defect/Feature ]  Neeed CMVC number. This can't be empty "
            exit_main(errorcode.ERROR_EXIT)

        if not release_name == "None":
            print " [ Fips Release Name ]  \t#String\t = %s" % (release_name)
        else:
            print " [ Fips release ]  Neeed fips release string. This can't be empty "
            exit_main(errorcode.ERROR_EXIT)

        if not path_name == "None":
            print " [ Build Repo Path ]  \t\t#String\t = %s" % (path_name)
        else:
            print " [ User Build Repo Path ]  \t\t#String\t = %s" % (path_name)

        # Optional, by default looks up predefined files
        if not file_name == "None":
            print " [ Files for Check-in - User List ]"
            for files in file_name.split(","):
                print " \t\t\t\t#", files
        else:
            print " [ Files for Check-in - Default List ]"
            for files in errorcode.CMVC_FILE_LIST.split(","):
                print " \t\t\t\t# ", files

        print "  ---------------------------------------------------------------------------------"

    #-------------------------------------------------------------
    # CMVC ENV check
    #-------------------------------------------------------------
    def UserCmvcENV():
        # Assumed the CMVC cofig is there in the user bash ENV
        # In .bashrc the CMVX ENV would look like this
        # CMVC specific example
        #-----------------------------------------------------------
        #export [email protected]@2035
        #export CMVC_BECOME=gkeishin
        #export CMVC_AUTH_METHOD=PWD
        #-----------------------------------------------------------

        l_found_cmvc_conf = False
        for key in os.environ.keys():
            if "CMVC" in key:
                print "\t %s : %s" % (key, os.environ[key])
                l_found_cmvc_conf = True

        if l_found_cmvc_conf == False:
            print "\n [ ERROR SETTING ] :  The CMVC specific ENV is not set"
            print " Please add the following CMVC details in ~/.bashrc"
            print " ------------------------------------------------------"
            print " export CMVC_FAMILY=aix@<yourcmvcdomian>@<portnumber>"
            print " export CMVC_BECOME=<your cmvc id>"
            print " export CMVC_AUTH_METHOD=PWD"
            print " ------------------------------------------------------"
            return errorcode.ERROR_SETTING

        return errorcode.SUCCESS_EXIT

    # Testing CMVC login session.. probe
    def CheckCmvcAccess():
        cmd = 'File -view src/sbei/sbfw/img/sbe_seeprom_DD1.bin -family aix -release fips910 >/dev/null 2>&1'
        rc = os.system(cmd)
        if rc:
            return errorcode.ERROR_CMVC_LOGIN

    #---------------------------------------------
    # Callling the Func defs in order
    #---------------------------------------------

    #------------------------------
    # 1) User input params/ Check ENV
    #------------------------------
    input_setting()

    print "\n [ Checking PPE ENV Pre-req ] "
    # Check if User has passed the path, else get it from ENV
    if path_name == "None":
        # Get the PPE path
        l_ppe_path = utilcode.utilppeSbENV("SBEROOT")
        if l_ppe_path == "None":
            print "  PPE Repo ENV Setting Path  : [ ERROR CODE: %s ] " % l_ppe_path
            exit_main(errorcode.ERROR_SETTING)
        else:
            print "  PPE Repo path Setting  : [ %s ]" % l_ppe_path
            path_name = l_ppe_path

    print "\n [ Checking CMVC user ENV Pre-req ] "
    rc_code = UserCmvcENV()
    if rc_code == errorcode.SUCCESS_EXIT:
        print "  CMVC Setting  : [ OK ] "
    else:
        print "  CMVC Setting  : [ ERORR CODE: %s ]" % rc_code

    #------------------------------
    # 2) Check the CMVC login access
    #------------------------------
    print "\n [ Checking CMVC user Login Session access ] "
    rc_cmvc = CheckCmvcAccess()
    if rc_cmvc == errorcode.ERROR_CMVC_LOGIN:
        print "  CMVC Login Access  : [ ERORR CODE: %s ]" % rc_cmvc
        print "\t  No cmvc login was found in this session."
        print "\t  Issue the cmvclog command to establish a login and re-run."
        print "\t  Command : cmvclog -in <login user id>"
        exit_main(rc_cmvc)
    else:
        print "  CMVC Session Login  : [ OK ] "

    # Call API/Utility funcs def here
    #------------------------------
    # 3) Check track status
    #------------------------------
    print "\n [ Checking CMVC track state ] "
    l_trackFix = utilcode.utilCheckTrackState(g_cmvc_num, release_name)
    if l_trackFix == errorcode.SUCCESS_TRACK_STATE:
        print "  Track in fix state. Suitable to continue."
    else:
        print "  Track not in fix state. Aborting activity."
        return errorcode.ERROR_TRACK_STATE

    #------------------------------
    # 4) Checkout the code
    #------------------------------
    print "\n  [ Creating Sandbox ]"
    origDir = os.getcwd()
    utilcode.utilCmvcChangeDir(g_cmvc_num)
    sbDir = os.getcwd()

    print "\n [ Checkout Files from CMVC ] "
    print " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    if file_name == "None":
        file_name = errorcode.CMVC_FILE_LIST
    for l_filename in file_name.split(","):
        rc_checkout = utilcode.utilCmvcCheckout(l_filename, release_name,
                                                g_cmvc_num)
        if rc_checkout == errorcode.ERROR_CMVC_CHECKOUT:
            print "  [ CMVC File Checkout Failed ] [Error code : %s]\t:%s" % (
                rc_checkout, l_filename)
            # Undo checkout.. dont check errors just do it
            utilcode.utilRollBack("checkout", g_cmvc_num, release_name)
            # Return to initial directory of operation
            os.chdir(origDir)
            shutil.rmtree(sbDir)
            exit_main(rc_checkout)
        else:
            print "  CMVC File Checkout  [ OK ]"
    print " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

    #------------------------------
    # 4) Copy the binaries and file
    #------------------------------
    # Find the files from the repo and copy to the Checkout dir
    print "\n [ Find files and Overide the checkout file ] "
    print " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    rc_copy = utilcode.utilCmvcRepoPath(path_name, g_cmvc_num, file_name)
    if rc_copy == errorcode.ERROR_CMVC_FILE_COPY:
        print "  [ File copy Failed ] [ Error code : %s]" % rc_copy
        # Return to initial directory of operation
        os.chdir(origDir)
        shutil.rmtree(sbDir)
        exit_main(rc_copy)
    else:
        print "  Files Copied Successfully  : [ OK ] "

    print " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

    #---------------------
    # 6) Checkin the files
    #---------------------
    print "\n [ Check-in Files from CMVC ] "
    print " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    if file_name == "None":
        file_name = errorcode.CMVC_FILE_LIST
    for files in file_name.split(","):
        rc_checkin = utilcode.utilCmvcCheckin(files, release_name, g_cmvc_num)
        if rc_checkin == errorcode.ERROR_CMVC_CHECKIN:
            print "  [ CMVC File Checkin Failed ] [Error code : %s]\t:%s" % (
                rc_checkin, files)
            # Undo checkin.. dont check errors just do it
            utilcode.utilRollBack("checkin", g_cmvc_num, release_name)
            # Return to initial directory of operation
            os.chdir(origDir)
            shutil.rmtree(sbDir)
            exit_main(rc_checkin)
        else:
            print "  CMVC File Checkin  [ OK ]"
    print " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

    #---------------------------------
    # 7) Fix record the defect/release
    #---------------------------------
    print "\n [ Fix the Record to complete in CMVC ] "
    utilcode.utilCmvcFixComplete(g_cmvc_num, release_name)

    #---------------------------------
    # 8) Trigger Jenkins CI Job
    #---------------------------------
    print "\n [ Trigering Jenkins job ] "
    rc_ci = utilcode.utilTriggerJenkins(g_cmvc_num, release_name, bvt)
    if rc_ci == errorcode.ERROR_CI_TRIGGER:
        print "  [ CI Trigger Failed ] [Error code : %s]\t" % (rc_ci)
        # Return to initial directory of operation
        os.chdir(origDir)
        shutil.rmtree(sbDir)
        exit_main(rc_ci)
    else:
        print "  CI Trigger [ OK ]"

    #-----------------------------------------
    # Return to initial directory of operation
    #-----------------------------------------
    os.chdir(origDir)
    shutil.rmtree(sbDir)

    # Clean exit
    print "\n [ Manually Integrate on CMVC post CI ] "
    exit_main(errorcode.SUCCESS_EXIT)