blob: ed525bdff81bc3da041bbb8520c99d06460df05c [file] [log] [blame]
/**
* Test salt models pipeline
* DEFAULT_GIT_REF
* DEFAULT_GIT_URL
* CREDENTIALS_ID
* EXTRA_FORMULAS
* CLUSTER_NAME
* NODE_TARGET
* SYSTEM_GIT_URL
* SYSTEM_GIT_REF
* FORMULAS_SOURCE
* RECLASS_VERSION
* MAX_CPU_PER_JOB
* LEGACY_TEST_MODE
* RECLASS_IGNORE_CLASS_NOTFOUND
* APT_REPOSITORY
* APT_REPOSITORY_GPG
*/
def common = new com.mirantis.mk.Common()
def gerrit = new com.mirantis.mk.Gerrit()
def git = new com.mirantis.mk.Git()
def ssh = new com.mirantis.mk.Ssh()
def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
def defaultGitRef = DEFAULT_GIT_REF
def defaultGitUrl = DEFAULT_GIT_URL
def checkouted = false
def reclassVersion = 'v1.5.4'
if (common.validInputParam('RECLASS_VERSION')) {
reclassVersion = RECLASS_VERSION
}
throttle(['test-model']) {
timeout(time: 1, unit: 'HOURS') {
node("python&&docker") {
try{
stage("checkout") {
if(defaultGitRef != "" && defaultGitUrl != "") {
checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
} else {
throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
}
if(checkouted) {
if (fileExists('classes/system')) {
if (SYSTEM_GIT_URL == "") {
ssh.prepareSshAgentKey(CREDENTIALS_ID)
dir('classes/system') {
remoteUrl = git.getGitRemote()
ssh.ensureKnownHosts(remoteUrl)
}
ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
} else {
dir('classes/system') {
if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
}
}
}
}
}
}
stage("test node") {
if (checkouted) {
def workspace = common.getWorkspace()
def testResult = false
common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
try {
def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
testResult = saltModelTesting.setupAndTestNode(
NODE_TARGET,
CLUSTER_NAME,
EXTRA_FORMULAS,
workspace,
FORMULAS_SOURCE,
FORMULAS_REVISION,
reclassVersion,
MAX_CPU_PER_JOB.toInteger(),
RECLASS_IGNORE_CLASS_NOTFOUND,
LEGACY_TEST_MODE,
APT_REPOSITORY,
APT_REPOSITORY_GPG,
DockerCName)
} catch (Exception e) {
if (e.getMessage() == "script returned exit code 124") {
common.errorMsg("Impossible to test node due to timeout of salt-master, ABORTING BUILD")
currentBuild.result = "ABORTED"
} else {
throw e
}
}
if (testResult) {
common.infoMsg("Test finished: SUCCESS")
} else {
error('Test node finished: FAILURE')
throw new RuntimeException('Test node stage finished: FAILURE')
}
}
}
} catch (Throwable e) {
// If there was an error or exception thrown, the build failed
currentBuild.result = "FAILURE"
currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
throw e
}
}
}
}