blob: 6c1c257bcc8d58ef8a4ba04a31bc18685b6c66e5 [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
Hanna Arhipova19429962019-10-17 15:16:49 +0300183@pytest.fixture(scope='class')
184def enable_openstack_update(reclass_actions, salt_actions):
185 param = "parameters._param.openstack_upgrade_enabled"
186 context_file = "cluster/*/infra/init.yml"
187
188 LOG.info("Enable openstack_upgrade_enabled in reclass")
189 reclass_actions.add_bool_key(param, "True", context_file)
190 salt_actions.run_state("*", "saltutil.refresh_pillar")
191 yield True
192 LOG.info("Disable openstack_upgrade_enabled in reclass")
193 reclass_actions.add_bool_key(param, "False", context_file)
194 salt_actions.run_state("*", "saltutil.refresh_pillar")
195
196
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300197@pytest.mark.usefixtures("switch_to_proposed_pipelines",
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300198 "update_to_tag",
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200199 "wa_for_galera_clustercheck_password_prod35705",
PGlazov215a4572022-03-05 05:09:04 +0400200 "wa_for_alerta_password_prod35958")
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300201class TestUpdateMcpCluster(object):
202 """
203 Following the steps in
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300204 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update.html#minor-update
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300205 """
206
207 @pytest.mark.grab_versions
208 @pytest.mark.parametrize("_", [settings.ENV_NAME])
209 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300210 def test_update_drivetrain(self, salt_actions, drivetrain_actions,
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300211 show_step, update_to_tag, _):
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300212 """Updating DriveTrain component to release/proposed/2019.2.0 version
213
214 Scenario:
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300215 1. Add workaround for PROD-32751
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300216 2. Run job git-mirror-downstream-mk-pipelines
217 3. Run job git-mirror-downstream-pipeline-library
dtsapikovcbff2332022-01-19 19:32:22 +0400218 4. Run job pre-upgrade-verify
219 5. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain'
220 6. Wait till salt-master completes all async jobs
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300221
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300222 Duration: ~70 min
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300223 """
224 salt = salt_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300225 dt = drivetrain_actions
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300226
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300227 # #################### Add workaround for PROD-32751 #################
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300228 show_step(1)
229
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300230 # FIXME: workaround for PROD-32751
231 salt.cmd_run("cfg01*", "cd /srv/salt/reclass; git add -u && \
232 git commit --allow-empty -m 'Cluster model update'")
233
234 # ################### Downstream mk-pipelines #########################
235 show_step(2)
236 job_name = 'git-mirror-downstream-mk-pipelines'
237 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300238 'BRANCHES': '*' or
239 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300240 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200241 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300242 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300243 job_parameters=job_parameters,
244 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300245
Hanna Arhipova508f6532021-01-27 15:52:45 +0200246 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300247
248 # ################### Downstream pipeline-library ####################
249 show_step(3)
250 job_name = 'git-mirror-downstream-pipeline-library'
251 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300252 'BRANCHES': '*' or
253 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300254 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200255 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300256 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300257 job_parameters=job_parameters,
258 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300259
Hanna Arhipova508f6532021-01-27 15:52:45 +0200260 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300261
dtsapikovcbff2332022-01-19 19:32:22 +0400262 # ############### Start 'Pre-upgrade verify' job (since 2019.2.17)#####
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300263 show_step(4)
dtsapikovcbff2332022-01-19 19:32:22 +0400264 job_name = 'pre-upgrade-verify'
265 job_parameters = {}
266
267 if(dt.check_job_exists_on_jenkins(job_name)):
268 LOG.info("Pre-upgrade verify job exists on Jenkins!")
269 job_result, job_description = dt.start_job_on_jenkins(
270 job_name=job_name,
271 job_parameters=job_parameters,
272 verbose=True,
273 build_timeout=4 * 60 * 60)
274
275 assert job_result == 'SUCCESS', job_description
276
277 # ################### Start 'Deploy - upgrade MCP Drivetrain' job #####
278 show_step(5)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300279
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300280 job_name = 'upgrade-mcp-release'
281 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300282 'GIT_REFSPEC': update_to_tag or 'release/proposed/2019.2.0',
PGlazov1df9e542021-11-16 02:31:49 +0400283 'MK_PIPELINES_REFSPEC':
284 update_to_tag or 'release/proposed/2019.2.0',
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300285 'TARGET_MCP_VERSION': update_to_tag or '2019.2.0',
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300286 "DRIVE_TRAIN_PARAMS": {
287 "OS_DIST_UPGRADE": True,
288 "OS_UPGRADE": True,
289 "BATCH_SIZE": 10
290 }
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300291 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200292 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300293 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300294 job_parameters=job_parameters,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300295 verbose=True,
Hanna Arhipovae7f2e322021-02-25 13:53:18 +0200296 build_timeout=4 * 60 * 60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300297
Hanna Arhipova508f6532021-01-27 15:52:45 +0200298 assert job_result == 'SUCCESS', job_description
Hanna Arhipova7a593da2021-06-25 11:16:09 +0300299 # ############### Wait till salt-master completes all async jobs #####
300 show_step(5)
301 salt.wait_jobs_completed(timeout=20*60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300302
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300303 @pytest.mark.grab_versions
304 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300305 @pytest.mark.run_mcp_update
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300306 def test_update_glusterfs(self, salt_actions, reclass_actions,
PGlazov7efe3b22022-02-16 17:29:05 +0400307 drivetrain_actions, show_step,
308 update_mysql_to_version, _):
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300309 """ Upgrade GlusterFS
310 Scenario:
311 1. In infra/init.yml in Reclass, add the glusterfs_version parameter
312 2. Start linux.system.repo state
313 3. Start "update-glusterfs" job
314 4. Check version for GlusterFS servers
315 5. Check version for GlusterFS clients
316
317 """
PGlazov7efe3b22022-02-16 17:29:05 +0400318
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300319 salt = salt_actions
320 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300321 dt = drivetrain_actions
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300322
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300323 # ############## Change reclass ######################################
324 show_step(1)
325 reclass.add_key(
326 "parameters._param.linux_system_repo_mcp_glusterfs_version_number",
327 "5",
328 "cluster/*/infra/init.yml"
329 )
330 # ################# Run linux.system state ###########################
331 show_step(2)
332 salt.enforce_state("*", "linux.system.repo")
333
334 # ############## Start deploy-upgrade-galera job #####################
335 show_step(3)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300336 job_name = 'update-glusterfs'
337
Hanna Arhipova508f6532021-01-27 15:52:45 +0200338 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300339 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300340 build_timeout=40 * 60)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300341
Hanna Arhipova508f6532021-01-27 15:52:45 +0200342 assert job_result == 'SUCCESS', job_description
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300343
344 # ################ Check GlusterFS version for servers ##############
345 show_step(4)
346 gluster_server_versions_by_nodes = salt.cmd_run(
347 "I@glusterfs:server",
348 "glusterd --version|head -n1")[0]
349
Hanna Arhipova19429962019-10-17 15:16:49 +0300350 assert has_only_similar(gluster_server_versions_by_nodes), \
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300351 gluster_server_versions_by_nodes
352
353 # ################ Check GlusterFS version for clients ##############
354 show_step(5)
355 gluster_client_versions_by_nodes = salt.cmd_run(
356 "I@glusterfs:client",
357 "glusterfs --version|head -n1")[0]
358
359 assert has_only_similar(gluster_client_versions_by_nodes), \
360 gluster_client_versions_by_nodes
361
362 @pytest.mark.grab_versions
363 @pytest.mark.parametrize("_", [settings.ENV_NAME])
364 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300365 def test_update_galera(self, salt_actions, reclass_actions,
PGlazov7efe3b22022-02-16 17:29:05 +0400366 drivetrain_actions, show_step,
367 update_mysql_to_version, _):
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300368 """ Upgrade Galera automatically
369
370 Scenario:
371 1. Include the Galera upgrade pipeline job to DriveTrain
PGlazov7efe3b22022-02-16 17:29:05 +0400372 2. Add fix for mysql 5.7
373 3. Apply the jenkins.client state on the Jenkins nodes
374 4. set the openstack_upgrade_enabled parameter to true
375 5. Refresh pillars
376 6. Add repositories with new Galera packages
377 7. Start job from Jenkins
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300378 """
379 salt = salt_actions
380 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300381 dt = drivetrain_actions
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300382 # ################### Enable pipeline #################################
383 show_step(1)
384 reclass.add_class(
385 "system.jenkins.client.job.deploy.update.upgrade_galera",
386 "cluster/*/cicd/control/leader.yml")
PGlazov7efe3b22022-02-16 17:29:05 +0400387 # ################### Fix for Mysql 5.7 ##############################
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300388 show_step(2)
PGlazov7efe3b22022-02-16 17:29:05 +0400389 if (update_mysql_to_version == '5.7'):
PGlazov7efe3b22022-02-16 17:29:05 +0400390 mysql_class = "cluster.{env_name}.openstack." \
391 "database.mysql_version"\
392 .format(env_name=settings.ENV_NAME)
393 reclass.add_class(
394 mysql_class,
395 "cluster/*/openstack/database/master.yml")
396 reclass.add_class(
397 mysql_class,
398 "cluster/*/openstack/database/slave.yml")
399 mysql_path = "cluster/{env_name}" \
400 "/openstack/database/mysql_version.yml"\
401 .format(env_name=settings.ENV_NAME)
402 galera_mysql_version = '5.7'
403 if update_mysql_to_version != '5.7':
404 galera_mysql_version = update_mysql_to_version
405 mysql_version = "parameters:\n" \
406 " _param:\n" \
407 " galera_mysql_version: {}"\
408 .format(galera_mysql_version)
409 if not os.path.isfile("/srv/salt/reclass/classes/{path}".format(
410 path=mysql_path)):
411 reclass.create_yaml_with_context(mysql_version,
412 mysql_path)
413 else:
414 reclass.merge_context(mysql_version,
415 mysql_path)
416 reclass_actions.commit(
417 "[from TCP-QA] Change for mysql new version")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300418
PGlazov7efe3b22022-02-16 17:29:05 +0400419 show_step(3)
Vladimir Khlyunev17468272022-06-29 16:19:36 +0400420 salt.run_state("I@jenkins:client and not I@salt:master",
421 "saltutil.refresh_pillar")
422 salt.enforce_state("I@jenkins:client and not I@salt:master",
423 "jenkins.client.job")
PGlazov7efe3b22022-02-16 17:29:05 +0400424 else:
425 LOG.info("Skip mysql upgrade fix")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300426 # ############### Enable automatic upgrade ############################
PGlazov7efe3b22022-02-16 17:29:05 +0400427 show_step(4)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300428 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
429 "True",
430 "cluster/*/infra/init.yml")
431
PGlazov7efe3b22022-02-16 17:29:05 +0400432 show_step(5)
Hanna Arhipova7cfeb072019-10-11 15:04:10 +0300433 salt.run_state("dbs*", "saltutil.refresh_pillar")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300434
435 # ############# Add repositories with new Galera packages #######
PGlazov7efe3b22022-02-16 17:29:05 +0400436 show_step(6)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300437 salt.enforce_state("dbs*", "linux.system.repo")
438 salt.enforce_state("cfg*", "salt.master")
439
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300440 # #################### Login Jenkins on cid01 node ###################
PGlazov7efe3b22022-02-16 17:29:05 +0400441 show_step(7)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300442
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300443 job_name = 'deploy-upgrade-galera'
444 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300445 'INTERACTIVE': 'false',
446 'OS_DIST_UPGRADE': 'true',
PGlazov7efe3b22022-02-16 17:29:05 +0400447 'OS_UPGRADE': 'true',
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300448 }
PGlazov554c4fd2022-03-23 14:31:41 +0400449 if (update_mysql_to_version == '5.7'):
PGlazov7efe3b22022-02-16 17:29:05 +0400450 job_parameters.update({'UPDATE_TO_MYSQL57': 'true'})
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300451
Hanna Arhipova508f6532021-01-27 15:52:45 +0200452 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300453 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300454 job_parameters=job_parameters,
455 build_timeout=40 * 60)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300456
Hanna Arhipova508f6532021-01-27 15:52:45 +0200457 assert job_result == 'SUCCESS', job_description
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300458
459 @pytest.fixture
460 def disable_automatic_failover_neutron_for_test(self, salt_actions):
461 """
462 On each OpenStack controller node, modify the neutron.conf file
463 Restart the neutron-server service
464 """
Hanna Arhipova19429962019-10-17 15:16:49 +0300465
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300466 def comment_line(node, file_name, word):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300467 """
468 Adds '#' before the specific line in specific file
469
470 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300471 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300472 :param word: string, the begin of line which should be commented
473 :return: None
474 """
475 salt_actions.cmd_run(node,
476 "sed -i 's/^{word}/#{word}/' {file}".
477 format(word=word,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300478 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300479
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300480 def add_line(node, file_name, line):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300481 """
482 Appends line to the end of file
483
484 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300485 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300486 :param line: string, line that should be added
487 :return: None
488 """
489 salt_actions.cmd_run(node, "echo {line} >> {file}".format(
Hanna Arhipova19429962019-10-17 15:16:49 +0300490 line=line,
491 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300492
493 neutron_conf = '/etc/neutron/neutron.conf'
494 neutron_server = "I@neutron:server"
495 # ######## Create backup for config file #######################
496 salt_actions.cmd_run(
497 neutron_server,
498 "cp -p {file} {file}.backup".format(file=neutron_conf))
499
500 # ## Change parameters in neutron.conf'
501 comment_line(neutron_server, neutron_conf,
Hanna Arhipova19429962019-10-17 15:16:49 +0300502 "allow_automatic_l3agent_failover", )
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300503 comment_line(neutron_server, neutron_conf,
504 "allow_automatic_dhcp_failover")
505 add_line(neutron_server, neutron_conf,
506 "allow_automatic_dhcp_failover = false")
507 add_line(neutron_server, neutron_conf,
508 "allow_automatic_l3agent_failover = false")
509
510 # ## Apply changed config to the neutron-server service
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300511 result = salt_actions.cmd_run(neutron_server,
512 "service neutron-server restart")
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300513 # TODO: add check that neutron-server is up and running
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300514 yield result
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300515 # ## Revert file changes
516 salt_actions.cmd_run(
517 neutron_server,
518 "cp -p {file}.backup {file}".format(file=neutron_conf))
519 salt_actions.cmd_run(neutron_server,
520 "service neutron-server restart")
521
522 @pytest.fixture
523 def disable_neutron_agents_for_test(self, salt_actions):
524 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300525 Disable the neutron services before the test and
526 enable it after test
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300527 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300528 result = salt_actions.cmd_run("I@neutron:server", """
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300529 service neutron-dhcp-agent stop && \
530 service neutron-l3-agent stop && \
531 service neutron-metadata-agent stop && \
532 service neutron-openvswitch-agent stop
533 """)
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300534 yield result
535 #
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300536 salt_actions.cmd_run("I@neutron:server", """
537 service neutron-dhcp-agent start && \
538 service neutron-l3-agent start && \
539 service neutron-metadata-agent start && \
540 service neutron-openvswitch-agent start
541 """)
542 # TODO: add check that all services are UP and running
543
544 @pytest.mark.grab_versions
545 @pytest.mark.parametrize("_", [settings.ENV_NAME])
546 @pytest.mark.run_mcp_update
547 def test_update_rabbit(self, salt_actions, reclass_actions,
548 drivetrain_actions, show_step, _,
549 disable_automatic_failover_neutron_for_test,
550 disable_neutron_agents_for_test):
551 """ Updates RabbitMQ
552 Scenario:
553 1. Include the RabbitMQ upgrade pipeline job to DriveTrain
554 2. Add repositories with new RabbitMQ packages
555 3. Start Deploy - upgrade RabbitMQ pipeline
556
557 Updating RabbitMq should be completed before the OpenStack updating
558 process starts
559 """
560 salt = salt_actions
561 reclass = reclass_actions
562 dt = drivetrain_actions
563
564 # ####### Include the RabbitMQ upgrade pipeline job to DriveTrain ####
565 show_step(1)
566 reclass.add_class(
567 "system.jenkins.client.job.deploy.update.upgrade_rabbitmq",
568 "cluster/*/cicd/control/leader.yml")
569 salt.enforce_state("I@jenkins:client", "jenkins.client")
570
571 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
572 "True",
573 "cluster/*/infra/init.yml")
574 salt.run_state("I@rabbitmq:server", "saltutil.refresh_pillar")
575
576 # ########### Add repositories with new RabbitMQ packages ############
577 show_step(2)
578 salt.enforce_state("I@rabbitmq:server", "linux.system.repo")
579
580 # ########### Start Deploy - upgrade RabbitMQ pipeline ############
581 show_step(3)
582 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300583 'INTERACTIVE': 'false',
584 'OS_DIST_UPGRADE': 'true',
585 'OS_UPGRADE': 'true'
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300586 }
587
Hanna Arhipova508f6532021-01-27 15:52:45 +0200588 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300589 job_name='deploy-upgrade-rabbitmq',
590 job_parameters=job_parameters,
PGlazov99364cb2021-09-20 12:36:18 +0400591 build_timeout=50 * 60
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300592 )
Hanna Arhipova508f6532021-01-27 15:52:45 +0200593 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300594
595 @pytest.mark.grab_versions
596 @pytest.mark.parametrize("_", [settings.ENV_NAME])
597 @pytest.mark.run_mcp_update
PGlazov215a4572022-03-05 05:09:04 +0400598 def test_update_ceph(self, salt_actions, drivetrain_actions,
599 reclass_actions, show_step, _):
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300600 """ Updates Ceph to the latest minor version
601
602 Scenario:
603 1. Add workaround for unhealth Ceph
604 2. Start ceph-upgrade job with default parameters
605 3. Check Ceph version for all nodes
PGlazov215a4572022-03-05 05:09:04 +0400606 4. WA id_reclaim only for nautilus
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300607
608 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update/ceph-update.html
609 """
610 salt = salt_actions
PGlazov215a4572022-03-05 05:09:04 +0400611 reclass = reclass_actions
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300612 dt = drivetrain_actions
613
614 # ###################### Add workaround for unhealth Ceph ############
615 show_step(1)
616 salt.cmd_run("I@ceph:radosgw",
617 "ceph config set 'mon pg warn max object skew' 20")
618 # ###################### Start ceph-upgrade pipeline #################
619 show_step(2)
620 job_parameters = {}
621
Hanna Arhipova508f6532021-01-27 15:52:45 +0200622 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300623 job_name='ceph-update',
624 job_parameters=job_parameters)
625
Hanna Arhipova508f6532021-01-27 15:52:45 +0200626 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300627
628 # ########## Verify Ceph version #####################################
629 show_step(3)
630
631 ceph_version_by_nodes = salt.cmd_run(
Hanna Arhipova19429962019-10-17 15:16:49 +0300632 "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server",
633 "ceph version")[0]
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300634
635 assert has_only_similar(ceph_version_by_nodes), ceph_version_by_nodes
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300636
PGlazov215a4572022-03-05 05:09:04 +0400637 # ########## WA id_reclaim only for nautilus #########################
638 show_step(4)
639
640 ceph_version = salt_actions.get_single_pillar(
641 "I@salt:master",
642 "_param:_param:ceph_version")
643 if ceph_version == "nautilus":
644 wa_cve_2021_20288_global_id_reclaim(reclass, salt)
645 else:
646 LOG.info("Skip WA for luminous")
647
Hanna Arhipovaac008562019-10-17 11:54:23 +0300648 @pytest.mark.grab_versions
649 @pytest.mark.parametrize("_", [settings.ENV_NAME])
650 @pytest.mark.run_mcp_update
651 def test_update_stacklight(self, _, drivetrain_actions):
652 """ Update packages for Stacklight
653 Scenario:
654 1. Start Deploy - upgrade Stacklight job
655 """
656 drivetrain = drivetrain_actions
657
658 job_parameters = {
659 "STAGE_UPGRADE_DOCKER_COMPONENTS": True,
660 "STAGE_UPGRADE_ES_KIBANA": True,
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300661 "STAGE_UPGRADE_SYSTEM_PART": True,
662 'OS_DIST_UPGRADE': 'true',
663 'OS_UPGRADE': 'true'
Hanna Arhipovaac008562019-10-17 11:54:23 +0300664 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200665 job_result, job_description = drivetrain.start_job_on_jenkins(
Hanna Arhipovaac008562019-10-17 11:54:23 +0300666 job_name="stacklight-upgrade",
667 job_parameters=job_parameters)
668
Hanna Arhipova508f6532021-01-27 15:52:45 +0200669 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaac008562019-10-17 11:54:23 +0300670
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300671
Hanna Arhipova19429962019-10-17 15:16:49 +0300672@pytest.mark.usefixtures("switch_to_proposed_pipelines",
673 "enable_openstack_update")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300674class TestOpenstackUpdate(object):
675
676 @pytest.mark.grab_versions
677 @pytest.mark.run_mcp_update
678 def test__pre_update__enable_pipeline_job(self,
679 reclass_actions, salt_actions,
680 show_step):
681 """ Enable pipeline in the Drivetrain
682
683 Scenario:
684 1. Add deploy.update.* classes to the reclass
685 2. Start jenkins.client salt state
686
687 """
688 salt = salt_actions
689 reclass = reclass_actions
690 show_step(1)
691 reclass.add_class("system.jenkins.client.job.deploy.update.upgrade",
692 "cluster/*/cicd/control/leader.yml")
693
694 reclass.add_class(
695 "system.jenkins.client.job.deploy.update.upgrade_ovs_gateway",
696 "cluster/*/cicd/control/leader.yml")
697
698 reclass.add_class(
699 "system.jenkins.client.job.deploy.update.upgrade_compute",
700 "cluster/*/cicd/control/leader.yml")
701
702 show_step(2)
703 r, errors = salt.enforce_state("I@jenkins:client", "jenkins.client")
704 assert errors is None
705
706 @pytest.mark.grab_versions
707 @pytest.mark.parametrize('target', get_control_plane_targets())
708 @pytest.mark.run_mcp_update
Hanna Arhipova19429962019-10-17 15:16:49 +0300709 def test__update__control_plane(self, drivetrain_actions, target):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300710 """Start 'Deploy - upgrade control VMs' for specific node
711 """
712 job_parameters = {
713 "TARGET_SERVERS": target,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200714 "OS_DIST_UPGRADE": True,
PGlazova5039252021-10-06 21:40:01 +0400715 "UPGRADE_SALTSTACK": True,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200716 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300717 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200718 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300719 job_name="deploy-upgrade-control",
720 job_parameters=job_parameters)
721
Hanna Arhipova508f6532021-01-27 15:52:45 +0200722 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300723
724 @pytest.mark.grab_versions
725 @pytest.mark.run_mcp_update
Hanna Arhipova606d5182019-12-13 13:23:55 +0200726 def test__update__data_plane(self, drivetrain_actions, salt_actions):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300727 """Start 'Deploy - upgrade OVS gateway'
728 """
Hanna Arhipova606d5182019-12-13 13:23:55 +0200729 if not salt_actions.cmd_run("gtw*", "test.ping")[0].keys():
730 pytest.skip("This deployment doesn't have gtw* nodes")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300731 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200732 "OS_DIST_UPGRADE": True,
733 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300734 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200735 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300736 job_name="deploy-upgrade-ovs-gateway",
737 job_parameters=job_parameters)
738
Hanna Arhipova508f6532021-01-27 15:52:45 +0200739 assert job_result == 'SUCCESS', job_description
Hanna Arhipova19429962019-10-17 15:16:49 +0300740
741 @pytest.mark.grab_versions
742 @pytest.mark.run_mcp_update
743 def test__update__computes(self, drivetrain_actions):
744 """Start 'Deploy - upgrade computes'
745 """
746 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200747 "OS_DIST_UPGRADE": True,
748 "OS_UPGRADE": True,
Hanna Arhipova19429962019-10-17 15:16:49 +0300749 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200750 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipova19429962019-10-17 15:16:49 +0300751 job_name="deploy-upgrade-compute",
752 job_parameters=job_parameters)
753
Hanna Arhipova508f6532021-01-27 15:52:45 +0200754 assert job_result == 'SUCCESS', job_description