Jiri Broulik | dc87d72 | 2017-11-03 15:43:22 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Upgrade Ceph mon/mgr/osd/rgw/client |
| 4 | * |
| 5 | * Requred parameters: |
| 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 8 | * |
| 9 | * ADMIN_HOST Host (minion id) with admin keyring and /etc/crushmap file present |
| 10 | * CLUSTER_FLAGS Comma separated list of tags to apply to cluster |
| 11 | * WAIT_FOR_HEALTHY Wait for cluster rebalance before stoping daemons |
| 12 | * ORIGIN_RELEASE Ceph release version before upgrade |
| 13 | * TARGET_RELEASE Ceph release version after upgrade |
| 14 | * STAGE_UPGRADE_MON Set to True if Ceph mon nodes upgrade is desired |
| 15 | * STAGE_UPGRADE_MGR Set to True if Ceph mgr nodes upgrade or new deploy is desired |
| 16 | * STAGE_UPGRADE_OSD Set to True if Ceph osd nodes upgrade is desired |
| 17 | * STAGE_UPGRADE_RGW Set to True if Ceph rgw nodes upgrade is desired |
| 18 | * STAGE_UPGRADE_CLIENT Set to True if Ceph client nodes upgrade is desired (includes for example ctl/cmp nodes) |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | common = new com.mirantis.mk.Common() |
| 23 | salt = new com.mirantis.mk.Salt() |
| 24 | def python = new com.mirantis.mk.Python() |
| 25 | |
| 26 | def pepperEnv = "pepperEnv" |
| 27 | def flags = CLUSTER_FLAGS.tokenize(',') |
| 28 | |
| 29 | def runCephCommand(master, target, cmd) { |
| 30 | return salt.cmdRun(master, target, cmd) |
| 31 | } |
| 32 | |
| 33 | def upgrade(master, target) { |
| 34 | |
| 35 | stage("Change ${target} repos") { |
| 36 | salt.runSaltProcessStep(master, "I@ceph:${target}", 'saltutil.refresh_pillar', [], null, true, 5) |
| 37 | salt.enforceState(master, "I@ceph:${target}", 'linux.system.repo', true) |
| 38 | } |
| 39 | |
| 40 | if (target == 'mgr') { |
| 41 | stage('Run ceph mgr state') { |
| 42 | salt.enforceState(master, "I@ceph:mgr", "ceph.mgr", true) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if (target == 'common') { |
| 47 | stage('Upgrade ceph-common pkgs') { |
| 48 | runCephCommand(master, "I@ceph:${target}", "apt install ceph-${target} -y ") |
| 49 | } |
| 50 | } else if (target == 'radosgw') { |
| 51 | stage('Upgrade radosgw pkgs') { |
| 52 | runCephCommand(master, "I@ceph:${target}", "apt install ${target} -y ") |
| 53 | } |
| 54 | // restart services |
| 55 | stage("Restart ${target} services") { |
| 56 | runCephCommand(master, "I@ceph:${target}", "systemctl restart ceph-${target}.target") |
| 57 | } |
| 58 | } else { |
| 59 | |
| 60 | // upgrade pkgs |
| 61 | stage("Upgrade ${target} pkgs") { |
| 62 | runCephCommand(master, "I@ceph:${target}", "apt install ceph-${target} -y ") |
| 63 | } |
| 64 | // restart services |
| 65 | stage("Restart ${target} services") { |
| 66 | runCephCommand(master, "I@ceph:${target}", "systemctl restart ceph-${target}.target") |
| 67 | } |
| 68 | } |
| 69 | runCephCommand(master, ADMIN_HOST, "ceph versions") |
| 70 | sleep(5) |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | node("python") { |
| 75 | |
| 76 | // create connection to salt master |
| 77 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 78 | |
| 79 | if (flags.size() > 0) { |
| 80 | stage('Set cluster flags') { |
| 81 | for (flag in flags) { |
| 82 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd set ' + flag) |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (STAGE_UPGRADE_MON.toBoolean() == true) { |
| 88 | upgrade(pepperEnv, 'mon') |
| 89 | stage("Verify mon services") { |
| 90 | runCephCommand(pepperEnv, ADMIN_HOST, "ceph mon stat") |
| 91 | } |
| 92 | stage('Ask for manual confirmation') { |
| 93 | input message: "From the verification command above, please check Ceph mons joined the cluster. If so, Do you want to continue?" |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if (STAGE_UPGRADE_MGR.toBoolean() == true) { |
| 98 | upgrade(pepperEnv, 'mgr') |
| 99 | stage("Verify mgr services") { |
| 100 | runCephCommand(pepperEnv, ADMIN_HOST, "ceph -s") |
| 101 | } |
| 102 | stage('Ask for manual confirmation') { |
| 103 | input message: "From the verification command above, please check Ceph mgr joined the cluster. If so, Do you want to continue?" |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (STAGE_UPGRADE_OSD.toBoolean() == true) { |
| 108 | upgrade(pepperEnv, 'osd') |
| 109 | stage("Verify osd services") { |
| 110 | runCephCommand(pepperEnv, ADMIN_HOST, "ceph osd stat") |
| 111 | } |
| 112 | stage('Ask for manual confirmation') { |
| 113 | input message: "From the verification command above, please check Ceph osds joined the cluster. If so, Do you want to continue?" |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if (STAGE_UPGRADE_RGW.toBoolean() == true) { |
| 118 | upgrade(pepperEnv, 'radosgw') |
| 119 | stage("Verify rgw services") { |
| 120 | runCephCommand(pepperEnv, ADMIN_HOST, "ceph -s") |
| 121 | } |
| 122 | stage('Ask for manual confirmation') { |
| 123 | input message: "From the verification command above, please check Ceph rgw joined the cluster. If so, Do you want to continue?" |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if (STAGE_UPGRADE_CLIENT.toBoolean() == true) { |
| 128 | upgrade(pepperEnv, 'common') |
| 129 | } |
| 130 | |
| 131 | // remove cluster flags |
| 132 | if (flags.size() > 0) { |
| 133 | stage('Unset cluster flags') { |
| 134 | for (flag in flags) { |
| 135 | if (!flag.contains('sortbitwise')) { |
| 136 | common.infoMsg('Removing flag ' + flag) |
| 137 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag) |
| 138 | } |
| 139 | |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | stage("Finalize ceph version upgrade") { |
| 145 | runCephCommand(pepperEnv, ADMIN_HOST, "ceph osd require-osd-release ${TARGET_RELEASE}") |
| 146 | try { |
| 147 | runCephCommand(pepperEnv, ADMIN_HOST, "ceph osd set-require-min-compat-client ${ORIGIN_RELEASE}") |
| 148 | } catch (Exception e) { |
| 149 | common.warningMsg(e) |
| 150 | } |
| 151 | runCephCommand(pepperEnv, ADMIN_HOST, "ceph osd crush tunables optimal") |
| 152 | } |
| 153 | |
| 154 | // wait for healthy cluster |
| 155 | if (WAIT_FOR_HEALTHY.toBoolean() == true) { |
| 156 | stage('Waiting for healthy cluster') { |
| 157 | while (true) { |
| 158 | def health = runCephCommand(pepperEnv, ADMIN_HOST, 'ceph -s')['return'][0].values()[0] |
| 159 | if (health.contains('HEALTH_OK')) { |
| 160 | common.infoMsg('Cluster is healthy') |
| 161 | break; |
| 162 | } |
| 163 | sleep(10) |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |