Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 1 | import pytest |
| 2 | |
| 3 | from tcp_tests import logger |
| 4 | from tcp_tests import settings |
| 5 | from tcp_tests.utils import run_jenkins_job |
| 6 | from tcp_tests.utils import get_jenkins_job_stages |
| 7 | |
| 8 | LOG = logger.logger |
| 9 | |
| 10 | |
| 11 | class TestUpdateMcpCluster(object): |
| 12 | """ |
| 13 | Following the steps in |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 14 | https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update.html#minor-update |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 15 | """ |
| 16 | |
| 17 | @pytest.mark.grab_versions |
| 18 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 19 | @pytest.mark.run_mcp_update |
| 20 | def test_update_drivetrain(self, salt_actions, show_step, _): |
| 21 | """Updating DriveTrain component to release/proposed/2019.2.0 version |
| 22 | |
| 23 | Scenario: |
| 24 | 1. Get CICD Jenkins access credentials from salt |
| 25 | 2. Run job git-mirror-downstream-mk-pipelines |
| 26 | 3. Run job git-mirror-downstream-pipeline-library |
| 27 | 4. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain' |
| 28 | |
| 29 | Duration: ~35 min |
| 30 | """ |
| 31 | salt = salt_actions |
| 32 | jenkins_creds = salt.get_cluster_jenkins_creds() |
| 33 | |
| 34 | # #################### Login Jenkins on cid01 node ################### |
| 35 | show_step(1) |
| 36 | |
| 37 | jenkins_url = jenkins_creds.get('url') |
| 38 | jenkins_user = jenkins_creds.get('user') |
| 39 | jenkins_pass = jenkins_creds.get('pass') |
| 40 | jenkins_start_timeout = 60 |
| 41 | jenkins_build_timeout = 1800 |
| 42 | |
| 43 | # FIXME: workaround for PROD-32751 |
| 44 | salt.cmd_run("cfg01*", "cd /srv/salt/reclass; git add -u && \ |
| 45 | git commit --allow-empty -m 'Cluster model update'") |
| 46 | |
| 47 | # ################### Downstream mk-pipelines ######################### |
| 48 | show_step(2) |
| 49 | job_name = 'git-mirror-downstream-mk-pipelines' |
| 50 | job_parameters = { |
| 51 | 'BRANCHES': 'release/proposed/2019.2.0' |
| 52 | } |
| 53 | update_pipelines = run_jenkins_job.run_job( |
| 54 | host=jenkins_url, |
| 55 | username=jenkins_user, |
| 56 | password=jenkins_pass, |
| 57 | start_timeout=jenkins_start_timeout, |
| 58 | build_timeout=jenkins_build_timeout, |
| 59 | verbose=False, |
| 60 | job_name=job_name, |
| 61 | job_parameters=job_parameters) |
| 62 | |
| 63 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 64 | host=jenkins_url, |
| 65 | username=jenkins_user, |
| 66 | password=jenkins_pass, |
| 67 | job_name=job_name, |
| 68 | build_number='lastBuild') |
| 69 | |
| 70 | LOG.info(description) |
| 71 | LOG.info('\n'.join(stages)) |
| 72 | |
| 73 | assert update_pipelines == 'SUCCESS', "{0}\n{1}".format( |
| 74 | description, '\n'.join(stages)) |
| 75 | |
| 76 | # ################### Downstream pipeline-library #################### |
| 77 | show_step(3) |
| 78 | job_name = 'git-mirror-downstream-pipeline-library' |
| 79 | job_parameters = { |
| 80 | 'BRANCHES': 'release/proposed/2019.2.0' |
| 81 | } |
| 82 | update_pipeline_library = run_jenkins_job.run_job( |
| 83 | host=jenkins_url, |
| 84 | username=jenkins_user, |
| 85 | password=jenkins_pass, |
| 86 | start_timeout=jenkins_start_timeout, |
| 87 | build_timeout=jenkins_build_timeout, |
| 88 | verbose=False, |
| 89 | job_name=job_name, |
| 90 | job_parameters=job_parameters) |
| 91 | |
| 92 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 93 | host=jenkins_url, |
| 94 | username=jenkins_user, |
| 95 | password=jenkins_pass, |
| 96 | job_name=job_name, |
| 97 | build_number='lastBuild') |
| 98 | |
| 99 | LOG.info(description) |
| 100 | LOG.info('\n'.join(stages)) |
| 101 | |
| 102 | assert update_pipeline_library == 'SUCCESS', "{0}\n{1}".format( |
| 103 | description, '\n'.join(stages)) |
| 104 | |
| 105 | # ################### Start 'Deploy - upgrade MCP Drivetrain' job ##### |
| 106 | show_step(4) |
| 107 | |
| 108 | jenkins_build_timeout = 3600 |
| 109 | job_name = 'upgrade-mcp-release' |
| 110 | job_parameters = { |
| 111 | 'MK_PIPELINES_REFSPEC': 'release/proposed/2019.2.0', |
| 112 | 'TARGET_MCP_VERSION': '2019.2.0' |
| 113 | } |
| 114 | update_drivetrain = run_jenkins_job.run_job( |
| 115 | host=jenkins_url, |
| 116 | username=jenkins_user, |
| 117 | password=jenkins_pass, |
| 118 | start_timeout=jenkins_start_timeout, |
| 119 | build_timeout=jenkins_build_timeout, |
| 120 | verbose=False, |
| 121 | job_name=job_name, |
| 122 | job_parameters=job_parameters) |
| 123 | |
| 124 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 125 | host=jenkins_url, |
| 126 | username=jenkins_user, |
| 127 | password=jenkins_pass, |
| 128 | job_name=job_name, |
| 129 | build_number='lastBuild') |
| 130 | |
| 131 | LOG.info(description) |
| 132 | LOG.info('\n'.join(stages)) |
| 133 | |
| 134 | assert update_drivetrain == 'SUCCESS', "{0}\n{1}".format( |
| 135 | description, '\n'.join(stages)) |
| 136 | |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 137 | @pytest.mark.grab_versions |
| 138 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 139 | @pytest.mark.run_mcp_update |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame^] | 140 | def test_update_glusterfs(self, salt_actions, reclass_actions, |
| 141 | show_step, _): |
| 142 | """ Upgrade GlusterFS |
| 143 | Scenario: |
| 144 | 1. In infra/init.yml in Reclass, add the glusterfs_version parameter |
| 145 | 2. Start linux.system.repo state |
| 146 | 3. Start "update-glusterfs" job |
| 147 | 4. Check version for GlusterFS servers |
| 148 | 5. Check version for GlusterFS clients |
| 149 | |
| 150 | """ |
| 151 | salt = salt_actions |
| 152 | reclass = reclass_actions |
| 153 | jenkins_creds = salt.get_cluster_jenkins_creds() |
| 154 | jenkins_url = jenkins_creds.get('url') |
| 155 | jenkins_user = jenkins_creds.get('user') |
| 156 | jenkins_pass = jenkins_creds.get('pass') |
| 157 | |
| 158 | def has_only_similar(param_by_nodes): |
| 159 | """ |
| 160 | :param param_by_nodes: dict |
| 161 | :return: bool, True if all items in the dict have similar keys |
| 162 | """ |
| 163 | params = list(param_by_nodes.values()) |
| 164 | |
| 165 | def are_similar(x): return x == params[0] |
| 166 | |
| 167 | return all(map(are_similar, params)), |
| 168 | # ############## Change reclass ###################################### |
| 169 | show_step(1) |
| 170 | reclass.add_key( |
| 171 | "parameters._param.linux_system_repo_mcp_glusterfs_version_number", |
| 172 | "5", |
| 173 | "cluster/*/infra/init.yml" |
| 174 | ) |
| 175 | # ################# Run linux.system state ########################### |
| 176 | show_step(2) |
| 177 | salt.enforce_state("*", "linux.system.repo") |
| 178 | |
| 179 | # ############## Start deploy-upgrade-galera job ##################### |
| 180 | show_step(3) |
| 181 | jenkins_build_timeout = 40 * 60 |
| 182 | job_name = 'update-glusterfs' |
| 183 | |
| 184 | update_glusterfs = run_jenkins_job.run_job( |
| 185 | host=jenkins_url, |
| 186 | username=jenkins_user, |
| 187 | password=jenkins_pass, |
| 188 | build_timeout=jenkins_build_timeout, |
| 189 | verbose=False, |
| 190 | job_name=job_name) |
| 191 | |
| 192 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 193 | host=jenkins_url, |
| 194 | username=jenkins_user, |
| 195 | password=jenkins_pass, |
| 196 | job_name=job_name, |
| 197 | build_number='lastBuild') |
| 198 | |
| 199 | LOG.info(description) |
| 200 | LOG.info('\n'.join(stages)) |
| 201 | |
| 202 | assert update_glusterfs == 'SUCCESS', "{0}\n{1}".format( |
| 203 | description, '\n'.join(stages)) |
| 204 | |
| 205 | # ################ Check GlusterFS version for servers ############## |
| 206 | show_step(4) |
| 207 | gluster_server_versions_by_nodes = salt.cmd_run( |
| 208 | "I@glusterfs:server", |
| 209 | "glusterd --version|head -n1")[0] |
| 210 | |
| 211 | assert has_only_similar(gluster_server_versions_by_nodes),\ |
| 212 | gluster_server_versions_by_nodes |
| 213 | |
| 214 | # ################ Check GlusterFS version for clients ############## |
| 215 | show_step(5) |
| 216 | gluster_client_versions_by_nodes = salt.cmd_run( |
| 217 | "I@glusterfs:client", |
| 218 | "glusterfs --version|head -n1")[0] |
| 219 | |
| 220 | assert has_only_similar(gluster_client_versions_by_nodes), \ |
| 221 | gluster_client_versions_by_nodes |
| 222 | |
| 223 | @pytest.mark.grab_versions |
| 224 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 225 | @pytest.mark.run_mcp_update |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 226 | def test_update_galera(self, salt_actions, reclass_actions, show_step, _): |
| 227 | """ Upgrade Galera automatically |
| 228 | |
| 229 | Scenario: |
| 230 | 1. Include the Galera upgrade pipeline job to DriveTrain |
| 231 | 2. Apply the jenkins.client state on the Jenkins nodes |
| 232 | 3. set the openstack_upgrade_enabled parameter to true |
| 233 | 4. Refresh pillars |
| 234 | 5. Add repositories with new Galera packages |
| 235 | 6. Start job from Jenkins |
| 236 | """ |
| 237 | salt = salt_actions |
| 238 | reclass = reclass_actions |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame^] | 239 | jenkins_creds = salt.get_cluster_jenkins_creds() |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 240 | # ################### Enable pipeline ################################# |
| 241 | show_step(1) |
| 242 | reclass.add_class( |
| 243 | "system.jenkins.client.job.deploy.update.upgrade_galera", |
| 244 | "cluster/*/cicd/control/leader.yml") |
| 245 | show_step(2) |
| 246 | salt.enforce_state("I@jenkins:client", "jenkins.client") |
| 247 | |
| 248 | # ############### Enable automatic upgrade ############################ |
| 249 | show_step(3) |
| 250 | reclass.add_bool_key("parameters._param.openstack_upgrade_enabled", |
| 251 | "True", |
| 252 | "cluster/*/infra/init.yml") |
| 253 | |
| 254 | show_step(4) |
| 255 | salt.enforce_state("dbs*", "saltutil.refresh_pillar") |
| 256 | |
| 257 | # ############# Add repositories with new Galera packages ####### |
| 258 | show_step(5) |
| 259 | salt.enforce_state("dbs*", "linux.system.repo") |
| 260 | salt.enforce_state("cfg*", "salt.master") |
| 261 | |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 262 | # #################### Login Jenkins on cid01 node ################### |
| 263 | show_step(6) |
| 264 | |
| 265 | jenkins_url = jenkins_creds.get('url') |
| 266 | jenkins_user = jenkins_creds.get('user') |
| 267 | jenkins_pass = jenkins_creds.get('pass') |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame^] | 268 | jenkins_build_timeout = 40 * 60 |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 269 | job_name = 'deploy-upgrade-galera' |
| 270 | job_parameters = { |
| 271 | 'INTERACTIVE': 'false' |
| 272 | } |
| 273 | |
| 274 | update_galera = run_jenkins_job.run_job( |
| 275 | host=jenkins_url, |
| 276 | username=jenkins_user, |
| 277 | password=jenkins_pass, |
| 278 | build_timeout=jenkins_build_timeout, |
| 279 | verbose=False, |
| 280 | job_name=job_name, |
| 281 | job_parameters=job_parameters) |
| 282 | |
| 283 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 284 | host=jenkins_url, |
| 285 | username=jenkins_user, |
| 286 | password=jenkins_pass, |
| 287 | job_name=job_name, |
| 288 | build_number='lastBuild') |
| 289 | |
| 290 | LOG.info(description) |
| 291 | LOG.info('\n'.join(stages)) |
| 292 | |
| 293 | assert update_galera == 'SUCCESS', "{0}\n{1}".format( |
| 294 | description, '\n'.join(stages)) |