blob: 15c47553ce627056bf26c194af5105dc45ecc1bb [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(
Pavel Glazov6ed8d442022-09-20 12:50:18 +0400138 '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(
Pavel Glazov6ed8d442022-09-20 12:50:18 +0400146 'parameters.ceph.common.config.mon.' +
147 'auth_allow_insecure_global_id_reclaim', "False", context_file)
PGlazovf5977292021-11-25 19:38:27 +0400148 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
Vladimir Khlyunev0ca3ba82022-10-31 12:12:30 +0400228@pytest.fixture(scope='class')
229def switch_to_staging_updates_mirantis_repo(reclass_actions, salt_actions):
230 version_param = "parameters._param.updates_mirantis_version"
231 infra_yml = "cluster/*/infra/init.yml"
232
233 current_version = reclass_actions.get_key(version_param, infra_yml)
234 if current_version == 'staging':
235 LOG.info("updates.mirantis.com already set to 'staging', skipping")
236 return
237 if current_version is None:
238 LOG.info("updates.mirantis.com is not enabled, "
239 "skipping /staging repo pillar")
240 return
241
242 LOG.info("Switch to updates.mirantis.com/staging repo")
243 reclass_actions.add_key(version_param, 'staging', infra_yml)
244
245 salt_actions.run_state("*", "saltutil.refresh_pillar")
246
247
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300248@pytest.mark.usefixtures("switch_to_proposed_pipelines",
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300249 "update_to_tag",
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200250 "wa_for_galera_clustercheck_password_prod35705",
Vladimir Khlyunev5fe0aaa2022-08-16 23:13:22 +0400251 "wa_for_alerta_password_prod35958",
Vladimir Khlyunev0ca3ba82022-10-31 12:12:30 +0400252 "wa_redis_server_version_3_prod36960",
253 "switch_to_staging_updates_mirantis_repo")
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300254class TestUpdateMcpCluster(object):
255 """
256 Following the steps in
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300257 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update.html#minor-update
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300258 """
259
260 @pytest.mark.grab_versions
261 @pytest.mark.parametrize("_", [settings.ENV_NAME])
262 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300263 def test_update_drivetrain(self, salt_actions, drivetrain_actions,
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300264 show_step, update_to_tag, _):
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300265 """Updating DriveTrain component to release/proposed/2019.2.0 version
266
267 Scenario:
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300268 1. Add workaround for PROD-32751
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300269 2. Run job git-mirror-downstream-mk-pipelines
270 3. Run job git-mirror-downstream-pipeline-library
dtsapikovcbff2332022-01-19 19:32:22 +0400271 4. Run job pre-upgrade-verify
272 5. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain'
273 6. Wait till salt-master completes all async jobs
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300274
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300275 Duration: ~70 min
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300276 """
277 salt = salt_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300278 dt = drivetrain_actions
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300279
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300280 # #################### Add workaround for PROD-32751 #################
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300281 show_step(1)
282
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300283 # FIXME: workaround for PROD-32751
284 salt.cmd_run("cfg01*", "cd /srv/salt/reclass; git add -u && \
285 git commit --allow-empty -m 'Cluster model update'")
286
287 # ################### Downstream mk-pipelines #########################
288 show_step(2)
289 job_name = 'git-mirror-downstream-mk-pipelines'
290 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300291 'BRANCHES': '*' or
292 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300293 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200294 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300295 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300296 job_parameters=job_parameters,
297 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300298
Hanna Arhipova508f6532021-01-27 15:52:45 +0200299 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300300
301 # ################### Downstream pipeline-library ####################
302 show_step(3)
303 job_name = 'git-mirror-downstream-pipeline-library'
304 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300305 'BRANCHES': '*' or
306 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300307 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200308 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300309 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300310 job_parameters=job_parameters,
311 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300312
Hanna Arhipova508f6532021-01-27 15:52:45 +0200313 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300314
dtsapikovcbff2332022-01-19 19:32:22 +0400315 # ############### Start 'Pre-upgrade verify' job (since 2019.2.17)#####
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300316 show_step(4)
dtsapikovcbff2332022-01-19 19:32:22 +0400317 job_name = 'pre-upgrade-verify'
318 job_parameters = {}
319
Pavel Glazov794b1a92022-10-03 16:33:04 +0400320 if (dt.check_job_exists_on_jenkins(job_name)):
dtsapikovcbff2332022-01-19 19:32:22 +0400321 LOG.info("Pre-upgrade verify job exists on Jenkins!")
322 job_result, job_description = dt.start_job_on_jenkins(
323 job_name=job_name,
324 job_parameters=job_parameters,
325 verbose=True,
326 build_timeout=4 * 60 * 60)
327
328 assert job_result == 'SUCCESS', job_description
329
330 # ################### Start 'Deploy - upgrade MCP Drivetrain' job #####
331 show_step(5)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300332
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300333 job_name = 'upgrade-mcp-release'
334 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300335 'GIT_REFSPEC': update_to_tag or 'release/proposed/2019.2.0',
PGlazov1df9e542021-11-16 02:31:49 +0400336 'MK_PIPELINES_REFSPEC':
337 update_to_tag or 'release/proposed/2019.2.0',
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300338 'TARGET_MCP_VERSION': update_to_tag or '2019.2.0',
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300339 "DRIVE_TRAIN_PARAMS": {
340 "OS_DIST_UPGRADE": True,
341 "OS_UPGRADE": True,
342 "BATCH_SIZE": 10
343 }
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300344 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200345 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300346 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300347 job_parameters=job_parameters,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300348 verbose=True,
Hanna Arhipovae7f2e322021-02-25 13:53:18 +0200349 build_timeout=4 * 60 * 60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300350
Hanna Arhipova508f6532021-01-27 15:52:45 +0200351 assert job_result == 'SUCCESS', job_description
Hanna Arhipova7a593da2021-06-25 11:16:09 +0300352 # ############### Wait till salt-master completes all async jobs #####
353 show_step(5)
354 salt.wait_jobs_completed(timeout=20*60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300355
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300356 @pytest.mark.grab_versions
357 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300358 @pytest.mark.run_mcp_update
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300359 def test_update_glusterfs(self, salt_actions, reclass_actions,
PGlazov7efe3b22022-02-16 17:29:05 +0400360 drivetrain_actions, show_step,
361 update_mysql_to_version, _):
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300362 """ Upgrade GlusterFS
363 Scenario:
364 1. In infra/init.yml in Reclass, add the glusterfs_version parameter
365 2. Start linux.system.repo state
366 3. Start "update-glusterfs" job
367 4. Check version for GlusterFS servers
368 5. Check version for GlusterFS clients
369
370 """
PGlazov7efe3b22022-02-16 17:29:05 +0400371
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300372 salt = salt_actions
373 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300374 dt = drivetrain_actions
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300375
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300376 # ############## Change reclass ######################################
377 show_step(1)
378 reclass.add_key(
379 "parameters._param.linux_system_repo_mcp_glusterfs_version_number",
380 "5",
381 "cluster/*/infra/init.yml"
382 )
383 # ################# Run linux.system state ###########################
384 show_step(2)
385 salt.enforce_state("*", "linux.system.repo")
386
387 # ############## Start deploy-upgrade-galera job #####################
388 show_step(3)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300389 job_name = 'update-glusterfs'
390
Hanna Arhipova508f6532021-01-27 15:52:45 +0200391 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300392 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300393 build_timeout=40 * 60)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300394
Hanna Arhipova508f6532021-01-27 15:52:45 +0200395 assert job_result == 'SUCCESS', job_description
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300396
397 # ################ Check GlusterFS version for servers ##############
398 show_step(4)
399 gluster_server_versions_by_nodes = salt.cmd_run(
400 "I@glusterfs:server",
401 "glusterd --version|head -n1")[0]
402
Hanna Arhipova19429962019-10-17 15:16:49 +0300403 assert has_only_similar(gluster_server_versions_by_nodes), \
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300404 gluster_server_versions_by_nodes
405
406 # ################ Check GlusterFS version for clients ##############
407 show_step(5)
408 gluster_client_versions_by_nodes = salt.cmd_run(
409 "I@glusterfs:client",
410 "glusterfs --version|head -n1")[0]
411
412 assert has_only_similar(gluster_client_versions_by_nodes), \
413 gluster_client_versions_by_nodes
414
415 @pytest.mark.grab_versions
416 @pytest.mark.parametrize("_", [settings.ENV_NAME])
417 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300418 def test_update_galera(self, salt_actions, reclass_actions,
PGlazov7efe3b22022-02-16 17:29:05 +0400419 drivetrain_actions, show_step,
420 update_mysql_to_version, _):
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300421 """ Upgrade Galera automatically
422
423 Scenario:
424 1. Include the Galera upgrade pipeline job to DriveTrain
PGlazov7efe3b22022-02-16 17:29:05 +0400425 2. Add fix for mysql 5.7
426 3. Apply the jenkins.client state on the Jenkins nodes
427 4. set the openstack_upgrade_enabled parameter to true
428 5. Refresh pillars
429 6. Add repositories with new Galera packages
430 7. Start job from Jenkins
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300431 """
432 salt = salt_actions
433 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300434 dt = drivetrain_actions
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300435 # ################### Enable pipeline #################################
436 show_step(1)
437 reclass.add_class(
438 "system.jenkins.client.job.deploy.update.upgrade_galera",
439 "cluster/*/cicd/control/leader.yml")
PGlazov7efe3b22022-02-16 17:29:05 +0400440 # ################### Fix for Mysql 5.7 ##############################
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300441 show_step(2)
PGlazov7efe3b22022-02-16 17:29:05 +0400442 if (update_mysql_to_version == '5.7'):
PGlazov7efe3b22022-02-16 17:29:05 +0400443 mysql_class = "cluster.{env_name}.openstack." \
444 "database.mysql_version"\
445 .format(env_name=settings.ENV_NAME)
446 reclass.add_class(
447 mysql_class,
448 "cluster/*/openstack/database/master.yml")
449 reclass.add_class(
450 mysql_class,
451 "cluster/*/openstack/database/slave.yml")
452 mysql_path = "cluster/{env_name}" \
453 "/openstack/database/mysql_version.yml"\
454 .format(env_name=settings.ENV_NAME)
455 galera_mysql_version = '5.7'
456 if update_mysql_to_version != '5.7':
457 galera_mysql_version = update_mysql_to_version
458 mysql_version = "parameters:\n" \
459 " _param:\n" \
460 " galera_mysql_version: {}"\
461 .format(galera_mysql_version)
462 if not os.path.isfile("/srv/salt/reclass/classes/{path}".format(
463 path=mysql_path)):
464 reclass.create_yaml_with_context(mysql_version,
465 mysql_path)
466 else:
467 reclass.merge_context(mysql_version,
468 mysql_path)
469 reclass_actions.commit(
470 "[from TCP-QA] Change for mysql new version")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300471
PGlazov7efe3b22022-02-16 17:29:05 +0400472 show_step(3)
Vladimir Khlyunev17468272022-06-29 16:19:36 +0400473 salt.run_state("I@jenkins:client and not I@salt:master",
474 "saltutil.refresh_pillar")
475 salt.enforce_state("I@jenkins:client and not I@salt:master",
476 "jenkins.client.job")
PGlazov7efe3b22022-02-16 17:29:05 +0400477 else:
478 LOG.info("Skip mysql upgrade fix")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300479 # ############### Enable automatic upgrade ############################
PGlazov7efe3b22022-02-16 17:29:05 +0400480 show_step(4)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300481 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
482 "True",
483 "cluster/*/infra/init.yml")
484
PGlazov7efe3b22022-02-16 17:29:05 +0400485 show_step(5)
Hanna Arhipova7cfeb072019-10-11 15:04:10 +0300486 salt.run_state("dbs*", "saltutil.refresh_pillar")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300487
488 # ############# Add repositories with new Galera packages #######
PGlazov7efe3b22022-02-16 17:29:05 +0400489 show_step(6)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300490 salt.enforce_state("dbs*", "linux.system.repo")
491 salt.enforce_state("cfg*", "salt.master")
492
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300493 # #################### Login Jenkins on cid01 node ###################
PGlazov7efe3b22022-02-16 17:29:05 +0400494 show_step(7)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300495
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300496 job_name = 'deploy-upgrade-galera'
497 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300498 'INTERACTIVE': 'false',
499 'OS_DIST_UPGRADE': 'true',
PGlazov7efe3b22022-02-16 17:29:05 +0400500 'OS_UPGRADE': 'true',
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300501 }
PGlazov554c4fd2022-03-23 14:31:41 +0400502 if (update_mysql_to_version == '5.7'):
PGlazov7efe3b22022-02-16 17:29:05 +0400503 job_parameters.update({'UPDATE_TO_MYSQL57': 'true'})
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300504
Hanna Arhipova508f6532021-01-27 15:52:45 +0200505 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300506 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300507 job_parameters=job_parameters,
508 build_timeout=40 * 60)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300509
Hanna Arhipova508f6532021-01-27 15:52:45 +0200510 assert job_result == 'SUCCESS', job_description
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300511
512 @pytest.fixture
513 def disable_automatic_failover_neutron_for_test(self, salt_actions):
514 """
515 On each OpenStack controller node, modify the neutron.conf file
516 Restart the neutron-server service
517 """
Hanna Arhipova19429962019-10-17 15:16:49 +0300518
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300519 def comment_line(node, file_name, word):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300520 """
521 Adds '#' before the specific line in specific file
522
523 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300524 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300525 :param word: string, the begin of line which should be commented
526 :return: None
527 """
528 salt_actions.cmd_run(node,
529 "sed -i 's/^{word}/#{word}/' {file}".
530 format(word=word,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300531 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300532
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300533 def add_line(node, file_name, line):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300534 """
535 Appends line to the end of file
536
537 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300538 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300539 :param line: string, line that should be added
540 :return: None
541 """
542 salt_actions.cmd_run(node, "echo {line} >> {file}".format(
Hanna Arhipova19429962019-10-17 15:16:49 +0300543 line=line,
544 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300545
546 neutron_conf = '/etc/neutron/neutron.conf'
547 neutron_server = "I@neutron:server"
548 # ######## Create backup for config file #######################
549 salt_actions.cmd_run(
550 neutron_server,
551 "cp -p {file} {file}.backup".format(file=neutron_conf))
552
553 # ## Change parameters in neutron.conf'
554 comment_line(neutron_server, neutron_conf,
Hanna Arhipova19429962019-10-17 15:16:49 +0300555 "allow_automatic_l3agent_failover", )
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300556 comment_line(neutron_server, neutron_conf,
557 "allow_automatic_dhcp_failover")
558 add_line(neutron_server, neutron_conf,
559 "allow_automatic_dhcp_failover = false")
560 add_line(neutron_server, neutron_conf,
561 "allow_automatic_l3agent_failover = false")
562
563 # ## Apply changed config to the neutron-server service
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300564 result = salt_actions.cmd_run(neutron_server,
565 "service neutron-server restart")
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300566 # TODO: add check that neutron-server is up and running
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300567 yield result
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300568 # ## Revert file changes
569 salt_actions.cmd_run(
570 neutron_server,
571 "cp -p {file}.backup {file}".format(file=neutron_conf))
572 salt_actions.cmd_run(neutron_server,
573 "service neutron-server restart")
574
575 @pytest.fixture
576 def disable_neutron_agents_for_test(self, salt_actions):
577 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300578 Disable the neutron services before the test and
579 enable it after test
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300580 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300581 result = salt_actions.cmd_run("I@neutron:server", """
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300582 service neutron-dhcp-agent stop && \
583 service neutron-l3-agent stop && \
584 service neutron-metadata-agent stop && \
585 service neutron-openvswitch-agent stop
586 """)
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300587 yield result
588 #
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300589 salt_actions.cmd_run("I@neutron:server", """
590 service neutron-dhcp-agent start && \
591 service neutron-l3-agent start && \
592 service neutron-metadata-agent start && \
593 service neutron-openvswitch-agent start
594 """)
595 # TODO: add check that all services are UP and running
596
597 @pytest.mark.grab_versions
598 @pytest.mark.parametrize("_", [settings.ENV_NAME])
599 @pytest.mark.run_mcp_update
600 def test_update_rabbit(self, salt_actions, reclass_actions,
601 drivetrain_actions, show_step, _,
602 disable_automatic_failover_neutron_for_test,
603 disable_neutron_agents_for_test):
604 """ Updates RabbitMQ
605 Scenario:
606 1. Include the RabbitMQ upgrade pipeline job to DriveTrain
607 2. Add repositories with new RabbitMQ packages
608 3. Start Deploy - upgrade RabbitMQ pipeline
609
610 Updating RabbitMq should be completed before the OpenStack updating
611 process starts
612 """
613 salt = salt_actions
614 reclass = reclass_actions
615 dt = drivetrain_actions
616
617 # ####### Include the RabbitMQ upgrade pipeline job to DriveTrain ####
618 show_step(1)
619 reclass.add_class(
620 "system.jenkins.client.job.deploy.update.upgrade_rabbitmq",
621 "cluster/*/cicd/control/leader.yml")
622 salt.enforce_state("I@jenkins:client", "jenkins.client")
623
624 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
625 "True",
626 "cluster/*/infra/init.yml")
627 salt.run_state("I@rabbitmq:server", "saltutil.refresh_pillar")
628
629 # ########### Add repositories with new RabbitMQ packages ############
630 show_step(2)
631 salt.enforce_state("I@rabbitmq:server", "linux.system.repo")
632
633 # ########### Start Deploy - upgrade RabbitMQ pipeline ############
634 show_step(3)
635 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300636 'INTERACTIVE': 'false',
637 'OS_DIST_UPGRADE': 'true',
638 'OS_UPGRADE': 'true'
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300639 }
640
Hanna Arhipova508f6532021-01-27 15:52:45 +0200641 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300642 job_name='deploy-upgrade-rabbitmq',
643 job_parameters=job_parameters,
PGlazov99364cb2021-09-20 12:36:18 +0400644 build_timeout=50 * 60
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300645 )
Hanna Arhipova508f6532021-01-27 15:52:45 +0200646 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300647
648 @pytest.mark.grab_versions
649 @pytest.mark.parametrize("_", [settings.ENV_NAME])
650 @pytest.mark.run_mcp_update
PGlazov215a4572022-03-05 05:09:04 +0400651 def test_update_ceph(self, salt_actions, drivetrain_actions,
652 reclass_actions, show_step, _):
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300653 """ Updates Ceph to the latest minor version
654
655 Scenario:
656 1. Add workaround for unhealth Ceph
657 2. Start ceph-upgrade job with default parameters
658 3. Check Ceph version for all nodes
PGlazov215a4572022-03-05 05:09:04 +0400659 4. WA id_reclaim only for nautilus
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300660
661 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update/ceph-update.html
662 """
663 salt = salt_actions
PGlazov215a4572022-03-05 05:09:04 +0400664 reclass = reclass_actions
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300665 dt = drivetrain_actions
666
667 # ###################### Add workaround for unhealth Ceph ############
668 show_step(1)
669 salt.cmd_run("I@ceph:radosgw",
670 "ceph config set 'mon pg warn max object skew' 20")
671 # ###################### Start ceph-upgrade pipeline #################
672 show_step(2)
673 job_parameters = {}
674
Hanna Arhipova508f6532021-01-27 15:52:45 +0200675 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300676 job_name='ceph-update',
677 job_parameters=job_parameters)
678
Hanna Arhipova508f6532021-01-27 15:52:45 +0200679 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300680
681 # ########## Verify Ceph version #####################################
682 show_step(3)
683
684 ceph_version_by_nodes = salt.cmd_run(
Hanna Arhipova19429962019-10-17 15:16:49 +0300685 "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server",
686 "ceph version")[0]
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300687
688 assert has_only_similar(ceph_version_by_nodes), ceph_version_by_nodes
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300689
PGlazov215a4572022-03-05 05:09:04 +0400690 # ########## WA id_reclaim only for nautilus #########################
691 show_step(4)
692
693 ceph_version = salt_actions.get_single_pillar(
694 "I@salt:master",
695 "_param:_param:ceph_version")
696 if ceph_version == "nautilus":
697 wa_cve_2021_20288_global_id_reclaim(reclass, salt)
698 else:
699 LOG.info("Skip WA for luminous")
700
Hanna Arhipovaac008562019-10-17 11:54:23 +0300701 @pytest.mark.grab_versions
702 @pytest.mark.parametrize("_", [settings.ENV_NAME])
703 @pytest.mark.run_mcp_update
704 def test_update_stacklight(self, _, drivetrain_actions):
705 """ Update packages for Stacklight
706 Scenario:
707 1. Start Deploy - upgrade Stacklight job
708 """
709 drivetrain = drivetrain_actions
710
711 job_parameters = {
712 "STAGE_UPGRADE_DOCKER_COMPONENTS": True,
713 "STAGE_UPGRADE_ES_KIBANA": True,
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300714 "STAGE_UPGRADE_SYSTEM_PART": True,
715 'OS_DIST_UPGRADE': 'true',
716 'OS_UPGRADE': 'true'
Hanna Arhipovaac008562019-10-17 11:54:23 +0300717 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200718 job_result, job_description = drivetrain.start_job_on_jenkins(
Hanna Arhipovaac008562019-10-17 11:54:23 +0300719 job_name="stacklight-upgrade",
720 job_parameters=job_parameters)
721
Hanna Arhipova508f6532021-01-27 15:52:45 +0200722 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaac008562019-10-17 11:54:23 +0300723
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300724
Hanna Arhipova19429962019-10-17 15:16:49 +0300725@pytest.mark.usefixtures("switch_to_proposed_pipelines",
726 "enable_openstack_update")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300727class TestOpenstackUpdate(object):
728
729 @pytest.mark.grab_versions
730 @pytest.mark.run_mcp_update
731 def test__pre_update__enable_pipeline_job(self,
732 reclass_actions, salt_actions,
733 show_step):
734 """ Enable pipeline in the Drivetrain
735
736 Scenario:
737 1. Add deploy.update.* classes to the reclass
738 2. Start jenkins.client salt state
739
740 """
741 salt = salt_actions
742 reclass = reclass_actions
743 show_step(1)
744 reclass.add_class("system.jenkins.client.job.deploy.update.upgrade",
745 "cluster/*/cicd/control/leader.yml")
746
747 reclass.add_class(
748 "system.jenkins.client.job.deploy.update.upgrade_ovs_gateway",
749 "cluster/*/cicd/control/leader.yml")
750
751 reclass.add_class(
752 "system.jenkins.client.job.deploy.update.upgrade_compute",
753 "cluster/*/cicd/control/leader.yml")
754
755 show_step(2)
756 r, errors = salt.enforce_state("I@jenkins:client", "jenkins.client")
757 assert errors is None
758
759 @pytest.mark.grab_versions
760 @pytest.mark.parametrize('target', get_control_plane_targets())
761 @pytest.mark.run_mcp_update
Hanna Arhipova19429962019-10-17 15:16:49 +0300762 def test__update__control_plane(self, drivetrain_actions, target):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300763 """Start 'Deploy - upgrade control VMs' for specific node
764 """
765 job_parameters = {
766 "TARGET_SERVERS": target,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200767 "OS_DIST_UPGRADE": True,
PGlazova5039252021-10-06 21:40:01 +0400768 "UPGRADE_SALTSTACK": True,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200769 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300770 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200771 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300772 job_name="deploy-upgrade-control",
773 job_parameters=job_parameters)
774
Hanna Arhipova508f6532021-01-27 15:52:45 +0200775 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300776
777 @pytest.mark.grab_versions
778 @pytest.mark.run_mcp_update
Hanna Arhipova606d5182019-12-13 13:23:55 +0200779 def test__update__data_plane(self, drivetrain_actions, salt_actions):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300780 """Start 'Deploy - upgrade OVS gateway'
781 """
Hanna Arhipova606d5182019-12-13 13:23:55 +0200782 if not salt_actions.cmd_run("gtw*", "test.ping")[0].keys():
783 pytest.skip("This deployment doesn't have gtw* nodes")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300784 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200785 "OS_DIST_UPGRADE": True,
786 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300787 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200788 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300789 job_name="deploy-upgrade-ovs-gateway",
790 job_parameters=job_parameters)
791
Hanna Arhipova508f6532021-01-27 15:52:45 +0200792 assert job_result == 'SUCCESS', job_description
Hanna Arhipova19429962019-10-17 15:16:49 +0300793
794 @pytest.mark.grab_versions
795 @pytest.mark.run_mcp_update
796 def test__update__computes(self, drivetrain_actions):
797 """Start 'Deploy - upgrade computes'
798 """
799 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200800 "OS_DIST_UPGRADE": True,
801 "OS_UPGRADE": True,
Hanna Arhipova19429962019-10-17 15:16:49 +0300802 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200803 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipova19429962019-10-17 15:16:49 +0300804 job_name="deploy-upgrade-compute",
805 job_parameters=job_parameters)
806
Hanna Arhipova508f6532021-01-27 15:52:45 +0200807 assert job_result == 'SUCCESS', job_description