blob: 4b7c3b100d4c411b5466c512231b9a52da04083f [file] [log] [blame]
Sergey Kolekonovba203982016-12-21 18:32:17 +04001package com.mirantis.mk
2
3/**
4 *
5 * SaltStack functions
6 *
7 */
8
9/**
10 * Login to Salt API and return auth token
11 *
12 * @param url Salt API server URL
13 * @param params Salt connection params
14 */
15def getSaltToken(url, params) {
16 def http = new com.mirantis.mk.http()
17 data = [
18 'username': params.creds.username,
19 'password': params.creds.password.toString(),
20 'eauth': 'pam'
21 ]
22 authToken = http.sendHttpGetRequest("${url}/login", data, ['Accept': '*/*'])['return'][0]['token']
23 return authToken
24}
25
26/**
27 * Salt connection and context parameters
28 *
29 * @param url Salt API server URL
30 * @param credentialsID ID of credentials store entry
31 */
32def createSaltConnection(url, credentialsId) {
33 def common = new com.mirantis.mk.common()
34 params = [
35 "url": url,
36 "credentialsId": credentialsId,
37 "authToken": null,
38 "creds": common.getPasswordCredentials(credentialsId)
39 ]
40 params["authToken"] = getSaltToken(url, params)
41
42 return params
43}
44
45/**
46 * Run action using Salt API
47 *
48 * @param master Salt connection object
49 * @param client Client type
50 * @param target Target specification, eg. for compound matches by Pillar
51 * data: ['expression': 'I@openssh:server', 'type': 'compound'])
52 * @param function Function to execute (eg. "state.sls")
53 * @param args Additional arguments to function
54 * @param kwargs Additional key-value arguments to function
55 */
Ales Komarekeeed8652017-01-03 15:20:21 +010056@NonCPS
Ales Komarekddb44d02017-01-04 13:17:04 +010057def runSaltCommand(master, client, target, function, batch = null, args = null, kwargs = null) {
Ales Komarekbfd10f42017-01-03 13:40:12 +010058 def http = new com.mirantis.mk.http()
59
Sergey Kolekonovba203982016-12-21 18:32:17 +040060 data = [
61 'tgt': target.expression,
62 'fun': function,
63 'client': client,
64 'expr_form': target.type,
65 ]
66
Ales Komarekddb44d02017-01-04 13:17:04 +010067 if (batch) {
68 data['batch'] = batch
69 }
70
Sergey Kolekonovba203982016-12-21 18:32:17 +040071 if (args) {
72 data['arg'] = args
73 }
Ales Komarekddb44d02017-01-04 13:17:04 +010074
Sergey Kolekonovba203982016-12-21 18:32:17 +040075 if (kwargs) {
76 data['kwarg'] = kwargs
77 }
78
79 headers = [
80 'X-Auth-Token': "${master.authToken}"
81 ]
82
83 return http.sendHttpPostRequest("${master.url}/", data, headers)
84}
85
86def getSaltPillar(master, target, pillar) {
87 def out = runSaltCommand(master, 'local', target, 'pillar.get', [pillar.replace('.', ':')])
88 return out
89}
90
91def enforceSaltState(master, target, state, output = false) {
92 def run_states
93 if (state instanceof String) {
94 run_states = state
95 } else {
96 run_states = state.join(',')
97 }
98
Ales Komarekddb44d02017-01-04 13:17:04 +010099 def out = runSaltCommand(master, 'local', target, 'state.sls', null, [run_states])
Sergey Kolekonovba203982016-12-21 18:32:17 +0400100 try {
101 checkSaltResult(out)
102 } finally {
103 if (output == true) {
104 printSaltResult(out)
105 }
106 }
107 return out
108}
109
110def runSaltCmd(master, target, cmd) {
Ales Komarekddb44d02017-01-04 13:17:04 +0100111 return runSaltCommand(master, 'local', target, 'cmd.run', null, [cmd])
Sergey Kolekonovba203982016-12-21 18:32:17 +0400112}
113
114def syncSaltAll(master, target) {
115 return runSaltCommand(master, 'local', target, 'saltutil.sync_all')
116}
117
118def enforceSaltApply(master, target, output = false) {
119 def out = runSaltCommand(master, 'local', target, 'state.highstate')
120 try {
121 checkSaltResult(out)
122 } finally {
123 if (output == true) {
124 printSaltResult(out)
125 }
126 }
127 return out
128}
129
130def generateSaltNodeKey(master, target, host, keysize = 4096) {
131 args = [host]
132 kwargs = ['keysize': keysize]
Ales Komarekddb44d02017-01-04 13:17:04 +0100133 return runSaltCommand(master, 'wheel', target, 'key.gen_accept', null, args, kwargs)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400134}
135
136def generateSaltNodeMetadata(master, target, host, classes, parameters) {
137 args = [host, '_generated']
138 kwargs = ['classes': classes, 'parameters': parameters]
Ales Komarekddb44d02017-01-04 13:17:04 +0100139 return runSaltCommand(master, 'local', target, 'reclass.node_create', null, args, kwargs)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400140}
141
142def orchestrateSaltSystem(master, target, orchestrate) {
Ales Komarekddb44d02017-01-04 13:17:04 +0100143 return runSaltCommand(master, 'runner', target, 'state.orchestrate', null, [orchestrate])
Sergey Kolekonovba203982016-12-21 18:32:17 +0400144}
145
146/**
147 * Check result for errors and throw exception if any found
148 *
149 * @param result Parsed response of Salt API
150 */
151def checkSaltResult(result) {
152 for (entry in result['return']) {
153 if (!entry) {
154 throw new Exception("Salt API returned empty response: ${result}")
155 }
156 for (node in entry) {
157 for (resource in node.value) {
158 if (resource instanceof String || resource.value.result.toString().toBoolean() != true) {
159 throw new Exception("Salt state on node ${node.key} failed: ${node.value}")
160 }
161 }
162 }
163 }
164}
165
166/**
167 * Print Salt run results in human-friendly form
168 *
169 * @param result Parsed response of Salt API
170 * @param onlyChanges If true (default), print only changed resources
171 * @param raw Simply pretty print what we have, no additional
172 * parsing
173 */
174def printSaltResult(result, onlyChanges = true, raw = false) {
175 if (raw == true) {
176 print new groovy.json.JsonBuilder(result).toPrettyString()
177 } else {
178 def out = [:]
179 for (entry in result['return']) {
180 for (node in entry) {
181 out[node.key] = [:]
182 for (resource in node.value) {
183 if (resource instanceof String) {
184 out[node.key] = node.value
185 } else if (resource.value.result.toString().toBoolean() == false || resource.value.changes || onlyChanges == false) {
186 out[node.key][resource.key] = resource.value
187 }
188 }
189 }
190 }
191
192 for (node in out) {
193 if (node.value) {
194 println "Node ${node.key} changes:"
195 print new groovy.json.JsonBuilder(node.value).toPrettyString()
196 } else {
197 println "No changes for node ${node.key}"
198 }
199 }
200 }
201}
202
Sergey Kolekonovba203982016-12-21 18:32:17 +0400203
Ales Komarekddb44d02017-01-04 13:17:04 +0100204def runSaltProcessStep(master, tgt, fun, arg = [], batch = null) {
205 if (batch) {
206 result = runSaltCommand(master, 'local_batch', ['expression': tgt, 'type': 'compound'], fun, String.valueOf(batch), arg)
207 }
208 else {
209 result = runSaltCommand(master, 'local', ['expression': tgt, 'type': 'compound'], fun, batch, arg)
210 }
211 echo("${result}")
Sergey Kolekonovba203982016-12-21 18:32:17 +0400212}
213
Sergey Kolekonovba203982016-12-21 18:32:17 +0400214
Ales Komarekddb44d02017-01-04 13:17:04 +0100215def validateFoundationInfra(master) {
216 runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['salt-key'])
217 runSaltProcessStep(master, 'I@salt:minion', 'test.version')
218 runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['reclass-salt --top'])
219 runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory')
220 runSaltProcessStep(master, 'I@salt:minion', 'state.show_top')
221}
Sergey Kolekonovba203982016-12-21 18:32:17 +0400222
Ales Komarekddb44d02017-01-04 13:17:04 +0100223
224def installFoundationInfra(master) {
225 runSaltProcessStep(master, 'I@salt:master', 'state.sls', ['salt.master,reclass'])
226 runSaltProcessStep(master, 'I@linux:system', 'saltutil.refresh_pillar')
227 runSaltProcessStep(master, 'I@linux:system', 'saltutil.sync_all')
228 runSaltProcessStep(master, 'I@linux:system', 'state.sls', ['linux,openssh,salt.minion,ntp'])
229}
230
Ales Komarek6f2bc662017-01-05 11:52:47 +0100231
232def installOpenstackMkInfra(master) {
Ales Komarekddb44d02017-01-04 13:17:04 +0100233 // Install keepaliveds
Ales Komarek6f2bc662017-01-05 11:52:47 +0100234 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
235 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keepalived'])
236 runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100237 // Check the keepalived VIPs
238 runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
239 // Install glusterfs
240 runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
Ales Komarek6f2bc662017-01-05 11:52:47 +0100241 //runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.setup'], 1)
242 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
243 runSaltProcessStep(master, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
244 runSaltProcessStep(master, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100245 runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
246 runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
247 // Install rabbitmq
248 runSaltProcessStep(master, 'I@rabbitmq:server', 'state.sls', ['rabbitmq'])
249 // Check the rabbitmq status
250 runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
251 // Install galera
252 runSaltProcessStep(master, 'I@galera:master', 'state.sls', ['galera'])
253 runSaltProcessStep(master, 'I@galera:slave', 'state.sls', ['galera'])
254 // Check galera status
255 runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
256 runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
257 // Install haproxy
258 runSaltProcessStep(master, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
259 runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
260 runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
261 // Install memcached
262 runSaltProcessStep(master, 'I@memcached:server', 'state.sls', ['memcached'])
263}
264
265
266def installOpenstackMkControl(master) {
267 // setup keystone service
Ales Komarek6f2bc662017-01-05 11:52:47 +0100268 //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
269 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keystone.server'])
270 runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100271 // populate keystone services/tenants/roles/users
272 runSaltProcessStep(master, 'I@keystone:client', 'state.sls', ['keystone.client'])
273 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'])
274 // Install glance and ensure glusterfs clusters
Ales Komarek6f2bc662017-01-05 11:52:47 +0100275 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
276 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['glance.server'])
277 runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100278 runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glusterfs.client'])
279 // Update fernet tokens before doing request on keystone server
280 runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'])
281 // Check glance service
282 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'])
283 // Install and check nova service
Ales Komarek6f2bc662017-01-05 11:52:47 +0100284 //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
285 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['nova'])
286 runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100287 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'])
288 // Install and check cinder service
Ales Komarek6f2bc662017-01-05 11:52:47 +0100289 //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
290 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['cinder'])
291 runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100292 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'])
293 // Install neutron service
Ales Komarek6f2bc662017-01-05 11:52:47 +0100294 //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
295 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['neutron'])
296 runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100297 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'])
298 // Install heat service
Ales Komarek6f2bc662017-01-05 11:52:47 +0100299 //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
300 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['heat'])
301 runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100302 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'])
303 // Install horizon dashboard
304 runSaltProcessStep(master, 'I@horizon:server', 'state.sls', ['horizon'])
305 runSaltProcessStep(master, 'I@nginx:server', 'state.sls', ['nginx'])
306}
307
308
309def installOpenstackMkNetwork(master) {
310 // Install opencontrail database services
Ales Komarek6f2bc662017-01-05 11:52:47 +0100311 //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
312 runSaltProcessStep(master, 'ntw01*', 'state.sls', ['opencontrail.database'])
313 runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100314 // Install opencontrail control services
Ales Komarek6f2bc662017-01-05 11:52:47 +0100315 //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
316 runSaltProcessStep(master, 'ntw01*', 'state.sls', ['opencontrail'])
317 runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100318 // Provision opencontrail control services
319 runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl01 --host_ip 172.16.10.101 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'])
320 runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl02 --host_ip 172.16.10.102 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'])
321 runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl03 --host_ip 172.16.10.103 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'])
322 // Test opencontrail
323 runSaltProcessStep(master, 'I@opencontrail:control', 'cmd.run', ['contrail-status'])
324 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
325 runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
326}
327
328
329def installOpenstackMkCompute(master) {
330 // Configure compute nodes
331 runSaltProcessStep(master, 'I@nova:compute', 'state.apply')
332 runSaltProcessStep(master, 'I@nova:compute', 'state.apply')
333 // Provision opencontrail virtual routers
334 runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_vrouter.py --host_name cmp01 --host_ip 172.16.10.105 --api_server_ip 172.16.10.254 --oper add --admin_user admin --admin_password workshop --admin_tenant_name admin'])
335 runSaltProcessStep(master, 'I@nova:compute', 'system.reboot')
336}
337
338
339def installOpenstackMcpInfra(master) {
340 // Comment nameserver
341 runSaltProcessStep(master, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
342 // Install glusterfs
343 runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
344 // Install keepalived
Ales Komarek6f2bc662017-01-05 11:52:47 +0100345 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keepalived'])
346 runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100347 // Check the keepalived VIPs
348 runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
349 // Setup glusterfs
Ales Komarek6f2bc662017-01-05 11:52:47 +0100350 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
351 runSaltProcessStep(master, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
352 runSaltProcessStep(master, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100353 runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
354 runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
355 // Install haproxy
356 runSaltProcessStep(master, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
357 runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
358 // Install docker
359 runSaltProcessStep(master, 'I@docker:host', 'state.sls', ['docker.host'])
360 runSaltProcessStep(master, 'I@docker:host', 'cmd.run', ['docker ps'])
361 // Install bird
362 runSaltProcessStep(master, 'I@bird:server', 'state.sls', ['bird'])
363 // Install etcd
364 runSaltProcessStep(master, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
365 runSaltProcessStep(master, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
366}
367
368
369def installOpenstackMcpControl(master) {
Tomáš Kukrále65f7b02017-01-19 13:16:43 +0100370
371 // Install Kubernetes pool and Calico
Ales Komarekddb44d02017-01-04 13:17:04 +0100372 runSaltProcessStep(master, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
Tomáš Kukrále65f7b02017-01-19 13:16:43 +0100373 runSaltProcessStep(master, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
374
375 // Setup etcd server
Ales Komarekddb44d02017-01-04 13:17:04 +0100376 runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
Tomáš Kukrále65f7b02017-01-19 13:16:43 +0100377
378 // Run k8s without master.setup
379 runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
380
381 // Run k8s master setup
Tomáš Kukrál9a58e142017-02-02 16:09:33 +0100382 runSaltProcessStep(master, 'ctl01*', 'state.sls', ['kubernetes.master.setup'])
Tomáš Kukrále65f7b02017-01-19 13:16:43 +0100383
Ales Komarekddb44d02017-01-04 13:17:04 +0100384 // Revert comment nameserver
385 runSaltProcessStep(master, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
Tomáš Kukrále65f7b02017-01-19 13:16:43 +0100386
387 // Set route
388 runSaltProcessStep(master, 'I@kubernetes:pool', 'cmd.run', ['ip r a 10.254.0.0/16 dev ens4'])
389
390 // Restart kubelet
391 runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
Ales Komarekddb44d02017-01-04 13:17:04 +0100392}
393
394
395def installOpenstackMcpCompute(master) {
396 // Install opencontrail
397 runSaltProcessStep(master, 'I@opencontrail:compute', 'state.sls', ['opencontrail'])
398 // Reboot compute nodes
399 runSaltProcessStep(master, 'I@opencontrail:compute', 'system.reboot')
400}
401
402
403def installStacklightControl(master) {
Ales Komarek6f2bc662017-01-05 11:52:47 +0100404 runSaltProcessStep(master, 'I@elasticsearch:server', 'state.sls', ['elasticsearch.server'])
405 runSaltProcessStep(master, 'I@influxdb:server', 'state.sls', ['influxdb'])
406 runSaltProcessStep(master, 'I@kibana:server', 'state.sls', ['kibana.server'])
407 runSaltProcessStep(master, 'I@grafana:server', 'state.sls', ['grafana'])
408 runSaltProcessStep(master, 'I@nagios:server', 'state.sls', ['nagios'])
409 runSaltProcessStep(master, 'I@elasticsearch:client', 'state.sls', ['elasticsearch.client'])
410 runSaltProcessStep(master, 'I@kibana:client', 'state.sls', ['kibana.client'])
Sergey Kolekonovba203982016-12-21 18:32:17 +0400411}
412
Tatyana Leontoviche9e6faa2017-01-20 18:50:36 +0200413/**
414 * Run e2e conformance tests
415 *
416 * @param k8s_api Kubernetes api address
417 * @param image Docker image with tests
418 */
419def runConformanceTests(master, k8s_api, image) {
420 runSaltProcessStep(master, 'ctl01*', 'cmd.run', ["docker run --rm --net=host -e API_SERVER=${k8s_api} ${image} >> e2e-conformance.log"])
421}
Ales Komarek6f2bc662017-01-05 11:52:47 +0100422
Sergey Kolekonovba203982016-12-21 18:32:17 +0400423/**
424 * Print Salt state run results in human-friendly form
425 *
426 * @param result Parsed response of Salt API
427 * @param onlyChanges If true (default), print only changed resources
428 * parsing
429 */
430def printSaltStateResult(result, onlyChanges = true) {
431 def out = [:]
432 for (entry in result['return']) {
433 for (node in entry) {
434 out[node.key] = [:]
435 for (resource in node.value) {
436 if (resource instanceof String) {
437 out[node.key] = node.value
438 } else if (resource.value.result.toString().toBoolean() == false || resource.value.changes || onlyChanges == false) {
439 out[node.key][resource.key] = resource.value
440 }
441 }
442 }
443 }
444
445 for (node in out) {
446 if (node.value) {
447 println "Node ${node.key} changes:"
448 print new groovy.json.JsonBuilder(node.value).toPrettyString()
449 } else {
450 println "No changes for node ${node.key}"
451 }
452 }
453}
454
455/**
456 * Print Salt state run results in human-friendly form
457 *
458 * @param result Parsed response of Salt API
459 * @param onlyChanges If true (default), print only changed resources
460 * parsing
461 */
462def printSaltCommandResult(result, onlyChanges = true) {
463 def out = [:]
464 for (entry in result['return']) {
465 for (node in entry) {
466 out[node.key] = [:]
467 for (resource in node.value) {
468 out[node.key] = node.value
469 }
470 }
471 }
472
473 for (node in out) {
474 if (node.value) {
475 println "Node ${node.key} changes:"
476 print new groovy.json.JsonBuilder(node.value).toPrettyString()
477 } else {
478 println "No changes for node ${node.key}"
479 }
480 }
481}