blob: b21b124dbd214067f730ba9abc4b3c89d4e202c1 [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 Arhipova672efc62021-03-15 09:55:14 +020070def dont_switch_to_proposed(request):
71 return request.config.getoption("--dont-switch-to-proposed")
72
73
74@pytest.fixture(scope='class')
75def switch_to_proposed_pipelines(reclass_actions, salt_actions,
76 dont_switch_to_proposed):
77 if dont_switch_to_proposed:
78 return True
79
Hanna Arhipova19429962019-10-17 15:16:49 +030080 reclass = reclass_actions
81 proposed_repo = "http://mirror.mirantis.com/update/proposed/"
82 repo_param = "parameters._param.linux_system_repo_update_url"
Hanna Arhipova7cfeb072019-10-11 15:04:10 +030083
Hanna Arhipova19429962019-10-17 15:16:49 +030084 proposed_pipeline_branch = "release/proposed/2019.2.0"
85 pipeline_branch_param = "parameters._param.jenkins_pipelines_branch"
86 infra_yml = "cluster/*/infra/init.yml"
87
88 LOG.info("Check reclass has release/proposed/2019.2.0 branches")
89 if reclass.get_key(pipeline_branch_param,
90 infra_yml) == proposed_pipeline_branch \
91 and reclass.get_key(repo_param, infra_yml) == proposed_repo:
92 return True
93
94 LOG.info("Switch to release/proposed/2019.2.0 branches")
95 reclass.add_key(pipeline_branch_param, proposed_pipeline_branch, infra_yml)
96
97 reclass.add_key(repo_param, proposed_repo, infra_yml)
98 reclass.add_key(repo_param, proposed_repo, "cluster/*/openstack/init.yml")
99 reclass.add_key(repo_param, proposed_repo, "cluster/*/stacklight/init.yml")
100 reclass.add_key(repo_param, proposed_repo, "cluster/*/ceph/init.yml")
Hanna Arhipova7cfeb072019-10-11 15:04:10 +0300101
102 salt_actions.run_state("*", "saltutil.refresh_pillar")
Hanna Arhipova9ee75902019-10-29 16:33:26 +0200103 salt_actions.enforce_state("*", "salt.minion")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300104 salt_actions.enforce_state("I@jenkins:client", "jenkins.client")
105
106
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300107@pytest.fixture
Hanna Arhipovaec201e72020-10-26 17:14:25 +0200108def wa_for_galera_clustercheck_password_prod35705(reclass_actions,
109 salt_actions):
Hanna Arhipova0e816d22021-01-29 00:17:44 +0200110 tgt = "I@galera:master or I@galera:slave"
111 if not salt_actions.get_pillar(tgt,
112 "_param:galera_clustercheck_password")[0]:
113 reclass_actions.add_key(
114 "parameters._param.galera_clustercheck_password",
115 "a"*32,
116 "cluster/*/infra/secrets.yml")
117 salt_actions.run_state(tgt, "saltutil.refresh_pillar")
118 salt_actions.enforce_state(tgt, "galera")
119 salt_actions.enforce_state(tgt, "haproxy")
120 reclass_actions.commit(
121 "[from TCP-QA] Add galera_clustercheck_password")
122 else:
Hanna Arhipova672efc62021-03-15 09:55:14 +0200123
Hanna Arhipova0e816d22021-01-29 00:17:44 +0200124 LOG.info("Skipping WA for Galera Clustercheck Password")
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300125
126
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200127@pytest.fixture
PGlazov29a323b2021-07-15 19:41:59 +0400128def wa_for_import_ceph_classes_after_infra_prod36461(reclass_actions,
129 salt_actions):
130 if salt_actions.cmd_run("rgw*", "test.ping")[0].keys():
131 # ####### WA for Ceph RGW* classes PROD-36461 ###
132 LOG.info("Changing class sequence for RGW PROD-36461")
133 reclass_actions.delete_class(
134 "cluster.${_param:cluster_name}.ceph",
135 "cluster/*/ceph/rgw.yml")
136 reclass_actions.delete_class(
137 "cluster.${_param:cluster_name}.ceph.common",
138 "cluster/*/ceph/rgw.yml")
139 reclass_actions.add_class(
140 "cluster.${_param:cluster_name}.ceph",
141 "cluster/*/ceph/rgw.yml")
142 reclass_actions.add_class(
143 "cluster.${_param:cluster_name}.ceph.common",
144 "cluster/*/ceph/rgw.yml")
145 reclass_actions.commit(
146 "[from TCP-QA] Changing class sequence for RGW")
147 else:
148 LOG.info("Skip WA for RGW PROD-36461")
149
150
151@pytest.fixture
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200152def wa_for_alerta_password_prod35958(reclass_actions,
153 salt_actions):
Hanna Arhipova0e816d22021-01-29 00:17:44 +0200154 if not salt_actions.get_pillar("I@prometheus:alerta",
155 "_param:alerta_admin_api_key_generated")[0]:
156 reclass_actions.add_key(
157 "parameters._param.alerta_admin_api_key_generated",
158 "a"*32,
159 "cluster/*/infra/secrets.yml")
160 reclass_actions.add_key(
161 "parameters._param.alerta_admin_key",
162 "${_param:alerta_admin_api_key_generated}",
163 "cluster/*/stacklight/init.yml")
164 reclass_actions.commit("[from TCP-QA] Add alerta_admin_key")
165 salt_actions.run_state(
166 "I@prometheus:alerta or I@prometheus:alertmanager",
167 "saltutil.refresh_pillar")
168 salt_actions.enforce_state(
169 "I@prometheus:alerta", "prometheus.alerta")
170 salt_actions.enforce_state(
171 "I@prometheus:alertmanager", "prometheus.alertmanager")
172 salt_actions.enforce_state(
173 "I@prometheus:alerta or I@prometheus:alertmanager",
174 "docker.client")
175 else:
176 LOG.info("Skipping WA for Alerta API key")
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200177
178
Hanna Arhipova19429962019-10-17 15:16:49 +0300179@pytest.fixture(scope='class')
180def enable_openstack_update(reclass_actions, salt_actions):
181 param = "parameters._param.openstack_upgrade_enabled"
182 context_file = "cluster/*/infra/init.yml"
183
184 LOG.info("Enable openstack_upgrade_enabled in reclass")
185 reclass_actions.add_bool_key(param, "True", context_file)
186 salt_actions.run_state("*", "saltutil.refresh_pillar")
187 yield True
188 LOG.info("Disable openstack_upgrade_enabled in reclass")
189 reclass_actions.add_bool_key(param, "False", context_file)
190 salt_actions.run_state("*", "saltutil.refresh_pillar")
191
192
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300193@pytest.mark.usefixtures("switch_to_proposed_pipelines",
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200194 "wa_for_galera_clustercheck_password_prod35705",
PGlazov29a323b2021-07-15 19:41:59 +0400195 "wa_for_alerta_password_prod35958",
196 "wa_for_import_ceph_classes_after_infra_prod36461")
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300197class TestUpdateMcpCluster(object):
198 """
199 Following the steps in
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300200 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update.html#minor-update
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300201 """
202
203 @pytest.mark.grab_versions
204 @pytest.mark.parametrize("_", [settings.ENV_NAME])
205 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300206 def test_update_drivetrain(self, salt_actions, drivetrain_actions,
Hanna Arhipova19429962019-10-17 15:16:49 +0300207 show_step, _):
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300208 """Updating DriveTrain component to release/proposed/2019.2.0 version
209
210 Scenario:
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300211 1. Add workaround for PROD-32751
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300212 2. Run job git-mirror-downstream-mk-pipelines
213 3. Run job git-mirror-downstream-pipeline-library
214 4. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain'
Hanna Arhipova7a593da2021-06-25 11:16:09 +0300215 5. Wait till salt-master completes all async jobs
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300216
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300217 Duration: ~70 min
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300218 """
219 salt = salt_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300220 dt = drivetrain_actions
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300221
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300222 # #################### Add workaround for PROD-32751 #################
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300223 show_step(1)
224
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300225 # FIXME: workaround for PROD-32751
226 salt.cmd_run("cfg01*", "cd /srv/salt/reclass; git add -u && \
227 git commit --allow-empty -m 'Cluster model update'")
228
229 # ################### Downstream mk-pipelines #########################
230 show_step(2)
231 job_name = 'git-mirror-downstream-mk-pipelines'
232 job_parameters = {
233 'BRANCHES': 'release/proposed/2019.2.0'
234 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200235 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300236 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300237 job_parameters=job_parameters,
238 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300239
Hanna Arhipova508f6532021-01-27 15:52:45 +0200240 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300241
242 # ################### Downstream pipeline-library ####################
243 show_step(3)
244 job_name = 'git-mirror-downstream-pipeline-library'
245 job_parameters = {
246 'BRANCHES': 'release/proposed/2019.2.0'
247 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200248 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300249 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300250 job_parameters=job_parameters,
251 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300252
Hanna Arhipova508f6532021-01-27 15:52:45 +0200253 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300254
255 # ################### Start 'Deploy - upgrade MCP Drivetrain' job #####
256 show_step(4)
257
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300258 job_name = 'upgrade-mcp-release'
259 job_parameters = {
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300260 'GIT_REFSPEC': 'release/proposed/2019.2.0',
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300261 'MK_PIPELINES_REFSPEC': 'release/proposed/2019.2.0',
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300262 'TARGET_MCP_VERSION': '2019.2.0',
263 "DRIVE_TRAIN_PARAMS": {
264 "OS_DIST_UPGRADE": True,
265 "OS_UPGRADE": True,
266 "BATCH_SIZE": 10
267 }
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300268 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200269 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300270 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300271 job_parameters=job_parameters,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300272 verbose=True,
Hanna Arhipovae7f2e322021-02-25 13:53:18 +0200273 build_timeout=4 * 60 * 60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300274
Hanna Arhipova508f6532021-01-27 15:52:45 +0200275 assert job_result == 'SUCCESS', job_description
Hanna Arhipova7a593da2021-06-25 11:16:09 +0300276 # ############### Wait till salt-master completes all async jobs #####
277 show_step(5)
278 salt.wait_jobs_completed(timeout=20*60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300279
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300280 @pytest.mark.grab_versions
281 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300282 @pytest.mark.run_mcp_update
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300283 def test_update_glusterfs(self, salt_actions, reclass_actions,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300284 drivetrain_actions, show_step, _):
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300285 """ Upgrade GlusterFS
286 Scenario:
287 1. In infra/init.yml in Reclass, add the glusterfs_version parameter
288 2. Start linux.system.repo state
289 3. Start "update-glusterfs" job
290 4. Check version for GlusterFS servers
291 5. Check version for GlusterFS clients
292
293 """
294 salt = salt_actions
295 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300296 dt = drivetrain_actions
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300297
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300298 # ############## Change reclass ######################################
299 show_step(1)
300 reclass.add_key(
301 "parameters._param.linux_system_repo_mcp_glusterfs_version_number",
302 "5",
303 "cluster/*/infra/init.yml"
304 )
305 # ################# Run linux.system state ###########################
306 show_step(2)
307 salt.enforce_state("*", "linux.system.repo")
308
309 # ############## Start deploy-upgrade-galera job #####################
310 show_step(3)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300311 job_name = 'update-glusterfs'
312
Hanna Arhipova508f6532021-01-27 15:52:45 +0200313 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300314 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300315 build_timeout=40 * 60)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300316
Hanna Arhipova508f6532021-01-27 15:52:45 +0200317 assert job_result == 'SUCCESS', job_description
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300318
319 # ################ Check GlusterFS version for servers ##############
320 show_step(4)
321 gluster_server_versions_by_nodes = salt.cmd_run(
322 "I@glusterfs:server",
323 "glusterd --version|head -n1")[0]
324
Hanna Arhipova19429962019-10-17 15:16:49 +0300325 assert has_only_similar(gluster_server_versions_by_nodes), \
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300326 gluster_server_versions_by_nodes
327
328 # ################ Check GlusterFS version for clients ##############
329 show_step(5)
330 gluster_client_versions_by_nodes = salt.cmd_run(
331 "I@glusterfs:client",
332 "glusterfs --version|head -n1")[0]
333
334 assert has_only_similar(gluster_client_versions_by_nodes), \
335 gluster_client_versions_by_nodes
336
337 @pytest.mark.grab_versions
338 @pytest.mark.parametrize("_", [settings.ENV_NAME])
339 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300340 def test_update_galera(self, salt_actions, reclass_actions,
341 drivetrain_actions, show_step, _):
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300342 """ Upgrade Galera automatically
343
344 Scenario:
345 1. Include the Galera upgrade pipeline job to DriveTrain
346 2. Apply the jenkins.client state on the Jenkins nodes
347 3. set the openstack_upgrade_enabled parameter to true
348 4. Refresh pillars
349 5. Add repositories with new Galera packages
350 6. Start job from Jenkins
351 """
352 salt = salt_actions
353 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300354 dt = drivetrain_actions
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300355 # ################### Enable pipeline #################################
356 show_step(1)
357 reclass.add_class(
358 "system.jenkins.client.job.deploy.update.upgrade_galera",
359 "cluster/*/cicd/control/leader.yml")
360 show_step(2)
361 salt.enforce_state("I@jenkins:client", "jenkins.client")
362
363 # ############### Enable automatic upgrade ############################
364 show_step(3)
365 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
366 "True",
367 "cluster/*/infra/init.yml")
368
369 show_step(4)
Hanna Arhipova7cfeb072019-10-11 15:04:10 +0300370 salt.run_state("dbs*", "saltutil.refresh_pillar")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300371
372 # ############# Add repositories with new Galera packages #######
373 show_step(5)
374 salt.enforce_state("dbs*", "linux.system.repo")
375 salt.enforce_state("cfg*", "salt.master")
376
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300377 # #################### Login Jenkins on cid01 node ###################
378 show_step(6)
379
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300380 job_name = 'deploy-upgrade-galera'
381 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300382 'INTERACTIVE': 'false',
383 'OS_DIST_UPGRADE': 'true',
384 'OS_UPGRADE': 'true'
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300385 }
386
Hanna Arhipova508f6532021-01-27 15:52:45 +0200387 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300388 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300389 job_parameters=job_parameters,
390 build_timeout=40 * 60)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300391
Hanna Arhipova508f6532021-01-27 15:52:45 +0200392 assert job_result == 'SUCCESS', job_description
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300393
394 @pytest.fixture
395 def disable_automatic_failover_neutron_for_test(self, salt_actions):
396 """
397 On each OpenStack controller node, modify the neutron.conf file
398 Restart the neutron-server service
399 """
Hanna Arhipova19429962019-10-17 15:16:49 +0300400
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300401 def comment_line(node, file_name, word):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300402 """
403 Adds '#' before the specific line in specific file
404
405 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300406 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300407 :param word: string, the begin of line which should be commented
408 :return: None
409 """
410 salt_actions.cmd_run(node,
411 "sed -i 's/^{word}/#{word}/' {file}".
412 format(word=word,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300413 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300414
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300415 def add_line(node, file_name, line):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300416 """
417 Appends line to the end of file
418
419 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300420 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300421 :param line: string, line that should be added
422 :return: None
423 """
424 salt_actions.cmd_run(node, "echo {line} >> {file}".format(
Hanna Arhipova19429962019-10-17 15:16:49 +0300425 line=line,
426 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300427
428 neutron_conf = '/etc/neutron/neutron.conf'
429 neutron_server = "I@neutron:server"
430 # ######## Create backup for config file #######################
431 salt_actions.cmd_run(
432 neutron_server,
433 "cp -p {file} {file}.backup".format(file=neutron_conf))
434
435 # ## Change parameters in neutron.conf'
436 comment_line(neutron_server, neutron_conf,
Hanna Arhipova19429962019-10-17 15:16:49 +0300437 "allow_automatic_l3agent_failover", )
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300438 comment_line(neutron_server, neutron_conf,
439 "allow_automatic_dhcp_failover")
440 add_line(neutron_server, neutron_conf,
441 "allow_automatic_dhcp_failover = false")
442 add_line(neutron_server, neutron_conf,
443 "allow_automatic_l3agent_failover = false")
444
445 # ## Apply changed config to the neutron-server service
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300446 result = salt_actions.cmd_run(neutron_server,
447 "service neutron-server restart")
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300448 # TODO: add check that neutron-server is up and running
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300449 yield result
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300450 # ## Revert file changes
451 salt_actions.cmd_run(
452 neutron_server,
453 "cp -p {file}.backup {file}".format(file=neutron_conf))
454 salt_actions.cmd_run(neutron_server,
455 "service neutron-server restart")
456
457 @pytest.fixture
458 def disable_neutron_agents_for_test(self, salt_actions):
459 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300460 Disable the neutron services before the test and
461 enable it after test
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300462 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300463 result = salt_actions.cmd_run("I@neutron:server", """
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300464 service neutron-dhcp-agent stop && \
465 service neutron-l3-agent stop && \
466 service neutron-metadata-agent stop && \
467 service neutron-openvswitch-agent stop
468 """)
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300469 yield result
470 #
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300471 salt_actions.cmd_run("I@neutron:server", """
472 service neutron-dhcp-agent start && \
473 service neutron-l3-agent start && \
474 service neutron-metadata-agent start && \
475 service neutron-openvswitch-agent start
476 """)
477 # TODO: add check that all services are UP and running
478
479 @pytest.mark.grab_versions
480 @pytest.mark.parametrize("_", [settings.ENV_NAME])
481 @pytest.mark.run_mcp_update
482 def test_update_rabbit(self, salt_actions, reclass_actions,
483 drivetrain_actions, show_step, _,
484 disable_automatic_failover_neutron_for_test,
485 disable_neutron_agents_for_test):
486 """ Updates RabbitMQ
487 Scenario:
488 1. Include the RabbitMQ upgrade pipeline job to DriveTrain
489 2. Add repositories with new RabbitMQ packages
490 3. Start Deploy - upgrade RabbitMQ pipeline
491
492 Updating RabbitMq should be completed before the OpenStack updating
493 process starts
494 """
495 salt = salt_actions
496 reclass = reclass_actions
497 dt = drivetrain_actions
498
499 # ####### Include the RabbitMQ upgrade pipeline job to DriveTrain ####
500 show_step(1)
501 reclass.add_class(
502 "system.jenkins.client.job.deploy.update.upgrade_rabbitmq",
503 "cluster/*/cicd/control/leader.yml")
504 salt.enforce_state("I@jenkins:client", "jenkins.client")
505
506 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
507 "True",
508 "cluster/*/infra/init.yml")
509 salt.run_state("I@rabbitmq:server", "saltutil.refresh_pillar")
510
511 # ########### Add repositories with new RabbitMQ packages ############
512 show_step(2)
513 salt.enforce_state("I@rabbitmq:server", "linux.system.repo")
514
515 # ########### Start Deploy - upgrade RabbitMQ pipeline ############
516 show_step(3)
517 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300518 'INTERACTIVE': 'false',
519 'OS_DIST_UPGRADE': 'true',
520 'OS_UPGRADE': 'true'
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300521 }
522
Hanna Arhipova508f6532021-01-27 15:52:45 +0200523 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300524 job_name='deploy-upgrade-rabbitmq',
525 job_parameters=job_parameters,
526 build_timeout=40 * 60
527 )
Hanna Arhipova508f6532021-01-27 15:52:45 +0200528 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300529
530 @pytest.mark.grab_versions
531 @pytest.mark.parametrize("_", [settings.ENV_NAME])
532 @pytest.mark.run_mcp_update
533 def test_update_ceph(self, salt_actions, drivetrain_actions, show_step, _):
534 """ Updates Ceph to the latest minor version
535
536 Scenario:
537 1. Add workaround for unhealth Ceph
538 2. Start ceph-upgrade job with default parameters
539 3. Check Ceph version for all nodes
540
541 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update/ceph-update.html
542 """
543 salt = salt_actions
544 dt = drivetrain_actions
545
546 # ###################### Add workaround for unhealth Ceph ############
547 show_step(1)
548 salt.cmd_run("I@ceph:radosgw",
549 "ceph config set 'mon pg warn max object skew' 20")
550 # ###################### Start ceph-upgrade pipeline #################
551 show_step(2)
552 job_parameters = {}
553
Hanna Arhipova508f6532021-01-27 15:52:45 +0200554 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300555 job_name='ceph-update',
556 job_parameters=job_parameters)
557
Hanna Arhipova508f6532021-01-27 15:52:45 +0200558 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300559
560 # ########## Verify Ceph version #####################################
561 show_step(3)
562
563 ceph_version_by_nodes = salt.cmd_run(
Hanna Arhipova19429962019-10-17 15:16:49 +0300564 "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server",
565 "ceph version")[0]
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300566
567 assert has_only_similar(ceph_version_by_nodes), ceph_version_by_nodes
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300568
Hanna Arhipovaac008562019-10-17 11:54:23 +0300569 @pytest.mark.grab_versions
570 @pytest.mark.parametrize("_", [settings.ENV_NAME])
571 @pytest.mark.run_mcp_update
572 def test_update_stacklight(self, _, drivetrain_actions):
573 """ Update packages for Stacklight
574 Scenario:
575 1. Start Deploy - upgrade Stacklight job
576 """
577 drivetrain = drivetrain_actions
578
579 job_parameters = {
580 "STAGE_UPGRADE_DOCKER_COMPONENTS": True,
581 "STAGE_UPGRADE_ES_KIBANA": True,
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300582 "STAGE_UPGRADE_SYSTEM_PART": True,
583 'OS_DIST_UPGRADE': 'true',
584 'OS_UPGRADE': 'true'
Hanna Arhipovaac008562019-10-17 11:54:23 +0300585 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200586 job_result, job_description = drivetrain.start_job_on_jenkins(
Hanna Arhipovaac008562019-10-17 11:54:23 +0300587 job_name="stacklight-upgrade",
588 job_parameters=job_parameters)
589
Hanna Arhipova508f6532021-01-27 15:52:45 +0200590 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaac008562019-10-17 11:54:23 +0300591
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300592
Hanna Arhipova19429962019-10-17 15:16:49 +0300593@pytest.mark.usefixtures("switch_to_proposed_pipelines",
594 "enable_openstack_update")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300595class TestOpenstackUpdate(object):
596
597 @pytest.mark.grab_versions
598 @pytest.mark.run_mcp_update
599 def test__pre_update__enable_pipeline_job(self,
600 reclass_actions, salt_actions,
601 show_step):
602 """ Enable pipeline in the Drivetrain
603
604 Scenario:
605 1. Add deploy.update.* classes to the reclass
606 2. Start jenkins.client salt state
607
608 """
609 salt = salt_actions
610 reclass = reclass_actions
611 show_step(1)
612 reclass.add_class("system.jenkins.client.job.deploy.update.upgrade",
613 "cluster/*/cicd/control/leader.yml")
614
615 reclass.add_class(
616 "system.jenkins.client.job.deploy.update.upgrade_ovs_gateway",
617 "cluster/*/cicd/control/leader.yml")
618
619 reclass.add_class(
620 "system.jenkins.client.job.deploy.update.upgrade_compute",
621 "cluster/*/cicd/control/leader.yml")
622
623 show_step(2)
624 r, errors = salt.enforce_state("I@jenkins:client", "jenkins.client")
625 assert errors is None
626
627 @pytest.mark.grab_versions
628 @pytest.mark.parametrize('target', get_control_plane_targets())
629 @pytest.mark.run_mcp_update
Hanna Arhipova19429962019-10-17 15:16:49 +0300630 def test__update__control_plane(self, drivetrain_actions, target):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300631 """Start 'Deploy - upgrade control VMs' for specific node
632 """
633 job_parameters = {
634 "TARGET_SERVERS": target,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200635 "OS_DIST_UPGRADE": True,
PGlazoved19b352020-05-21 16:42:27 +0400636 "UPGRADE_SALTSTACK": False,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200637 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300638 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200639 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300640 job_name="deploy-upgrade-control",
641 job_parameters=job_parameters)
642
Hanna Arhipova508f6532021-01-27 15:52:45 +0200643 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300644
645 @pytest.mark.grab_versions
646 @pytest.mark.run_mcp_update
Hanna Arhipova606d5182019-12-13 13:23:55 +0200647 def test__update__data_plane(self, drivetrain_actions, salt_actions):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300648 """Start 'Deploy - upgrade OVS gateway'
649 """
Hanna Arhipova606d5182019-12-13 13:23:55 +0200650 if not salt_actions.cmd_run("gtw*", "test.ping")[0].keys():
651 pytest.skip("This deployment doesn't have gtw* nodes")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300652 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200653 "OS_DIST_UPGRADE": True,
654 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300655 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200656 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300657 job_name="deploy-upgrade-ovs-gateway",
658 job_parameters=job_parameters)
659
Hanna Arhipova508f6532021-01-27 15:52:45 +0200660 assert job_result == 'SUCCESS', job_description
Hanna Arhipova19429962019-10-17 15:16:49 +0300661
662 @pytest.mark.grab_versions
663 @pytest.mark.run_mcp_update
664 def test__update__computes(self, drivetrain_actions):
665 """Start 'Deploy - upgrade computes'
666 """
667 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200668 "OS_DIST_UPGRADE": True,
669 "OS_UPGRADE": True,
Hanna Arhipova19429962019-10-17 15:16:49 +0300670 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200671 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipova19429962019-10-17 15:16:49 +0300672 job_name="deploy-upgrade-compute",
673 job_parameters=job_parameters)
674
Hanna Arhipova508f6532021-01-27 15:52:45 +0200675 assert job_result == 'SUCCESS', job_description