blob: 1ff12945f7fa916a723feff76e6ae6ee89371cd3 [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')
75def switch_to_proposed_pipelines(reclass_actions, salt_actions,
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +030076 update_to_tag):
77 if update_to_tag:
Hanna Arhipova672efc62021-03-15 09:55:14 +020078 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
128def wa_for_alerta_password_prod35958(reclass_actions,
129 salt_actions):
Pavel Glazovea439c42021-07-25 00:20:20 +0000130
Hanna Arhipova0e816d22021-01-29 00:17:44 +0200131 if not salt_actions.get_pillar("I@prometheus:alerta",
132 "_param:alerta_admin_api_key_generated")[0]:
133 reclass_actions.add_key(
134 "parameters._param.alerta_admin_api_key_generated",
135 "a"*32,
136 "cluster/*/infra/secrets.yml")
137 reclass_actions.add_key(
138 "parameters._param.alerta_admin_key",
139 "${_param:alerta_admin_api_key_generated}",
140 "cluster/*/stacklight/init.yml")
141 reclass_actions.commit("[from TCP-QA] Add alerta_admin_key")
142 salt_actions.run_state(
143 "I@prometheus:alerta or I@prometheus:alertmanager",
144 "saltutil.refresh_pillar")
145 salt_actions.enforce_state(
146 "I@prometheus:alerta", "prometheus.alerta")
147 salt_actions.enforce_state(
148 "I@prometheus:alertmanager", "prometheus.alertmanager")
149 salt_actions.enforce_state(
150 "I@prometheus:alerta or I@prometheus:alertmanager",
151 "docker.client")
152 else:
153 LOG.info("Skipping WA for Alerta API key")
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200154
155
Hanna Arhipova19429962019-10-17 15:16:49 +0300156@pytest.fixture(scope='class')
157def enable_openstack_update(reclass_actions, salt_actions):
158 param = "parameters._param.openstack_upgrade_enabled"
159 context_file = "cluster/*/infra/init.yml"
160
161 LOG.info("Enable openstack_upgrade_enabled in reclass")
162 reclass_actions.add_bool_key(param, "True", context_file)
163 salt_actions.run_state("*", "saltutil.refresh_pillar")
164 yield True
165 LOG.info("Disable openstack_upgrade_enabled in reclass")
166 reclass_actions.add_bool_key(param, "False", context_file)
167 salt_actions.run_state("*", "saltutil.refresh_pillar")
168
169
Hanna Arhipova745fdbb2020-03-30 14:40:44 +0300170@pytest.mark.usefixtures("switch_to_proposed_pipelines",
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300171 "update_to_tag",
Hanna Arhipova97fac6e2020-12-03 13:10:56 +0200172 "wa_for_galera_clustercheck_password_prod35705",
Pavel Glazovea439c42021-07-25 00:20:20 +0000173 "wa_for_alerta_password_prod35958")
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300174class TestUpdateMcpCluster(object):
175 """
176 Following the steps in
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300177 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update.html#minor-update
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300178 """
179
180 @pytest.mark.grab_versions
181 @pytest.mark.parametrize("_", [settings.ENV_NAME])
182 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300183 def test_update_drivetrain(self, salt_actions, drivetrain_actions,
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300184 show_step, update_to_tag, _):
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300185 """Updating DriveTrain component to release/proposed/2019.2.0 version
186
187 Scenario:
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300188 1. Add workaround for PROD-32751
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300189 2. Run job git-mirror-downstream-mk-pipelines
190 3. Run job git-mirror-downstream-pipeline-library
191 4. If jobs are passed then start 'Deploy - upgrade MCP Drivetrain'
Hanna Arhipova7a593da2021-06-25 11:16:09 +0300192 5. Wait till salt-master completes all async jobs
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300193
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300194 Duration: ~70 min
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300195 """
196 salt = salt_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300197 dt = drivetrain_actions
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300198
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300199 # #################### Add workaround for PROD-32751 #################
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300200 show_step(1)
201
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300202 # FIXME: workaround for PROD-32751
203 salt.cmd_run("cfg01*", "cd /srv/salt/reclass; git add -u && \
204 git commit --allow-empty -m 'Cluster model update'")
205
206 # ################### Downstream mk-pipelines #########################
207 show_step(2)
208 job_name = 'git-mirror-downstream-mk-pipelines'
209 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300210 'BRANCHES': '*' or
211 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300212 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200213 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300214 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300215 job_parameters=job_parameters,
216 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300217
Hanna Arhipova508f6532021-01-27 15:52:45 +0200218 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300219
220 # ################### Downstream pipeline-library ####################
221 show_step(3)
222 job_name = 'git-mirror-downstream-pipeline-library'
223 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300224 'BRANCHES': '*' or
225 'release/proposed/2019.2.0'
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300226 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200227 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300228 job_name=job_name,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300229 job_parameters=job_parameters,
230 verbose=True)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300231
Hanna Arhipova508f6532021-01-27 15:52:45 +0200232 assert job_result == 'SUCCESS', job_description
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300233
234 # ################### Start 'Deploy - upgrade MCP Drivetrain' job #####
235 show_step(4)
236
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300237 job_name = 'upgrade-mcp-release'
238 job_parameters = {
Hanna Arhipovae1dd27a2021-07-28 12:40:40 +0300239 'GIT_REFSPEC': update_to_tag or 'release/proposed/2019.2.0',
240 'TARGET_MCP_VERSION': update_to_tag or '2019.2.0',
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300241 "DRIVE_TRAIN_PARAMS": {
242 "OS_DIST_UPGRADE": True,
243 "OS_UPGRADE": True,
244 "BATCH_SIZE": 10
245 }
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300246 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200247 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300248 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300249 job_parameters=job_parameters,
Hanna Arhipovac3c59292020-04-23 16:29:09 +0300250 verbose=True,
Hanna Arhipovae7f2e322021-02-25 13:53:18 +0200251 build_timeout=4 * 60 * 60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300252
Hanna Arhipova508f6532021-01-27 15:52:45 +0200253 assert job_result == 'SUCCESS', job_description
Hanna Arhipova7a593da2021-06-25 11:16:09 +0300254 # ############### Wait till salt-master completes all async jobs #####
255 show_step(5)
256 salt.wait_jobs_completed(timeout=20*60)
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300257
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300258 @pytest.mark.grab_versions
259 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Hanna Arhipova71ecc272019-08-20 14:54:22 +0300260 @pytest.mark.run_mcp_update
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300261 def test_update_glusterfs(self, salt_actions, reclass_actions,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300262 drivetrain_actions, show_step, _):
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300263 """ Upgrade GlusterFS
264 Scenario:
265 1. In infra/init.yml in Reclass, add the glusterfs_version parameter
266 2. Start linux.system.repo state
267 3. Start "update-glusterfs" job
268 4. Check version for GlusterFS servers
269 5. Check version for GlusterFS clients
270
271 """
272 salt = salt_actions
273 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300274 dt = drivetrain_actions
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300275
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300276 # ############## Change reclass ######################################
277 show_step(1)
278 reclass.add_key(
279 "parameters._param.linux_system_repo_mcp_glusterfs_version_number",
280 "5",
281 "cluster/*/infra/init.yml"
282 )
283 # ################# Run linux.system state ###########################
284 show_step(2)
285 salt.enforce_state("*", "linux.system.repo")
286
287 # ############## Start deploy-upgrade-galera job #####################
288 show_step(3)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300289 job_name = 'update-glusterfs'
290
Hanna Arhipova508f6532021-01-27 15:52:45 +0200291 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300292 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300293 build_timeout=40 * 60)
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300294
Hanna Arhipova508f6532021-01-27 15:52:45 +0200295 assert job_result == 'SUCCESS', job_description
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300296
297 # ################ Check GlusterFS version for servers ##############
298 show_step(4)
299 gluster_server_versions_by_nodes = salt.cmd_run(
300 "I@glusterfs:server",
301 "glusterd --version|head -n1")[0]
302
Hanna Arhipova19429962019-10-17 15:16:49 +0300303 assert has_only_similar(gluster_server_versions_by_nodes), \
Hanna Arhipovacc3759b2019-08-28 16:01:11 +0300304 gluster_server_versions_by_nodes
305
306 # ################ Check GlusterFS version for clients ##############
307 show_step(5)
308 gluster_client_versions_by_nodes = salt.cmd_run(
309 "I@glusterfs:client",
310 "glusterfs --version|head -n1")[0]
311
312 assert has_only_similar(gluster_client_versions_by_nodes), \
313 gluster_client_versions_by_nodes
314
315 @pytest.mark.grab_versions
316 @pytest.mark.parametrize("_", [settings.ENV_NAME])
317 @pytest.mark.run_mcp_update
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300318 def test_update_galera(self, salt_actions, reclass_actions,
319 drivetrain_actions, show_step, _):
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300320 """ Upgrade Galera automatically
321
322 Scenario:
323 1. Include the Galera upgrade pipeline job to DriveTrain
324 2. Apply the jenkins.client state on the Jenkins nodes
325 3. set the openstack_upgrade_enabled parameter to true
326 4. Refresh pillars
327 5. Add repositories with new Galera packages
328 6. Start job from Jenkins
329 """
330 salt = salt_actions
331 reclass = reclass_actions
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300332 dt = drivetrain_actions
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300333 # ################### Enable pipeline #################################
334 show_step(1)
335 reclass.add_class(
336 "system.jenkins.client.job.deploy.update.upgrade_galera",
337 "cluster/*/cicd/control/leader.yml")
338 show_step(2)
339 salt.enforce_state("I@jenkins:client", "jenkins.client")
340
341 # ############### Enable automatic upgrade ############################
342 show_step(3)
343 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
344 "True",
345 "cluster/*/infra/init.yml")
346
347 show_step(4)
Hanna Arhipova7cfeb072019-10-11 15:04:10 +0300348 salt.run_state("dbs*", "saltutil.refresh_pillar")
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300349
350 # ############# Add repositories with new Galera packages #######
351 show_step(5)
352 salt.enforce_state("dbs*", "linux.system.repo")
353 salt.enforce_state("cfg*", "salt.master")
354
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300355 # #################### Login Jenkins on cid01 node ###################
356 show_step(6)
357
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300358 job_name = 'deploy-upgrade-galera'
359 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300360 'INTERACTIVE': 'false',
361 'OS_DIST_UPGRADE': 'true',
362 'OS_UPGRADE': 'true'
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300363 }
364
Hanna Arhipova508f6532021-01-27 15:52:45 +0200365 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300366 job_name=job_name,
Hanna Arhipova17b2c102019-09-06 16:44:17 +0300367 job_parameters=job_parameters,
368 build_timeout=40 * 60)
Hanna Arhipova94a8abe2019-08-22 14:11:46 +0300369
Hanna Arhipova508f6532021-01-27 15:52:45 +0200370 assert job_result == 'SUCCESS', job_description
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300371
372 @pytest.fixture
373 def disable_automatic_failover_neutron_for_test(self, salt_actions):
374 """
375 On each OpenStack controller node, modify the neutron.conf file
376 Restart the neutron-server service
377 """
Hanna Arhipova19429962019-10-17 15:16:49 +0300378
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300379 def comment_line(node, file_name, word):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300380 """
381 Adds '#' before the specific line in specific file
382
383 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300384 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300385 :param word: string, the begin of line which should be commented
386 :return: None
387 """
388 salt_actions.cmd_run(node,
389 "sed -i 's/^{word}/#{word}/' {file}".
390 format(word=word,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300391 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300392
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300393 def add_line(node, file_name, line):
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300394 """
395 Appends line to the end of file
396
397 :param node: string, salt target of node where the file locates
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300398 :param file_name: string, full path to the file
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300399 :param line: string, line that should be added
400 :return: None
401 """
402 salt_actions.cmd_run(node, "echo {line} >> {file}".format(
Hanna Arhipova19429962019-10-17 15:16:49 +0300403 line=line,
404 file=file_name))
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300405
406 neutron_conf = '/etc/neutron/neutron.conf'
407 neutron_server = "I@neutron:server"
408 # ######## Create backup for config file #######################
409 salt_actions.cmd_run(
410 neutron_server,
411 "cp -p {file} {file}.backup".format(file=neutron_conf))
412
413 # ## Change parameters in neutron.conf'
414 comment_line(neutron_server, neutron_conf,
Hanna Arhipova19429962019-10-17 15:16:49 +0300415 "allow_automatic_l3agent_failover", )
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300416 comment_line(neutron_server, neutron_conf,
417 "allow_automatic_dhcp_failover")
418 add_line(neutron_server, neutron_conf,
419 "allow_automatic_dhcp_failover = false")
420 add_line(neutron_server, neutron_conf,
421 "allow_automatic_l3agent_failover = false")
422
423 # ## Apply changed config to the neutron-server service
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300424 result = salt_actions.cmd_run(neutron_server,
425 "service neutron-server restart")
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300426 # TODO: add check that neutron-server is up and running
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300427 yield result
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300428 # ## Revert file changes
429 salt_actions.cmd_run(
430 neutron_server,
431 "cp -p {file}.backup {file}".format(file=neutron_conf))
432 salt_actions.cmd_run(neutron_server,
433 "service neutron-server restart")
434
435 @pytest.fixture
436 def disable_neutron_agents_for_test(self, salt_actions):
437 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300438 Disable the neutron services before the test and
439 enable it after test
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300440 """
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300441 result = salt_actions.cmd_run("I@neutron:server", """
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300442 service neutron-dhcp-agent stop && \
443 service neutron-l3-agent stop && \
444 service neutron-metadata-agent stop && \
445 service neutron-openvswitch-agent stop
446 """)
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300447 yield result
448 #
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300449 salt_actions.cmd_run("I@neutron:server", """
450 service neutron-dhcp-agent start && \
451 service neutron-l3-agent start && \
452 service neutron-metadata-agent start && \
453 service neutron-openvswitch-agent start
454 """)
455 # TODO: add check that all services are UP and running
456
457 @pytest.mark.grab_versions
458 @pytest.mark.parametrize("_", [settings.ENV_NAME])
459 @pytest.mark.run_mcp_update
460 def test_update_rabbit(self, salt_actions, reclass_actions,
461 drivetrain_actions, show_step, _,
462 disable_automatic_failover_neutron_for_test,
463 disable_neutron_agents_for_test):
464 """ Updates RabbitMQ
465 Scenario:
466 1. Include the RabbitMQ upgrade pipeline job to DriveTrain
467 2. Add repositories with new RabbitMQ packages
468 3. Start Deploy - upgrade RabbitMQ pipeline
469
470 Updating RabbitMq should be completed before the OpenStack updating
471 process starts
472 """
473 salt = salt_actions
474 reclass = reclass_actions
475 dt = drivetrain_actions
476
477 # ####### Include the RabbitMQ upgrade pipeline job to DriveTrain ####
478 show_step(1)
479 reclass.add_class(
480 "system.jenkins.client.job.deploy.update.upgrade_rabbitmq",
481 "cluster/*/cicd/control/leader.yml")
482 salt.enforce_state("I@jenkins:client", "jenkins.client")
483
484 reclass.add_bool_key("parameters._param.openstack_upgrade_enabled",
485 "True",
486 "cluster/*/infra/init.yml")
487 salt.run_state("I@rabbitmq:server", "saltutil.refresh_pillar")
488
489 # ########### Add repositories with new RabbitMQ packages ############
490 show_step(2)
491 salt.enforce_state("I@rabbitmq:server", "linux.system.repo")
492
493 # ########### Start Deploy - upgrade RabbitMQ pipeline ############
494 show_step(3)
495 job_parameters = {
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300496 'INTERACTIVE': 'false',
497 'OS_DIST_UPGRADE': 'true',
498 'OS_UPGRADE': 'true'
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300499 }
500
Hanna Arhipova508f6532021-01-27 15:52:45 +0200501 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300502 job_name='deploy-upgrade-rabbitmq',
503 job_parameters=job_parameters,
PGlazov99364cb2021-09-20 12:36:18 +0400504 build_timeout=50 * 60
Hanna Arhipova1fcaf442019-09-06 15:30:45 +0300505 )
Hanna Arhipova508f6532021-01-27 15:52:45 +0200506 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300507
508 @pytest.mark.grab_versions
509 @pytest.mark.parametrize("_", [settings.ENV_NAME])
510 @pytest.mark.run_mcp_update
511 def test_update_ceph(self, salt_actions, drivetrain_actions, show_step, _):
512 """ Updates Ceph to the latest minor version
513
514 Scenario:
515 1. Add workaround for unhealth Ceph
516 2. Start ceph-upgrade job with default parameters
517 3. Check Ceph version for all nodes
518
519 https://docs.mirantis.com/mcp/master/mcp-operations-guide/update-upgrade/minor-update/ceph-update.html
520 """
521 salt = salt_actions
522 dt = drivetrain_actions
523
524 # ###################### Add workaround for unhealth Ceph ############
525 show_step(1)
526 salt.cmd_run("I@ceph:radosgw",
527 "ceph config set 'mon pg warn max object skew' 20")
528 # ###################### Start ceph-upgrade pipeline #################
529 show_step(2)
530 job_parameters = {}
531
Hanna Arhipova508f6532021-01-27 15:52:45 +0200532 job_result, job_description = dt.start_job_on_jenkins(
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300533 job_name='ceph-update',
534 job_parameters=job_parameters)
535
Hanna Arhipova508f6532021-01-27 15:52:45 +0200536 assert job_result == 'SUCCESS', job_description
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300537
538 # ########## Verify Ceph version #####################################
539 show_step(3)
540
541 ceph_version_by_nodes = salt.cmd_run(
Hanna Arhipova19429962019-10-17 15:16:49 +0300542 "I@ceph:* and not I@ceph:monitoring and not I@ceph:backup:server",
543 "ceph version")[0]
Hanna Arhipovad35a29b2019-09-04 13:24:06 +0300544
545 assert has_only_similar(ceph_version_by_nodes), ceph_version_by_nodes
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300546
Hanna Arhipovaac008562019-10-17 11:54:23 +0300547 @pytest.mark.grab_versions
548 @pytest.mark.parametrize("_", [settings.ENV_NAME])
549 @pytest.mark.run_mcp_update
550 def test_update_stacklight(self, _, drivetrain_actions):
551 """ Update packages for Stacklight
552 Scenario:
553 1. Start Deploy - upgrade Stacklight job
554 """
555 drivetrain = drivetrain_actions
556
557 job_parameters = {
558 "STAGE_UPGRADE_DOCKER_COMPONENTS": True,
559 "STAGE_UPGRADE_ES_KIBANA": True,
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300560 "STAGE_UPGRADE_SYSTEM_PART": True,
561 'OS_DIST_UPGRADE': 'true',
562 'OS_UPGRADE': 'true'
Hanna Arhipovaac008562019-10-17 11:54:23 +0300563 }
Hanna Arhipova508f6532021-01-27 15:52:45 +0200564 job_result, job_description = drivetrain.start_job_on_jenkins(
Hanna Arhipovaac008562019-10-17 11:54:23 +0300565 job_name="stacklight-upgrade",
566 job_parameters=job_parameters)
567
Hanna Arhipova508f6532021-01-27 15:52:45 +0200568 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaac008562019-10-17 11:54:23 +0300569
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300570
Hanna Arhipova19429962019-10-17 15:16:49 +0300571@pytest.mark.usefixtures("switch_to_proposed_pipelines",
572 "enable_openstack_update")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300573class TestOpenstackUpdate(object):
574
575 @pytest.mark.grab_versions
576 @pytest.mark.run_mcp_update
577 def test__pre_update__enable_pipeline_job(self,
578 reclass_actions, salt_actions,
579 show_step):
580 """ Enable pipeline in the Drivetrain
581
582 Scenario:
583 1. Add deploy.update.* classes to the reclass
584 2. Start jenkins.client salt state
585
586 """
587 salt = salt_actions
588 reclass = reclass_actions
589 show_step(1)
590 reclass.add_class("system.jenkins.client.job.deploy.update.upgrade",
591 "cluster/*/cicd/control/leader.yml")
592
593 reclass.add_class(
594 "system.jenkins.client.job.deploy.update.upgrade_ovs_gateway",
595 "cluster/*/cicd/control/leader.yml")
596
597 reclass.add_class(
598 "system.jenkins.client.job.deploy.update.upgrade_compute",
599 "cluster/*/cicd/control/leader.yml")
600
601 show_step(2)
602 r, errors = salt.enforce_state("I@jenkins:client", "jenkins.client")
603 assert errors is None
604
605 @pytest.mark.grab_versions
606 @pytest.mark.parametrize('target', get_control_plane_targets())
607 @pytest.mark.run_mcp_update
Hanna Arhipova19429962019-10-17 15:16:49 +0300608 def test__update__control_plane(self, drivetrain_actions, target):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300609 """Start 'Deploy - upgrade control VMs' for specific node
610 """
611 job_parameters = {
612 "TARGET_SERVERS": target,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200613 "OS_DIST_UPGRADE": True,
PGlazova5039252021-10-06 21:40:01 +0400614 "UPGRADE_SALTSTACK": True,
Hanna Arhipova606d5182019-12-13 13:23:55 +0200615 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300616 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200617 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300618 job_name="deploy-upgrade-control",
619 job_parameters=job_parameters)
620
Hanna Arhipova508f6532021-01-27 15:52:45 +0200621 assert job_result == 'SUCCESS', job_description
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300622
623 @pytest.mark.grab_versions
624 @pytest.mark.run_mcp_update
Hanna Arhipova606d5182019-12-13 13:23:55 +0200625 def test__update__data_plane(self, drivetrain_actions, salt_actions):
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300626 """Start 'Deploy - upgrade OVS gateway'
627 """
Hanna Arhipova606d5182019-12-13 13:23:55 +0200628 if not salt_actions.cmd_run("gtw*", "test.ping")[0].keys():
629 pytest.skip("This deployment doesn't have gtw* nodes")
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300630 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200631 "OS_DIST_UPGRADE": True,
632 "OS_UPGRADE": True,
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300633 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200634 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipovaeb3a2112019-09-13 18:45:21 +0300635 job_name="deploy-upgrade-ovs-gateway",
636 job_parameters=job_parameters)
637
Hanna Arhipova508f6532021-01-27 15:52:45 +0200638 assert job_result == 'SUCCESS', job_description
Hanna Arhipova19429962019-10-17 15:16:49 +0300639
640 @pytest.mark.grab_versions
641 @pytest.mark.run_mcp_update
642 def test__update__computes(self, drivetrain_actions):
643 """Start 'Deploy - upgrade computes'
644 """
645 job_parameters = {
Hanna Arhipova606d5182019-12-13 13:23:55 +0200646 "OS_DIST_UPGRADE": True,
647 "OS_UPGRADE": True,
Hanna Arhipova19429962019-10-17 15:16:49 +0300648 "INTERACTIVE": False}
Hanna Arhipova508f6532021-01-27 15:52:45 +0200649 job_result, job_description = drivetrain_actions.start_job_on_jenkins(
Hanna Arhipova19429962019-10-17 15:16:49 +0300650 job_name="deploy-upgrade-compute",
651 job_parameters=job_parameters)
652
Hanna Arhipova508f6532021-01-27 15:52:45 +0200653 assert job_result == 'SUCCESS', job_description