diff options
author | George Keishing <gkeishin@in.ibm.com> | 2016-03-17 00:49:49 -0500 |
---|---|---|
committer | Sachin Gupta <sgupta2m@in.ibm.com> | 2016-03-23 01:32:30 -0400 |
commit | 911cc624014689c649651764ba784237c58c815a (patch) | |
tree | b8f8161bdb1eaf5b28f30002acfdacfebed58b54 /sbe/build | |
parent | f00fe995e05f6ba871ad912dac4c86a0d091190f (diff) | |
download | talos-sbe-911cc624014689c649651764ba784237c58c815a.tar.gz talos-sbe-911cc624014689c649651764ba784237c58c815a.zip |
SBE : Automate SBE Image integration into FIPS driver
Change-Id: Ifed799f9a4f3b786e4b1468ea6c75a58ffa53efa
RTC: 142215
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/22163
Tested-by: Jenkins Server
Reviewed-by: Santosh S. Puranik <santosh.puranik@in.ibm.com>
Reviewed-by: Sachin Gupta <sgupta2m@in.ibm.com>
Diffstat (limited to 'sbe/build')
-rwxr-xr-x | sbe/build/tools/CommitSbeImageToCMVC.py | 353 | ||||
-rw-r--r-- | sbe/build/tools/README | 39 | ||||
-rwxr-xr-x | sbe/build/tools/sbeCmvcConstants.py | 61 | ||||
-rwxr-xr-x | sbe/build/tools/sbeCmvcUtility.py | 522 | ||||
-rwxr-xr-x | sbe/build/tools/sbeDistribute.py | 210 |
5 files changed, 1185 insertions, 0 deletions
diff --git a/sbe/build/tools/CommitSbeImageToCMVC.py b/sbe/build/tools/CommitSbeImageToCMVC.py new file mode 100755 index 00000000..e667cd7f --- /dev/null +++ b/sbe/build/tools/CommitSbeImageToCMVC.py @@ -0,0 +1,353 @@ +#!/usr/bin/python +''' +########################################################### +# @file CommitSbeImageToCMVC.py +# @author: George Keishing <gkeishin@in.ibm.com> +# Sangeetha TS <sangeet2@in.ibm.com> +# @brief Main Module to support CMVC operation +# +# Created on March 03, 2016 +# ---------------------------------------------------- +# @version Developer Date Description +# ---------------------------------------------------- +# 1.0 gkeishin 03/03/16 Initial create +########################################################### +''' + +#------------------------- +# Imports +#------------------------- +import getopt +import os, sys, glob +import shutil + +# Libraries/utility funcs and user define const +import sbeCmvcConstants as errorcode +import sbeCmvcUtility as utilcode + +#------------------------- +# Main Function +#------------------------- +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 CMVC_FAMILY=aix@auscmvc1.austin.ibm.com@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.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) + + +if __name__=="__main__": + main() + diff --git a/sbe/build/tools/README b/sbe/build/tools/README new file mode 100644 index 00000000..ff9fd33e --- /dev/null +++ b/sbe/build/tools/README @@ -0,0 +1,39 @@ +-------------------- +CONTENT OF THIS FILE +-------------------- +1. Tools: + * Automate SBE Image integration into FIPS driver + * Developer SBE fips tool for copy and compile ( TBD ) + + +------------------------------------------------- +* Automate SBE Image integration into FIPS driver +------------------------------------------------- + [ Files ] : CommitSbeImageToCMVC.py (Main) + sbeCmvcConstants.py + sbeCmvcUtility.py + + [ Brief ] : This tool will check in the SBE FW fips files to CMVC, Fix Complete the track and trigger Jenkin Job. + + [ Feature ] : + - By default, the tool will check in the files from a default list pre-defined for sbe + Refer: sbeCmvcConstants.py + + - User can selectively choose which file/files it wants to upload to CMVC from the default list + + - The tool roll backs all the checkout/checkin in case of CMVC Operation failure + + - The tool will auto complete fix record on completion of successful code check in + + - The internal of the work flow validates the Hash of the files on the SBE repo vs files to be + check in to be sure that the files are correctly uploaded + + - The pre-req checks CMVC bash env and CMVC access session availability and provides verbose + help to follow on failures + + - Jenkin job trigger at the end after fix completing record. + + +------------------------------------------------- +* Developer SBE fips tool for copy and compile ( TBD ) +------------------------------------------------- diff --git a/sbe/build/tools/sbeCmvcConstants.py b/sbe/build/tools/sbeCmvcConstants.py new file mode 100755 index 00000000..a1d8fe4a --- /dev/null +++ b/sbe/build/tools/sbeCmvcConstants.py @@ -0,0 +1,61 @@ +''' +########################################################### +# @file sbeCmvcConstants.py +# @author George Keishing <gkeishin@in.ibm.com> +# Sangeetha TS <sangeet2@in.ibm.com> +# @brief Constants support tool operation +# +# Created on March 03, 2016 +# ---------------------------------------------------- +# @version Developer Date Description +# ---------------------------------------------------- +# 1.0 gkeishin 03/03/16 Initial create +########################################################### +''' + + +''' +Generic Failure RC code +''' +SUCCESS_EXIT = 0 +SHELL_EXIT = 1 +ERROR_EXIT = 2 +HELP_EXIT = 3 +SUCCESS_DEV_EXIT = 4 +ERROR_SYS_EXIT = 100 + + +# This funcs specific error codes +ERROR_SETTING = 10 # No CMV ENV set in the .bashrc or a generic error for Sandbox ENV not set +ERROR_CMVC_LOGIN = 11 # No Cmvc login access session not established +ERROR_CMVC_CHECKOUT = 12 # Failed file checkout +ERROR_CMVC_CHECKIN = 13 # Failed file check in +ERROR_CMVC_FIX_RECORD = 14 # Failed fixing complete record +ERROR_CMVC_FILE_COPY = 15 # Copying file failed +ERROR_TRACK_STATE = 16 # Track not in required state +ERROR_CI_TRIGGER = 17 # CI not started successfully + +SUCCESS_CMVC_CHECKOUT = 50 +SUCCESS_CMVC_CHECKIN = 51 +SUCCESS_CMVC_FIX_RECORD = 52 +SUCCESS_TRACK_STATE = 53 +SUCCESS_CI_TRIGGER = 54 + +# This is a default files list to Check-in +CMVC_FILE_LIST ="sbe_sp_intf.H,simics.tar,sbe_pibmem.bin,sbe_seeprom.bin" +CMVC_FILE_UNDO_LIST ="src/sbei/sbfw/sbe_sp_intf.H src/sbei/sbfw/simics.tar src/sbei/sbfw/img/sbe_pibmem.bin src/sbei/sbfw/img/sbe_seeprom.bin" + +#CMVC_FILE_LIST ="src/sbei/sbfw/sbe_sp_intf.H,src/sbei/sbfw/simics.tar,src/sbei/sbfw/img/sbe_main.bin,src/sbei/sbfw/img/sbe_pibmem.bin,src/sbei/sbfw/img/sbe_seeprom.bin" +CMVC_DIR_CREATE ="sandbox_" + + +# Hashing specfic +SUCCESS_HASH_CHECK = 100 +ERROR_HASH_CHECK = 101 + + +# For Development +ERROR_SANDBOX_EXIST = 200 # Sandbox doesnt exist +ERROR_FILE_INPUT = 201 # User have entered no file +ERROR_BUILD_FAILED = 202 # Compilation failed +FILE_LOOKUP_LIST ="src/sbei/sbfw/sbe_sp_intf.H,src/sbei/sbfw/simics.tar,src/sbei/sbfw/img/sbe_pibmem.bin,src/sbei/sbfw/img/sbe_seeprom.bin" diff --git a/sbe/build/tools/sbeCmvcUtility.py b/sbe/build/tools/sbeCmvcUtility.py new file mode 100755 index 00000000..357aa8fd --- /dev/null +++ b/sbe/build/tools/sbeCmvcUtility.py @@ -0,0 +1,522 @@ +#!/usr/bin/python +''' +########################################################### +# @file sbeCmvcUtility.py +# @author: George Keishing <gkeishin@in.ibm.com> +# Sangeetha TS <sangeet2@in.ibm.com> +# @brief Utilility Module to support CMVC operation +# +# Created on March 03, 2016 +# ---------------------------------------------------- +# @version Developer Date Description +# ---------------------------------------------------- +# 1.0 gkeishin 03/03/16 Initial create +########################################################### +''' + +#------------------------- +# Imports +#------------------------- +import os, sys +import time +import os.path +import subprocess +import shutil +import hashlib +from subprocess import Popen, PIPE +from os.path import expanduser # for getting $HOME PATH +import stat # for File permission op + +# Libraries/utility funcs and user define const +import sbeCmvcConstants as errorcode + + +########################################################################## +# Function : utilCmvcChangeDir +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @brief Create a directory +# +########################################################################## +def utilCmvcChangeDir(i_cmvcnum): + l_home_path= expanduser("~") + "/" + errorcode.CMVC_DIR_CREATE + i_cmvcnum + + print " Sandbox path\t: ",l_home_path + cmd='mkdir -p ' + l_home_path + os.system(cmd) + os.chdir(l_home_path) + +########################################################################## +# Function :utilCmvcRepoPath +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @param i_pathname : SBE repo Path location +# +# @param i_filename : Files to be copied +# +# @brief find the files in repo +# +########################################################################## +def utilCmvcRepoPath(i_pathname, i_cmvcnum, i_filename): + l_home_path= expanduser("~") + "/" + errorcode.CMVC_DIR_CREATE + i_cmvcnum + # Strip the last string from the file path input + + print " Sandbox path\t: ",l_home_path + print " SBE Repo path\t: ",i_pathname + + if i_filename == "None": + i_filename = errorcode.CMVC_FILE_LIST + + for l_filename in i_filename.split(","): + + # Find the files and copy + l_sb_path = utilFindFile(l_filename,l_home_path) + l_repo_path = utilFindFile(l_filename,i_pathname) + + if l_sb_path is None : + print " ERROR: Checked out sandbox does not contain " + l_filename + return errorcode.ERROR_CMVC_FILE_COPY + if l_repo_path is None : + print " ERROR: File Not Found in SBE repo " + l_filename + return errorcode.ERROR_CMVC_FILE_COPY + + cp_cmd = 'cp ' + l_repo_path + ' ' + l_sb_path + rc=os.system(cp_cmd ) + if rc: + return errorcode.ERROR_CMVC_FILE_COPY + else: + # validate the copied files via hashing + l_src = l_repo_path + l_dest = l_sb_path + hash_err = utilCheckFileHash(l_src,l_dest) + if hash_err == errorcode.ERROR_HASH_CHECK: + return hash_err + + # Returned success + return errorcode.SUCCESS_EXIT + +########################################################################## +# Function :utilFindFile +# +# @param i_filename : File Name +# +# @param i_path : Directory to search in +# +# @brief Finds a given file and returns the absoulte path +# +########################################################################## +def utilFindFile(i_filename, i_path): + for root, dirs, files in os.walk(i_path): + if i_filename in files: + return os.path.join(root, i_filename) + +########################################################################## +# Function :utilFindFilePPE +# +# @param i_filename : File Name +# +# @param i_path : Directory to search in +# +# @brief Finds a given file ins PPE repo and returns the absoulte path +# +########################################################################## +def utilFindFilePPE(i_filename, i_path, i_sandbox_name): + for root, dirs, files in os.walk(i_path): + if i_filename in files: + # Ignore the test sandbox files in the PPE + if not i_sandbox_name in root: + return os.path.join(root, i_filename) + +########################################################################## +# Function :utilCmvcCheckout +# +# @param i_filename : File Name +# +# @param i_release : Fips FW Release to checkout (ex: fips910 ) +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @brief Check out a given file +# +########################################################################## +def utilCmvcCheckout(i_filename, i_release, i_cmvcnum): + print " File Name\t: ",i_filename + print " Release\t: ",i_release + + # The file simics.tar is not unique so provide the relative path + if i_filename == "simics.tar": + i_filename = 'src/sbei/sbfw/simics.tar' + + print " CMVC #\t: ",i_cmvcnum[1:] + l_home_path= expanduser("~") + "/" + errorcode.CMVC_DIR_CREATE + i_cmvcnum + + cmd='File -checkout ' + i_filename + ' -release '+ i_release + ' -relative ' + l_home_path + if i_cmvcnum[:1] == "D": + cmd += ' -defect ' + i_cmvcnum[1:] + else: + cmd += ' -feature ' + i_cmvcnum[1:] + + print " Executing\t: ", cmd + rc = os.system(cmd) + if rc: + # rc 256 File not found in CMVC + if rc == 256: + print " * File was not found or Error operation in CMVC" + return errorcode.ERROR_CMVC_CHECKOUT + else: + return errorcode.SUCCESS_CMVC_CHECKOUT + + +########################################################################## +# Function :utilCmvcCheckin +# +# @param i_filename : Relative Path of the File +# +# @param i_release : Fips FW Release to checkout (ex: fips910 ) +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @brief Check in a given file +# +########################################################################## +def utilCmvcCheckin(i_filename, i_release, i_cmvcnum): + print " File Name\t: ",i_filename + print " Release\t: ",i_release + print " CMVC #\t: ",i_cmvcnum[1:] + + l_home_path= expanduser("~") + "/" + errorcode.CMVC_DIR_CREATE + i_cmvcnum + l_base_path = utilFindFile(i_filename,l_home_path) + # This will give the ablsolute path, strip it from src + for l_var in l_base_path.split("/src"): + if i_filename in l_var: + l_str = 'src' + l_var + + cmd='File -checkin ' + l_str + ' -release '+ i_release + ' -relative ' + l_home_path + if i_cmvcnum[:1] == "D": + cmd += ' -defect ' + i_cmvcnum[1:] + else: + cmd += ' -feature ' + i_cmvcnum[1:] + + print " Executing\t: ", cmd + rc = os.system(cmd) + if rc: + return errorcode.ERROR_CMVC_CHECKIN + else: + return errorcode.SUCCESS_CMVC_CHECKIN + + +########################################################################## +# Function :utilCmvcFixComplete +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @param i_release : Fips Release string +# +# @brief Fix the record to complete +# +########################################################################## +def utilCmvcFixComplete(i_cmvcnum, i_release): + print " CMVC #\t: ",i_cmvcnum + l_cmvcnum =i_cmvcnum[1:] + + if i_cmvcnum[:1] == "D": + cmd='Fix -complete ' + ' -defect ' + l_cmvcnum + ' -r ' + i_release + ' -component esw_sbei' + else: + cmd='Fix -complete ' + ' -feature ' + l_cmvcnum + ' -r ' + i_release + ' -component esw_sbei' + + print " Executing\t: ", cmd + rc = os.system(cmd) + if rc: + return errorcode.ERROR_CMVC_FIX_RECORD + else: + return errorcode.SUCCESS_CMVC_FIX_RECORD + +########################################################################## +# Function :utilCheckTrackState +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @param i_release : Fips Release string +# +# @brief Check if the track is in fix state or not +# +########################################################################## +def utilCheckTrackState(i_cmvcnum, i_release): + print " CMVC #\t: ",i_cmvcnum + print " Release\t: ",i_release + + l_cmvcnum =i_cmvcnum[1:] + cmd = 'Track -view -release ' + i_release + if i_cmvcnum[:1] == "D": + cmd += ' -defect ' + l_cmvcnum + else: + cmd += ' -feature ' + l_cmvcnum + cmd += ' | grep state ' + + print " Executing\t: ", cmd + ex_cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + for line in ex_cmd.stdout : + if not line: continue + line = line.strip() + if "fix" in line : + return errorcode.SUCCESS_TRACK_STATE + return errorcode.ERROR_TRACK_STATE + +########################################################################## +# Function :utilCheckFileHash +# +# @param i_src : Source location of the file to be copy from +# +# @param i_dest : Destination location of the file to be copied to +# +# @brief Make sure after copying files, the hash matches +# +########################################################################## +def utilCheckFileHash(i_src, i_dest): + print " Source\t: ",i_src + print " Destination\t: ",i_dest + + sha_orig = hashlib.sha256() + sha_orig.update(file(i_src).read()) + orig_hash=sha_orig.hexdigest() + print " * Orig Hash\t [ %s : %s ] "% (os.path.basename(i_src),orig_hash) + + sha_copy = hashlib.sha256() + sha_copy.update(file(i_dest).read()) + copied_hash=sha_copy.hexdigest() + print " * Copied Hash\t [ %s : %s ] "% (os.path.basename(i_dest),copied_hash) + + if orig_hash == copied_hash: + print " -> Hash Match .. Continue\n" + return errorcode.SUCCESS_HASH_CHECK + else: + print " Mismatch Hash.. Abort" + return errorcode.ERROR_HASH_CHECK + +########################################################################## +# Function :utilRollBack +# +# @param i_action : Undo Checkout or checkin +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @param i_release : Fips FW Release to checkout (ex: fips910 ) +# +# @brief Brute force undo of all files +# +########################################################################## +def utilRollBack(i_action, i_cmvcnum, i_release): + print "\n * Action request\t: ",i_action + if i_action == "checkin": + print " * Undoing All default File list" + if i_cmvcnum[:1] == "D": + cmd = 'File -undo ' + errorcode.CMVC_FILE_UNDO_LIST + ' -release ' + i_release + ' -defect ' + i_cmvcnum[1:] + ' >/dev/null 2>&1' + else: + cmd = 'File -undo ' + errorcode.CMVC_FILE_UNDO_LIST + ' -release ' + i_release + ' -feature ' + i_cmvcnum[1:] + ' >/dev/null 2>&1' + else: + print " * Unlocking All default Files list" + if i_cmvcnum[:1] == "D": + cmd = 'File -unlock ' + errorcode.CMVC_FILE_UNDO_LIST + ' -release ' + i_release + ' >/dev/null 2>&1' + else: + cmd = 'File -unlock ' + errorcode.CMVC_FILE_UNDO_LIST + ' -release ' + i_release + ' >/dev/null 2>&1' + + #print " Executing : ", cmd + rc = os.system(cmd) + # CMVC throws this rc even if its successfull + if rc != 1024 and rc !=0: + print "\n Error [ %s ] in Undoing/Unlocking Files.. Please check manually"%rc + else: + print "\n Roll Back Successfull.. Please Revisit your inputs [ OK ] " + + +########################################################################## +# Function :utilTriggerJenkins +# +# @param i_cmvcnum : CMVC defect or Feature number +# +# @param i_release : Fips FW Release to checkout (ex: fips910 ) +# +# @param i_bvt : Fips BVT xml file +# +# @brief Trigger Jenkins CI job +# +########################################################################## +def utilTriggerJenkins(i_cmvcnum,i_release,i_bvt): + print " Jenkins job for %s" % i_cmvcnum + #PATH : /afs/austin.ibm.com/projects/esw/bin/fsp-CI-jenkins + cmd = "fsp-CI-jenkins -r " + i_release + " -t " + i_cmvcnum[1:] + " --test_on_hardware=y" + if not i_bvt == "None" : + cmd += " -b " + i_bvt + rc = os.system(cmd) + if rc : + return errorcode.ERROR_CI_TRIGGER + else : + return errorcode.SUCCESS_CI_TRIGGER + + +########################################################################## +# Function :utilCopyFileToSandbox +# +# @param i_pathname : SBE repo Path location +# +# @param i_sandboxname : Sandbox repo Path location +# +# @param i_filename : Files to be copied +# +# @brief find the files in repo and copy to the sandbox +# +########################################################################## +def utilCopyFileToSandbox(i_pathname,i_sandboxname,i_filename): + + print "\n *** For Development *** \n" + print " Sandbox path\t: ",i_sandboxname + print " SBE Repo path\t: ",i_pathname + print "\n" + + if i_filename == "None": + i_filename = errorcode.CMVC_FILE_LIST + #print " No User supplied Files to copy" + #return errorcode.ERROR_FILE_INPUT + + for l_filename in i_filename.split(","): + # Find the files and copy + l_sandbox_name = os.path.basename(i_sandboxname) + l_repo_path = utilFindFilePPE(l_filename,i_pathname,l_sandbox_name) + if l_repo_path is None : + print " File [ %s ] not found in Repo..\t Check your repo and retry "%l_filename + return errorcode.ERROR_CMVC_FILE_COPY + else: + for files in errorcode.FILE_LOOKUP_LIST.split(","): + if l_filename in files: + break + + # Append this src path and to the sanbox base and copy the file + sb_cp_path = i_sandboxname + '/' + files + + # Check if this path exist in the sandbox , if not create and copy + if os.path.exists(sb_cp_path) == False: + cmd='mkdir -p ' + os.path.dirname(sb_cp_path) + #print " Creating dir %s "%cmd + os.system(cmd) + + # Copy the file + copy_cmd = 'cp -rf ' + l_repo_path + ' ' + sb_cp_path + rc = os.system(copy_cmd) + if rc: + print " RC code :",rc + print " ERROR : Copying file : ",copy_cmd + return errorcode.ERROR_CMVC_FILE_COPY + else: + print " Copied file : ",copy_cmd + + return errorcode.SUCCESS_DEV_EXIT + + +########################################################################## +# Function :utilppeSbENV +# +# @param i_env_key : ENV paramter +# +# @brief find the PPE Repo path from ENV and returns the path string +# +########################################################################## +def utilppeSbENV(i_env_key): + #----------------------------------------------------------- + # SBEROOT=/gsa/ausgsa/projects/i/indiateam04/gkeishin/PPE_CHANGES + #----------------------------------------------------------- + l_found_ppe_conf = False + env_ppe_path="None" + for key in os.environ.keys(): + if i_env_key in key: + #print "\t %s : %s" % (key,os.environ[key]) + env_ppe_path = os.environ[key] + l_found_ppe_conf = True + + if l_found_ppe_conf == False: + print " ---------------------------------------------------------" + print " | [ ERROR SETTING ] : The PPE Repository ENV is not set |" + print " | Please do ./sb workon to set/load the PPE repo ENV |" + print " ---------------------------------------------------------" + + return env_ppe_path + +########################################################################## +# Function : utilFind_sb_base +# +# @param i_sb_name : Sandbox name +# +# @brief find the sandbox base path +# +########################################################################## +def utilFind_sb_base(i_sb_name): + out_str= "None" + + # workon -m ppc sbeisb -c 'env | grep SANDBOXBASE' + find_sb_base = 'workon -m ppc ' + i_sb_name + " -c 'env | grep SANDBOXBASE ' | grep SANDBOXBASE" + + # SANDBOXBASE=/gsa/ausgsa/projects/i/indiateam04/gkeishin/sbeisb + out_str = os.popen(find_sb_base).read() + + if not out_str: + return "None" + else: + return out_str.strip('SANDBOXBASE=') + +########################################################################## +# Function : utilFind_ENV_string +# +# @param i_env_name : ENV string +# +# @brief find the ENV string set in the env +# +########################################################################## +def utilFind_ENV_string(i_env_name): + out_str= "None" + + find_env_name = "env | grep " + i_env_name + + out_str = os.popen(find_env_name).read() + + if not out_str: + return "None" + else: + # Strip string + l_strip=i_env_name +"=" + return out_str.strip(l_strip) + +########################################################################## +# Function : utilWriteShell_hooks +# +# @param i_sandbox_path : Sandbox full path +# +# @brief find the ENV string set in the env +# +########################################################################## +def utilWriteShell_hooks(i_sandbox_path): + # Write the compile shell hook on the fips sandbox location + hook_file=i_sandbox_path + '/src/compilesb' + f = open(hook_file,'w') + + # compilesb: This hook schell script will look like this + # + # #!/bin/sh + # cd /gsa/ausgsa/projects/i/indiateam04/gkeishin/sbeisb/src/sbei/sbfw/ + # mk -a + # mk install_all + + f.write('#!/bin/sh \n') + cd_cmd= 'cd ' + i_sandbox_path + '/src/sbei/sbfw/' + f.write(cd_cmd) + f.write('\n') + f.write('mk -a \n') + f.write('mk install_all \n') + f.close() + + # Change the file permission for execute + perm_st = os.stat(hook_file) + os.chmod(hook_file, perm_st.st_mode | stat.S_IEXEC) + + return hook_file # path of the shell file + diff --git a/sbe/build/tools/sbeDistribute.py b/sbe/build/tools/sbeDistribute.py new file mode 100755 index 00000000..9615621a --- /dev/null +++ b/sbe/build/tools/sbeDistribute.py @@ -0,0 +1,210 @@ +#!/usr/bin/python +''' +########################################################### +# @file sbeDistribute.py +# @author: George Keishing <gkeishin@in.ibm.com> +# @brief Main Module to support developer compilation +# and patching. +# +# Created on March 03, 2016 +# ---------------------------------------------------- +# @version Developer Date Description +# ---------------------------------------------------- +# 1.0 gkeishin 022/03/16 Initial create +########################################################### +''' + +#------------------------- +# Imports +#------------------------- +import getopt +import os, sys, glob +import shutil +import stat # for File permission op + +# Libraries/utility funcs and user define const +import sbeCmvcConstants as errorcode +import sbeCmvcUtility as utilcode + +#------------------------- +# Main Function +#------------------------- +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 -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,sbe_pibmem.bin,sbe_seeprom.bin" + 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 completed [ OK ] " + sys.exit(0) + + #------------------------------------------ + # Local var place name holder's + #------------------------------------------ + sandbox_name = "None" + path_name = "None" # PPE Repo + file_name = "None" + + #---------------------------- + # Read command line args + #---------------------------- + opts, args = getopt.getopt(sys.argv[1:],"s:i:h",['sb=', 'files=', 'help']) + for opt, arg in opts: + if opt in ('-h', '--help'): + usage() + exit_main(errorcode.HELP_EXIT) + elif opt in ('-s', '--sb'): + sandbox_name = arg + elif opt in ('-i', '--files'): + file_name = 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') + + 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 + + #---------------------------------------- + # 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 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 + + #---------------------------------------- + # 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: + compile_cmd="workon -m ppc " + sb_name + " -c " + hook_file + sandbox_root +"/.sandboxrc" + + 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) + + +if __name__=="__main__": + main() + |