Alexandr Lovtsov | 1a4e142 | 2019-05-15 11:56:29 +0300 | [diff] [blame] | 1 | /** |
| 2 | * Update packages on given server nodes |
| 3 | * |
| 4 | * Expected parameters: |
| 5 | * DRIVE_TRAIN_PARAMS Yaml, DriveTrain releated params: |
| 6 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 7 | * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000] |
| 8 | * IGNORE_CLIENT_VERSION Does not validate that all clients have been updated |
| 9 | * IGNORE_SERVER_VERSION Does not validate that all servers have been updated |
| 10 | * CLUSTER_OP_VERSION GlusterFS cluster.op-verion option to set. Default is to be set to current cluster.max-op-version if available. |
| 11 | */ |
| 12 | |
| 13 | def pEnv = "pepperEnv" |
| 14 | def salt = new com.mirantis.mk.Salt() |
| 15 | def common = new com.mirantis.mk.Common() |
| 16 | def python = new com.mirantis.mk.Python() |
| 17 | |
| 18 | // Convert parameters from yaml to env variables |
| 19 | params = readYaml text: env.DRIVE_TRAIN_PARAMS |
| 20 | for (key in params.keySet()) { |
| 21 | value = params[key] |
| 22 | env.setProperty(key, value) |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * - ensure that cluster.op-version can be updated |
| 27 | * - check that all servers have been updated to version no less then CLUSTER_OP_VERSION or cluster.max-op-version |
| 28 | * - check that all clients have been updated to version no less then CLUSTER_OP_VERSION or cluster.max-op-version |
| 29 | * - set cluster.op-version |
| 30 | */ |
| 31 | |
| 32 | /** |
| 33 | * Convert glusterfs' cluster.op-version to regular version string |
| 34 | * |
| 35 | * @param version string representing cluster.op-version, i.e. 50400 |
| 36 | * @return string version number, i.e. 5.4.0 |
| 37 | */ |
| 38 | def convertVersion(version) { |
| 39 | new_version = version[0] |
| 40 | for (i=1;i<version.length();i++) { |
| 41 | if (i%2 == 0) { |
| 42 | new_version += version[i] |
| 43 | } else if (version[i] == '0') { |
| 44 | new_version += '.' |
| 45 | } else { |
| 46 | new_version += '.' + version[i] |
| 47 | } |
| 48 | } |
| 49 | return new_version |
| 50 | } |
| 51 | |
| 52 | timeout(time: 12, unit: 'HOURS') { |
| 53 | node() { |
| 54 | try { |
| 55 | |
| 56 | stage('Setup virtualenv for Pepper') { |
| 57 | python.setupPepperVirtualenv(pEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 58 | } |
| 59 | stage('Get current cluster.op-version') { |
| 60 | volume = salt.getReturnValues(salt.cmdRun(pEnv, 'I@glusterfs:server:role:primary', "gluster volume list")).split('\n')[0] |
| 61 | currentOpVersion = salt.getReturnValues(salt.cmdRun(pEnv, 'I@glusterfs:server:role:primary', "gluster volume get ${volume} cluster.op-version | grep cluster.op-version | awk '{print \$2}'")).split('\n')[0] |
| 62 | } |
| 63 | if (CLUSTER_OP_VERSION.isEmpty()) { |
| 64 | stage('Get cluster.max-op-version') { |
| 65 | CLUSTER_OP_VERSION = salt.getReturnValues(salt.cmdRun(pEnv, 'I@glusterfs:server:role:primary', "gluster volume get all cluster.max-op-version 2>/dev/null | grep cluster.max-op-version | awk '{print \$2}'")).split('\n')[0] |
| 66 | } |
| 67 | } |
| 68 | if (CLUSTER_OP_VERSION.isEmpty() || CLUSTER_OP_VERSION.length() != 5) { |
| 69 | msg = 'No cluster.op-version specified to set' |
| 70 | common.errorMsg(msg) |
| 71 | currentBuild.result = "FAILURE" |
| 72 | currentBuild.description = msg |
| 73 | } else if (currentOpVersion == CLUSTER_OP_VERSION) { |
| 74 | common.warningMsg("cluster.op-version is already set to ${currentOpVersion}") |
| 75 | } else { |
| 76 | version = convertVersion(CLUSTER_OP_VERSION) |
| 77 | if (!IGNORE_SERVER_VERSION.toBoolean()){ |
| 78 | stage('Check that all servers have been updated') { |
| 79 | salt.commandStatus(pEnv, 'I@glusterfs:server', "dpkg --compare-versions \$(glusterfsd --version | head -n1| awk '{print \$2}') gt ${version} && echo good", 'good', true, true, null, true, 1) |
| 80 | common.successMsg('All servers have been updated to desired version') |
| 81 | } |
| 82 | } else { |
| 83 | common.warningMsg("Check of servers' version has been disabled") |
| 84 | } |
| 85 | if (!IGNORE_CLIENT_VERSION.toBoolean()){ |
| 86 | stage('Check that all clients have been updated') { |
| 87 | salt.commandStatus(pEnv, 'I@glusterfs:client', "dpkg --compare-versions \$(glusterfsd --version | head -n1| awk '{print \$2}') gt ${version} && echo good", 'good', true, true, null, true, 1) |
| 88 | common.successMsg('All clients have been updated to desired version') |
| 89 | } |
| 90 | } else { |
| 91 | common.warningMsg("Check of clients' version has been disabled") |
| 92 | } |
| 93 | stage("Update cluster.op-version") { |
| 94 | salt.cmdRun(pEnv, 'I@glusterfs:server:role:primary', "gluster volume set all cluster.op-version ${CLUSTER_OP_VERSION}") |
| 95 | } |
| 96 | stage("Validate cluster.op-version") { |
| 97 | newOpVersion = salt.getReturnValues(salt.cmdRun(pEnv, 'I@glusterfs:server:role:primary', "gluster volume get ${volume} cluster.op-version | grep cluster.op-version | awk '{print \$2}'")).split('\n')[0] |
| 98 | if (newOpVersion != CLUSTER_OP_VERSION) { |
| 99 | throw new Exception("cluster.op-version was not set to ${CLUSTER_OP_VERSION}") |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } catch (Throwable e) { |
| 104 | // If there was an error or exception thrown, the build failed |
| 105 | currentBuild.result = "FAILURE" |
| 106 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 107 | throw e |
| 108 | } |
| 109 | } |
| 110 | } |