blob: c4db64b5f2cbcc05da29552c3dea9639c2a15d13 [file] [log] [blame]
Jakub Pavlik77fe1542017-06-12 13:02:52 +02001/**
Denis Egorenkoff9325a2019-12-23 18:10:22 +04002 * Deploy OpenStack compute node
Jakub Pavlik77fe1542017-06-12 13:02:52 +02003 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000].
7 * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian].
Denis Egorenko70002bc2019-08-19 19:41:27 +04008 * BATCH_SIZE Use batching for large amount of target nodes
Jakub Pavlik77fe1542017-06-12 13:02:52 +02009 *
10**/
11
12def common = new com.mirantis.mk.Common()
13def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020014def python = new com.mirantis.mk.Python()
Jakub Pavlik77fe1542017-06-12 13:02:52 +020015
chnyda625f4b42017-10-11 14:10:31 +020016def pepperEnv = "pepperEnv"
Jakub Pavlik77fe1542017-06-12 13:02:52 +020017def minions
18def result
19def command
20def commandKwargs
21
Denis Egorenko70002bc2019-08-19 19:41:27 +040022def batch_size = ''
23if (common.validInputParam('BATCH_SIZE')) {
24 batch_size = "${BATCH_SIZE}"
25}
26
Jakub Josefa63f9862018-01-11 17:58:38 +010027timeout(time: 12, unit: 'HOURS') {
28 node() {
29 try {
Jakub Pavlik77fe1542017-06-12 13:02:52 +020030
Jakub Josefa63f9862018-01-11 17:58:38 +010031 stage('Setup virtualenv for Pepper') {
32 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020033 }
34
Jakub Josefa63f9862018-01-11 17:58:38 +010035 stage('List target servers') {
36 minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020037
Jakub Josefa63f9862018-01-11 17:58:38 +010038 if (minions.isEmpty()) {
39 throw new Exception("No minion was targeted")
40 }
41
42 targetLiveAll = minions.join(' or ')
43 common.infoMsg("Found nodes: ${targetLiveAll}")
44 common.infoMsg("Selected nodes: ${targetLiveAll}")
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +030045 }
Jakub Josefa63f9862018-01-11 17:58:38 +010046
Denis Egorenkoff9325a2019-12-23 18:10:22 +040047 stage('Sync modules') {
48 // Sync all of the modules from the salt master.
49 salt.syncAll(pepperEnv, targetLiveAll, batch_size)
50 }
51
Jakub Josefa63f9862018-01-11 17:58:38 +010052 stage("Trusty workaround") {
53 if(salt.getGrain(pepperEnv, minions[0], "oscodename")['return'][0].values()[0]["oscodename"] == "trusty") {
54 common.infoMsg("First node %nodename% has trusty")
55 common.infoMsg("Assuming trusty on all cluster, running extra network states...")
56 common.infoMsg("Network iteration #1. Bonding")
Denis Egorenko70002bc2019-08-19 19:41:27 +040057 salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010058 common.infoMsg("Network iteration #2. Vlan tagging and bridging")
Denis Egorenko70002bc2019-08-19 19:41:27 +040059 salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010060 }
61 }
62
63 stage("Setup repositories") {
Denis Egorenko70002bc2019-08-19 19:41:27 +040064 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010065 }
66
67 stage("Upgrade packages") {
Denis Egorenko70002bc2019-08-19 19:41:27 +040068 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], batch_size, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010069 }
70
71 stage("Setup networking") {
Jakub Josefa63f9862018-01-11 17:58:38 +010072 // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection.
Denis Egorenko70002bc2019-08-19 19:41:27 +040073 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], batch_size, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010074
75 // Restart salt-minion to take effect.
Denis Egorenko70002bc2019-08-19 19:41:27 +040076 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], batch_size, true, 10)
Jakub Josefa63f9862018-01-11 17:58:38 +010077
78 // Configure networking excluding vhost0 interface.
Denis Egorenko70002bc2019-08-19 19:41:27 +040079 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], batch_size, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010080
81 // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network.
Denis Egorenko70002bc2019-08-19 19:41:27 +040082 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], batch_size, false)
83 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], batch_size, false)
Jakub Josefa63f9862018-01-11 17:58:38 +010084
Denis Egorenkoff9325a2019-12-23 18:10:22 +040085 // Restart networking to bring UP all interfaces and restart minion to catch network changes.
86 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["salt-call service.restart networking; salt-call service.restart salt-minion"], batch_size, true, 300)
Jakub Josefa63f9862018-01-11 17:58:38 +010087 }
88
89 stage("Highstate compute") {
90 // Execute highstate without state opencontrail.client.
Pavel Cizinsky1c435302018-07-31 17:16:13 +020091 common.retry(2){
Denis Egorenko70002bc2019-08-19 19:41:27 +040092 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], batch_size, true)
Pavel Cizinsky1c435302018-07-31 17:16:13 +020093 }
Jakub Josefa63f9862018-01-11 17:58:38 +010094
95 // Apply nova state to remove libvirt default bridge virbr0.
Denis Egorenko70002bc2019-08-19 19:41:27 +040096 salt.enforceState(pepperEnv, targetLiveAll, 'nova', true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +010097
98 // Execute highstate.
Denis Egorenko70002bc2019-08-19 19:41:27 +040099 salt.enforceHighstate(pepperEnv, targetLiveAll, true, true, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100100
Jiri Broulik1903cfb2018-02-06 10:07:02 +0100101 // Apply salt and collectd if is present to update information about current network interfaces.
Denis Egorenko70002bc2019-08-19 19:41:27 +0400102 salt.enforceState(pepperEnv, targetLiveAll, 'salt', true, true, batch_size)
Jiri Broulik1903cfb2018-02-06 10:07:02 +0100103 if(!salt.getPillar(pepperEnv, minions[0], "collectd")['return'][0].values()[0].isEmpty()) {
Denis Egorenko70002bc2019-08-19 19:41:27 +0400104 salt.enforceState(pepperEnv, targetLiveAll, 'collectd', true, true, batch_size)
Jiri Broulik1903cfb2018-02-06 10:07:02 +0100105 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100106 }
107
Denis Egorenkod92d6dd2020-01-28 13:58:41 +0400108 // host records and fingerprints for compute nodes are generated dynamically - so apply state after node setup
109 stage('Update Hosts file and fingerprints') {
110 salt.enforceState(pepperEnv, "I@linux:network:host", 'linux.network.host', true, true, batch_size)
111 salt.enforceState(pepperEnv, "I@linux:system", 'openssh', true, true, batch_size)
Denis Egorenkoff9325a2019-12-23 18:10:22 +0400112 }
Sam Stoelinga87d1f1b2018-04-02 14:10:49 -0700113
Denis Egorenkoff9325a2019-12-23 18:10:22 +0400114 // discover added compute hosts
115 stage('Discover compute hosts') {
116 salt.runSaltProcessStep(pepperEnv, 'I@nova:controller:role:primary', 'state.sls_id', ['nova_controller_discover_hosts', 'nova.controller'], batch_size, true)
117 }
118
119 stage("Update/Install monitoring") {
120 def slaServers = 'I@prometheus:server'
121 def slaMinions = salt.getMinions(pepperEnv, slaServers)
122
123 if (slaMinions.isEmpty()) {
124 common.infoMsg('Monitoring is not enabled on environment, skipping...')
125 } else {
126 //Collect Grains
127 salt.enforceState(pepperEnv, targetLiveAll, 'salt.minion.grains', true, true, batch_size)
128 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_modules', [], batch_size)
129 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'mine.update', [], batch_size)
130 sleep(5)
131
132 salt.enforceState(pepperEnv, targetLiveAll, 'prometheus', true, true, batch_size)
133 salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus', true, true, batch_size)
134 }
135 }
Michal Kobusd8874842018-03-13 12:42:07 +0100136
Jakub Josefa63f9862018-01-11 17:58:38 +0100137 } catch (Throwable e) {
138 // If there was an error or exception thrown, the build failed
139 currentBuild.result = "FAILURE"
140 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
141 throw e
Dmitry Stremkouski067d25e2017-09-22 15:00:38 +0300142 }
Jakub Pavlik77fe1542017-06-12 13:02:52 +0200143 }
144}