Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 1 | import pytest |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 2 | import sys |
| 3 | import os |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 4 | |
| 5 | from tcp_tests import logger |
| 6 | from tcp_tests import settings |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 7 | |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 8 | sys.path.append(os.getcwd()) |
| 9 | try: |
| 10 | from tcp_tests.fixtures import config_fixtures |
| 11 | from tcp_tests.managers import underlay_ssh_manager |
| 12 | from tcp_tests.managers import saltmanager as salt_manager |
| 13 | except ImportError: |
| 14 | print("ImportError: Run the application from the tcp-qa directory or " |
| 15 | "set the PYTHONPATH environment variable to directory which contains" |
| 16 | " ./tcp_tests") |
| 17 | sys.exit(1) |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 18 | LOG = logger.logger |
| 19 | |
| 20 | |
Hanna Arhipova | d35a29b | 2019-09-04 13:24:06 +0300 | [diff] [blame] | 21 | def has_only_similar(values_by_nodes): |
| 22 | """ |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 23 | :param values_by_nodes: dict |
Hanna Arhipova | d35a29b | 2019-09-04 13:24:06 +0300 | [diff] [blame] | 24 | :return: bool, True if all items in the dict have similar values |
| 25 | """ |
| 26 | values = list(values_by_nodes.values()) |
| 27 | return all(value == values[0] for value in values) |
| 28 | |
| 29 | |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 30 | def get_control_plane_targets(): |
| 31 | config = config_fixtures.config() |
| 32 | underlay = underlay_ssh_manager.UnderlaySSHManager(config) |
| 33 | saltmanager = salt_manager.SaltManager(config, underlay) |
Hanna Arhipova | fbcea85 | 2019-10-03 13:24:53 +0300 | [diff] [blame] | 34 | targets = list() |
| 35 | try: |
| 36 | targets += saltmanager.run_state( |
| 37 | "I@keystone:server", 'test.ping')[0]['return'][0].keys() |
| 38 | targets += saltmanager.run_state( |
| 39 | "I@nginx:server and not I@salt:master", |
| 40 | "test.ping")[0]['return'][0].keys() |
| 41 | except BaseException as err: |
| 42 | LOG.warning("Can't retrieve data from Salt. \ |
| 43 | Maybe cluster is not deployed completely.\ |
| 44 | Err: {}".format(err)) |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 45 | |
Hanna Arhipova | 75f21bb | 2019-10-07 19:22:15 +0300 | [diff] [blame^] | 46 | # check for Manila existence |
| 47 | # if saltmanager.get_single_pillar("I@salt:master", |
| 48 | # "_param:manila_service_protocol"): |
| 49 | # targets.append('share*') |
| 50 | |
| 51 | # check for Tenant Telemetry existence |
| 52 | if saltmanager.get_single_pillar("I@salt:master", |
| 53 | "_param:openstack_telemetry_hostname"): |
| 54 | targets.append('mdb*') |
| 55 | |
| 56 | # check for Barbican existence |
| 57 | if saltmanager.get_single_pillar("I@salt:master", |
| 58 | "_param:barbican_enabled"): |
| 59 | targets.append('kmn*') |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 60 | return targets |
| 61 | |
| 62 | |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 63 | @pytest.fixture(scope='class') |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 64 | def switch_to_proposed_pipelines(reclass_actions, salt_actions): |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 65 | reclass = reclass_actions |
| 66 | proposed_repo = "http://mirror.mirantis.com/update/proposed/" |
| 67 | repo_param = "parameters._param.linux_system_repo_update_url" |
Hanna Arhipova | 7cfeb07 | 2019-10-11 15:04:10 +0300 | [diff] [blame] | 68 | |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 69 | proposed_pipeline_branch = "release/proposed/2019.2.0" |
| 70 | pipeline_branch_param = "parameters._param.jenkins_pipelines_branch" |
| 71 | infra_yml = "cluster/*/infra/init.yml" |
| 72 | |
| 73 | LOG.info("Check reclass has release/proposed/2019.2.0 branches") |
| 74 | if reclass.get_key(pipeline_branch_param, |
| 75 | infra_yml) == proposed_pipeline_branch \ |
| 76 | and reclass.get_key(repo_param, infra_yml) == proposed_repo: |
| 77 | return True |
| 78 | |
| 79 | LOG.info("Switch to release/proposed/2019.2.0 branches") |
| 80 | reclass.add_key(pipeline_branch_param, proposed_pipeline_branch, infra_yml) |
| 81 | |
| 82 | reclass.add_key(repo_param, proposed_repo, infra_yml) |
| 83 | reclass.add_key(repo_param, proposed_repo, "cluster/*/openstack/init.yml") |
| 84 | reclass.add_key(repo_param, proposed_repo, "cluster/*/stacklight/init.yml") |
| 85 | reclass.add_key(repo_param, proposed_repo, "cluster/*/ceph/init.yml") |
Hanna Arhipova | 7cfeb07 | 2019-10-11 15:04:10 +0300 | [diff] [blame] | 86 | |
| 87 | salt_actions.run_state("*", "saltutil.refresh_pillar") |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 88 | salt_actions.enforce_state("I@jenkins:client", "jenkins.client") |
| 89 | |
| 90 | |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 91 | @pytest.fixture(scope='class') |
| 92 | def enable_openstack_update(reclass_actions, salt_actions): |
| 93 | param = "parameters._param.openstack_upgrade_enabled" |
| 94 | context_file = "cluster/*/infra/init.yml" |
| 95 | |
| 96 | LOG.info("Enable openstack_upgrade_enabled in reclass") |
| 97 | reclass_actions.add_bool_key(param, "True", context_file) |
| 98 | salt_actions.run_state("*", "saltutil.refresh_pillar") |
| 99 | yield True |
| 100 | LOG.info("Disable openstack_upgrade_enabled in reclass") |
| 101 | reclass_actions.add_bool_key(param, "False", context_file) |
| 102 | salt_actions.run_state("*", "saltutil.refresh_pillar") |
| 103 | |
| 104 | |
| 105 | @pytest.mark.usefixtures("switch_to_proposed_pipelines") |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 106 | class TestUpdateMcpCluster(object): |
| 107 | """ |
| 108 | Following the steps in |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 109 | 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] | 110 | """ |
| 111 | |
| 112 | @pytest.mark.grab_versions |
| 113 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 114 | @pytest.mark.run_mcp_update |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 115 | def test_update_drivetrain(self, salt_actions, drivetrain_actions, |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 116 | show_step, _): |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 117 | """Updating DriveTrain component to release/proposed/2019.2.0 version |
| 118 | |
| 119 | Scenario: |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 120 | 1. Add workaround for PROD-32751 |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 121 | 2. Run job git-mirror-downstream-mk-pipelines |
| 122 | 3. Run job git-mirror-downstream-pipeline-library |
| 123 | 4. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain' |
| 124 | |
Hanna Arhipova | d35a29b | 2019-09-04 13:24:06 +0300 | [diff] [blame] | 125 | Duration: ~70 min |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 126 | """ |
| 127 | salt = salt_actions |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 128 | dt = drivetrain_actions |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 129 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 130 | # #################### Add workaround for PROD-32751 ################# |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 131 | show_step(1) |
| 132 | |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 133 | # FIXME: workaround for PROD-32751 |
| 134 | salt.cmd_run("cfg01*", "cd /srv/salt/reclass; git add -u && \ |
| 135 | git commit --allow-empty -m 'Cluster model update'") |
| 136 | |
| 137 | # ################### Downstream mk-pipelines ######################### |
| 138 | show_step(2) |
| 139 | job_name = 'git-mirror-downstream-mk-pipelines' |
| 140 | job_parameters = { |
| 141 | 'BRANCHES': 'release/proposed/2019.2.0' |
| 142 | } |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 143 | update_pipelines = dt.start_job_on_cid_jenkins( |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 144 | job_name=job_name, |
| 145 | job_parameters=job_parameters) |
| 146 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 147 | assert update_pipelines == 'SUCCESS' |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 148 | |
| 149 | # ################### Downstream pipeline-library #################### |
| 150 | show_step(3) |
| 151 | job_name = 'git-mirror-downstream-pipeline-library' |
| 152 | job_parameters = { |
| 153 | 'BRANCHES': 'release/proposed/2019.2.0' |
| 154 | } |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 155 | update_pipeline_library = dt.start_job_on_cid_jenkins( |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 156 | job_name=job_name, |
| 157 | job_parameters=job_parameters) |
| 158 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 159 | assert update_pipeline_library == 'SUCCESS' |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 160 | |
| 161 | # ################### Start 'Deploy - upgrade MCP Drivetrain' job ##### |
| 162 | show_step(4) |
| 163 | |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 164 | job_name = 'upgrade-mcp-release' |
| 165 | job_parameters = { |
Hanna Arhipova | d35a29b | 2019-09-04 13:24:06 +0300 | [diff] [blame] | 166 | 'GIT_REFSPEC': 'release/proposed/2019.2.0', |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 167 | 'MK_PIPELINES_REFSPEC': 'release/proposed/2019.2.0', |
| 168 | 'TARGET_MCP_VERSION': '2019.2.0' |
| 169 | } |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 170 | update_drivetrain = dt.start_job_on_cid_jenkins( |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 171 | job_name=job_name, |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 172 | job_parameters=job_parameters, |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 173 | build_timeout=90 * 60) |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 174 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 175 | assert update_drivetrain == 'SUCCESS' |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 176 | |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 177 | @pytest.mark.grab_versions |
| 178 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
Hanna Arhipova | 71ecc27 | 2019-08-20 14:54:22 +0300 | [diff] [blame] | 179 | @pytest.mark.run_mcp_update |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 180 | def test_update_glusterfs(self, salt_actions, reclass_actions, |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 181 | drivetrain_actions, show_step, _): |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 182 | """ Upgrade GlusterFS |
| 183 | Scenario: |
| 184 | 1. In infra/init.yml in Reclass, add the glusterfs_version parameter |
| 185 | 2. Start linux.system.repo state |
| 186 | 3. Start "update-glusterfs" job |
| 187 | 4. Check version for GlusterFS servers |
| 188 | 5. Check version for GlusterFS clients |
| 189 | |
| 190 | """ |
| 191 | salt = salt_actions |
| 192 | reclass = reclass_actions |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 193 | dt = drivetrain_actions |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 194 | |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 195 | # ############## Change reclass ###################################### |
| 196 | show_step(1) |
| 197 | reclass.add_key( |
| 198 | "parameters._param.linux_system_repo_mcp_glusterfs_version_number", |
| 199 | "5", |
| 200 | "cluster/*/infra/init.yml" |
| 201 | ) |
| 202 | # ################# Run linux.system state ########################### |
| 203 | show_step(2) |
| 204 | salt.enforce_state("*", "linux.system.repo") |
| 205 | |
| 206 | # ############## Start deploy-upgrade-galera job ##################### |
| 207 | show_step(3) |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 208 | job_name = 'update-glusterfs' |
| 209 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 210 | update_glusterfs = dt.start_job_on_cid_jenkins( |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 211 | job_name=job_name, |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 212 | build_timeout=40 * 60) |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 213 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 214 | assert update_glusterfs == 'SUCCESS' |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 215 | |
| 216 | # ################ Check GlusterFS version for servers ############## |
| 217 | show_step(4) |
| 218 | gluster_server_versions_by_nodes = salt.cmd_run( |
| 219 | "I@glusterfs:server", |
| 220 | "glusterd --version|head -n1")[0] |
| 221 | |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 222 | assert has_only_similar(gluster_server_versions_by_nodes), \ |
Hanna Arhipova | cc3759b | 2019-08-28 16:01:11 +0300 | [diff] [blame] | 223 | gluster_server_versions_by_nodes |
| 224 | |
| 225 | # ################ Check GlusterFS version for clients ############## |
| 226 | show_step(5) |
| 227 | gluster_client_versions_by_nodes = salt.cmd_run( |
| 228 | "I@glusterfs:client", |
| 229 | "glusterfs --version|head -n1")[0] |
| 230 | |
| 231 | assert has_only_similar(gluster_client_versions_by_nodes), \ |
| 232 | gluster_client_versions_by_nodes |
| 233 | |
| 234 | @pytest.mark.grab_versions |
| 235 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 236 | @pytest.mark.run_mcp_update |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 237 | def test_update_galera(self, salt_actions, reclass_actions, |
| 238 | drivetrain_actions, show_step, _): |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 239 | """ Upgrade Galera automatically |
| 240 | |
| 241 | Scenario: |
| 242 | 1. Include the Galera upgrade pipeline job to DriveTrain |
| 243 | 2. Apply the jenkins.client state on the Jenkins nodes |
| 244 | 3. set the openstack_upgrade_enabled parameter to true |
| 245 | 4. Refresh pillars |
| 246 | 5. Add repositories with new Galera packages |
| 247 | 6. Start job from Jenkins |
| 248 | """ |
| 249 | salt = salt_actions |
| 250 | reclass = reclass_actions |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 251 | dt = drivetrain_actions |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 252 | # ################### Enable pipeline ################################# |
| 253 | show_step(1) |
| 254 | reclass.add_class( |
| 255 | "system.jenkins.client.job.deploy.update.upgrade_galera", |
| 256 | "cluster/*/cicd/control/leader.yml") |
| 257 | show_step(2) |
| 258 | salt.enforce_state("I@jenkins:client", "jenkins.client") |
| 259 | |
| 260 | # ############### Enable automatic upgrade ############################ |
| 261 | show_step(3) |
| 262 | reclass.add_bool_key("parameters._param.openstack_upgrade_enabled", |
| 263 | "True", |
| 264 | "cluster/*/infra/init.yml") |
| 265 | |
| 266 | show_step(4) |
Hanna Arhipova | 7cfeb07 | 2019-10-11 15:04:10 +0300 | [diff] [blame] | 267 | salt.run_state("dbs*", "saltutil.refresh_pillar") |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 268 | |
| 269 | # ############# Add repositories with new Galera packages ####### |
| 270 | show_step(5) |
| 271 | salt.enforce_state("dbs*", "linux.system.repo") |
| 272 | salt.enforce_state("cfg*", "salt.master") |
| 273 | |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 274 | # #################### Login Jenkins on cid01 node ################### |
| 275 | show_step(6) |
| 276 | |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 277 | job_name = 'deploy-upgrade-galera' |
| 278 | job_parameters = { |
| 279 | 'INTERACTIVE': 'false' |
| 280 | } |
| 281 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 282 | update_galera = dt.start_job_on_cid_jenkins( |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 283 | job_name=job_name, |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 284 | job_parameters=job_parameters, |
| 285 | build_timeout=40 * 60) |
Hanna Arhipova | 94a8abe | 2019-08-22 14:11:46 +0300 | [diff] [blame] | 286 | |
Hanna Arhipova | 17b2c10 | 2019-09-06 16:44:17 +0300 | [diff] [blame] | 287 | assert update_galera == 'SUCCESS' |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 288 | |
| 289 | @pytest.fixture |
| 290 | def disable_automatic_failover_neutron_for_test(self, salt_actions): |
| 291 | """ |
| 292 | On each OpenStack controller node, modify the neutron.conf file |
| 293 | Restart the neutron-server service |
| 294 | """ |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 295 | |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 296 | def comment_line(node, file_name, word): |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 297 | """ |
| 298 | Adds '#' before the specific line in specific file |
| 299 | |
| 300 | :param node: string, salt target of node where the file locates |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 301 | :param file_name: string, full path to the file |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 302 | :param word: string, the begin of line which should be commented |
| 303 | :return: None |
| 304 | """ |
| 305 | salt_actions.cmd_run(node, |
| 306 | "sed -i 's/^{word}/#{word}/' {file}". |
| 307 | format(word=word, |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 308 | file=file_name)) |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 309 | |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 310 | def add_line(node, file_name, line): |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 311 | """ |
| 312 | Appends line to the end of file |
| 313 | |
| 314 | :param node: string, salt target of node where the file locates |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 315 | :param file_name: string, full path to the file |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 316 | :param line: string, line that should be added |
| 317 | :return: None |
| 318 | """ |
| 319 | salt_actions.cmd_run(node, "echo {line} >> {file}".format( |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 320 | line=line, |
| 321 | file=file_name)) |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 322 | |
| 323 | neutron_conf = '/etc/neutron/neutron.conf' |
| 324 | neutron_server = "I@neutron:server" |
| 325 | # ######## Create backup for config file ####################### |
| 326 | salt_actions.cmd_run( |
| 327 | neutron_server, |
| 328 | "cp -p {file} {file}.backup".format(file=neutron_conf)) |
| 329 | |
| 330 | # ## Change parameters in neutron.conf' |
| 331 | comment_line(neutron_server, neutron_conf, |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 332 | "allow_automatic_l3agent_failover", ) |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 333 | comment_line(neutron_server, neutron_conf, |
| 334 | "allow_automatic_dhcp_failover") |
| 335 | add_line(neutron_server, neutron_conf, |
| 336 | "allow_automatic_dhcp_failover = false") |
| 337 | add_line(neutron_server, neutron_conf, |
| 338 | "allow_automatic_l3agent_failover = false") |
| 339 | |
| 340 | # ## Apply changed config to the neutron-server service |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 341 | result = salt_actions.cmd_run(neutron_server, |
| 342 | "service neutron-server restart") |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 343 | # TODO: add check that neutron-server is up and running |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 344 | yield result |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 345 | # ## Revert file changes |
| 346 | salt_actions.cmd_run( |
| 347 | neutron_server, |
| 348 | "cp -p {file}.backup {file}".format(file=neutron_conf)) |
| 349 | salt_actions.cmd_run(neutron_server, |
| 350 | "service neutron-server restart") |
| 351 | |
| 352 | @pytest.fixture |
| 353 | def disable_neutron_agents_for_test(self, salt_actions): |
| 354 | """ |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 355 | Disable the neutron services before the test and |
| 356 | enable it after test |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 357 | """ |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 358 | result = salt_actions.cmd_run("I@neutron:server", """ |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 359 | service neutron-dhcp-agent stop && \ |
| 360 | service neutron-l3-agent stop && \ |
| 361 | service neutron-metadata-agent stop && \ |
| 362 | service neutron-openvswitch-agent stop |
| 363 | """) |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 364 | yield result |
| 365 | # |
Hanna Arhipova | 1fcaf44 | 2019-09-06 15:30:45 +0300 | [diff] [blame] | 366 | salt_actions.cmd_run("I@neutron:server", """ |
| 367 | service neutron-dhcp-agent start && \ |
| 368 | service neutron-l3-agent start && \ |
| 369 | service neutron-metadata-agent start && \ |
| 370 | service neutron-openvswitch-agent start |
| 371 | """) |
| 372 | # TODO: add check that all services are UP and running |
| 373 | |
| 374 | @pytest.mark.grab_versions |
| 375 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 376 | @pytest.mark.run_mcp_update |
| 377 | def test_update_rabbit(self, salt_actions, reclass_actions, |
| 378 | drivetrain_actions, show_step, _, |
| 379 | disable_automatic_failover_neutron_for_test, |
| 380 | disable_neutron_agents_for_test): |
| 381 | """ Updates RabbitMQ |
| 382 | Scenario: |
| 383 | 1. Include the RabbitMQ upgrade pipeline job to DriveTrain |
| 384 | 2. Add repositories with new RabbitMQ packages |
| 385 | 3. Start Deploy - upgrade RabbitMQ pipeline |
| 386 | |
| 387 | Updating RabbitMq should be completed before the OpenStack updating |
| 388 | process starts |
| 389 | """ |
| 390 | salt = salt_actions |
| 391 | reclass = reclass_actions |
| 392 | dt = drivetrain_actions |
| 393 | |
| 394 | # ####### Include the RabbitMQ upgrade pipeline job to DriveTrain #### |
| 395 | show_step(1) |
| 396 | reclass.add_class( |
| 397 | "system.jenkins.client.job.deploy.update.upgrade_rabbitmq", |
| 398 | "cluster/*/cicd/control/leader.yml") |
| 399 | salt.enforce_state("I@jenkins:client", "jenkins.client") |
| 400 | |
| 401 | reclass.add_bool_key("parameters._param.openstack_upgrade_enabled", |
| 402 | "True", |
| 403 | "cluster/*/infra/init.yml") |
| 404 | salt.run_state("I@rabbitmq:server", "saltutil.refresh_pillar") |
| 405 | |
| 406 | # ########### Add repositories with new RabbitMQ packages ############ |
| 407 | show_step(2) |
| 408 | salt.enforce_state("I@rabbitmq:server", "linux.system.repo") |
| 409 | |
| 410 | # ########### Start Deploy - upgrade RabbitMQ pipeline ############ |
| 411 | show_step(3) |
| 412 | job_parameters = { |
| 413 | 'INTERACTIVE': 'false' |
| 414 | } |
| 415 | |
| 416 | update_rabbit = dt.start_job_on_cid_jenkins( |
| 417 | job_name='deploy-upgrade-rabbitmq', |
| 418 | job_parameters=job_parameters, |
| 419 | build_timeout=40 * 60 |
| 420 | ) |
| 421 | assert update_rabbit == 'SUCCESS' |
Hanna Arhipova | d35a29b | 2019-09-04 13:24:06 +0300 | [diff] [blame] | 422 | |
| 423 | @pytest.mark.grab_versions |
| 424 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 425 | @pytest.mark.run_mcp_update |
| 426 | def test_update_ceph(self, salt_actions, drivetrain_actions, show_step, _): |
| 427 | """ Updates Ceph to the latest minor version |
| 428 | |
| 429 | Scenario: |
| 430 | 1. Add workaround for unhealth Ceph |
| 431 | 2. Start ceph-upgrade job with default parameters |
| 432 | 3. Check Ceph version for all nodes |
| 433 | |
| 434 | https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update/ceph-update.html |
| 435 | """ |
| 436 | salt = salt_actions |
| 437 | dt = drivetrain_actions |
| 438 | |
| 439 | # ###################### Add workaround for unhealth Ceph ############ |
| 440 | show_step(1) |
| 441 | salt.cmd_run("I@ceph:radosgw", |
| 442 | "ceph config set 'mon pg warn max object skew' 20") |
| 443 | # ###################### Start ceph-upgrade pipeline ################# |
| 444 | show_step(2) |
| 445 | job_parameters = {} |
| 446 | |
| 447 | update_ceph = dt.start_job_on_cid_jenkins( |
| 448 | job_name='ceph-update', |
| 449 | job_parameters=job_parameters) |
| 450 | |
| 451 | assert update_ceph == 'SUCCESS' |
| 452 | |
| 453 | # ########## Verify Ceph version ##################################### |
| 454 | show_step(3) |
| 455 | |
| 456 | ceph_version_by_nodes = salt.cmd_run( |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 457 | "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server", |
| 458 | "ceph version")[0] |
Hanna Arhipova | d35a29b | 2019-09-04 13:24:06 +0300 | [diff] [blame] | 459 | |
| 460 | assert has_only_similar(ceph_version_by_nodes), ceph_version_by_nodes |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 461 | |
Hanna Arhipova | ac00856 | 2019-10-17 11:54:23 +0300 | [diff] [blame] | 462 | @pytest.mark.grab_versions |
| 463 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 464 | @pytest.mark.run_mcp_update |
| 465 | def test_update_stacklight(self, _, drivetrain_actions): |
| 466 | """ Update packages for Stacklight |
| 467 | Scenario: |
| 468 | 1. Start Deploy - upgrade Stacklight job |
| 469 | """ |
| 470 | drivetrain = drivetrain_actions |
| 471 | |
| 472 | job_parameters = { |
| 473 | "STAGE_UPGRADE_DOCKER_COMPONENTS": True, |
| 474 | "STAGE_UPGRADE_ES_KIBANA": True, |
| 475 | "STAGE_UPGRADE_SYSTEM_PART": True |
| 476 | } |
| 477 | upgrade_control_pipeline = drivetrain.start_job_on_cid_jenkins( |
| 478 | job_name="stacklight-upgrade", |
| 479 | job_parameters=job_parameters) |
| 480 | |
| 481 | assert upgrade_control_pipeline == 'SUCCESS' |
| 482 | |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 483 | |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 484 | @pytest.mark.usefixtures("switch_to_proposed_pipelines", |
| 485 | "enable_openstack_update") |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 486 | class TestOpenstackUpdate(object): |
| 487 | |
| 488 | @pytest.mark.grab_versions |
| 489 | @pytest.mark.run_mcp_update |
| 490 | def test__pre_update__enable_pipeline_job(self, |
| 491 | reclass_actions, salt_actions, |
| 492 | show_step): |
| 493 | """ Enable pipeline in the Drivetrain |
| 494 | |
| 495 | Scenario: |
| 496 | 1. Add deploy.update.* classes to the reclass |
| 497 | 2. Start jenkins.client salt state |
| 498 | |
| 499 | """ |
| 500 | salt = salt_actions |
| 501 | reclass = reclass_actions |
| 502 | show_step(1) |
| 503 | reclass.add_class("system.jenkins.client.job.deploy.update.upgrade", |
| 504 | "cluster/*/cicd/control/leader.yml") |
| 505 | |
| 506 | reclass.add_class( |
| 507 | "system.jenkins.client.job.deploy.update.upgrade_ovs_gateway", |
| 508 | "cluster/*/cicd/control/leader.yml") |
| 509 | |
| 510 | reclass.add_class( |
| 511 | "system.jenkins.client.job.deploy.update.upgrade_compute", |
| 512 | "cluster/*/cicd/control/leader.yml") |
| 513 | |
| 514 | show_step(2) |
| 515 | r, errors = salt.enforce_state("I@jenkins:client", "jenkins.client") |
| 516 | assert errors is None |
| 517 | |
| 518 | @pytest.mark.grab_versions |
| 519 | @pytest.mark.parametrize('target', get_control_plane_targets()) |
| 520 | @pytest.mark.run_mcp_update |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 521 | def test__update__control_plane(self, drivetrain_actions, target): |
Hanna Arhipova | eb3a211 | 2019-09-13 18:45:21 +0300 | [diff] [blame] | 522 | """Start 'Deploy - upgrade control VMs' for specific node |
| 523 | """ |
| 524 | job_parameters = { |
| 525 | "TARGET_SERVERS": target, |
| 526 | "INTERACTIVE": False} |
| 527 | upgrade_control_pipeline = drivetrain_actions.start_job_on_cid_jenkins( |
| 528 | job_name="deploy-upgrade-control", |
| 529 | job_parameters=job_parameters) |
| 530 | |
| 531 | assert upgrade_control_pipeline == 'SUCCESS' |
| 532 | |
| 533 | @pytest.mark.grab_versions |
| 534 | @pytest.mark.run_mcp_update |
| 535 | def test__update__data_plane(self, drivetrain_actions): |
| 536 | """Start 'Deploy - upgrade OVS gateway' |
| 537 | """ |
| 538 | job_parameters = { |
| 539 | "INTERACTIVE": False} |
| 540 | upgrade_data_pipeline = drivetrain_actions.start_job_on_cid_jenkins( |
| 541 | job_name="deploy-upgrade-ovs-gateway", |
| 542 | job_parameters=job_parameters) |
| 543 | |
| 544 | assert upgrade_data_pipeline == 'SUCCESS' |
Hanna Arhipova | 1942996 | 2019-10-17 15:16:49 +0300 | [diff] [blame] | 545 | |
| 546 | @pytest.mark.grab_versions |
| 547 | @pytest.mark.run_mcp_update |
| 548 | def test__update__computes(self, drivetrain_actions): |
| 549 | """Start 'Deploy - upgrade computes' |
| 550 | """ |
| 551 | job_parameters = { |
| 552 | "INTERACTIVE": False} |
| 553 | upgrade_compute_pipeline = drivetrain_actions.start_job_on_cid_jenkins( |
| 554 | job_name="deploy-upgrade-compute", |
| 555 | job_parameters=job_parameters) |
| 556 | |
| 557 | assert upgrade_compute_pipeline == 'SUCCESS' |