blob: a2698b7e62f33cab2b321fd576a1ee08a95d5b5c [file] [log] [blame]
Martin Polreich4a9f71c2018-10-17 16:40:51 +02001/**
2 * Generate cookiecutter cluster by individual products
3 *
4 * Expected parameters:
5 * COOKIECUTTER_TEMPLATE_CONTEXT Context parameters for the template generation.
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
8 *
9 **/
10
11import static groovy.json.JsonOutput.toJson
12
13common = new com.mirantis.mk.Common()
14python = new com.mirantis.mk.Python()
15salt = new com.mirantis.mk.Salt()
16ssh = new com.mirantis.mk.Ssh()
17
18pepperEnv = "pepperEnv"
19
20slaveNode = env.SLAVE_NODE ?: 'python&&docker'
21model_job = 0
22
23timeout(time: 2, unit: 'HOURS') {
24 node(slaveNode) {
25 try {
26 def templateContext = readYaml text: COOKIECUTTER_TEMPLATE_CONTEXT
27 def clusterName = templateContext.default_context.cluster_name
28 def aioNodeHostname = templateContext.default_context.aio_node_hostname
29 def aioInternalAddress = templateContext.default_context.aio_internal_address
30 def drivetrainInternalAddress = templateContext.default_context.drivetrain_internal_address
31 def artifact_tar_file = "${clusterName}.tar.gz"
32 def rsyncUser = templateContext.default_context.rsync_user
33 def masterIP = templateContext.default_context.drivetrain_external_address
34 def masterUrl = "http://" + masterIP + ":6969"
35 def rsyncLocation = templateContext.default_context.get("rsync_location", "/srv/salt/reclass/classes/cluster")
36 def rsyncPath = rsyncUser + "@" + masterIP + ":" + rsyncLocation
37 def rsyncSSHKey = templateContext.default_context.rsync_ssh_key
38 def outputDirectory = env.WORKSPACE + "/"
39 def rsyncKeyFile = outputDirectory + "publication_key"
40 def outputDestination = outputDirectory + artifact_tar_file
41 def outputCluster = outputDirectory + "/classes/cluster/" + clusterName
42 currentBuild.description = "Cluster " + clusterName + " on " + masterIP
43
44 stage("Generate AIO model") {
45 model_job = build(job: 'generate-salt-model-separated-products',
46 parameters: [
47 [$class: 'StringParameterValue', name: 'COOKIECUTTER_TEMPLATE_CONTEXT', value: COOKIECUTTER_TEMPLATE_CONTEXT ],
48 [$class: 'BooleanParameterValue', name: 'TEST_MODEL', value: false],
49 ])
50 }
51
52 stage("Download artifact with model") {
53 artifact_tar_url = "${env.JENKINS_URL}/job/generate-salt-model-separated-products/${model_job.number}/artifact/output-${clusterName}/${artifact_tar_file}"
54 sh "wget --progress=dot:mega --auth-no-challenge -O ${outputDestination} '${artifact_tar_url}'"
55 sh "tar -xzvf ${outputDestination}"
56 }
57
58 stage("Send model to Salt master node") {
59 ssh.ensureKnownHosts(masterIP)
60 writeFile(file: rsyncKeyFile, text: rsyncSSHKey)
61 sh("chmod 600 ${rsyncKeyFile}")
62 common.infoMsg("Copying cluster model to ${rsyncPath}")
63 sh("rsync -r -e \"ssh -i ${rsyncKeyFile}\" ${outputCluster} ${rsyncPath}")
64 }
65
66 stage("Setup virtualenv for Pepper") {
Ivan Berezovskiy46b7bbc2018-10-30 22:32:13 +040067 python.setupPepperVirtualenv(pepperEnv, masterUrl, SALT_MASTER_CREDENTIALS)
Martin Polreich4a9f71c2018-10-17 16:40:51 +020068 }
69
70 stage("Prepare AIO node"){
71 tgt = "S@" + aioInternalAddress
72 // Classify AIO node
73 eventData = [:]
74 eventData["node_control_ip"] = aioInternalAddress
75 eventData["node_os"] = "xenial"
76 eventData["node_master_ip"] = drivetrainInternalAddress
77 eventData["node_hostname"] = aioNodeHostname
78 eventData["node_cluster"] = clusterName
79 eventJson = toJson(eventData)
80 event = "salt-call event.send \"reclass/minion/classify\" \'" + eventJson + "\'"
81 salt.cmdRun(pepperEnv, tgt, event)
82 sleep(30)
83 // Upgrade Salt minion
84 salt.runSaltProcessStep(pepperEnv, tgt, 'pkg.install', "salt-minion")
85 sleep(10)
86 // Run core states on AIO node
87 salt.fullRefresh(pepperEnv, '*')
88 salt.enforceState(pepperEnv, tgt, 'linux')
89 salt.enforceState(pepperEnv, tgt, 'salt')
90 salt.enforceState(pepperEnv, tgt, 'openssh')
91 salt.enforceState(pepperEnv, tgt, 'ntp')
92 salt.enforceState(pepperEnv, tgt, 'rsyslog')
93 }
94
95 stage("Deploy Openstack") {
96 build(job: 'deploy_openstack',
97 parameters: [
Ivan Berezovskiy46b7bbc2018-10-30 22:32:13 +040098 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
Martin Polreich4a9f71c2018-10-17 16:40:51 +020099 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: masterUrl],
100 [$class: 'StringParameterValue', name: 'STACK_INSTALL', value: 'openstack']
101 ])
102 }
103 } catch (Throwable e) {
104 currentBuild.result = "FAILURE"
105 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
106 throw e
107 } finally {
108 stage('Clean workspace directories') {
109 sh(script: 'find . -mindepth 1 -delete > /dev/null || true')
110 }
111 // common.sendNotification(currentBuild.result,"",["slack"])
112 }
113 }
114}