-
Notifications
You must be signed in to change notification settings - Fork 95
/
mgmt_cli_test.py
1658 lines (1421 loc) · 88.2 KB
/
mgmt_cli_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright (c) 2016 ScyllaDB
# pylint: disable=too-many-lines
# pylint: disable=too-many-lines
import random
import threading
from enum import Enum
from pathlib import Path
from functools import cached_property
import re
import time
from textwrap import dedent
from datetime import datetime, timedelta
from dataclasses import dataclass
import boto3
import yaml
from docker.errors import InvalidArgument
from invoke import exceptions
from argus.client.generic_result import Status
from sdcm import mgmt
from sdcm.argus_results import send_manager_benchmark_results_to_argus, submit_results_to_argus, \
ManagerBackupReadResult, ManagerBackupBenchmarkResult
from sdcm.mgmt import ScyllaManagerError, TaskStatus, HostStatus, HostSsl, HostRestStatus
from sdcm.mgmt.cli import ScyllaManagerTool, RestoreTask
from sdcm.mgmt.common import reconfigure_scylla_manager, get_persistent_snapshots
from sdcm.provision.helpers.certificate import TLSAssets
from sdcm.remote import shell_script_cmd
from sdcm.tester import ClusterTester
from sdcm.cluster import TestConfig
from sdcm.nemesis import MgmtRepair
from sdcm.utils.adaptive_timeouts import adaptive_timeout, Operations
from sdcm.utils.common import reach_enospc_on_node, clean_enospc_on_node
from sdcm.utils.issues import SkipPerIssues
from sdcm.utils.loader_utils import LoaderUtilsMixin
from sdcm.utils.time_utils import ExecutionTimer
from sdcm.sct_events.system import InfoEvent
from sdcm.sct_events.group_common_events import ignore_no_space_errors, ignore_stream_mutation_fragments_errors
from sdcm.utils.compaction_ops import CompactionOps
from sdcm.utils.gce_utils import get_gce_storage_client
from sdcm.utils.azure_utils import AzureService
from sdcm.utils.tablets.common import TabletsConfiguration
from sdcm.exceptions import FilesNotCorrupted
@dataclass
class ManagerTestMetrics:
backup_time = "N/A"
restore_time = "N/A"
@dataclass
class SnapshotData:
"""Describes the backup snapshot:
- bucket: S3 bucket name
- tag: snapshot tag, for example 'sm_20240816185129UTC'
- exp_timeout: expected timeout for the restore operation
- keyspaces: list of keyspaces presented in backup
- cs_read_cmd_template: cassandra-stress read command template
- prohibit_verification_read: if True, the verification read will be prohibited. Most likely, such a backup was
created via c-s user profile.
- number_of_rows: number of data rows written in the DB
- node_ids: list of node ids where backup was created
"""
bucket: str
tag: str
exp_timeout: int
keyspaces: list[str]
ks_tables_map: dict[str, list[str]]
cs_read_cmd_template: str
prohibit_verification_read: bool
number_of_rows: int
node_ids: list[str]
class DatabaseOperations(ClusterTester):
def get_keyspace_name(self, ks_prefix: str = 'keyspace', ks_number: int = 1) -> list:
"""Get keyspace name based on the following logic:
- if keyspaces number > 1, numeric indexes are used in the ks name;
- if keyspaces number == 1, ks name depends on whether compression is applied to keyspace. If applied,
the compression postfix will be used in the name, otherwise numeric index (keyspace1)
"""
if ks_number > 1:
return ['{}{}'.format(ks_prefix, i) for i in range(1, ks_number + 1)]
else:
stress_cmd = self.params.get('stress_read_cmd')
if 'compression' in stress_cmd:
compression_postfix = re.search('compression=(.*)Compressor', stress_cmd).group(1)
keyspace_name = '{}_{}'.format(ks_prefix, compression_postfix.lower())
else:
keyspace_name = '{}{}'.format(ks_prefix, ks_number)
return [keyspace_name]
def get_table_id(self, node, table_name, keyspace_name=None, remove_hyphen=True):
"""
:param keyspace_name: not mandatory. Should be used when there's more than one table with the same
name in different keyspaces
:param remove_hyphen: In the table's directory, scylla removes the hyphens from the id. Setting
the attribute to True will remove the hyphens.
"""
query = f"SELECT id FROM system_schema.tables WHERE table_name='{table_name}'"
if keyspace_name:
query += f"and keyspace_name='{keyspace_name}'"
with self.db_cluster.cql_connection_patient(node) as session:
results = session.execute(query)
base_id = str(results[0].id)
if remove_hyphen:
return base_id.replace('-', '')
return base_id
def create_keyspace_and_basic_table(self, keyspace_name, table_name="example_table",
replication_factor=1):
self.log.info("creating keyspace {}".format(keyspace_name))
keyspace_existence = self.create_keyspace(keyspace_name, replication_factor)
assert keyspace_existence, "keyspace creation failed"
# Keyspaces without tables won't appear in the repair, so the must have one
self.log.info("creating the table {} in the keyspace {}".format(table_name, keyspace_name))
self.create_table(table_name, keyspace_name=keyspace_name)
def create_ks_and_tables(self, num_ks, num_table):
# FIXME: beforehand we better change to have RF=1 to avoid restoring content while restoring replica of data
table_name = []
with self.db_cluster.cql_connection_patient(self.db_cluster.nodes[0]) as session:
for keyspace in range(num_ks):
session.execute(f"CREATE KEYSPACE IF NOT EXISTS ks00{keyspace} "
"WITH replication={'class':'NetworkTopologyStrategy', 'replication_factor':1}")
for table in range(num_table):
session.execute(f'CREATE COLUMNFAMILY IF NOT EXISTS ks00{keyspace}.table00{table} '
'(key varchar, c varchar, v varchar, PRIMARY KEY(key, c))')
table_name.append(f'ks00{keyspace}.table00{table}')
# FIXME: improve the structure + data insertion
# can use this function to populate tables better?
# self.populate_data_parallel()
return table_name
def delete_keyspace_directory(self, db_node, keyspace_name):
# Stop scylla service before deleting sstables to avoid partial deletion of files that are under compaction
db_node.stop_scylla_server(verify_up=False, verify_down=True)
try:
directoy_path = f"/var/lib/scylla/data/{keyspace_name}"
directory_size_result = db_node.remoter.sudo(f"du -h --max-depth=0 {directoy_path}")
result = db_node.remoter.sudo(f'rm -rf {directoy_path}')
if result.stderr:
raise FilesNotCorrupted('Files were not corrupted. CorruptThenRepair nemesis can\'t be run. '
'Error: {}'.format(result))
if directory_size_result.stdout:
directory_size = directory_size_result.stdout[:directory_size_result.stdout.find("\t")]
self.log.debug("Removed the directory of keyspace {} from node {}\nThe size of the directory is {}".format(
keyspace_name, db_node, directory_size))
finally:
db_node.start_scylla_server(verify_up=True, verify_down=False)
def insert_data_while_excluding_each_node(self, total_num_of_rows, keyspace_name="keyspace2"):
"""
The function split the number of rows to the number of nodes (minus 1) and in loop does the following:
shuts down one node, insert one part of the rows and starts the node again.
As a result, each node that was shut down will have missing rows and will require repair.
"""
num_of_nodes = self.params.get("n_db_nodes")
num_of_rows_per_insertion = int(total_num_of_rows / (num_of_nodes - 1))
stress_command_template = "cassandra-stress write cl=QUORUM n={} -schema 'keyspace={}" \
" replication(strategy=NetworkTopologyStrategy,replication_factor=3)'" \
" -col 'size=FIXED(1024) n=FIXED(1)' -pop seq={}..{} -mode cql3" \
" native -rate threads=200 -log interval=5"
start_of_range = 1
# We can't shut down node 1 since it's the default contact point of the stress command, and we have no way
# of changing that. As such, we skip it.
for node in self.db_cluster.nodes[1:]:
self.log.info("inserting {} rows to every node except {}".format(num_of_rows_per_insertion, node.name))
end_of_range = start_of_range + num_of_rows_per_insertion - 1
node.stop_scylla_server(verify_up=False, verify_down=True)
stress_thread = self.run_stress_thread(stress_cmd=stress_command_template.format(num_of_rows_per_insertion,
keyspace_name,
start_of_range,
end_of_range))
time.sleep(15)
self.log.info('load={}'.format(stress_thread.get_results()))
node.start_scylla_server(verify_up=True, verify_down=False)
start_of_range = end_of_range + 1
with self.db_cluster.cql_connection_patient(self.db_cluster.nodes[0]) as session:
session.execute(f"ALTER TABLE {keyspace_name}.standard1 WITH read_repair_chance = 0.0")
for node in self.db_cluster.nodes:
node.run_nodetool("flush")
def create_missing_rows_in_cluster(self, create_missing_rows_in_multiple_nodes, total_num_of_rows,
keyspace_to_be_repaired=None):
if create_missing_rows_in_multiple_nodes:
self.insert_data_while_excluding_each_node(total_num_of_rows=total_num_of_rows,
keyspace_name=keyspace_to_be_repaired)
self.wait_no_compactions_running(n=40, sleep_time=10)
else:
target_node = self.db_cluster.nodes[2]
self.delete_keyspace_directory(db_node=target_node, keyspace_name="keyspace1")
class StressLoadOperations(ClusterTester, LoaderUtilsMixin):
def _generate_load(self, keyspace_name: str = None):
self.log.info('Starting c-s write workload')
stress_cmd = self.params.get('stress_cmd')
stress_thread = self.run_stress_thread(stress_cmd=stress_cmd, keyspace_name=keyspace_name)
self.log.info('Sleeping for 15s to let cassandra-stress run...')
time.sleep(15)
return stress_thread
def generate_load_and_wait_for_results(self, keyspace_name: str = None):
load_thread = self._generate_load(keyspace_name=keyspace_name)
load_results = load_thread.get_results()
self.log.info(f'load={load_results}')
def generate_background_read_load(self):
self.log.info('Starting c-s read')
stress_cmd = self.params.get('stress_read_cmd')
number_of_nodes = self.params.get("n_db_nodes")
number_of_loaders = self.params.get("n_loaders")
throttle_per_node = 14666
throttle_per_loader = int(throttle_per_node * number_of_nodes / number_of_loaders)
stress_cmd = stress_cmd.replace("<THROTTLE_PLACE_HOLDER>", str(throttle_per_loader))
stress_thread = self.run_stress_thread(stress_cmd=stress_cmd)
self.log.info('Sleeping for 15s to let cassandra-stress run...')
time.sleep(15)
return stress_thread
def run_verification_read_stress(self, ks_names=None):
stress_queue = []
stress_cmd = self.params.get('stress_read_cmd')
keyspace_num = self.params.get('keyspace_num')
InfoEvent(message='Starting read stress for data verification').publish()
stress_start_time = datetime.now()
if ks_names:
self.assemble_and_run_all_stress_cmd_by_ks_names(stress_queue, stress_cmd, ks_names)
else:
self.assemble_and_run_all_stress_cmd(stress_queue, stress_cmd, keyspace_num)
for stress in stress_queue:
self.verify_stress_thread(cs_thread_pool=stress)
stress_run_time = datetime.now() - stress_start_time
InfoEvent(message=f'The read stress run was completed. Total run time: {stress_run_time}').publish()
def prepare_and_run_stress_read(self, command_template, keyspace_name, number_of_rows):
stress_queue = []
number_of_loaders = self.params.get("n_loaders")
rows_per_loader = int(number_of_rows / number_of_loaders)
for loader_index in range(number_of_loaders):
stress_command = command_template.format(num_of_rows=rows_per_loader,
keyspace_name=keyspace_name,
sequence_start=rows_per_loader * loader_index + 1,
sequence_end=rows_per_loader * (loader_index + 1),)
read_thread = self.run_stress_thread(stress_cmd=stress_command, round_robin=True,
stop_test_on_failure=False)
stress_queue.append(read_thread)
return stress_queue
class ClusterOperations(ClusterTester):
CLUSTER_NAME = "mgr_cluster1"
def ensure_and_get_cluster(self, manager_tool, force_add: bool = False):
"""Get the cluster if it is already added, otherwise add it to manager.
Use force_add=True if you want to re-add the cluster (delete and add again) even if it already added.
"""
mgr_cluster = manager_tool.get_cluster(cluster_name=self.CLUSTER_NAME)
if not mgr_cluster or force_add:
if mgr_cluster:
mgr_cluster.delete()
mgr_cluster = manager_tool.add_cluster(name=self.CLUSTER_NAME, db_cluster=self.db_cluster,
auth_token=self.monitors.mgmt_auth_token)
return mgr_cluster
def get_cluster_hosts_ip(self):
return ScyllaManagerTool.get_cluster_hosts_ip(self.db_cluster)
def get_cluster_hosts_with_ips(self):
return ScyllaManagerTool.get_cluster_hosts_with_ips(self.db_cluster)
def get_all_dcs_names(self):
dcs_names = set()
for node in self.db_cluster.nodes:
data_center = self.db_cluster.get_nodetool_info(node)['Data Center']
dcs_names.add(data_center)
return dcs_names
class BucketOperations(ClusterTester):
backup_azure_blob_service = None
backup_azure_blob_sas = None
def _run_cmd_with_retry(self, executor, cmd, retries=10):
for _ in range(retries):
try:
executor(cmd)
break
except exceptions.UnexpectedExit as ex:
self.log.debug("cmd %s failed with error %s, will retry", cmd, ex)
def install_awscli_dependencies(self, node):
if node.distro.is_ubuntu or node.distro.is_debian:
cmd = dedent("""
apt update
apt install -y python3-pip
PIP_BREAK_SYSTEM_PACKAGES=1 pip install awscli
""")
elif node.distro.is_rhel_like:
cmd = dedent("""
yum install -y epel-release
yum install -y python-pip
yum remove -y epel-release
pip install awscli==1.18.140
""")
else:
raise RuntimeError("This distro is not supported")
self._run_cmd_with_retry(executor=node.remoter.sudo, cmd=shell_script_cmd(cmd))
def install_gsutil_dependencies(self, node):
if node.distro.is_ubuntu or node.distro.is_debian:
cmd = dedent("""
echo 'deb https://packages.cloud.google.com/apt cloud-sdk main' | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
""")
self._run_cmd_with_retry(executor=node.remoter.run, cmd=shell_script_cmd(cmd))
node.install_package("google-cloud-cli")
else:
raise NotImplementedError("At the moment, we only support debian installation")
def install_azcopy_dependencies(self, node):
self._run_cmd_with_retry(executor=node.remoter.sudo, cmd=shell_script_cmd("""\
curl -L https://aka.ms/downloadazcopy-v10-linux | \
tar xz -C /usr/bin --strip-components 1 --wildcards '*/azcopy'
"""))
self.backup_azure_blob_service = \
f"https://{self.test_config.backup_azure_blob_credentials['account']}.blob.core.windows.net/"
self.backup_azure_blob_sas = self.test_config.backup_azure_blob_credentials["download_sas"]
@staticmethod
def download_from_s3(node, source, destination):
node.remoter.sudo(f"aws s3 cp '{source}' '{destination}'")
@staticmethod
def download_from_gs(node, source, destination):
node.remoter.sudo(f"gsutil cp '{source.replace('gcs://', 'gs://')}' '{destination}'")
def download_from_azure(self, node, source, destination):
# azure://<bucket>/<path> -> https://<account>.blob.core.windows.net/<bucket>/<path>?SAS
source = f"{source.replace('azure://', self.backup_azure_blob_service)}{self.backup_azure_blob_sas}"
node.remoter.sudo(f"azcopy copy '{source}' '{destination}'")
class SnapshotOperations(ClusterTester):
@staticmethod
def get_snapshot_data(snapshot_name: str) -> SnapshotData:
snapshots_config = "defaults/manager_restore_benchmark_snapshots.yaml"
with open(snapshots_config, encoding="utf-8") as snapshots_yaml:
all_snapshots_dict = yaml.safe_load(snapshots_yaml)
try:
snapshot_dict = all_snapshots_dict["sizes"][snapshot_name]
except KeyError:
raise ValueError(f"Snapshot data for size '{snapshot_name}'GB was not found in the {snapshots_config} file")
ks_tables_map = {}
for ks, ts in snapshot_dict["schema"].items():
t_names = [list(t.keys())[0] for t in ts]
ks_tables_map[ks] = t_names
snapshot_data = SnapshotData(
bucket=all_snapshots_dict["bucket"],
tag=snapshot_dict["tag"],
exp_timeout=snapshot_dict["exp_timeout"],
keyspaces=list(snapshot_dict["schema"].keys()),
ks_tables_map=ks_tables_map,
cs_read_cmd_template=all_snapshots_dict["cs_read_cmd_template"],
prohibit_verification_read=snapshot_dict["prohibit_verification_read"],
number_of_rows=snapshot_dict["number_of_rows"],
node_ids=snapshot_dict.get("node_ids"),
)
return snapshot_data
@staticmethod
def _get_all_snapshot_files_s3(cluster_id, bucket_name, region_name):
file_set = set()
s3_client = boto3.client('s3', region_name=region_name)
paginator = s3_client.get_paginator('list_objects')
pages = paginator.paginate(Bucket=bucket_name, Prefix=f'backup/sst/cluster/{cluster_id}')
for page in pages:
# No Contents key means that no snapshot file of the cluster exist,
# probably no backup ran before this function
if "Contents" in page:
content_list = page["Contents"]
file_set.update([item["Key"] for item in content_list])
return file_set
@staticmethod
def _get_all_snapshot_files_gce(cluster_id, bucket_name):
file_set = set()
storage_client, _ = get_gce_storage_client()
blobs = storage_client.list_blobs(bucket_or_name=bucket_name, prefix=f'backup/sst/cluster/{cluster_id}')
for listing_object in blobs:
file_set.add(listing_object.name)
# Unlike S3, if no files match the prefix, no error will occur
return file_set
@staticmethod
def _get_all_snapshot_files_azure(cluster_id, bucket_name):
file_set = set()
azure_service = AzureService()
container_client = azure_service.blob.get_container_client(container=bucket_name)
dir_listing = container_client.list_blobs(name_starts_with=f'backup/sst/cluster/{cluster_id}')
for listing_object in dir_listing:
file_set.add(listing_object.name)
return file_set
def get_all_snapshot_files(self, cluster_id):
bucket_name = self.params.get('backup_bucket_location').split()[0]
if self.params.get('backup_bucket_backend') == 's3':
region_name = self.params.get("backup_bucket_region") or self.params.get("region_name").split()[0]
return self._get_all_snapshot_files_s3(cluster_id=cluster_id, bucket_name=bucket_name,
region_name=region_name)
elif self.params.get('backup_bucket_backend') == 'gcs':
return self._get_all_snapshot_files_gce(cluster_id=cluster_id, bucket_name=bucket_name)
elif self.params.get('backup_bucket_backend') == 'azure':
return self._get_all_snapshot_files_azure(cluster_id=cluster_id, bucket_name=bucket_name)
else:
raise ValueError(f'"{self.params.get("backup_bucket_backend")}" not supported')
class ManagerTestFunctionsMixIn(
DatabaseOperations,
StressLoadOperations,
ClusterOperations,
BucketOperations,
SnapshotOperations,
):
test_config = TestConfig()
manager_test_metrics = ManagerTestMetrics()
def get_email_data(self):
self.log.info("Prepare data for email")
email_data = self._get_common_email_data()
restore_parameters = self.params.get("mgmt_restore_extra_params")
agent_backup_config = self.params.get("mgmt_agent_backup_config")
if agent_backup_config:
agent_backup_config = agent_backup_config.dict()
email_data.update(
{
"manager_server_repo": self.params.get("scylla_mgmt_address"),
"manager_agent_repo": (self.params.get("scylla_mgmt_agent_address") or
self.params.get("scylla_mgmt_address")),
"backup_time": str(self.manager_test_metrics.backup_time),
"restore_time": str(self.manager_test_metrics.restore_time),
"restore_parameters": restore_parameters,
"agent_backup_config": agent_backup_config,
}
)
return email_data
@cached_property
def locations(self) -> list[str]:
backend = self.params.get("backup_bucket_backend")
buckets = self.params.get("backup_bucket_location")
if not isinstance(buckets, list):
buckets = buckets.split()
# FIXME: Make it works with multiple locations or file a bug for scylla-manager.
return [f"{backend}:{location}" for location in buckets[:1]]
# pylint: disable=too-many-arguments
def verify_backup_success(self, mgr_cluster, backup_task, ks_names: list = None, tables_names: list = None,
truncate=True, restore_data_with_task=False, timeout=None):
if ks_names is None:
ks_names = ['keyspace1']
if tables_names is None:
tables_names = ['standard1']
ks_tables_map = {keyspace: tables_names for keyspace in ks_names}
if truncate:
for ks, tables in ks_tables_map.items():
for table_name in tables:
self.log.info(f'running truncate on {ks}.{table_name}')
self.db_cluster.nodes[0].run_cqlsh(f'TRUNCATE {ks}.{table_name}')
if restore_data_with_task:
self.restore_backup_with_task(mgr_cluster=mgr_cluster, snapshot_tag=backup_task.get_snapshot_tag(),
timeout=timeout, restore_data=True)
else:
snapshot_tag = backup_task.get_snapshot_tag()
self.restore_backup_without_manager(mgr_cluster=mgr_cluster, snapshot_tag=snapshot_tag,
ks_tables_list=ks_tables_map)
def restore_backup_without_manager(self, mgr_cluster, snapshot_tag, ks_tables_list, location=None,
precreated_backup=False):
"""Restore backup without Scylla Manager but using the `nodetool refresh` operation
(https://opensource.docs.scylladb.com/stable/operating-scylla/nodetool-commands/refresh.html).
The method downloads backup files from the backup bucket (aws s3 cp ...) and then loads them (nodetool refresh)
into the cluster node by node and table by table.
Two flows are supported:
- restore to a new cluster from pre-created backup.
- restore from backup created at the same cluster.
The difference between these two flows is in the way the node_id is retrieved - if the backup was created with
the cluster under test use node_ids of cluster under test, otherwise, get node_id from `sctool backup files...`
"""
backup_bucket_backend = self.params.get("backup_bucket_backend")
if backup_bucket_backend == "s3":
install_dependencies = self.install_awscli_dependencies
download = self.download_from_s3
elif backup_bucket_backend == "gcs":
install_dependencies = self.install_gsutil_dependencies
download = self.download_from_gs
elif backup_bucket_backend == "azure":
install_dependencies = self.install_azcopy_dependencies
download = self.download_from_azure
else:
raise ValueError(f'{backup_bucket_backend=} is not supported')
browse_all_clusters = True if precreated_backup else False
per_node_backup_file_paths = mgr_cluster.get_backup_files_dict(snapshot_tag, location, browse_all_clusters)
# One path is for schema, it should be filtrated as this method is supposed to be run on restored schema cluster
backed_up_node_ids = [i for i in per_node_backup_file_paths if 'schema' not in i]
nodetool_refresh_extra_flags = self.params.get('mgmt_nodetool_refresh_flags') or ""
for index, node in enumerate(self.db_cluster.nodes):
install_dependencies(node=node)
node_data_path = Path("/var/lib/scylla/data")
# If the backup was not created with the cluster under test (precreated backup), get node_id from
# sctool backup files output, otherwise, use node_ids of cluster under test
backed_up_node_id = backed_up_node_ids[index] if precreated_backup else node.host_id
for keyspace, tables in ks_tables_list.items():
keyspace_path = node_data_path / keyspace
for table in tables:
table_id = self.get_table_id(node=node, table_name=table, keyspace_name=keyspace)
table_upload_path = keyspace_path / f"{table}-{table_id}" / "upload"
with ExecutionTimer() as timer:
for file_path in per_node_backup_file_paths[backed_up_node_id][keyspace][table]:
download(node=node, source=file_path, destination=table_upload_path)
self.log.info(f"[Node {index}][{keyspace}.{table}] Download took {timer.duration}")
node.remoter.sudo(f"chown scylla:scylla -Rf {table_upload_path}")
with ExecutionTimer() as timer:
node.run_nodetool(f"refresh {keyspace} {table} {nodetool_refresh_extra_flags}")
self.log.info(f"[Node {index}][{keyspace}.{table}] Nodetool refresh took {timer.duration}")
def restore_backup_with_task(self, mgr_cluster, snapshot_tag, timeout, restore_schema=False, restore_data=False,
location_list=None, extra_params=None):
location_list = location_list if location_list else self.locations
restore_task = mgr_cluster.create_restore_task(restore_schema=restore_schema, restore_data=restore_data,
location_list=location_list, snapshot_tag=snapshot_tag,
extra_params=extra_params)
restore_task.wait_and_get_final_status(step=30, timeout=timeout)
assert restore_task.status == TaskStatus.DONE, f"Restoration of {snapshot_tag} has failed!"
InfoEvent(message=f'The restore task has ended successfully. '
f'Restore run time: {restore_task.duration}.').publish()
if restore_schema:
self.db_cluster.restart_scylla() # After schema restoration, you should restart the nodes
return restore_task
def create_repair_and_alter_it_with_repair_control(self):
keyspace_to_be_repaired = "keyspace2"
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = manager_tool.add_cluster(name=self.CLUSTER_NAME + '_repair_control',
db_cluster=self.db_cluster,
auth_token=self.monitors.mgmt_auth_token)
# writing 292968720 rows, equal to the amount of data written in the prepare (around 100gb per node),
# to create a large data fault and therefore a longer running repair
self.create_missing_rows_in_cluster(create_missing_rows_in_multiple_nodes=True,
keyspace_to_be_repaired=keyspace_to_be_repaired,
total_num_of_rows=292968720)
arg_list = [{"intensity": .0001},
{"intensity": 0},
{"parallel": 1},
{"intensity": 2, "parallel": 1}]
InfoEvent(message="Repair started").publish()
repair_task = mgr_cluster.create_repair_task(keyspace="keyspace2")
next_percentage_block = 20
repair_task.wait_for_percentage(next_percentage_block)
for args in arg_list:
next_percentage_block += 20
InfoEvent(message=f"Changing repair args to: {args}").publish()
mgr_cluster.control_repair(**args)
repair_task.wait_for_percentage(next_percentage_block)
repair_task.wait_and_get_final_status(step=30)
InfoEvent(message="Repair ended").publish()
class ManagerRestoreTests(ManagerTestFunctionsMixIn):
def test_restore_multiple_backup_snapshots(self): # pylint: disable=too-many-locals # noqa: PLR0914
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
cluster_backend = self.params.get('cluster_backend')
if cluster_backend != 'aws':
self.log.error("Test supports only AWS ATM")
return
persistent_manager_snapshots_dict = get_persistent_snapshots()
target_bucket = persistent_manager_snapshots_dict[cluster_backend]["bucket"]
backup_bucket_backend = self.params.get("backup_bucket_backend")
location_list = [f"{backup_bucket_backend}:{target_bucket}"]
confirmation_stress_template = persistent_manager_snapshots_dict[cluster_backend]["confirmation_stress_template"]
read_stress_list = []
snapshot_sizes = persistent_manager_snapshots_dict[cluster_backend]["snapshots_sizes"]
for size in snapshot_sizes:
number_of_rows = persistent_manager_snapshots_dict[cluster_backend]["snapshots_sizes"][size]["number_of_rows"]
expected_timeout = persistent_manager_snapshots_dict[cluster_backend]["snapshots_sizes"][size]["expected_timeout"]
snapshot_dict = persistent_manager_snapshots_dict[cluster_backend]["snapshots_sizes"][size]["snapshots"]
snapshot_tag = random.choice(list(snapshot_dict.keys()))
keyspace_name = snapshot_dict[snapshot_tag]["keyspace_name"]
self.restore_backup_with_task(mgr_cluster=mgr_cluster, snapshot_tag=snapshot_tag,
timeout=180, restore_schema=True, location_list=location_list)
self.restore_backup_with_task(mgr_cluster=mgr_cluster, snapshot_tag=snapshot_tag,
timeout=expected_timeout, restore_data=True, location_list=location_list)
stress_command = confirmation_stress_template.format(num_of_rows=number_of_rows,
keyspace_name=keyspace_name,
sequence_start=1,
sequence_end=number_of_rows)
read_stress_list.append(stress_command)
for stress in read_stress_list:
read_thread = self.run_stress_thread(stress_cmd=stress, round_robin=False)
self.verify_stress_thread(cs_thread_pool=read_thread)
def test_restore_backup_with_task(self, ks_names: list = None):
self.log.info('starting test_restore_backup_with_task')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
if not ks_names:
ks_names = ['keyspace1']
backup_task = mgr_cluster.create_backup_task(location_list=self.locations, keyspace_list=ks_names)
backup_task_status = backup_task.wait_and_get_final_status(timeout=1500)
assert backup_task_status == TaskStatus.DONE, \
f"Backup task ended in {backup_task_status} instead of {TaskStatus.DONE}"
soft_timeout = 36 * 60
hard_timeout = 50 * 60
with adaptive_timeout(Operations.MGMT_REPAIR, self.db_cluster.data_nodes[0], timeout=soft_timeout):
self.verify_backup_success(mgr_cluster=mgr_cluster, backup_task=backup_task, ks_names=ks_names,
restore_data_with_task=True, timeout=hard_timeout)
self.run_verification_read_stress(ks_names)
mgr_cluster.delete() # remove cluster at the end of the test
self.log.info('finishing test_restore_backup_with_task')
class ManagerBackupTests(ManagerRestoreTests):
def test_basic_backup(self, ks_names: list = None):
self.log.info('starting test_basic_backup')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
backup_task = mgr_cluster.create_backup_task(location_list=self.locations)
backup_task_status = backup_task.wait_and_get_final_status(timeout=1500)
assert backup_task_status == TaskStatus.DONE, \
f"Backup task ended in {backup_task_status} instead of {TaskStatus.DONE}"
self.verify_backup_success(mgr_cluster=mgr_cluster, backup_task=backup_task, ks_names=ks_names)
self.run_verification_read_stress(ks_names)
mgr_cluster.delete() # remove cluster at the end of the test
self.log.info('finishing test_basic_backup')
def test_backup_multiple_ks_tables(self):
self.log.info('starting test_backup_multiple_ks_tables')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
tables = self.create_ks_and_tables(10, 100)
self.log.debug('tables list = {}'.format(tables))
# TODO: insert data to those tables
backup_task = mgr_cluster.create_backup_task(location_list=self.locations)
backup_task_status = backup_task.wait_and_get_final_status(timeout=1500)
assert backup_task_status == TaskStatus.DONE, \
f"Backup task ended in {backup_task_status} instead of {TaskStatus.DONE}"
self.verify_backup_success(mgr_cluster=mgr_cluster, backup_task=backup_task)
self.log.info('finishing test_backup_multiple_ks_tables')
def test_backup_location_with_path(self):
self.log.info('starting test_backup_location_with_path')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
try:
mgr_cluster.create_backup_task(location_list=[f'{location}/path_testing/' for location in self.locations])
except ScyllaManagerError as error:
self.log.info('Expected to fail - error: {}'.format(error))
self.log.info('finishing test_backup_location_with_path')
def test_backup_rate_limit(self):
self.log.info('starting test_backup_rate_limit')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
rate_limit_list = [f'{dc}:{random.randint(15, 25)}' for dc in self.get_all_dcs_names()]
self.log.info('rate limit will be {}'.format(rate_limit_list))
backup_task = mgr_cluster.create_backup_task(location_list=self.locations, rate_limit_list=rate_limit_list)
task_status = backup_task.wait_and_get_final_status(timeout=18000)
assert task_status == TaskStatus.DONE, \
f"Task {backup_task.id} did not end successfully:\n{backup_task.detailed_progress}"
self.log.info('backup task finished with status {}'.format(task_status))
# TODO: verify that the rate limit is as set in the cmd
self.verify_backup_success(mgr_cluster=mgr_cluster, backup_task=backup_task)
self.log.info('finishing test_backup_rate_limit')
def test_backup_purge_removes_orphan_files(self):
"""
The test stops a backup task mid-upload, so that orphan files will remain in the destination bucket.
Afterwards, the test reruns the backup task from scratch (with the --no-continue flag, so it's practically
a new task) and after the task concludes (successfully) the test makes sure the manager has deleted the
previously mentioned orphan files from the bucket.
"""
self.log.info('starting test_backup_purge_removes_orphan_files')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
snapshot_file_list_pre_test = self.get_all_snapshot_files(cluster_id=mgr_cluster.id)
backup_task = mgr_cluster.create_backup_task(location_list=self.locations, retention=1)
backup_task.wait_for_uploading_stage(step=5)
backup_task.stop()
snapshot_file_list_post_task_stopping = self.get_all_snapshot_files(cluster_id=mgr_cluster.id)
orphan_files_pre_rerun = snapshot_file_list_post_task_stopping.difference(snapshot_file_list_pre_test)
assert orphan_files_pre_rerun, "SCT could not create orphan snapshots by stopping a backup task"
# So that the files' names will be different form the previous ones,
# and they won't simply replace the previous files in the bucket
for node in self.db_cluster.nodes:
node.run_nodetool("compact")
backup_task.start(continue_task=False)
backup_task.wait_and_get_final_status(step=10)
snapshot_file_list_post_purge = self.get_all_snapshot_files(cluster_id=mgr_cluster.id)
orphan_files_post_rerun = snapshot_file_list_post_purge.intersection(orphan_files_pre_rerun)
assert not orphan_files_post_rerun, "orphan files were not deleted!"
self.log.info('finishing test_backup_purge_removes_orphan_files')
def test_enospc_during_backup(self):
self.log.info('starting test_enospc_during_backup')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
# deleting previous snapshots so that the current backup will last longer
previous_backup_tasks = mgr_cluster.backup_task_list
for backup_task in previous_backup_tasks:
backup_task.delete_backup_snapshot()
target_node = self.db_cluster.nodes[1]
with ignore_no_space_errors(node=target_node):
try:
backup_task = mgr_cluster.create_backup_task(location_list=self.locations)
backup_task.wait_for_uploading_stage()
backup_task.stop()
reach_enospc_on_node(target_node=target_node)
backup_task.start()
backup_task.wait_and_get_final_status()
assert backup_task.status == TaskStatus.DONE, "The backup failed to run on a node with no free space," \
" while it should have had the room for snapshots due " \
"to the previous run"
finally:
clean_enospc_on_node(target_node=target_node, sleep_time=30)
self.log.info('finishing test_enospc_during_backup')
def test_enospc_before_restore(self):
self.log.info('starting test_enospc_before_restore')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
backup_task = mgr_cluster.create_backup_task(location_list=self.locations, keyspace_list=["keyspace1"])
backup_task_status = backup_task.wait_and_get_final_status(timeout=1500)
assert backup_task_status == TaskStatus.DONE, \
f"Backup task ended in {backup_task_status} instead of {TaskStatus.DONE}"
target_node = self.db_cluster.nodes[1]
with ignore_no_space_errors(node=target_node), ignore_stream_mutation_fragments_errors():
try:
reach_enospc_on_node(target_node=target_node)
snapshot_tag = backup_task.get_snapshot_tag()
restore_task = mgr_cluster.create_restore_task(restore_data=True, location_list=self.locations,
snapshot_tag=snapshot_tag)
final_status = restore_task.wait_and_get_final_status(step=30)
assert final_status == TaskStatus.ERROR, \
f"The restore task is supposed to fail, since node {target_node} lacks the disk space to download" \
f"the snapshot files"
if not SkipPerIssues("scylladb/scylla-manager#4087", self.params):
full_progress_string = restore_task.progress_string(parse_table_res=False,
is_verify_errorless_result=True).stdout
assert "not enough disk space" in full_progress_string.lower(), \
f"The restore failed as expected when one of the nodes was out of disk space, " \
f"but with an ill fitting error message: {full_progress_string}"
finally:
clean_enospc_on_node(target_node=target_node, sleep_time=30)
self.log.info('finishing test_enospc_before_restore')
def test_backup_feature(self):
self.generate_load_and_wait_for_results()
with self.subTest('Backup Multiple KS\' and Tables'):
self.test_backup_multiple_ks_tables()
with self.subTest('Backup to Location with path'):
self.test_backup_location_with_path()
with self.subTest('Test Backup Rate Limit'):
self.test_backup_rate_limit()
with self.subTest('Test Backup Purge Removes Orphans Files'):
self.test_backup_purge_removes_orphan_files()
with self.subTest('Test restore a backup with restore task'):
self.test_restore_backup_with_task()
with self.subTest('Test Backup end of space'): # Preferably at the end
self.test_enospc_during_backup()
with self.subTest('Test Restore end of space'):
self.test_enospc_before_restore()
def test_no_delta_backup_at_disabled_compaction(self):
"""The purpose of test is to check that delta backup (no changes to DB between backups) takes time -> 0.
Important test precondition is to disable compaction on all nodes in the cluster.
Otherwise, new set of SSTables is created what ends up in the situation that almost no deduplication is applied.
For more details https://github.com/scylladb/scylla-manager/issues/3936#issuecomment-2277611709
"""
self.log.info('starting test_consecutive_backups')
self.log.info('Run write stress')
self.run_prepare_write_cmd()
self.log.info('Disable compaction for every node in the cluster')
compaction_ops = CompactionOps(cluster=self.db_cluster)
for node in self.db_cluster.nodes:
compaction_ops.disable_autocompaction_on_ks_cf(node=node)
self.log.info('Prepare Manager')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool, force_add=True)
self.log.info('Run backup #1')
backup_task_1 = mgr_cluster.create_backup_task(location_list=self.locations)
backup_task_1_status = backup_task_1.wait_and_get_final_status(timeout=3600)
assert backup_task_1_status == TaskStatus.DONE, \
f"Backup task ended in {backup_task_1_status} instead of {TaskStatus.DONE}"
self.log.info(f'Backup task #1 duration - {backup_task_1.duration}')
self.log.info('Run backup #2')
backup_task_2 = mgr_cluster.create_backup_task(location_list=self.locations)
backup_task_2_status = backup_task_2.wait_and_get_final_status(timeout=60)
assert backup_task_2_status == TaskStatus.DONE, \
f"Backup task ended in {backup_task_2_status} instead of {TaskStatus.DONE}"
self.log.info(f'Backup task #2 duration - {backup_task_2.duration}')
assert backup_task_2.duration < timedelta(seconds=15), "No-delta backup took more than 15 seconds"
self.log.info('Verify restore from backup #2')
self.verify_backup_success(mgr_cluster=mgr_cluster, backup_task=backup_task_2,
restore_data_with_task=True, timeout=3600)
self.log.info('Run verification read stress')
self.run_verification_read_stress()
self.log.info('finishing test_consecutive_backups')
class ManagerRepairTests(ManagerTestFunctionsMixIn):
LOCALSTRATEGY_KEYSPACE_NAME = "localstrategy_keyspace"
NETWORKSTRATEGY_KEYSPACE_NAME = "networkstrategy_keyspace"
def _test_intensity_and_parallel(self, fault_multiple_nodes):
keyspace_to_be_repaired = "keyspace2"
InfoEvent(message='starting test_intensity_and_parallel').publish()
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = manager_tool.add_cluster(
name=self.CLUSTER_NAME + '_intensity_and_parallel',
db_cluster=self.db_cluster,
auth_token=self.monitors.mgmt_auth_token,
)
InfoEvent(message="Starting faulty load (to be repaired)").publish()
self.create_missing_rows_in_cluster(create_missing_rows_in_multiple_nodes=fault_multiple_nodes,
keyspace_to_be_repaired=keyspace_to_be_repaired,
total_num_of_rows=29296872)
InfoEvent(message="Starting a repair with no intensity").publish()
base_repair_task = mgr_cluster.create_repair_task(keyspace="keyspace*")
base_repair_task.wait_and_get_final_status(step=30)
assert base_repair_task.status == TaskStatus.DONE, "The base repair task did not end in the expected time"
InfoEvent(message=f"The base repair, with no intensity argument, took {base_repair_task.duration}").publish()
with self.db_cluster.cql_connection_patient(self.db_cluster.nodes[0]) as session:
session.execute(f"DROP KEYSPACE IF EXISTS {keyspace_to_be_repaired}")
arg_list = [{"intensity": .5},
{"intensity": .25},
{"intensity": .0001},
{"intensity": 2},
{"intensity": 4},
{"parallel": 1},
{"parallel": 2},
{"intensity": 2, "parallel": 1},
{"intensity": 100},
{"intensity": 0}]
for arg_dict in arg_list:
InfoEvent(message="Starting faulty load (to be repaired)").publish()
self.create_missing_rows_in_cluster(create_missing_rows_in_multiple_nodes=fault_multiple_nodes,
keyspace_to_be_repaired=keyspace_to_be_repaired,
total_num_of_rows=29296872)
InfoEvent(message=f"Starting a repair with {arg_dict}").publish()
repair_task = mgr_cluster.create_repair_task(**arg_dict, keyspace="keyspace*")
repair_task.wait_and_get_final_status(step=30)
InfoEvent(message=f"repair with {arg_dict} took {repair_task.duration}").publish()
with self.db_cluster.cql_connection_patient(self.db_cluster.nodes[0]) as session:
session.execute(f"DROP KEYSPACE IF EXISTS {keyspace_to_be_repaired}")
InfoEvent(message='finishing test_intensity_and_parallel').publish()
def test_repair_intensity_feature(self, fault_multiple_nodes):
InfoEvent(message="Starting C-S write load").publish()
self.run_prepare_write_cmd()
InfoEvent(message="Flushing").publish()
for node in self.db_cluster.nodes:
node.run_nodetool("flush")
InfoEvent(message="Waiting for compactions to end").publish()
self.wait_no_compactions_running(n=30, sleep_time=30)
InfoEvent(message="Starting C-S read load").publish()
stress_read_thread = self.generate_background_read_load()
time.sleep(600) # So we will see the base load of the cluster
InfoEvent(message="Sleep ended - Starting tests").publish()
with self.subTest('test_intensity_and_parallel'):
self._test_intensity_and_parallel(fault_multiple_nodes=fault_multiple_nodes)
load_results = stress_read_thread.get_results()
self.log.info('load={}'.format(load_results))
def test_repair_multiple_keyspace_types(self): # pylint: disable=invalid-name
self.log.info('starting test_repair_multiple_keyspace_types')
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.monitors.nodes[0])
mgr_cluster = self.ensure_and_get_cluster(manager_tool)
self.create_keyspace_and_basic_table(self.NETWORKSTRATEGY_KEYSPACE_NAME, replication_factor=2)
self.create_keyspace_and_basic_table(self.LOCALSTRATEGY_KEYSPACE_NAME, replication_factor=0)
repair_task = mgr_cluster.create_repair_task()
task_final_status = repair_task.wait_and_get_final_status(timeout=7200)
assert task_final_status == TaskStatus.DONE, 'Task: {} final status is: {}.'.format(repair_task.id,
str(repair_task.status))
self.log.info('Task: {} is done.'.format(repair_task.id))
self.log.debug("sctool version is : {}".format(manager_tool.sctool.version))
expected_keyspaces_to_be_repaired = ["system_distributed", self.NETWORKSTRATEGY_KEYSPACE_NAME]
if not self.db_cluster.nodes[0].raft.is_consistent_topology_changes_enabled:
expected_keyspaces_to_be_repaired.append("system_auth")
self.log.debug("Keyspaces expected to be repaired: {}".format(expected_keyspaces_to_be_repaired))
per_keyspace_progress = repair_task.per_keyspace_progress
self.log.info("Looking in the repair output for all of the required keyspaces")
for keyspace_name in expected_keyspaces_to_be_repaired:
keyspace_repair_percentage = per_keyspace_progress.get(keyspace_name, None)
assert keyspace_repair_percentage is not None, \
"The keyspace {} was not included in the repair!".format(keyspace_name)
assert keyspace_repair_percentage == 100, \
"The repair of the keyspace {} stopped at {}%".format(
keyspace_name, keyspace_repair_percentage)
localstrategy_keyspace_percentage = per_keyspace_progress.get(self.LOCALSTRATEGY_KEYSPACE_NAME, None)
assert localstrategy_keyspace_percentage is None, \
"The keyspace with the replication strategy of localstrategy was included in repair, when it shouldn't"
self.log.info("the sctool repair command was completed successfully")
mgr_cluster.delete() # remove cluster at the end of the test
self.log.info('finishing test_repair_multiple_keyspace_types')
def test_repair_intensity_feature_on_multiple_node(self):
self.test_repair_intensity_feature(fault_multiple_nodes=True)
def test_repair_intensity_feature_on_single_node(self):
self.test_repair_intensity_feature(fault_multiple_nodes=False)
def test_repair_control(self):
InfoEvent(message="Starting C-S write load").publish()
self.run_prepare_write_cmd()
InfoEvent(message="Flushing").publish()
for node in self.db_cluster.nodes: