blob: 15a0586987db06df483bc966daec64f5d98dc5a3 [file] [log] [blame]
Hanna Arhipova71ecc272019-08-20 14:54:22 +03001import pytest
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +03002import sys
3import os
Hanna Arhipova71ecc272019-08-20 14:54:22 +03004
5from tcp_tests import logger
6from tcp_tests import settings
Hanna Arhipova71ecc272019-08-20 14:54:22 +03007
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +03008sys.path.append(os.getcwd())
9try:
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
13except 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 Arhipova71ecc272019-08-20 14:54:22 +030018LOG = logger.logger
19
20
Hanna Arhipovad35a29b2019-09-04 13:24:06 +030021def has_only_similar(values_by_nodes):
22 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +030023 :param values_by_nodes: dict
Hanna Arhipovad35a29b2019-09-04 13:24:06 +030024 :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 Arhipovaeb3a2112019-09-13 18:45:21 +030030def get_control_plane_targets():
31 config = config_fixtures.config()
32 underlay = underlay_ssh_manager.UnderlaySSHManager(config)
33 saltmanager = salt_manager.SaltManager(config, underlay)
Hanna Arhipovafbcea852019-10-03 13:24:53 +030034 targets = list()
Hanna Arhipova52bb17d2019-10-28 19:15:17 +020035 telemetry_exists = False
36 barbican_exists = False
Hanna Arhipovafbcea852019-10-03 13:24:53 +030037 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 Arhipova4462dd02019-10-28 19:05:08 +020043 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 Arhipovafbcea852019-10-03 13:24:53 +030049 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 Arhipovaeb3a2112019-09-13 18:45:21 +030053
Hanna Arhipova75f21bb2019-10-07 19:22:15 +030054 # 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 Arhipova4462dd02019-10-28 19:05:08 +020060 if telemetry_exists:
Hanna Arhipova75f21bb2019-10-07 19:22:15 +030061 targets.append('mdb*')
62
63 # check for Barbican existence
Hanna Arhipova4462dd02019-10-28 19:05:08 +020064 if barbican_exists:
Hanna Arhipova75f21bb2019-10-07 19:22:15 +030065 targets.append('kmn*')
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +030066 return targets
67
68
Hanna Arhipova19429962019-10-17 15:16:49 +030069@pytest.fixture(scope='class')
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +030070def update_to_tag(request):
71 return request.config.getoption("--update-to-tag")
Hanna Arhipova672efc62021-03-15 09:55:14 +020072
73
74@pytest.fixture(scope='class')
PGlazov7efe3b22022-02-16 17:29:05 +040075def update_mysql_to_version(request):
76 return request.config.getoption("--update-mysql-version")
77
78
79@pytest.fixture(scope='class')
Hanna Arhipova672efc62021-03-15 09:55:14 +020080def switch_to_proposed_pipelines(reclass_actions, salt_actions,
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +030081 update_to_tag):
82 if update_to_tag:
Hanna Arhipova672efc62021-03-15 09:55:14 +020083 return True
84
Hanna Arhipova19429962019-10-17 15:16:49 +030085 reclass = reclass_actions
86 proposed_repo = "http://mirror.mirantis.com/update/proposed/"
87 repo_param = "parameters._param.linux_system_repo_update_url"
Hanna Arhipova7cfeb072019-10-11 15:04:10 +030088
Hanna Arhipova19429962019-10-17 15:16:49 +030089 proposed_pipeline_branch = "release/proposed/2019.2.0"
90 pipeline_branch_param = "parameters._param.jenkins_pipelines_branch"
91 infra_yml = "cluster/*/infra/init.yml"
92
93 LOG.info("Check reclass has release/proposed/2019.2.0 branches")
94 if reclass.get_key(pipeline_branch_param,
95 infra_yml) == proposed_pipeline_branch \
96 and reclass.get_key(repo_param, infra_yml) == proposed_repo:
97 return True
98
99 LOG.info("Switch to release/proposed/2019.2.0 branches")
100 reclass.add_key(pipeline_branch_param, proposed_pipeline_branch, infra_yml)
101
102 reclass.add_key(repo_param, proposed_repo, infra_yml)
103 reclass.add_key(repo_param, proposed_repo, "cluster/*/openstack/init.yml")
104 reclass.add_key(repo_param, proposed_repo, "cluster/*/stacklight/init.yml")
105 reclass.add_key(repo_param, proposed_repo, "cluster/*/ceph/init.yml")
Hanna Arhipova7cfeb072019-10-11 15:04:10 +0300106
107 salt_actions.run_state("*", "saltutil.refresh_pillar")
Hanna Arhipova9ee75902019-10-29 16:33:26 +0200108 salt_actions.enforce_state("*", "salt.minion")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300109 salt_actions.enforce_state("I@jenkins:client", "jenkins.client")
110
111
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300112@pytest.fixture
Hanna Arhipovaec201e72020-10-26 17:14:25 +0200113def wa_for_galera_clustercheck_password_prod35705(reclass_actions,
114 salt_actions):
Hanna Arhipova0e816d22021-01-29 00:17:44 +0200115 tgt = "I@galera:master or I@galera:slave"
116 if not salt_actions.get_pillar(tgt,
117 "_param:galera_clustercheck_password")[0]:
118 reclass_actions.add_key(
119 "parameters._param.galera_clustercheck_password",
120 "a"*32,
121 "cluster/*/infra/secrets.yml")
122 salt_actions.run_state(tgt, "saltutil.refresh_pillar")
123 salt_actions.enforce_state(tgt, "galera")
124 salt_actions.enforce_state(tgt, "haproxy")
125 reclass_actions.commit(
126 "[from TCP-QA] Add galera_clustercheck_password")
127 else:
Hanna Arhipova672efc62021-03-15 09:55:14 +0200128
Hanna Arhipova0e816d22021-01-29 00:17:44 +0200129 LOG.info("Skipping WA for Galera Clustercheck Password")
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300130
131
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200132@pytest.fixture
PGlazovf5977292021-11-25 19:38:27 +0400133def wa_cve_2021_20288_global_id_reclaim(reclass_actions,
134 salt_actions):
135 tgt = "I@ceph:common"
136 context_file = "cluster/*/ceph/common.yml"
137 if not reclass_actions.check_existence(
138 'parameters.ceph.common.config.mon.'
139 + 'auth_allow_insecure_global_id_reclaim'):
PGlazov4b013962022-01-31 14:01:42 +0400140 if salt_actions.get_single_pillar(
141 "I@ceph:mgr and *01.*",
142 "_param.ceph_version") == 'luminous':
143 LOG.info('Skip reclaim set')
144 return
PGlazovf5977292021-11-25 19:38:27 +0400145 reclass_actions.add_bool_key(
146 'parameters.ceph.common.config.mon.'
147 + 'auth_allow_insecure_global_id_reclaim', "False", context_file)
148 salt_actions.run_state(tgt, "state.apply", "ceph.common")
149 salt_actions.cmd_run(tgt, "systemctl restart ceph-mon.target")
150 else:
151 LOG.info("Skipping WA ceph set auth_allow_insecure_global_id_reclaim")
152
153
154@pytest.fixture
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200155def wa_for_alerta_password_prod35958(reclass_actions,
156 salt_actions):
Pavel Glazovea439c42021-07-25 00:20:20 +0000157
Hanna Arhipova0e816d22021-01-29 00:17:44 +0200158 if not salt_actions.get_pillar("I@prometheus:alerta",
159 "_param:alerta_admin_api_key_generated")[0]:
160 reclass_actions.add_key(
161 "parameters._param.alerta_admin_api_key_generated",
162 "a"*32,
163 "cluster/*/infra/secrets.yml")
164 reclass_actions.add_key(
165 "parameters._param.alerta_admin_key",
166 "${_param:alerta_admin_api_key_generated}",
167 "cluster/*/stacklight/init.yml")
168 reclass_actions.commit("[from TCP-QA] Add alerta_admin_key")
169 salt_actions.run_state(
170 "I@prometheus:alerta or I@prometheus:alertmanager",
171 "saltutil.refresh_pillar")
172 salt_actions.enforce_state(
173 "I@prometheus:alerta", "prometheus.alerta")
174 salt_actions.enforce_state(
175 "I@prometheus:alertmanager", "prometheus.alertmanager")
176 salt_actions.enforce_state(
177 "I@prometheus:alerta or I@prometheus:alertmanager",
178 "docker.client")
179 else:
180 LOG.info("Skipping WA for Alerta API key")
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200181
182
Vladimir Khlyunev5fe0aaa2022-08-16 23:13:22 +0400183@pytest.fixture
184def wa_redis_server_version_3_prod36960(reclass_actions, salt_actions):
185 version_pillar = "redis:server:version"
186 tgt = "I@{}".format(version_pillar)
187 pillar_file = "cluster/*/openstack/telemetry.yml"
188 redis_target_version = "5.0"
189
190 msg_nodes = salt_actions.get_minions_by_target(tgt)
191 if not msg_nodes:
192 LOG.info("dbs* nodes not found, skipping")
193 return
194 else:
195 msg_node = msg_nodes[0]
196
197 if str(salt_actions.get_single_pillar(
198 msg_node,
199 version_pillar)) == redis_target_version:
200 LOG.info("Redis-server is already '{}', skipping".format(
201 redis_target_version))
202 return
203
204 LOG.info("Setting redis-server version to '{}'".format(
205 redis_target_version))
206 reclass_actions.add_key(
207 "parameters.{}".format(version_pillar.replace(":", ".")),
208 redis_target_version,
209 pillar_file)
210 salt_actions.run_state(" or ".join(msg_nodes),
211 "saltutil.refresh_pillar")
212
213
Hanna Arhipova19429962019-10-17 15:16:49 +0300214@pytest.fixture(scope='class')
215def enable_openstack_update(reclass_actions, salt_actions):
216 param = "parameters._param.openstack_upgrade_enabled"
217 context_file = "cluster/*/infra/init.yml"
218
219 LOG.info("Enable openstack_upgrade_enabled in reclass")
220 reclass_actions.add_bool_key(param, "True", context_file)
221 salt_actions.run_state("*", "saltutil.refresh_pillar")
222 yield True
223 LOG.info("Disable openstack_upgrade_enabled in reclass")
224 reclass_actions.add_bool_key(param, "False", context_file)
225 salt_actions.run_state("*", "saltutil.refresh_pillar")
226
227
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300228@pytest.mark.usefixtures("switch_to_proposed_pipelines",
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300229 "update_to_tag",
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200230 "wa_for_galera_clustercheck_password_prod35705",
Vladimir Khlyunev5fe0aaa2022-08-16 23:13:22 +0400231 "wa_for_alerta_password_prod35958",
232 "wa_redis_server_version_3_prod36960")
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300233class TestUpdateMcpCluster(object):
234 """
235 Following the steps in
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300236 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update.html#minor-update
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300237 """
238
239 @pytest.mark.grab_versions
240 @pytest.mark.parametrize("_", [settings.ENV_NAME])
241 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300242 def test_update_drivetrain(self, salt_actions, drivetrain_actions,
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300243 show_step, update_to_tag, _):
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300244 """Updating DriveTrain component to release/proposed/2019.2.0 version
245
246 Scenario:
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300247 1. Add workaround for PROD-32751
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300248 2. Run job git-mirror-downstream-mk-pipelines
249 3. Run job git-mirror-downstream-pipeline-library
dtsapikovcbff2332022-01-19 19:32:22 +0400250 4. Run job pre-upgrade-verify
251 5. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain'
252 6. Wait till salt-master completes all async jobs
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300253
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300254 Duration: ~70 min
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300255 """
256 salt = salt_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300257 dt = drivetrain_actions
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300258
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300259 # #################### Add workaround for PROD-32751 #################
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300260 show_step(1)
261
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300262 # FIXME: workaround for PROD-32751
263 salt.cmd_run("cfg01*", "cd /srv/salt/reclass; git add -u && \
264 git commit --allow-empty -m 'Cluster model update'")
265
266 # ################### Downstream mk-pipelines #########################
267 show_step(2)
268 job_name = 'git-mirror-downstream-mk-pipelines'
269 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300270 'BRANCHES': '*' or
271 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300272 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200273 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300274 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300275 job_parameters=job_parameters,
276 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300277
Hanna Arhipova508f6532021-01-27 15:52:45 +0200278 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300279
280 # ################### Downstream pipeline-library ####################
281 show_step(3)
282 job_name = 'git-mirror-downstream-pipeline-library'
283 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300284 'BRANCHES': '*' or
285 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300286 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200287 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300288 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300289 job_parameters=job_parameters,
290 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300291
Hanna Arhipova508f6532021-01-27 15:52:45 +0200292 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300293
dtsapikovcbff2332022-01-19 19:32:22 +0400294 # ############### Start 'Pre-upgrade verify' job (since 2019.2.17)#####
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300295 show_step(4)
dtsapikovcbff2332022-01-19 19:32:22 +0400296 job_name = 'pre-upgrade-verify'
297 job_parameters = {}
298
299 if(dt.check_job_exists_on_jenkins(job_name)):
300 LOG.info("Pre-upgrade verify job exists on Jenkins!")
301 job_result, job_description = dt.start_job_on_jenkins(
302 job_name=job_name,
303 job_parameters=job_parameters,
304 verbose=True,
305 build_timeout=4 * 60 * 60)
306
307 assert job_result == 'SUCCESS', job_description
308
309 # ################### Start 'Deploy - upgrade MCP Drivetrain' job #####
310 show_step(5)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300311
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300312 job_name = 'upgrade-mcp-release'
313 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300314 'GIT_REFSPEC': update_to_tag or 'release/proposed/2019.2.0',
PGlazov1df9e542021-11-16 02:31:49 +0400315 'MK_PIPELINES_REFSPEC':
316 update_to_tag or 'release/proposed/2019.2.0',
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300317 'TARGET_MCP_VERSION': update_to_tag or '2019.2.0',
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300318 "DRIVE_TRAIN_PARAMS": {
319 "OS_DIST_UPGRADE": True,
320 "OS_UPGRADE": True,
321 "BATCH_SIZE": 10
322 }
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300323 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200324 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300325 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300326 job_parameters=job_parameters,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300327 verbose=True,
Hanna Arhipovae7f2e322021-02-25 13:53:18 +0200328 build_timeout=4 * 60 * 60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300329
Hanna Arhipova508f6532021-01-27 15:52:45 +0200330 assert job_result == 'SUCCESS', job_description
Hanna Arhipova7a593da2021-06-25 11:16:09 +0300331 # ############### Wait till salt-master completes all async jobs #####
332 show_step(5)
333 salt.wait_jobs_completed(timeout=20*60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300334
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300335 @pytest.mark.grab_versions
336 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300337 @pytest.mark.run_mcp_update
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300338 def test_update_glusterfs(self, salt_actions, reclass_actions,
PGlazov7efe3b22022-02-16 17:29:05 +0400339 drivetrain_actions, show_step,
340 update_mysql_to_version, _):
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300341 """ Upgrade GlusterFS
342 Scenario:
343 1. In infra/init.yml in Reclass, add the glusterfs_version parameter
344 2. Start linux.system.repo state
345 3. Start "update-glusterfs" job
346 4. Check version for GlusterFS servers
347 5. Check version for GlusterFS clients
348
349 """
PGlazov7efe3b22022-02-16 17:29:05 +0400350
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300351 salt = salt_actions
352 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300353 dt = drivetrain_actions
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300354
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300355 # ############## Change reclass ######################################
356 show_step(1)
357 reclass.add_key(
358 "parameters._param.linux_system_repo_mcp_glusterfs_version_number",
359 "5",
360 "cluster/*/infra/init.yml"
361 )
362 # ################# Run linux.system state ###########################
363 show_step(2)
364 salt.enforce_state("*", "linux.system.repo")
365
366 # ############## Start deploy-upgrade-galera job #####################
367 show_step(3)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300368 job_name = 'update-glusterfs'
369
Hanna Arhipova508f6532021-01-27 15:52:45 +0200370 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300371 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300372 build_timeout=40 * 60)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300373
Hanna Arhipova508f6532021-01-27 15:52:45 +0200374 assert job_result == 'SUCCESS', job_description
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300375
376 # ################ Check GlusterFS version for servers ##############
377 show_step(4)
378 gluster_server_versions_by_nodes = salt.cmd_run(
379 "I@glusterfs:server",
380 "glusterd --version|head -n1")[0]
381
Hanna Arhipova19429962019-10-17 15:16:49 +0300382 assert has_only_similar(gluster_server_versions_by_nodes), \
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300383 gluster_server_versions_by_nodes
384
385 # ################ Check GlusterFS version for clients ##############
386 show_step(5)
387 gluster_client_versions_by_nodes = salt.cmd_run(
388 "I@glusterfs:client",
389 "glusterfs --version|head -n1")[0]
390
391 assert has_only_similar(gluster_client_versions_by_nodes), \
392 gluster_client_versions_by_nodes
393
394 @pytest.mark.grab_versions
395 @pytest.mark.parametrize("_", [settings.ENV_NAME])
396 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300397 def test_update_galera(self, salt_actions, reclass_actions,
PGlazov7efe3b22022-02-16 17:29:05 +0400398 drivetrain_actions, show_step,
399 update_mysql_to_version, _):
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300400 """ Upgrade Galera automatically
401
402 Scenario:
403 1. Include the Galera upgrade pipeline job to DriveTrain
PGlazov7efe3b22022-02-16 17:29:05 +0400404 2. Add fix for mysql 5.7
405 3. Apply the jenkins.client state on the Jenkins nodes
406 4. set the openstack_upgrade_enabled parameter to true
407 5. Refresh pillars
408 6. Add repositories with new Galera packages
409 7. Start job from Jenkins
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300410 """
411 salt = salt_actions
412 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300413 dt = drivetrain_actions
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300414 # ################### Enable pipeline #################################
415 show_step(1)
416 reclass.add_class(
417 "system.jenkins.client.job.deploy.update.upgrade_galera",
418 "cluster/*/cicd/control/leader.yml")
PGlazov7efe3b22022-02-16 17:29:05 +0400419 # ################### Fix for Mysql 5.7 ##############################
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300420 show_step(2)
PGlazov7efe3b22022-02-16 17:29:05 +0400421 if (update_mysql_to_version == '5.7'):
PGlazov7efe3b22022-02-16 17:29:05 +0400422 mysql_class = "cluster.{env_name}.openstack." \
423 "database.mysql_version"\
424 .format(env_name=settings.ENV_NAME)
425 reclass.add_class(
426 mysql_class,
427 "cluster/*/openstack/database/master.yml")
428 reclass.add_class(
429 mysql_class,
430 "cluster/*/openstack/database/slave.yml")
431 mysql_path = "cluster/{env_name}" \
432 "/openstack/database/mysql_version.yml"\
433 .format(env_name=settings.ENV_NAME)
434 galera_mysql_version = '5.7'
435 if update_mysql_to_version != '5.7':
436 galera_mysql_version = update_mysql_to_version
437 mysql_version = "parameters:\n" \
438 " _param:\n" \
439 " galera_mysql_version: {}"\
440 .format(galera_mysql_version)
441 if not os.path.isfile("/srv/salt/reclass/classes/{path}".format(
442 path=mysql_path)):
443 reclass.create_yaml_with_context(mysql_version,
444 mysql_path)
445 else:
446 reclass.merge_context(mysql_version,
447 mysql_path)
448 reclass_actions.commit(
449 "[from TCP-QA] Change for mysql new version")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300450
PGlazov7efe3b22022-02-16 17:29:05 +0400451 show_step(3)
Vladimir Khlyunev17468272022-06-29 16:19:36 +0400452 salt.run_state("I@jenkins:client and not I@salt:master",
453 "saltutil.refresh_pillar")
454 salt.enforce_state("I@jenkins:client and not I@salt:master",
455 "jenkins.client.job")
PGlazov7efe3b22022-02-16 17:29:05 +0400456 else:
457 LOG.info("Skip mysql upgrade fix")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300458 # ############### Enable automatic upgrade ############################
PGlazov7efe3b22022-02-16 17:29:05 +0400459 show_step(4)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300460 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
461 "True",
462 "cluster/*/infra/init.yml")
463
PGlazov7efe3b22022-02-16 17:29:05 +0400464 show_step(5)
Hanna Arhipova7cfeb072019-10-11 15:04:10 +0300465 salt.run_state("dbs*", "saltutil.refresh_pillar")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300466
467 # ############# Add repositories with new Galera packages #######
PGlazov7efe3b22022-02-16 17:29:05 +0400468 show_step(6)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300469 salt.enforce_state("dbs*", "linux.system.repo")
470 salt.enforce_state("cfg*", "salt.master")
471
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300472 # #################### Login Jenkins on cid01 node ###################
PGlazov7efe3b22022-02-16 17:29:05 +0400473 show_step(7)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300474
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300475 job_name = 'deploy-upgrade-galera'
476 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300477 'INTERACTIVE': 'false',
478 'OS_DIST_UPGRADE': 'true',
PGlazov7efe3b22022-02-16 17:29:05 +0400479 'OS_UPGRADE': 'true',
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300480 }
PGlazov554c4fd2022-03-23 14:31:41 +0400481 if (update_mysql_to_version == '5.7'):
PGlazov7efe3b22022-02-16 17:29:05 +0400482 job_parameters.update({'UPDATE_TO_MYSQL57': 'true'})
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300483
Hanna Arhipova508f6532021-01-27 15:52:45 +0200484 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300485 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300486 job_parameters=job_parameters,
487 build_timeout=40 * 60)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300488
Hanna Arhipova508f6532021-01-27 15:52:45 +0200489 assert job_result == 'SUCCESS', job_description
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300490
491 @pytest.fixture
492 def disable_automatic_failover_neutron_for_test(self, salt_actions):
493 """
494 On each OpenStack controller node, modify the neutron.conf file
495 Restart the neutron-server service
496 """
Hanna Arhipova19429962019-10-17 15:16:49 +0300497
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300498 def comment_line(node, file_name, word):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300499 """
500 Adds '#' before the specific line in specific file
501
502 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300503 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300504 :param word: string, the begin of line which should be commented
505 :return: None
506 """
507 salt_actions.cmd_run(node,
508 "sed -i 's/^{word}/#{word}/' {file}".
509 format(word=word,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300510 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300511
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300512 def add_line(node, file_name, line):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300513 """
514 Appends line to the end of file
515
516 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300517 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300518 :param line: string, line that should be added
519 :return: None
520 """
521 salt_actions.cmd_run(node, "echo {line} >> {file}".format(
Hanna Arhipova19429962019-10-17 15:16:49 +0300522 line=line,
523 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300524
525 neutron_conf = '/etc/neutron/neutron.conf'
526 neutron_server = "I@neutron:server"
527 # ######## Create backup for config file #######################
528 salt_actions.cmd_run(
529 neutron_server,
530 "cp -p {file} {file}.backup".format(file=neutron_conf))
531
532 # ## Change parameters in neutron.conf'
533 comment_line(neutron_server, neutron_conf,
Hanna Arhipova19429962019-10-17 15:16:49 +0300534 "allow_automatic_l3agent_failover", )
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300535 comment_line(neutron_server, neutron_conf,
536 "allow_automatic_dhcp_failover")
537 add_line(neutron_server, neutron_conf,
538 "allow_automatic_dhcp_failover = false")
539 add_line(neutron_server, neutron_conf,
540 "allow_automatic_l3agent_failover = false")
541
542 # ## Apply changed config to the neutron-server service
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300543 result = salt_actions.cmd_run(neutron_server,
544 "service neutron-server restart")
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300545 # TODO: add check that neutron-server is up and running
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300546 yield result
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300547 # ## Revert file changes
548 salt_actions.cmd_run(
549 neutron_server,
550 "cp -p {file}.backup {file}".format(file=neutron_conf))
551 salt_actions.cmd_run(neutron_server,
552 "service neutron-server restart")
553
554 @pytest.fixture
555 def disable_neutron_agents_for_test(self, salt_actions):
556 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300557 Disable the neutron services before the test and
558 enable it after test
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300559 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300560 result = salt_actions.cmd_run("I@neutron:server", """
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300561 service neutron-dhcp-agent stop && \
562 service neutron-l3-agent stop && \
563 service neutron-metadata-agent stop && \
564 service neutron-openvswitch-agent stop
565 """)
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300566 yield result
567 #
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300568 salt_actions.cmd_run("I@neutron:server", """
569 service neutron-dhcp-agent start && \
570 service neutron-l3-agent start && \
571 service neutron-metadata-agent start && \
572 service neutron-openvswitch-agent start
573 """)
574 # TODO: add check that all services are UP and running
575
576 @pytest.mark.grab_versions
577 @pytest.mark.parametrize("_", [settings.ENV_NAME])
578 @pytest.mark.run_mcp_update
579 def test_update_rabbit(self, salt_actions, reclass_actions,
580 drivetrain_actions, show_step, _,
581 disable_automatic_failover_neutron_for_test,
582 disable_neutron_agents_for_test):
583 """ Updates RabbitMQ
584 Scenario:
585 1. Include the RabbitMQ upgrade pipeline job to DriveTrain
586 2. Add repositories with new RabbitMQ packages
587 3. Start Deploy - upgrade RabbitMQ pipeline
588
589 Updating RabbitMq should be completed before the OpenStack updating
590 process starts
591 """
592 salt = salt_actions
593 reclass = reclass_actions
594 dt = drivetrain_actions
595
596 # ####### Include the RabbitMQ upgrade pipeline job to DriveTrain ####
597 show_step(1)
598 reclass.add_class(
599 "system.jenkins.client.job.deploy.update.upgrade_rabbitmq",
600 "cluster/*/cicd/control/leader.yml")
601 salt.enforce_state("I@jenkins:client", "jenkins.client")
602
603 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
604 "True",
605 "cluster/*/infra/init.yml")
606 salt.run_state("I@rabbitmq:server", "saltutil.refresh_pillar")
607
608 # ########### Add repositories with new RabbitMQ packages ############
609 show_step(2)
610 salt.enforce_state("I@rabbitmq:server", "linux.system.repo")
611
612 # ########### Start Deploy - upgrade RabbitMQ pipeline ############
613 show_step(3)
614 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300615 'INTERACTIVE': 'false',
616 'OS_DIST_UPGRADE': 'true',
617 'OS_UPGRADE': 'true'
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300618 }
619
Hanna Arhipova508f6532021-01-27 15:52:45 +0200620 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300621 job_name='deploy-upgrade-rabbitmq',
622 job_parameters=job_parameters,
PGlazov99364cb2021-09-20 12:36:18 +0400623 build_timeout=50 * 60
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300624 )
Hanna Arhipova508f6532021-01-27 15:52:45 +0200625 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300626
627 @pytest.mark.grab_versions
628 @pytest.mark.parametrize("_", [settings.ENV_NAME])
629 @pytest.mark.run_mcp_update
PGlazov215a4572022-03-05 05:09:04 +0400630 def test_update_ceph(self, salt_actions, drivetrain_actions,
631 reclass_actions, show_step, _):
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300632 """ Updates Ceph to the latest minor version
633
634 Scenario:
635 1. Add workaround for unhealth Ceph
636 2. Start ceph-upgrade job with default parameters
637 3. Check Ceph version for all nodes
PGlazov215a4572022-03-05 05:09:04 +0400638 4. WA id_reclaim only for nautilus
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300639
640 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update/ceph-update.html
641 """
642 salt = salt_actions
PGlazov215a4572022-03-05 05:09:04 +0400643 reclass = reclass_actions
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300644 dt = drivetrain_actions
645
646 # ###################### Add workaround for unhealth Ceph ############
647 show_step(1)
648 salt.cmd_run("I@ceph:radosgw",
649 "ceph config set 'mon pg warn max object skew' 20")
650 # ###################### Start ceph-upgrade pipeline #################
651 show_step(2)
652 job_parameters = {}
653
Hanna Arhipova508f6532021-01-27 15:52:45 +0200654 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300655 job_name='ceph-update',
656 job_parameters=job_parameters)
657
Hanna Arhipova508f6532021-01-27 15:52:45 +0200658 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300659
660 # ########## Verify Ceph version #####################################
661 show_step(3)
662
663 ceph_version_by_nodes = salt.cmd_run(
Hanna Arhipova19429962019-10-17 15:16:49 +0300664 "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server",
665 "ceph version")[0]
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300666
667 assert has_only_similar(ceph_version_by_nodes), ceph_version_by_nodes
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300668
PGlazov215a4572022-03-05 05:09:04 +0400669 # ########## WA id_reclaim only for nautilus #########################
670 show_step(4)
671
672 ceph_version = salt_actions.get_single_pillar(
673 "I@salt:master",
674 "_param:_param:ceph_version")
675 if ceph_version == "nautilus":
676 wa_cve_2021_20288_global_id_reclaim(reclass, salt)
677 else:
678 LOG.info("Skip WA for luminous")
679
Hanna Arhipovaac008562019-10-17 11:54:23 +0300680 @pytest.mark.grab_versions
681 @pytest.mark.parametrize("_", [settings.ENV_NAME])
682 @pytest.mark.run_mcp_update
683 def test_update_stacklight(self, _, drivetrain_actions):
684 """ Update packages for Stacklight
685 Scenario:
686 1. Start Deploy - upgrade Stacklight job
687 """
688 drivetrain = drivetrain_actions
689
690 job_parameters = {
691 "STAGE_UPGRADE_DOCKER_COMPONENTS": True,
692 "STAGE_UPGRADE_ES_KIBANA": True,
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300693 "STAGE_UPGRADE_SYSTEM_PART": True,
694 'OS_DIST_UPGRADE': 'true',
695 'OS_UPGRADE': 'true'
Hanna Arhipovaac008562019-10-17 11:54:23 +0300696 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200697 job_result, job_description = drivetrain.start_job_on_jenkins(
Hanna Arhipovaac008562019-10-17 11:54:23 +0300698 job_name="stacklight-upgrade",
699 job_parameters=job_parameters)
700
Hanna Arhipova508f6532021-01-27 15:52:45 +0200701 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaac008562019-10-17 11:54:23 +0300702
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300703
Hanna Arhipova19429962019-10-17 15:16:49 +0300704@pytest.mark.usefixtures("switch_to_proposed_pipelines",
705 "enable_openstack_update")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300706class TestOpenstackUpdate(object):
707
708 @pytest.mark.grab_versions
709 @pytest.mark.run_mcp_update
710 def test__pre_update__enable_pipeline_job(self,
711 reclass_actions, salt_actions,
712 show_step):
713 """ Enable pipeline in the Drivetrain
714
715 Scenario:
716 1. Add deploy.update.* classes to the reclass
717 2. Start jenkins.client salt state
718
719 """
720 salt = salt_actions
721 reclass = reclass_actions
722 show_step(1)
723 reclass.add_class("system.jenkins.client.job.deploy.update.upgrade",
724 "cluster/*/cicd/control/leader.yml")
725
726 reclass.add_class(
727 "system.jenkins.client.job.deploy.update.upgrade_ovs_gateway",
728 "cluster/*/cicd/control/leader.yml")
729
730 reclass.add_class(
731 "system.jenkins.client.job.deploy.update.upgrade_compute",
732 "cluster/*/cicd/control/leader.yml")
733
734 show_step(2)
735 r, errors = salt.enforce_state("I@jenkins:client", "jenkins.client")
736 assert errors is None
737
738 @pytest.mark.grab_versions
739 @pytest.mark.parametrize('target', get_control_plane_targets())
740 @pytest.mark.run_mcp_update
Hanna Arhipova19429962019-10-17 15:16:49 +0300741 def test__update__control_plane(self, drivetrain_actions, target):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300742 """Start 'Deploy - upgrade control VMs' for specific node
743 """
744 job_parameters = {
745 "TARGET_SERVERS": target,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200746 "OS_DIST_UPGRADE": True,
PGlazova5039252021-10-06 21:40:01 +0400747 "UPGRADE_SALTSTACK": True,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200748 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300749 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200750 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300751 job_name="deploy-upgrade-control",
752 job_parameters=job_parameters)
753
Hanna Arhipova508f6532021-01-27 15:52:45 +0200754 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300755
756 @pytest.mark.grab_versions
757 @pytest.mark.run_mcp_update
Hanna Arhipova606d5182019-12-13 13:23:55 +0200758 def test__update__data_plane(self, drivetrain_actions, salt_actions):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300759 """Start 'Deploy - upgrade OVS gateway'
760 """
Hanna Arhipova606d5182019-12-13 13:23:55 +0200761 if not salt_actions.cmd_run("gtw*", "test.ping")[0].keys():
762 pytest.skip("This deployment doesn't have gtw* nodes")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300763 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200764 "OS_DIST_UPGRADE": True,
765 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300766 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200767 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300768 job_name="deploy-upgrade-ovs-gateway",
769 job_parameters=job_parameters)
770
Hanna Arhipova508f6532021-01-27 15:52:45 +0200771 assert job_result == 'SUCCESS', job_description
Hanna Arhipova19429962019-10-17 15:16:49 +0300772
773 @pytest.mark.grab_versions
774 @pytest.mark.run_mcp_update
775 def test__update__computes(self, drivetrain_actions):
776 """Start 'Deploy - upgrade computes'
777 """
778 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200779 "OS_DIST_UPGRADE": True,
780 "OS_UPGRADE": True,
Hanna Arhipova19429962019-10-17 15:16:49 +0300781 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200782 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipova19429962019-10-17 15:16:49 +0300783 job_name="deploy-upgrade-compute",
784 job_parameters=job_parameters)
785
Hanna Arhipova508f6532021-01-27 15:52:45 +0200786 assert job_result == 'SUCCESS', job_description