blob: 3f1d02ad54c5e6f1eb07564790d7c19956bdb309 [file] [log] [blame]
Sergey Galkin24ebd762020-01-14 14:36:34 +04001- job-template:
2 project-type: pipeline
3 description: '{job-description}'
4 concurrent: true
5 disabled: false
6 sandbox: true
7 triggers:
8 - timed: H(40-59) 0 * * 1-5
9 dsl: |-
10 /**
11 *
12 * Deploy the product cluster using Jenkins master on CICD cluster
13 *
14 * Expected parameters:
15 * STACKS List of deployments from 'all physical' view in the Jenkins
16 They should be separated by newline
17 * PARENT_NODE_NAME
18 * OS_AUTH_URL OpenStack keystone catalog URL
19 * OS_PROJECT_NAME OpenStack project (tenant) name
20 * OS_CREDENTIALS OpenStack username and password credentials ID in Jenkins
21
22 * TCP_QA_REFS Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41
23 */
24 @Library('tcp-qa')_
25
26 common = new com.mirantis.mk.Common()
27 shared = new com.mirantis.system_qa.SharedPipeline()
28 import jenkins.model.*
29
30 def stacks = env.STACKS.readLines()
31
32 def get_last_build_time(job_name) {{
33 def job = Hudson.instance.getJob(job_name)
34 def last_build = Jenkins.instance.getItemByFullName(job.fullName).getLastBuild()
35 if (last_build == null) {{
36 return null
37 }}
38 def upStreamBuild = Jenkins.getInstance().getItemByFullName(job.fullName).getBuildByNumber(last_build.getNumber())
39 return upStreamBuild.getTime()
40 }}
41
42 @NonCPS
43 def oldest_job(map) {{
44 println map.sort({{a, b -> a.value <=> b.value}})*.value
45 return map.sort({{a, b -> a.value <=> b.value}})*.key[0]
46 }}
47
48 // ============================================================================
49 timeout(time: 15, unit: 'HOURS') {{
50 node (env.PARENT_NODE_NAME) {{
51 stage("Remove extra stacks") {{
52 withCredentials([
53 [$class : 'UsernamePasswordMultiBinding',
54 credentialsId : env.OS_CREDENTIALS,
55 passwordVariable: 'OS_PASSWORD',
56 usernameVariable: 'OS_USERNAME']
57 ]) {{
58 env.OS_IDENTITY_API_VERSION = 3
59 for (stack_name in stacks) {{
60 shared.run_cmd("""
61 # export OS_IDENTITY_API_VERSION=3
62 # export OS_AUTH_URL=${{OS_AUTH_URL}}
63 # export OS_USERNAME=${{OS_USERNAME}}
64 # export OS_PASSWORD=${{OS_PASSWORD}}
65 # export OS_PROJECT_NAME=${{OS_PROJECT_NAME}}
66 openstack --insecure stack delete -y ${{stack_name}} || true
67 timeout 20m /bin/bash -c "while openstack --insecure stack show ${{stack_name}} -f value -c stack_status; do sleep 10; done";
68 """)
69 }}
70 }}
71 }}
72
73 stage("Reboot HW nodes ") {{
74 bm_ips = [
75 "185.8.59.227",
76 "185.8.59.229",
77 "5.43.225.88",
78 "5.43.225.112",
79 "5.43.225.208",
80 "5.43.227.118",
81 "185.8.58.248",
82 "185.8.59.222",
83 "5.43.225.228",
84 "5.43.229.28",
85 "5.43.225.23",
86 "185.8.58.9",
87 "185.8.58.246",
88 "185.8.58.243",
89 "185.8.58.244"
90 ]
91
92 lab_user = "engineer"
93 lab_pass = "KBwdcRqwed3w2"
94 for (ip in bm_ips) {{ sh ("ipmitool -H ${{ip}} -U ${{lab_user}} -P ${{lab_pass}} chassis power off")}}
95 for (ip in bm_ips) {{ sh ("ipmitool -H ${{ip}} -U ${{lab_user}} -P ${{lab_pass}} chassis bootdev pxe")}}
96 }}
97
98 stage("Start deployment") {{
99 def jobs_map = [:]
100 for (stack_name in stacks) {{
101 println stack_name
102 println get_last_build_time(stack_name)
103 jobs_map.put ("${{stack_name}}", get_last_build_time(stack_name))
104 }}
105 stack_to_deploy = oldest_job(jobs_map)
106
107 println "Build ${{stack_to_deploy}}"
108 currentBuild.description = "${{stack_to_deploy}}"
109 // Trigger job
110 def deploy = build job: "${{stack_to_deploy}}",
111 parameters: [
112 string(name: 'PARENT_NODE_NAME', value: env.PARENT_NODE_NAME),
113 string(name: 'OS_CREDENTIALS', value: env.OS_CREDENTIALS)
114 ]
115 // currentBuild.status = deploy.status
116 }}
117 }}
118 }}
119 name: deploy_bm
120 parameters:
121 - string:
122 default: sre-qa-ci-eu
123 description: ''
124 name: OS_CREDENTIALS
125 trim: 'false'
126 - text:
127 default: |-
128 bm-cicd-pike-ovs-maas
129 bm-cicd-queens-ovs-maas
130 heat-bm-cicd-pike-contrail-sl
131 heat-bm-cicd-queens-contrail-sl
132 description: List of stacks for deployment. Separated by newline
133 name: STACKS
134 trim: 'false'
135 - string:
136 default: ''
137 description: ''
138 name: TCP_QA_REFS
139 trim: 'false'
140 - string:
141 default: sre-team-infra
142 description: ''
143 name: PARENT_NODE_NAME
144 trim: 'false'
145 - string:
146 default: https://ic-eu.ssl.mirantis.net:5000/v3
147 description: ''
148 name: OS_AUTH_URL
149 trim: 'false'
150 - string:
151 default: sre-team
152 description: ''
153 name: OS_PROJECT_NAME
154 trim: 'false'
155