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