Oleksandr Bryndzii | 30397e9 | 2019-05-06 15:59:30 +0300 | [diff] [blame^] | 1 | /** |
| 2 | * Upgrade RabbitMQ packages on msg nodes. |
| 3 | * Update packages on given nodes |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 7 | * SALT_MASTER_URL Full Salt API address [http://10.10.10.15:6969]. |
| 8 | * OS_DIST_UPGRADE Upgrade system packages including kernel (apt-get dist-upgrade) |
| 9 | * OS_UPGRADE Upgrade all installed applications (apt-get upgrade) |
| 10 | * TARGET_SERVERS Comma separated list of salt compound definitions to upgrade. |
| 11 | * INTERACTIVE Ask interactive questions during pipeline run (bool). |
| 12 | * |
| 13 | **/ |
| 14 | |
| 15 | def common = new com.mirantis.mk.Common() |
| 16 | def salt = new com.mirantis.mk.Salt() |
| 17 | def python = new com.mirantis.mk.Python() |
| 18 | def debian = new com.mirantis.mk.Debian() |
| 19 | def openstack = new com.mirantis.mk.Openstack() |
| 20 | |
| 21 | def interactive = INTERACTIVE.toBoolean() |
| 22 | def LinkedHashMap upgradeStageMap = [:] |
| 23 | |
| 24 | upgradeStageMap.put('Pre upgrade', |
| 25 | [ |
| 26 | 'Description': 'Only non destructive actions will be applied during this phase. Basic service verification will be performed.', |
| 27 | 'Status': 'NOT_LAUNCHED', |
| 28 | 'Expected behaviors': ''' |
| 29 | * No service downtime |
| 30 | * No workload downtime''', |
| 31 | 'Launched actions': ''' |
| 32 | * Verify API, perform basic CRUD operations for services. |
| 33 | * Verify rabbitmq is running and operational.''', |
| 34 | 'State result': 'Basic checks around services API are passed.' |
| 35 | ]) |
| 36 | |
| 37 | upgradeStageMap.put('Stop RabbitMQ service', |
| 38 | [ |
| 39 | 'Description': 'All rabbitmq services will be stopped on All TARGET_SERVERS nodes.', |
| 40 | 'Status': 'NOT_LAUNCHED', |
| 41 | 'Expected behaviors': ''' |
| 42 | * RabbitMQ services are stopped. |
| 43 | * OpenStack APIs are not accessible from this point. |
| 44 | * No workload downtime''', |
| 45 | 'Launched actions': ''' |
| 46 | * Stop RabbitMQ services''', |
| 47 | 'State result': 'RabbitMQ service is stopped', |
| 48 | ]) |
| 49 | |
| 50 | upgradeStageMap.put('Upgrade OS', |
| 51 | [ |
| 52 | 'Description': 'Optional step. OS packages will be upgraded during this phase, depending on the job parameters dist-upgrade might be called. And reboot of node executed.', |
| 53 | 'Status': 'NOT_LAUNCHED', |
| 54 | 'Expected behaviors': ''' |
| 55 | * No workload downtime |
| 56 | * The nodes might be rebooted''', |
| 57 | 'Launched actions': ''' |
| 58 | * Install new version of system packages |
| 59 | * If doing dist-upgrade new kernel might be installed and node rebooted |
| 60 | * System packages are updated |
| 61 | * Node might be rebooted |
| 62 | ''' |
| 63 | ]) |
| 64 | |
| 65 | upgradeStageMap.put('Upgrade RabbitMQ server', |
| 66 | [ |
| 67 | 'Description': 'RabbitMQ and Erlang code will be upgraded during this stage. No workload downtime is expected.', |
| 68 | 'Status': 'NOT_LAUNCHED', |
| 69 | 'Expected behaviors': ''' |
| 70 | * OpenStack services loose connection to rabbitmq-server |
| 71 | * No workload downtime''', |
| 72 | 'Launched actions': ''' |
| 73 | * Install new version of RabbitMQ and Erlang packages |
| 74 | * Render version of configs''', |
| 75 | 'State result': ''' |
| 76 | * RabbitMQ packages are upgraded''', |
| 77 | ]) |
| 78 | |
| 79 | upgradeStageMap.put('Start RabbitMQ service', |
| 80 | [ |
| 81 | 'Description': 'All rabbitmq services will be running on All TARGET_SERVERS nodes.', |
| 82 | 'Status': 'NOT_LAUNCHED', |
| 83 | 'Expected behaviors': ''' |
| 84 | * RabbitMQ service is running. |
| 85 | * OpenStack API are accessible from this point. |
| 86 | * No workload downtime''', |
| 87 | 'Launched actions': ''' |
| 88 | * Start RabbitMQ service''', |
| 89 | 'State result': 'RabbitMQ service is running', |
| 90 | ]) |
| 91 | |
| 92 | def env = "env" |
| 93 | timeout(time: 12, unit: 'HOURS') { |
| 94 | node() { |
| 95 | |
| 96 | stage('Setup virtualenv for Pepper') { |
| 97 | python.setupPepperVirtualenv(env, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 98 | } |
| 99 | |
| 100 | def upgradeTargets = salt.getMinionsSorted(env, TARGET_SERVERS) |
| 101 | |
| 102 | if (upgradeTargets.isEmpty()) { |
| 103 | error("No servers for upgrade matched by ${TARGET_SERVERS}") |
| 104 | } |
| 105 | |
| 106 | def stopTargets = upgradeTargets.reverse() |
| 107 | |
| 108 | common.printStageMap(upgradeStageMap) |
| 109 | if (interactive){ |
| 110 | input message: common.getColorizedString( |
| 111 | "Above you can find detailed info this pipeline will execute.\nThe info provides brief description of each stage, actions that will be performed and service/workload impact during each stage.\nPlease read it carefully.", "yellow") |
| 112 | } |
| 113 | |
| 114 | for (target in upgradeTargets){ |
| 115 | common.stageWrapper(upgradeStageMap, "Pre upgrade", target, interactive) { |
| 116 | openstack.runOpenStackUpgradePhase(env, target, 'pre') |
| 117 | openstack.runOpenStackUpgradePhase(env, target, 'verify') |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | for (target in stopTargets) { |
| 122 | common.stageWrapper(upgradeStageMap, "Stop RabbitMQ service", target, interactive) { |
| 123 | openstack.runOpenStackUpgradePhase(env, target, 'service_stopped') |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | for (target in upgradeTargets) { |
| 128 | common.stageWrapper(upgradeStageMap, "Upgrade OS", target, interactive) { |
| 129 | if (OS_DIST_UPGRADE.toBoolean() == true){ |
| 130 | upgrade_mode = 'dist-upgrade' |
| 131 | } else if (OS_UPGRADE.toBoolean() == true){ |
| 132 | upgrade_mode = 'upgrade' |
| 133 | } |
| 134 | if (OS_DIST_UPGRADE.toBoolean() == true || OS_UPGRADE.toBoolean() == true) { |
| 135 | debian.osUpgradeNode(env, target, upgrade_mode, false) |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | for (target in upgradeTargets) { |
| 141 | common.stageWrapper(upgradeStageMap, "Upgrade RabbitMQ server", target, interactive) { |
| 142 | openstack.runOpenStackUpgradePhase(env, target, 'pkgs_latest') |
| 143 | openstack.runOpenStackUpgradePhase(env, target, 'render_config') |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | for (target in upgradeTargets) { |
| 148 | common.stageWrapper(upgradeStageMap, "Start RabbitMQ service", target, interactive) { |
| 149 | openstack.runOpenStackUpgradePhase(env, target, 'service_running') |
| 150 | openstack.applyOpenstackAppsStates(env, target) |
| 151 | openstack.runOpenStackUpgradePhase(env, target, 'verify') |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |