blob: 49103a93e1752a6f731a4796e2780fb2ed1ce0ab [file] [log] [blame]
Hanna Arhipovad62fef42020-01-03 22:56:15 +02001/**
2 *
3 * Deploy the product cluster using Jenkins master on CICD cluster
4 *
5 * Expected parameters:
6 * STACKS List of deployments from 'all physical' view in the Jenkins
7 They should be separated by newline
8 * PARENT_NODE_NAME
9 * OS_AUTH_URL OpenStack keystone catalog URL
10 * OS_PROJECT_NAME OpenStack project (tenant) name
11 * OS_CREDENTIALS OpenStack username and password credentials ID in Jenkins
12
13 * TCP_QA_REFS Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41
14 */
15@Library('tcp-qa')_
16
17common = new com.mirantis.mk.Common()
18shared = new com.mirantis.system_qa.SharedPipeline()
19import jenkins.model.*
20
21def stacks = env.STACKS.readLines()
22
23def get_last_build_time(job_name) {
24 def job = Hudson.instance.getJob(job_name)
25 def last_build = Jenkins.instance.getItemByFullName(job.fullName).getLastBuild()
26 if (last_build == null) {
27 return null
28 }
29 def upStreamBuild = Jenkins.getInstance().getItemByFullName(job.fullName).getBuildByNumber(last_build.getNumber())
30 return upStreamBuild.getTime()
31}
32
33@NonCPS
34def oldest_job(map) {
35 println map.sort({a, b -> a.value <=> b.value})*.value
36 return map.sort({a, b -> a.value <=> b.value})*.key[0]
37}
38
39// ============================================================================
40timeout(time: 15, unit: 'HOURS') {
41 node (env.PARENT_NODE_NAME) {
42 stage("Remove extra stacks") {
43 withCredentials([
44 [$class : 'UsernamePasswordMultiBinding',
45 credentialsId : env.OS_CREDENTIALS,
46 passwordVariable: 'OS_PASSWORD',
47 usernameVariable: 'OS_USERNAME']
48 ]) {
49 env.OS_IDENTITY_API_VERSION = 3
50 for (stack_name in stacks) {
51 shared.run_cmd("""
52 # export OS_IDENTITY_API_VERSION=3
53 # export OS_AUTH_URL=${OS_AUTH_URL}
54 # export OS_USERNAME=${OS_USERNAME}
55 # export OS_PASSWORD=${OS_PASSWORD}
56 # export OS_PROJECT_NAME=${OS_PROJECT_NAME}
57 openstack --insecure stack delete -y ${stack_name} || true
58 timeout 20m /bin/bash -c "while openstack --insecure stack show ${stack_name} -f value -c stack_status; do sleep 10; done";
59 """)
60 }
61 }
62 }
63
64 stage("Reboot HW nodes ") {
65 bm_ips = [
66 "185.8.59.227",
67 "185.8.59.229",
68 "5.43.225.88",
69 "5.43.225.112",
70 "5.43.225.208",
71 "5.43.227.118",
72 "185.8.58.248",
73 "185.8.59.222",
74 "5.43.225.228",
75 "5.43.229.28",
76 "5.43.225.23",
77 "185.8.58.9",
78 "185.8.58.246",
79 "185.8.58.243",
80 "185.8.58.244"
81 ]
82
83 withCredentials([
84 [$class : 'UsernamePasswordMultiBinding',
85 credentialsId : 'lab_engineer',
86 passwordVariable: 'lab_pass',
87 usernameVariable: 'lab_user']
88 ]) {
89 for (ip in bm_ips) { sh ("ipmitool -H ${ip} -U ${lab_user} -P ${lab_pass} chassis power off")}
90 for (ip in bm_ips) { sh ("ipmitool -H ${ip} -U ${lab_user} -P ${lab_pass} chassis bootdev pxe")}
91 }
92 }
93
94 stage("Start deployment") {
95 def jobs_map = [:]
96 for (stack_name in stacks) {
97 println stack_name
98 println get_last_build_time(stack_name)
99 jobs_map.put ("${stack_name}", get_last_build_time(stack_name))
100 }
101 stack_to_deploy = oldest_job(jobs_map)
102
103 println "Build ${stack_to_deploy}"
104 currentBuild.description = "${stack_to_deploy}"
105 // Trigger job
106 def deploy = build job: "${stack_to_deploy}",
107 parameters: [
108 string(name: 'PARENT_NODE_NAME', value: env.PARENT_NODE_NAME),
109 string(name: 'OS_CREDENTIALS', value: env.OS_CREDENTIALS)
110 ]
111 }
112 }
113}