Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 1 | /** |
Denis Egorenko | ff9325a | 2019-12-23 18:10:22 +0400 | [diff] [blame] | 2 | * Deploy OpenStack compute node |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 3 | * |
| 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 Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 8 | * BATCH_SIZE Use batching for large amount of target nodes |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 9 | * |
| 10 | **/ |
| 11 | |
| 12 | def common = new com.mirantis.mk.Common() |
| 13 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 14 | def python = new com.mirantis.mk.Python() |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 15 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 16 | def pepperEnv = "pepperEnv" |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 17 | def minions |
| 18 | def result |
| 19 | def command |
| 20 | def commandKwargs |
| 21 | |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 22 | def batch_size = '' |
| 23 | if (common.validInputParam('BATCH_SIZE')) { |
| 24 | batch_size = "${BATCH_SIZE}" |
| 25 | } |
| 26 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 27 | timeout(time: 12, unit: 'HOURS') { |
| 28 | node() { |
| 29 | try { |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 30 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 31 | stage('Setup virtualenv for Pepper') { |
| 32 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 35 | stage('List target servers') { |
| 36 | minions = salt.getMinions(pepperEnv, TARGET_SERVERS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 37 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 38 | 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 Stremkouski | 067d25e | 2017-09-22 15:00:38 +0300 | [diff] [blame] | 45 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 46 | |
Denis Egorenko | ff9325a | 2019-12-23 18:10:22 +0400 | [diff] [blame] | 47 | stage('Sync modules') { |
| 48 | // Sync all of the modules from the salt master. |
| 49 | salt.syncAll(pepperEnv, targetLiveAll, batch_size) |
| 50 | } |
| 51 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 52 | 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 Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 57 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 58 | common.infoMsg("Network iteration #2. Vlan tagging and bridging") |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 59 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.network', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | stage("Setup repositories") { |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 64 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | stage("Upgrade packages") { |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 68 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.upgrade', [], batch_size, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | stage("Setup networking") { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 72 | // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 73 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 74 | |
| 75 | // Restart salt-minion to take effect. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 76 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'service.restart', ['salt-minion'], batch_size, true, 10) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 77 | |
| 78 | // Configure networking excluding vhost0 interface. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 79 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], batch_size, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 80 | |
| 81 | // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 82 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifup'], batch_size, false) |
| 83 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'ps.pkill', ['ifdown'], batch_size, false) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 84 | |
Denis Egorenko | ff9325a | 2019-12-23 18:10:22 +0400 | [diff] [blame] | 85 | // 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | stage("Highstate compute") { |
| 90 | // Execute highstate without state opencontrail.client. |
Pavel Cizinsky | 1c43530 | 2018-07-31 17:16:13 +0200 | [diff] [blame] | 91 | common.retry(2){ |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 92 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], batch_size, true) |
Pavel Cizinsky | 1c43530 | 2018-07-31 17:16:13 +0200 | [diff] [blame] | 93 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 94 | |
| 95 | // Apply nova state to remove libvirt default bridge virbr0. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 96 | salt.enforceState(pepperEnv, targetLiveAll, 'nova', true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 97 | |
| 98 | // Execute highstate. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 99 | salt.enforceHighstate(pepperEnv, targetLiveAll, true, true, batch_size) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 100 | |
Jiri Broulik | 1903cfb | 2018-02-06 10:07:02 +0100 | [diff] [blame] | 101 | // Apply salt and collectd if is present to update information about current network interfaces. |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 102 | salt.enforceState(pepperEnv, targetLiveAll, 'salt', true, true, batch_size) |
Jiri Broulik | 1903cfb | 2018-02-06 10:07:02 +0100 | [diff] [blame] | 103 | if(!salt.getPillar(pepperEnv, minions[0], "collectd")['return'][0].values()[0].isEmpty()) { |
Denis Egorenko | 70002bc | 2019-08-19 19:41:27 +0400 | [diff] [blame] | 104 | salt.enforceState(pepperEnv, targetLiveAll, 'collectd', true, true, batch_size) |
Jiri Broulik | 1903cfb | 2018-02-06 10:07:02 +0100 | [diff] [blame] | 105 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Denis Egorenko | d92d6dd | 2020-01-28 13:58:41 +0400 | [diff] [blame] | 108 | // 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 Egorenko | ff9325a | 2019-12-23 18:10:22 +0400 | [diff] [blame] | 112 | } |
Sam Stoelinga | 87d1f1b | 2018-04-02 14:10:49 -0700 | [diff] [blame] | 113 | |
Denis Egorenko | ff9325a | 2019-12-23 18:10:22 +0400 | [diff] [blame] | 114 | // 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 Kobus | d887484 | 2018-03-13 12:42:07 +0100 | [diff] [blame] | 136 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 137 | } 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 Stremkouski | 067d25e | 2017-09-22 15:00:38 +0300 | [diff] [blame] | 142 | } |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 143 | } |
| 144 | } |