blob: 8d35d371e06b62dbc9ef3f420c1226125b86dfce [file] [log] [blame]
Oleksii Grudevbc824722018-07-03 12:32:38 +03001/**
2 *
3 * Deploy Master of Masters and edge clouds
4 *
5 * Expected parameters:
6 * FORMULA_PKG_REVISION Formula revision
7 * STACK_CLUSTER_NAME The name of cluster model to use
8 * STACK_RECLASS_ADDRESS Reclass repository
9 * STACK_RECLASS_BRANCH Reclass barnch
10 * OPENSTACK_API_PROJECT OpenStack project to connect to
11 * HEAT_STACK_ZONE Heat stack availability zone
12 * STACK_TEMPLATE_URL URL to git repo with stack templates
13 * STACK_TEMPLATE_BRANCH Stack templates repo branch
14 * STACK_TEMPLATE File with stack template
15 * STACK_TEST Run tests (bool)
16 * EDGE_DEPLOY_SCHEMAS Env schemas to deploy as edge clouds
Oleh Hryhorov0cead882018-07-11 13:38:40 +030017 * MOM_JOB Job name to deploy Master-of-Masters stack
Oleksii Grudevbc824722018-07-03 12:32:38 +030018 */
19
20common = new com.mirantis.mk.Common()
21salt = new com.mirantis.mk.Salt()
22
23def slave_node = 'python'
24
25if (common.validInputParam('SLAVE_NODE')) {
26 slave_node = SLAVE_NODE
27}
28
29def deployMoMJob = 'deploy-heat-virtual_mcp11_aio'
30if (common.validInputParam('MOM_JOB')) {
31 deployMoMJob = MOM_JOB
32}
33
Oleh Hryhorov0cead882018-07-11 13:38:40 +030034def deploy_schemas = '{os_ha_ovs: {deploy_job_name: "deploy-heat-os_ha_ovs", properties: {SLAVE_NODE: "python", STACK_INSTALL: "openstack,ovs", STACK_TEMPLATE: "os_ha_ovs", STACK_TYPE: "heat", FORMULA_PKG_REVISION: "testing", STACK_DELETE: false, STACK_CLUSTER_NAME: "os-ha-ovs", STACK_RECLASS_ADDRESS: "", STACK_RECLASS_BRANCH: ""}}}'
Oleksii Grudevbc824722018-07-03 12:32:38 +030035if (common.validInputParam('EDGE_DEPLOY_SCHEMAS')) {
36 deploy_schemas = EDGE_DEPLOY_SCHEMAS
37}
38
39def salt_overrides_list = SALT_OVERRIDES.tokenize('\n')
40
41def enableSyndic(saltMasterURL, nodeName, saltMasterCred, saltMoMIP) {
42
43 def saltMaster
44 saltMaster = salt.connection(saltMasterURL, saltMasterCred)
45
46 // Set up test_target parameter on node level
47 def fullnodename = salt.getMinions(saltMaster, nodeName).get(0)
48 def saltMasterExpression = 'I@salt:master'
49 def saltMasterTarget = ['expression': saltMasterExpression, 'type': 'compound']
50 def result
51 def classes_to_add = ['system.salt.syndic.single']
52 def params_to_add = ['salt_syndic_master_address': saltMoMIP]
53
54 result = salt.runSaltCommand(saltMaster, 'local', saltMasterTarget, 'reclass.node_update', null, null, ['name': "${fullnodename}", 'classes': classes_to_add, 'parameters': params_to_add])
55 salt.checkResult(result)
56
57 common.infoMsg('Perform full refresh for all nodes')
58 salt.fullRefresh(saltMaster, '*')
59
60 if (salt.testTarget(saltMaster, 'I@salt:syndic:enabled:True')) {
61 salt.enforceState(saltMaster, 'I@salt:syndic:enabled', 'salt.syndic', true, true, null, false, 180, 2)
62 }
63
64
65}
66
67node(slave_node) {
68
69 def momBuild
70 def salt_mom_url
71 def salt_mom_ip
72 def deploy_edges_infra = [:]
73 def deploy_edges = [:]
74 def edgeBuildsInfra = [:]
75 def edgeBuilds = [:]
76 def edge_deploy_schemas = readJSON text: deploy_schemas
77
78 stage('Deploy MoM stack'){
79 momBuild = build job: deployMoMJob, propagate: true, parameters: [
80 [$class: 'StringParameterValue', name: 'FORMULA_PKG_REVISION', value: FORMULA_PKG_REVISION],
81 [$class: 'StringParameterValue', name: 'STACK_CLUSTER_NAME', value: STACK_CLUSTER_NAME],
82 [$class: 'StringParameterValue', name: 'STACK_INSTALL', value: 'core'],
83 [$class: 'BooleanParameterValue', name: 'STACK_DELETE', value: STACK_DELETE.toBoolean()],
84 [$class: 'StringParameterValue', name: 'STACK_RECLASS_ADDRESS', value: STACK_RECLASS_ADDRESS],
85 [$class: 'StringParameterValue', name: 'STACK_RECLASS_BRANCH', value: STACK_RECLASS_BRANCH],
86 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
87 [$class: 'StringParameterValue', name: 'HEAT_STACK_ZONE', value: HEAT_STACK_ZONE],
88 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE_URL', value: STACK_TEMPLATE_URL],
89 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE_BRANCH', value: STACK_TEMPLATE_BRANCH],
90 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE', value: STACK_TEMPLATE],
91 [$class: 'StringParameterValue', name: 'STACK_TEST', value: STACK_TEST],
92 [$class: 'BooleanParameterValue', name: 'TEST_DOCKER_INSTALL', value: false],
93 [$class: 'StringParameterValue', name: 'SLAVE_NODE', value: slave_node],
94 ]
95
96 if (momBuild.result == 'SUCCESS') {
97 // get salt master url
98 salt_mom_url = "http://${momBuild.description.tokenize(' ')[1]}:6969"
99 salt_mom_ip = "${momBuild.description.tokenize(' ')[1]}"
100 node_name = "${momBuild.description.tokenize(' ')[2]}"
101 salt_overrides_list.add("salt_syndic_master_address: ${momBuild.description.tokenize(' ')[1]}")
102 common.infoMsg("Salt API is accessible via ${salt_mom_url}")
103 common.infoMsg("Enabling salt_syndic_enabled through overrides")
104 salt_overrides_list.add("salt_syndic_enabled: true")
105 } else {
106 common.errorMsg("Deployment of MoM has failed with result: " + momBuild.result)
107
108 }
109
110 }
111
112 stage('Deploy edge clouds'){
113 salt_overrides_list.add("salt_syndic_enabled: true")
114
115 for (edge_deploy_schema in edge_deploy_schemas.keySet()) {
116 def props
117 def deploy_job
118 def stack_name
119 def ed = edge_deploy_schema
120
121 deploy_job = edge_deploy_schemas[edge_deploy_schema]['deploy_job_name']
122
123 common.infoMsg("Edge cloud: ${edge_deploy_schema}")
124 common.infoMsg("Deploy job name: ${edge_deploy_schemas[edge_deploy_schema]['deploy_job_name']}")
125
126 props = edge_deploy_schemas[edge_deploy_schema]['properties']
127
128 if (env.BUILD_USER_ID) {
129 stack_name = "${env.BUILD_USER_ID}-${edge_deploy_schema}-${BUILD_NUMBER}"
130 } else {
131 stack_name = "replayed-${edge_deploy_schema}-${BUILD_NUMBER}"
132 }
133 deploy_edges_infra["Deploy ${ed} infra"] = {
134 node(slave_node) {
135 edgeBuildsInfra["${ed}"] = build job: deploy_job, propagate: false, parameters: [
136 [$class: 'StringParameterValue', name: 'HEAT_STACK_ZONE', value: HEAT_STACK_ZONE],
137 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
138 [$class: 'StringParameterValue', name: 'SLAVE_NODE', value: props['SLAVE_NODE']],
139 [$class: 'StringParameterValue', name: 'STACK_INSTALL', value: 'core'],
140 [$class: 'StringParameterValue', name: 'STACK_NAME', value: stack_name],
141 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE', value: props['STACK_TEMPLATE']],
142 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE_URL', value: STACK_TEMPLATE_URL],
143 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE_BRANCH', value: 'master'],
144 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: 'heat'],
Oleh Hryhorov0cead882018-07-11 13:38:40 +0300145 [$class: 'StringParameterValue', name: 'STACK_RECLASS_ADDRESS', value: props['STACK_RECLASS_ADDRESS']],
146 [$class: 'StringParameterValue', name: 'STACK_RECLASS_BRANCH', value: props['STACK_RECLASS_BRANCH']],
Oleksii Grudevbc824722018-07-03 12:32:38 +0300147 [$class: 'StringParameterValue', name: 'FORMULA_PKG_REVISION', value: props['FORMULA_PKG_REVISION']],
148 [$class: 'StringParameterValue', name: 'STACK_CLUSTER_NAME', value: props['STACK_CLUSTER_NAME']],
149 [$class: 'StringParameterValue', name: 'STACK_TEST', value: ''],
150 [$class: 'StringParameterValue', name: 'SALT_VERSION', value: 'stable 2017.7'],
151 [$class: 'BooleanParameterValue', name: 'TEST_DOCKER_INSTALL', value: false],
152 [$class: 'TextParameterValue', name: 'SALT_OVERRIDES', value: salt_overrides_list.join('\n')],
153 [$class: 'BooleanParameterValue', name: 'STACK_DELETE', value: props['STACK_DELETE'].toBoolean()],
154 ]
155 }
156 }
157 }
158
159 parallel deploy_edges_infra
160
161 for (k in edgeBuildsInfra.keySet()) {
162 common.infoMsg("keyset1: ${[k]}")
163 def ed_ = k
164 def deploy_job
165 def props_
166 def extra_target
167 def saltMasterURL
168
169 if (edgeBuildsInfra[ed_].result == 'SUCCESS') {
170 extra_target = "and *${edgeBuildsInfra[ed_].description.tokenize(' ')[0]}*"
171 saltMasterURL = "http://${edgeBuildsInfra[ed_].description.tokenize(' ')[1]}:6969"
172
173
Denis Egorenkoe983d452019-08-23 14:29:34 +0400174 enableSyndic(saltMasterURL, 'I@salt:master', SALT_MASTER_CREDENTIALS, salt_mom_ip)
Oleksii Grudevbc824722018-07-03 12:32:38 +0300175
176 props_ = edge_deploy_schemas[ed_]['properties']
177 deploy_job = edge_deploy_schemas[ed_]['deploy_job_name']
178
179
180 deploy_edges["Deploy ${ed_} with MoM"] = {
181 node(slave_node) {
182 edgeBuilds["${ed_}"] = build job: deploy_job, propagate: false, parameters: [
183 [$class: 'StringParameterValue', name: 'HEAT_STACK_ZONE', value: HEAT_STACK_ZONE],
184 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
185 [$class: 'StringParameterValue', name: 'SLAVE_NODE', value: props_['SLAVE_NODE']],
186 [$class: 'StringParameterValue', name: 'STACK_INSTALL', value: props_['STACK_INSTALL']],
187 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE', value: props_['STACK_TEMPLATE']],
188 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE_URL', value: STACK_TEMPLATE_URL],
189 [$class: 'StringParameterValue', name: 'STACK_TEMPLATE_BRANCH', value: 'master'],
190 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: 'physical'],
191 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: salt_mom_url],
192 [$class: 'StringParameterValue', name: 'EXTRA_TARGET', value: extra_target],
193 [$class: 'StringParameterValue', name: 'FORMULA_PKG_REVISION', value: props_['FORMULA_PKG_REVISION']],
194 [$class: 'StringParameterValue', name: 'STACK_CLUSTER_NAME', value: props_['STACK_CLUSTER_NAME']],
195 [$class: 'StringParameterValue', name: 'STACK_TEST', value: ''],
196 [$class: 'BooleanParameterValue', name: 'TEST_DOCKER_INSTALL', value: false],
197 [$class: 'TextParameterValue', name: 'SALT_OVERRIDES', value: salt_overrides_list.join('\n')],
198 [$class: 'BooleanParameterValue', name: 'STACK_DELETE', value: props_['STACK_DELETE'].toBoolean()],
199 ]
200 }
201 }
202 } else {
203 common.successMsg("${k} : " + edgeBuilds[k].result)
204 common.errorMsg("${k} : " + edgeBuilds[k].result)
205 }
206 }
207
208 parallel deploy_edges
209
210 }
211
212
213}