firmware_tools/autobuild/Common_scripts/test/testethernetproduct.groovy
2023-01-08 14:01:08 +00:00

273 lines
14 KiB
Groovy

import jenkins.model.Jenkins
def TEST_ENVIRONMENT;
pipeline {
agent { label AGENT_LABEL }
stages {
stage ("Initial Setup") {
steps{
script {
//Load the common build tools.
meta = load("${WORKSPACE}/autobuild/Common_scripts/autobuilder.groovy").startnonbuild(this)
subJobs = []
//Set the label of the build job to reflect what triggered the job to run.
try{
currentBuild.description = "Running On ${env.NODE_NAME}, Triggered by ${currentBuild.upstreamBuilds[0].getFullDisplayName()}"
}
catch(Throwable e){
currentBuild.description = "Running On ${env.NODE_NAME}, Triggered Directly"
}
}
}
}
stage ("Checkout test environment") {
steps {
script {
toolsimporter = load("${autobuilder.commonscripts()}/configuration/tools.groovy")
def TEST_ENVIRONMENT_URL = 'git@hydra:gistest/jenkins-ethernet-test-environment.git'
def TEST_ENVIRONMENT_DIR = 'TestEnvironmentDir'
def TEST_ENVIRONMENT_REVISION = 'origin/master'
def environmentoptions = toolsimporter.getNewToolOptions()
environmentoptions.toolName('Ethernet product test environment')
environmentoptions.toolRepo(TEST_ENVIRONMENT_URL, TEST_SOURCE_REVISION)
toolsimporter.getTool(meta, environmentoptions, TEST_ENVIRONMENT_DIR)
TEST_ENVIRONMENT_FILE = "${TEST_ENVIRONMENT_DIR}/environment.json"
def alltestenvironment = readJSON(file: TEST_ENVIRONMENT_FILE)
//TODO: Configure the build jobs to submit the product name only of the resource we wish to query e.g. HMB_SE_D3000, not HMB_SE_D3000_2
//TEST_ENVIRONMENT = load("${autobuilder.commonscripts()}/test/testresourceselector.groovy").LocateResources(ETHERNET_PRODUCT_TO_RUN_TEST)
TEST_ENVIRONMENT = alltestenvironment[PRODUCT_NAME]
//HMBUtils = load("${autobuilder.commonscripts()}/test/powercontrollerutils.groovy")
echo "Selected environment:\n${TEST_ENVIRONMENT}"
}
}
}
stage ("Checkout dependencies") {
steps {
script {
def PYTHON_URL = 'git@hydra:tools/python.git'
if (isUnix()) {
PYTHON_REVISION = 'origin/3.6.3_linux'
}
else {
PYTHON_REVISION = 'origin/3.8.10_windows_for_test'
}
PYTHONDIR = "${WORKSPACE}/python"
def pythonimportoptions = toolsimporter.getNewToolOptions()
pythonimportoptions.toolName('Python')
pythonimportoptions.toolRepo(PYTHON_URL, PYTHON_REVISION)
toolsimporter.getTool(meta, pythonimportoptions, PYTHONDIR)
if (isUnix()) {
env.PYTHON = "${PYTHONDIR}/usr/local/bin/python3"
}
else {
env.PYTHON = "${PYTHONDIR}/ver/python.exe"
}
def TEST_SOURCE_URL = 'git@hydra:hmb_regression/hmb_tests.git'
TEST_SUITE_DIR = 'TestSuiteDir'
env.GIS_TEST_SUITE_HOME = "${WORKSPACE}/${TEST_SUITE_DIR}"
def regressiontestimportoptions = toolsimporter.getNewToolOptions()
regressiontestimportoptions.toolName('Tests')
regressiontestimportoptions.toolRepo(TEST_SOURCE_URL, TEST_SOURCE_REVISION)
toolsimporter.getTool(meta, regressiontestimportoptions, GIS_TEST_SUITE_HOME)
//env.HISTORY_FOLDER = "${WORKSPACE}/testhistory"
//HISTORY_REVISION =
//HISTORY_REPO
//def resultimportoptions = toolsimporter.getNewToolOptions()
//resultimportoptions.toolName('Test history')
//resultimportoptions.toolRepo(HISTORY_REPO, HISTORY_REVISION)
//toolsimporter.getTool(meta, resultimportoptions, HISTORY_FOLDER)
def CORE_SOURCE_URL = 'git@hydra:gistest/giscorelite.git'
env.GIS_TEST_SUITE_CORE = "${WORKSPACE}/GisCore"
def coreimportoptions = toolsimporter.getNewToolOptions()
coreimportoptions.toolName('Test core')
coreimportoptions.toolRepo(CORE_SOURCE_URL, CORE_SOURCE_REVISION)
toolsimporter.getTool(meta, coreimportoptions, GIS_TEST_SUITE_CORE)
//def HISTORY_PROCESSING_REPO = 'git@hydra:gistestresults/ethernet-products-history-processing.git'
//HISTORY_PROCESSING_DIR = "${WORKSPACE}/HistoryProcessing"
//def resultprocessingoptions = toolsimporter.getNewToolOptions()
//resultprocessingoptions.toolName('History processing')
//resultprocessingoptions.toolRepo(HISTORY_PROCESSING_REPO, HISTORY_PROCESSING_REVISION)
//toolsimporter.getTool(meta, resultprocessingoptions, HISTORY_PROCESSING_DIR)
}
}
}
stage ("Import application to test") {
steps {
script {
importer = load("${autobuilder.commonscripts()}/import/importer.groovy")
APPLICATION_UNDER_TEST = 'application_under_test'
env.APPLICATION_ARTIFACT_FOLDER = "${WORKSPACE}/${APPLICATION_UNDER_TEST}"
def applicationimportoptions = importer.getNewImportOptions()
applicationimportoptions.jenkinsjob(APPLICATION_ARTIFACT_PROJECT, APPLICATION_ARTIFACT_SELECTOR)
applicationimportoptions.setfilter('app_package/**,control_package/**')
applicationmeta = importer.artifactimport(meta, applicationimportoptions, APPLICATION_ARTIFACT_FOLDER)
meta.productinfo.set(applicationmeta.productinfo)
meta.productinfo.subcomponentname = "${applicationmeta.productinfo.subcomponentname}_TEST"
meta.gitinfo.set(applicationmeta.gitinfo)
meta.buildstampinfo.set(applicationmeta.buildstampinfo)
}
}
}
stage("Clean") {
steps {
script {
LOGGING_ROOT = 'Logging'
env.GIS_TEST_OUTPUT_LOGGING_ROOT = "${WORKSPACE}/${LOGGING_ROOT}"
cleanfolders = [
GIS_TEST_OUTPUT_LOGGING_ROOT,
]
cleaner = load("${autobuilder.commonscripts()}/clean/clean.groovy")
cleaner.clean(cleanfolders)
}
}
}
stage ('Update HMB and Run Tests') {
steps {
script {
//Set 3 Hour timeout.
timeout(180){
//load the hmb utils onto the node that is using them.
HMBUtils = load("${autobuilder.commonscripts()}/test/powercontrollerutils.groovy");
env.SM_IP_ADDRESS = TEST_ENVIRONMENT["SM_200"]["IP_ADDRESS"];
env.HMB_IP_ADDRESS = TEST_ENVIRONMENT["IP_ADDRESS"];
SMReady = bat (script:"""
"${PYTHON}" "${GIS_TEST_SUITE_CORE}/HMBCommon/hmbpollforlife.py" -t "${SM_IP_ADDRESS}"
""",
returnStatus: true
)
if (0 != SMReady){
HMBUtils.PowerUpHMB(
TEST_ENVIRONMENT["SM_200"]['POWER_CONTROLLER']["HOST"],
TEST_ENVIRONMENT["SM_200"]['POWER_CONTROLLER']["NAME"],
TEST_ENVIRONMENT["SM_200"]['POWER_CONTROLLER']["CHANNEL"]);
SMReady = bat (script:"""
"${PYTHON}" "${GIS_TEST_SUITE_CORE}/HMBCommon/hmbpollforlife.py" -t "${SM_IP_ADDRESS}"
""",
returnStatus: true
);
println("SMReady is..." );
println(SMReady);
if (0 != SMReady ){
error("Unable to get SM200 into correct state.")
}
}
else {
println("SM detected at ${SM_IP_ADDRESS}")
}
if (POWER_CYCLE_HARDWARE == 'true') {
println("Attempted to turn on HMB")
HMBUtils.PowerDownHMB(
TEST_ENVIRONMENT['POWER_CONTROLLER']["HOST"],
TEST_ENVIRONMENT['POWER_CONTROLLER']["NAME"],
TEST_ENVIRONMENT['POWER_CONTROLLER']["CHANNEL"]
)
}
//Always turn the hardware back on.
HMBUtils.PowerUpHMB(
TEST_ENVIRONMENT['POWER_CONTROLLER']["HOST"],
TEST_ENVIRONMENT['POWER_CONTROLLER']["NAME"],
TEST_ENVIRONMENT['POWER_CONTROLLER']["CHANNEL"]
)
Ready = bat (script:"""
"${PYTHON}" "${GIS_TEST_SUITE_CORE}/HMBCommon/hmbpollforlife.py" -t "${HMB_IP_ADDRESS}"
""",
returnStatus: true
)
if (Ready != 0){
error("unable to get hardware at address" + TEST_ENVIRONMENT["IP_ADDRESS"] + "into a known state before upgrade.");
}
else {
println("hardware at address" + TEST_ENVIRONMENT["IP_ADDRESS"] + "is available and ready for next steps.");
}
if (UPDATE_HARDWARE == 'true') {
println("Updating Hardware")
dir(GIS_TEST_SUITE_CORE) {
bat """
"${PYTHON}" "${GIS_TEST_SUITE_CORE}/HMBCommon/hmbPackageDeployer.py" -p "${APPLICATION_ARTIFACT_FOLDER}" -c -t "${TEST_ENVIRONMENT['IP_ADDRESS']}"
"""
Ready = bat (script:"""
"${PYTHON}" "${GIS_TEST_SUITE_CORE}/HMBCommon/hmbpollforlife.py" -t "${HMB_IP_ADDRESS}"
""",
returnStatus: true
)
if (Ready != 0){
error("unable to get hardware at address" + TEST_ENVIRONMENT["IP_ADDRESS"] + "into a known state before upgrade.");
}
}
}
TestSuiteProfileUtils = load("${autobuilder.commonscripts()}/test/testprofileutils.groovy")
def TEST_PRODUCT_NAME = TestSuiteProfileUtils.LookUpProduct(PRODUCT_NAME)
def PRODUCT_UNDER_TEST = TestSuiteProfileUtils.LookUpTestArgument(PRODUCT_NAME)
def TEST_INCLUDE_FILTER = TestSuiteProfileUtils.LookUpTestFilter(PRODUCT_NAME)
println("Swapping target Ipaddress on target to match that which is configured in test profile.")
rc = bat(script:"""
${PYTHON} "${GIS_TEST_SUITE_CORE}/HMBCommon/swapconfig.py" -p ${TEST_PRODUCT_NAME} -t "${HMB_IP_ADDRESS}"
""",
returnStatus: true
)
if (rc != 0) {
error('Failed to update test profile, client will miss target hardware.')
}
if (DO_TEST == 'true') {
rc = bat(script:"""
${PYTHON} "${GIS_TEST_SUITE_CORE}/GISTestMaster.py" ${PRODUCT_UNDER_TEST} installed -fl --include ${TEST_INCLUDE_FILTER}
""",
returnStatus: true
)
if (rc == 1) {
unstable('FAILED while running tests')
}
}
}
}
}
}
/*stage("Archive Test History") {
steps{
script {
dir(HISTORY_FOLDER) {
rc = bat (script:"""
"${PYTHON}" "${HISTORY_PROCESSING_DIR}/GitCyclicPush.py"
""",
returnStatus: true
)
if (rc == 1) {
unstable('FAILED to process history')
}
}
}
}
}
*/
stage("Archive test artifacts"){
steps{
script {
def artifactlist = meta.generateartifacts([ "${LOGGING_ROOT}/**"])
artifactarchiver = load("${autobuilder.commonscripts()}/artifacts/archiver.groovy")
artifactarchiver.archive(meta, artifactlist)
}
}
}
}
}