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