Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Update packages on given nodes |
| 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]. |
| 8 | * |
| 9 | **/ |
| 10 | |
| 11 | def common = new com.mirantis.mk.Common() |
| 12 | def salt = new com.mirantis.mk.Salt() |
| 13 | |
| 14 | def saltMaster |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 15 | def minions |
| 16 | def result |
| 17 | def command |
| 18 | def commandKwargs |
| 19 | |
| 20 | |
| 21 | node() { |
| 22 | try { |
| 23 | |
| 24 | stage('Connect to Salt master') { |
| 25 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 26 | } |
| 27 | |
| 28 | stage('List target servers') { |
Tomáš Kukrál | c86c8b4 | 2017-07-13 10:26:51 +0200 | [diff] [blame] | 29 | minions = salt.getMinions(saltMaster, TARGET_SERVERS) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 30 | |
| 31 | if (minions.isEmpty()) { |
| 32 | throw new Exception("No minion was targeted") |
| 33 | } |
| 34 | |
| 35 | targetLiveAll = minions.join(' or ') |
| 36 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 37 | common.infoMsg("Selected nodes: ${targetLiveAll}") |
| 38 | } |
| 39 | |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 40 | stage("Setup repositories") { |
| 41 | salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo', true) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Alexander Noskov | 227ea93 | 2017-07-13 17:17:15 +0400 | [diff] [blame] | 44 | stage("Upgrade packages") { |
| 45 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'pkg.upgrade', [], null, true) |
| 46 | } |
| 47 | |
| 48 | stage("Setup networking") { |
| 49 | // Sync all of the modules from the salt master. |
| 50 | salt.syncAll(saltMaster, targetLiveAll) |
| 51 | |
| 52 | // Apply state 'salt' to install python-psutil for network configuration without restarting salt-minion to avoid losing connection. |
| 53 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['salt', 'exclude=[{\'id\': \'salt_minion_service\'}, {\'id\': \'salt_minion_service_restart\'}, {\'id\': \'salt_minion_sync_all\'}]'], null, true) |
| 54 | |
| 55 | // Restart salt-minion to take effect. |
| 56 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['salt-minion'], null, true, 10) |
| 57 | |
| 58 | // Configure networking excluding vhost0 interface. |
| 59 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.apply', ['linux.network', 'exclude=[{\'id\': \'linux_interface_vhost0\'}]'], null, true) |
| 60 | |
| 61 | // Kill unnecessary processes ifup/ifdown which is stuck from previous state linux.network. |
| 62 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifup'], null, false) |
| 63 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'ps.pkill', ['ifdown'], null, false) |
| 64 | |
| 65 | // Restart networking to bring UP all interfaces. |
| 66 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['networking'], null, true, 300) |
| 67 | } |
| 68 | |
| 69 | stage("Highstate compute") { |
| 70 | // Execute highstate without state opencontrail.client. |
| 71 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'state.highstate', ['exclude=opencontrail.client'], null, true) |
| 72 | |
| 73 | // Apply nova state to remove libvirt default bridge virbr0. |
| 74 | salt.enforceState(saltMaster, targetLiveAll, 'nova', true) |
| 75 | |
| 76 | // Execute highstate. |
| 77 | salt.enforceHighstate(saltMaster, targetLiveAll, true) |
| 78 | |
| 79 | // Restart supervisor-vrouter. |
| 80 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'service.restart', ['supervisor-vrouter'], null, true, 300) |
| 81 | |
| 82 | // Apply salt,collectd to update information about current network interfaces. |
| 83 | salt.enforceState(saltMaster, targetLiveAll, 'salt,collectd', true) |
Jakub Pavlik | 77fe154 | 2017-06-12 13:02:52 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | } catch (Throwable e) { |
| 87 | // If there was an error or exception thrown, the build failed |
| 88 | currentBuild.result = "FAILURE" |
| 89 | throw e |
| 90 | } |
| 91 | } |