Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 1 | package 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 | */ |
| 15 | def 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 | */ |
| 32 | def 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 Komarek | eeed865 | 2017-01-03 15:20:21 +0100 | [diff] [blame] | 56 | @NonCPS |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 57 | def runSaltCommand(master, client, target, function, batch = null, args = null, kwargs = null) { |
Ales Komarek | bfd10f4 | 2017-01-03 13:40:12 +0100 | [diff] [blame] | 58 | def http = new com.mirantis.mk.http() |
| 59 | |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 60 | data = [ |
| 61 | 'tgt': target.expression, |
| 62 | 'fun': function, |
| 63 | 'client': client, |
| 64 | 'expr_form': target.type, |
| 65 | ] |
| 66 | |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 67 | if (batch) { |
| 68 | data['batch'] = batch |
| 69 | } |
| 70 | |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 71 | if (args) { |
| 72 | data['arg'] = args |
| 73 | } |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 74 | |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 75 | 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 | |
| 86 | def getSaltPillar(master, target, pillar) { |
| 87 | def out = runSaltCommand(master, 'local', target, 'pillar.get', [pillar.replace('.', ':')]) |
| 88 | return out |
| 89 | } |
| 90 | |
| 91 | def 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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 99 | def out = runSaltCommand(master, 'local', target, 'state.sls', null, [run_states]) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 100 | try { |
| 101 | checkSaltResult(out) |
| 102 | } finally { |
| 103 | if (output == true) { |
| 104 | printSaltResult(out) |
| 105 | } |
| 106 | } |
| 107 | return out |
| 108 | } |
| 109 | |
| 110 | def runSaltCmd(master, target, cmd) { |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 111 | return runSaltCommand(master, 'local', target, 'cmd.run', null, [cmd]) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | def syncSaltAll(master, target) { |
| 115 | return runSaltCommand(master, 'local', target, 'saltutil.sync_all') |
| 116 | } |
| 117 | |
| 118 | def 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 | |
| 130 | def generateSaltNodeKey(master, target, host, keysize = 4096) { |
| 131 | args = [host] |
| 132 | kwargs = ['keysize': keysize] |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 133 | return runSaltCommand(master, 'wheel', target, 'key.gen_accept', null, args, kwargs) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | def generateSaltNodeMetadata(master, target, host, classes, parameters) { |
| 137 | args = [host, '_generated'] |
| 138 | kwargs = ['classes': classes, 'parameters': parameters] |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 139 | return runSaltCommand(master, 'local', target, 'reclass.node_create', null, args, kwargs) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | def orchestrateSaltSystem(master, target, orchestrate) { |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 143 | return runSaltCommand(master, 'runner', target, 'state.orchestrate', null, [orchestrate]) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Check result for errors and throw exception if any found |
| 148 | * |
| 149 | * @param result Parsed response of Salt API |
| 150 | */ |
| 151 | def 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 | */ |
| 174 | def 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 Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 203 | |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 204 | def 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 Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 212 | } |
| 213 | |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 214 | |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 215 | def 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 Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 222 | |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 223 | |
| 224 | def 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 Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 231 | |
| 232 | def installOpenstackMkInfra(master) { |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 233 | // Install keepaliveds |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 234 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 237 | // 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 Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 241 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 245 | 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 | |
| 266 | def installOpenstackMkControl(master) { |
| 267 | // setup keystone service |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 268 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 271 | // 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 Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 275 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 278 | 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 Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 284 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 287 | runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list']) |
| 288 | // Install and check cinder service |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 289 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 292 | runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list']) |
| 293 | // Install neutron service |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 294 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 297 | runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list']) |
| 298 | // Install heat service |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 299 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 302 | 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 | |
| 309 | def installOpenstackMkNetwork(master) { |
| 310 | // Install opencontrail database services |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 311 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 314 | // Install opencontrail control services |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 315 | //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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 318 | // 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 | |
| 329 | def 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 | |
| 339 | def 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 Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 345 | runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keepalived']) |
| 346 | runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived']) |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 347 | // Check the keepalived VIPs |
| 348 | runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2']) |
| 349 | // Setup glusterfs |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 350 | 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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 353 | 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 | |
| 369 | def installOpenstackMcpControl(master) { |
Tomáš Kukrál | e65f7b0 | 2017-01-19 13:16:43 +0100 | [diff] [blame] | 370 | |
| 371 | // Install Kubernetes pool and Calico |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 372 | runSaltProcessStep(master, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool']) |
Tomáš Kukrál | e65f7b0 | 2017-01-19 13:16:43 +0100 | [diff] [blame] | 373 | runSaltProcessStep(master, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status']) |
| 374 | |
| 375 | // Setup etcd server |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 376 | runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup']) |
Tomáš Kukrál | e65f7b0 | 2017-01-19 13:16:43 +0100 | [diff] [blame] | 377 | |
| 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ál | 9a58e14 | 2017-02-02 16:09:33 +0100 | [diff] [blame] | 382 | runSaltProcessStep(master, 'ctl01*', 'state.sls', ['kubernetes.master.setup']) |
Tomáš Kukrál | e65f7b0 | 2017-01-19 13:16:43 +0100 | [diff] [blame] | 383 | |
Ales Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 384 | // 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ál | e65f7b0 | 2017-01-19 13:16:43 +0100 | [diff] [blame] | 386 | |
| 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 Komarek | ddb44d0 | 2017-01-04 13:17:04 +0100 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
| 395 | def 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 | |
| 403 | def installStacklightControl(master) { |
Ales Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 404 | 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 Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 411 | } |
| 412 | |
Tatyana Leontovich | e9e6faa | 2017-01-20 18:50:36 +0200 | [diff] [blame] | 413 | /** |
| 414 | * Run e2e conformance tests |
| 415 | * |
| 416 | * @param k8s_api Kubernetes api address |
| 417 | * @param image Docker image with tests |
| 418 | */ |
| 419 | def 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 Komarek | 6f2bc66 | 2017-01-05 11:52:47 +0100 | [diff] [blame] | 422 | |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 423 | /** |
| 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 | */ |
| 430 | def 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 | */ |
| 462 | def 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 | } |