blob: a19b9700920f14f5d7fc8bd0390349bc272080fe [file] [log] [blame]
/**
* Generate cookiecutter cluster by individual products
*
* Expected parameters:
* COOKIECUTTER_TEMPLATE_CONTEXT Context parameters for the template generation.
* SALT_MASTER_URL URL of Salt master
* SALT_MASTER_CREDENTIALS Credentials to the Salt API
*
**/
import static groovy.json.JsonOutput.toJson
common = new com.mirantis.mk.Common()
python = new com.mirantis.mk.Python()
salt = new com.mirantis.mk.Salt()
ssh = new com.mirantis.mk.Ssh()
pepperEnv = "pepperEnv"
slaveNode = env.SLAVE_NODE ?: 'python&&docker'
model_job = 0
timeout(time: 2, unit: 'HOURS') {
node(slaveNode) {
try {
def templateContext = readYaml text: COOKIECUTTER_TEMPLATE_CONTEXT
def clusterName = templateContext.default_context.cluster_name
def aioNodeHostname = templateContext.default_context.aio_node_hostname
def aioInternalAddress = templateContext.default_context.aio_internal_address
def drivetrainInternalAddress = templateContext.default_context.drivetrain_internal_address
def artifact_tar_file = "${clusterName}.tar.gz"
def masterIP = templateContext.default_context.drivetrain_external_address
if ( templateContext.default_context.get("docker_deployment", "False").toBoolean() ) {
masterIP = drivetrainInternalAddress
}
def masterUrl = "http://" + masterIP + ":6969"
def outputDirectory = env.WORKSPACE + "/"
def outputDestination = outputDirectory + artifact_tar_file
def outputCluster = outputDirectory + "/classes/cluster/" + clusterName
def rsyncLocation = templateContext.default_context.get("rsync_location", "/srv/salt/reclass/classes/cluster")
def rsyncCredentials = templateContext.default_context.get("rsync_credentials", "lab")
c = common.getSshCredentials(rsyncCredentials)
def rsyncSSHKey = c.getPrivateKey()
def rsyncUser = c.getUsername()
def rsyncKeyFile = outputDirectory + "rsync_key"
def rsyncPath = rsyncUser + "@" + masterIP + ":" + rsyncLocation
currentBuild.description = "Cluster " + clusterName + " on " + masterIP
stage("Generate AIO model") {
model_job = build(job: 'generate-salt-model-separated-products',
parameters: [
[$class: 'StringParameterValue', name: 'COOKIECUTTER_TEMPLATE_CONTEXT', value: COOKIECUTTER_TEMPLATE_CONTEXT ],
[$class: 'BooleanParameterValue', name: 'TEST_MODEL', value: false],
])
}
stage("Download artifact with model") {
artifact_tar_url = "${env.JENKINS_URL}/job/generate-salt-model-separated-products/${model_job.number}/artifact/output-${clusterName}/${artifact_tar_file}"
sh "wget --progress=dot:mega --auth-no-challenge -O ${outputDestination} '${artifact_tar_url}'"
sh "tar -xzvf ${outputDestination}"
}
stage("Send model to Salt master node") {
ssh.ensureKnownHosts(masterIP)
writeFile(file: rsyncKeyFile, text: rsyncSSHKey)
sh("chmod 600 ${rsyncKeyFile}")
common.infoMsg("Copying cluster model to ${rsyncPath}")
sh("rsync -r -e \"ssh -i ${rsyncKeyFile}\" ${outputCluster} ${rsyncPath}")
}
stage("Setup virtualenv for Pepper") {
python.setupPepperVirtualenv(pepperEnv, masterUrl, SALT_MASTER_CREDENTIALS)
}
stage("Prepare AIO node"){
tgt = "S@" + aioInternalAddress
// Classify AIO node
eventData = [:]
eventData["node_control_ip"] = aioInternalAddress
eventData["node_os"] = "xenial"
eventData["node_master_ip"] = drivetrainInternalAddress
eventData["node_hostname"] = aioNodeHostname
eventData["node_cluster"] = clusterName
eventJson = toJson(eventData)
event = "salt-call event.send \"reclass/minion/classify\" \'" + eventJson + "\'"
salt.cmdRun(pepperEnv, tgt, event)
sleep(30)
// Upgrade Salt minion
salt.runSaltProcessStep(pepperEnv, tgt, 'pkg.install', "salt-minion")
sleep(10)
// Run core states on AIO node
salt.fullRefresh(pepperEnv, '*')
salt.enforceState(pepperEnv, tgt, 'linux')
salt.enforceState(pepperEnv, tgt, 'salt')
salt.enforceState(pepperEnv, tgt, 'openssh')
salt.enforceState(pepperEnv, tgt, 'ntp')
salt.enforceState(pepperEnv, tgt, 'rsyslog')
}
stage("Deploy Openstack") {
build(job: 'deploy_openstack',
parameters: [
[$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
[$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: masterUrl],
[$class: 'StringParameterValue', name: 'STACK_INSTALL', value: 'openstack']
])
}
} catch (Throwable e) {
currentBuild.result = "FAILURE"
currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
throw e
} finally {
stage('Clean workspace directories') {
sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
}
// common.sendNotification(currentBuild.result,"",["slack"])
}
}
}