forked from scylladb/scylla-cluster-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_version_utils.py
613 lines (530 loc) · 28.8 KB
/
test_version_utils.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
from __future__ import absolute_import
import os
import unittest
from unittest import mock
import pytest
import requests
import sdcm
from sdcm.utils.version_utils import (
assume_version,
get_all_versions,
get_branch_version,
get_branch_version_for_multiple_repositories,
get_docker_image_by_version,
get_git_tag_from_helm_chart_version,
get_scylla_urls_from_repository,
get_specific_tag_of_docker_image,
is_enterprise,
scylla_versions,
ComparableScyllaOperatorVersion,
ComparableScyllaVersion,
MethodVersionNotFound,
RepositoryDetails,
ScyllaFileType,
SCYLLA_VERSION_GROUPED_RE,
VERSION_NOT_FOUND_ERROR,
)
BASE_S3_DOWNLOAD_URL = 'https://s3.amazonaws.com/downloads.scylladb.com'
DEB_URL = \
f'{BASE_S3_DOWNLOAD_URL}/enterprise/deb/unstable/stretch/9f724fedb93b4734fcfaec1156806921ff46e956-2bdfa9f7e' \
f'f592edaf15e028faf3b7f695f39ebc1-525a0255f73d454f8f97f32b8bdd71c8dec35d3d/68/scylladb-2019.1/' \
f'scylla.list'
RPM_URL = \
f'{BASE_S3_DOWNLOAD_URL}/enterprise/rpm/unstable/centos/9f724fedb93b4734fcfaec1156806921ff46e956-2bdfa9f7e' \
f'f592edaf15e028faf3b7f695f39ebc1-525a0255f73d454f8f97f32b8bdd71c8dec35d3d-a6b2b2355c666b1893f702a587287da' \
f'978aeec22/71/scylla.repo'
BROKEN_URL = 'https://www.google.com'
class TestVersionUtils(unittest.TestCase):
def check_multiple_urls(self, urls):
expected_versions, repo_urls = [], []
for (url, expected_version) in urls:
repo_urls.append(url)
expected_versions.append(expected_version)
for branch_version, expected_version in zip(get_branch_version_for_multiple_repositories(urls=repo_urls),
expected_versions):
self.assertEqual(branch_version, expected_version)
def test_01_get_branch_version_from_list(self):
self.assertEqual(get_branch_version(DEB_URL), '2019.1.1')
def test_02_get_branch_version_from_repo(self):
self.check_multiple_urls(urls=[(RPM_URL, "2019.1.1")])
def test_03_get_branch_version(self):
self.check_multiple_urls(urls=[(RPM_URL, "2019.1.1"), (DEB_URL, "2019.1.1")])
def test_04_get_branch_version_failed(self):
msg_error = VERSION_NOT_FOUND_ERROR
self.assertRaisesRegex(ValueError, msg_error, get_branch_version, BROKEN_URL)
self.assertRaisesRegex(ValueError, msg_error, get_branch_version, BROKEN_URL)
self.assertRaisesRegex(ValueError, msg_error, get_branch_version, BROKEN_URL)
def test_05_is_enterprise(self):
self.assertEqual(is_enterprise('2019.1.1'), True)
self.assertEqual(is_enterprise('2018'), True)
self.assertEqual(is_enterprise('3.1'), False)
self.assertEqual(is_enterprise('2.2'), False)
self.assertEqual(is_enterprise('666.development'), False)
def test_06_get_scylla_urls_from_repository_rpm_one_arch(self):
with unittest.mock.patch.object(sdcm.utils.version_utils, 'get_url_content', return_value='', clear=True):
urls = get_scylla_urls_from_repository(
RepositoryDetails(
type=ScyllaFileType.YUM,
urls=[
'baseurl=http://downloads.scylladb.com/unstable/scylla/master/rpm/centos/2021-06-29T00:59:00Z/scylla/$basearch/',
'[scylla-generic]', 'enabled=1',
'name=Scylla for centos $releasever',
'[scylla]',
'name=Scylla for Centos $releasever - $basearch',
'baseurl=http://downloads.scylladb.com/unstable/scylla/master/rpm/centos/2021-06-29T00:59:00Z/scylla/noarch/',
'gpgcheck=0'
]
)
)
self.assertEqual(
{
'http://downloads.scylladb.com/unstable/scylla/master/rpm/centos/2021-06-29T00:59:00Z/scylla/noarch'
'/repodata/repomd.xml',
'http://downloads.scylladb.com/unstable/scylla/master/rpm/centos/2021-06-29T00:59:00Z/scylla/x86_64'
'/repodata/repomd.xml',
},
urls)
def test_06_get_scylla_urls_from_repository_deb_one_arch(self):
with unittest.mock.patch.object(sdcm.utils.version_utils, 'get_url_content', return_value='', clear=True):
urls = get_scylla_urls_from_repository(RepositoryDetails(
type=ScyllaFileType.DEBIAN,
urls=['deb [arch=amd64] http://downloads.scylladb.com/unstable/scylla/master/deb/unified/'
'2021-06-23T10:53:35Z/scylladb-master stable main'],
))
self.assertEqual(
{
'http://downloads.scylladb.com/unstable/scylla/master/deb/unified/2021-06-23T10:53:35Z/scylladb-master/'
'dists/stable/main/binary-amd64/Packages',
},
urls)
def test_06_get_scylla_urls_from_repository_deb_two_archs(self):
with unittest.mock.patch.object(sdcm.utils.version_utils, 'get_url_content', return_value='', clear=True):
urls = get_scylla_urls_from_repository(RepositoryDetails(
type=ScyllaFileType.DEBIAN,
urls=['deb [arch=amd64,arm64] http://downloads.scylladb.com/unstable/scylla/master/deb/unified/'
'2021-06-23T10:53:35Z/scylladb-master stable main'],
))
self.assertEqual(
{
'http://downloads.scylladb.com/unstable/scylla/master/deb/unified/2021-06-23T10:53:35Z/scylladb-master/'
'dists/stable/main/binary-amd64/Packages',
'http://downloads.scylladb.com/unstable/scylla/master/deb/unified/2021-06-23T10:53:35Z/scylladb-master/'
'dists/stable/main/binary-arm64/Packages',
},
urls)
def test_06_get_scylla_urls_from_repository_no_urls(self):
with unittest.mock.patch.object(sdcm.utils.version_utils, 'get_url_content', return_value='', clear=True):
urls = get_scylla_urls_from_repository(RepositoryDetails(
type=ScyllaFileType.DEBIAN,
urls=[''],
))
self.assertEqual(
set(),
urls)
def test_07_get_all_versions(self):
self.assertIn('4.5.3', get_all_versions(
'https://s3.amazonaws.com/downloads.scylladb.com/rpm/centos/scylla-4.5.repo'))
def test_08_assume_versions_oss(self):
with unittest.mock.patch.object(os.environ, 'get', return_value='branch-5.0', clear=True):
params = {}
is_version_enterprise, version = assume_version(params)
self.assertTrue(not is_version_enterprise, 'This should be OSS')
self.assertEqual(version, 'nightly-5.0', 'Version should be 5.0')
scylla_version = '5.0'
is_version_enterprise, version = assume_version(params, scylla_version)
self.assertTrue(not is_version_enterprise, 'This should be OSS')
self.assertEqual(version, 'nightly-5.0', 'Version should be 5.0')
repo_url = 'https://s3.amazonaws.com/downloads.scylladb.com/unstable/scylla/branch-5.0/rpm/centos/' \
'2022-05-10T07:40:41Z/scylla.repo'
params.update({'scylla_repo': repo_url})
is_version_enterprise, version = assume_version(params)
self.assertTrue(not is_version_enterprise, 'This should be OSS')
self.assertEqual(version, 'nightly-5.0', 'Version should be 5.0')
def test_09_assume_versions_enterprise(self):
with unittest.mock.patch.object(os.environ, 'get', return_value='branch-2022.1', clear=True):
params = {}
is_version_enterprise, version = assume_version(params)
self.assertTrue(is_version_enterprise, 'This should be enterprise')
self.assertEqual(version, 'nightly-2022.1', 'Version should be 2022.1')
scylla_version = '2022.1'
is_version_enterprise, version = assume_version(params, scylla_version)
self.assertTrue(is_version_enterprise, 'This should be enterprise')
self.assertEqual(version, 'nightly-2022.1', 'Version should be 2022.1')
repo_url = 'http://downloads.scylladb.com/unstable/scylla-enterprise/enterprise-2022.1/deb/unified/' \
'2022-05-10T22:12:50Z/scylladb-2022.1/scylla.list'
params.update({'scylla_repo': repo_url})
is_version_enterprise, version = assume_version(params)
self.assertTrue(is_version_enterprise, 'This should be enterprise')
self.assertEqual(version, 'nightly-2022.1', 'Version should be 2022.1')
@pytest.mark.parametrize("chart_version,git_tag", [
("v1.1.0-rc.2-0-gc86ad89", "v1.1.0-rc.2"),
("v1.1.0-rc.1-1-g6d35b37", "v1.1.0-rc.1"),
("v1.1.0-rc.1", "v1.1.0-rc.1"),
("v1.1.0-alpha.0-3-g6594091-nightly", "v1.1.0-alpha.0"),
("v1.1.0-alpha.0-3-g6594091", "v1.1.0-alpha.0"),
("v1.0.0", "v1.0.0"),
("v1.0.0-39-g5bc1839", "v1.0.0"),
("v1.0.0-rc0-53-g489398a-nightly", "v1.0.0-rc0"),
("v1.0.0-rc0-53-g489398a", "v1.0.0-rc0"),
("v1.0.0-rc0-51-ga52c206-latest", "v1.0.0-rc0"),
])
def test_06_get_git_tag_from_helm_chart_version(chart_version, git_tag):
assert get_git_tag_from_helm_chart_version(chart_version) == git_tag
@pytest.mark.parametrize("chart_version", [
"", "fake", "V1.0.0", "1.0.0", "1.1.0-rc.1", "1.1.0-rc.1-1-g6d35b37",
])
def test_07_get_git_tag_from_helm_chart_version__wrong_input(chart_version):
try:
git_tag = get_git_tag_from_helm_chart_version(chart_version)
except ValueError:
return
assert False, f"'ValueError' was expected, but absent. Returned value: {git_tag}"
class ClassWithVersiondMethods: # pylint: disable=too-few-public-methods
def __init__(self, scylla_version, nemesis_like_class):
params = {"scylla_version": scylla_version}
if scylla_version.startswith('enterprise:'):
node_scylla_version = "2023.1.dev"
elif scylla_version.startswith('master:') or scylla_version == "":
node_scylla_version = "4.7.dev"
else:
if ":" in scylla_version:
node_scylla_version = scylla_version.split(":")[0]
if node_scylla_version.count(".") < 1:
node_scylla_version += ".0"
node_scylla_version += ".dev"
else:
node_scylla_version = scylla_version
nodes = [type("Node", (object,), {"scylla_version": node_scylla_version})]
if nemesis_like_class:
self.cluster = type("Cluster", (object,), {
"params": params,
"nodes": nodes,
})
else:
self.params = params
self.nodes = nodes
@scylla_versions((None, "4.3"))
def oss_method(self): # pylint: disable=no-self-use
return "any 4.3.x and lower"
@scylla_versions(("4.4.rc1", "4.4.rc1"), ("4.4.rc4", "4.5"))
def oss_method(self): # pylint: disable=no-self-use,function-redefined
return "all 4.4 and 4.5 except 4.4.rc2 and 4.4.rc3"
@scylla_versions(("4.6.rc1", None))
def oss_method(self): # pylint: disable=no-self-use,function-redefined
return "4.6.rc1 and higher"
@scylla_versions((None, "2019.1"))
def es_method(self): # pylint: disable=no-self-use
return "any 2019.1.x and lower"
@scylla_versions(("2020.1.rc1", "2020.1.rc1"), ("2020.1.rc4", "2021.1"))
def es_method(self): # pylint: disable=no-self-use,function-redefined
return "all 2020.1 and 2021.1 except 2020.1.rc2 and 2020.1.rc3"
@scylla_versions(("2022.1.rc1", None))
def es_method(self): # pylint: disable=no-self-use,function-redefined
return "2022.1.rc1 and higher"
@scylla_versions((None, "4.3"), (None, "2019.1"))
def mixed_method(self): # pylint: disable=no-self-use
return "any 4.3.x and lower, any 2019.1.x and lower"
@scylla_versions(("4.4.rc1", "4.4.rc1"), ("4.4.rc4", "4.5"),
("2020.1.rc1", "2020.1.rc1"), ("2020.1.rc4", "2021.1"))
def mixed_method(self): # pylint: disable=no-self-use,function-redefined
return "all 4.4, 4.5, 2020.1 and 2021.1 except 4.4.rc2, 4.4.rc3, 2020.1.rc2 and 2020.1.rc3"
@scylla_versions(("4.6.rc1", None), ("2022.1.rc1", None))
def mixed_method(self): # pylint: disable=no-self-use,function-redefined
return "4.6.rc1 and higher, 2022.1.rc1 and higher"
@scylla_versions(("4.6.rc1", None))
def new_oss_method(self): # pylint: disable=no-self-use,function-redefined
return "4.6.rc1 and higher"
@scylla_versions(("2022.1.rc1", None))
def new_es_method(self): # pylint: disable=no-self-use,function-redefined
return "4.6.rc1 and higher"
@scylla_versions(("4.6.rc1", None), ("2022.1.rc1", None))
def new_mixed_method(self): # pylint: disable=no-self-use,function-redefined
return "4.6.rc1 and higher"
@pytest.mark.parametrize("scylla_version,method", [(scylla_version, method) for scylla_version in (
"", "4.2.rc1", "4.2", "4.2.0", "4.2.1",
"4.3.rc1", "4.3", "4.3.0", "4.3.1",
"4.4.rc1", "4.4.rc4", "4.4", "4.4.0", "4.4.4",
"4.5.rc1", "4.5", "4.5.0", "4.5.1",
"4.6.rc1", "4.6", "4.6.0", "4.6.1",
"4.7.rc1", "4.7", "4.7.0", "4.7.1",
"5.0.rc1", "5.0", "5.0.0", "5.0.1",
"4.7:latest", "master:latest",
) for method in ("oss_method", "mixed_method")] + [(scylla_version, method) for scylla_version in (
"2019.1", "2019.1.0", "2019.1.1",
"2020.1", "2020.1.0", "2020.1.1",
"2021.1", "2021.1.0", "2021.1.1",
"2022.1", "2022.1.0", "2022.1.1",
"2023:latest", "enterprise:latest",
) for method in ("es_method", "mixed_method")] + [(scylla_version, method) for scylla_version in (
"4.6.rc1", "4.6", "4.6.0", "4.6.1", "4.7:latest", "master:latest",
) for method in ("new_oss_method", "new_mixed_method")] + [(scylla_version, method) for scylla_version in (
"2022.1.rc1", "2022.1", "2022.1.0", "2022.1.1", "2023:latest", "enterprise:latest",
) for method in ("new_es_method", "new_mixed_method")])
def test_scylla_versions_decorator_positive(scylla_version, method):
for nemesis_like_class in (True, False):
cls_instance = ClassWithVersiondMethods(
scylla_version=scylla_version, nemesis_like_class=nemesis_like_class)
assert getattr(cls_instance, method)()
@pytest.mark.parametrize("scylla_version,method", (
("4.4.rc2", "oss_method"),
("4.4.rc2", "mixed_method"),
("4.4.rc3", "oss_method"),
("4.4.rc3", "mixed_method"),
("2020.1.rc2", "es_method"),
("2020.1.rc2", "mixed_method"),
("2020.1.rc3", "es_method"),
("2020.1.rc3", "mixed_method"),
("4.4", "es_method"),
("2020.1", "oss_method"),
("4.5", "new_oss_method"),
("4.5", "new_mixed_method"),
("4.6.rc1", "new_es_method"),
("2021.1", "new_es_method"),
("2021.1", "new_mixed_method"),
("2022.1.rc1", "new_oss_method"),
))
def test_scylla_versions_decorator_negative(scylla_version, method):
for nemesis_like_class in (True, False):
try:
cls_instance = ClassWithVersiondMethods(
scylla_version=scylla_version, nemesis_like_class=nemesis_like_class)
getattr(cls_instance, method)()
except MethodVersionNotFound as exc:
assert "Method '{}' with version '{}' is not supported in '{}'!".format(
method, scylla_version, cls_instance.__class__.__name__) in str(exc)
else:
assert False, f"Versioned method must have been not found for the '{scylla_version}' scylla version"
def test_scylla_versions_decorator_negative_latest_scylla_no_nodes():
scylla_version = "master:latest"
for nemesis_like_class in (True, False):
try:
cls_instance = ClassWithVersiondMethods(
scylla_version=scylla_version, nemesis_like_class=nemesis_like_class)
try:
cls_instance.cluster.nodes = []
except AttributeError:
cls_instance.nodes = []
cls_instance.oss_method()
except MethodVersionNotFound as exc:
assert "Method 'oss_method' with version 'n/a' is not supported in '{}'!".format(
cls_instance.__class__.__name__) in str(exc)
else:
assert False, f"Versioned method must have been not found for the '{scylla_version}' scylla version"
def test_scylla_versions_decorator_negative_latest_scylla_no_attr():
scylla_version = "master:latest"
for nemesis_like_class in (True, False):
try:
cls_instance = ClassWithVersiondMethods(
scylla_version=scylla_version, nemesis_like_class=nemesis_like_class)
try:
delattr(cls_instance.cluster.nodes[0], "scylla_version")
except AttributeError:
delattr(cls_instance.nodes[0], "scylla_version")
cls_instance.oss_method()
except MethodVersionNotFound as exc:
assert "Method 'oss_method' with version 'n/a' is not supported in '{}'!".format(
cls_instance.__class__.__name__) in str(exc)
else:
assert False, f"Versioned method must have been not found for the '{scylla_version}' scylla version"
@pytest.mark.need_network
@pytest.mark.integration
@pytest.mark.parametrize('docker_repo', ['scylladb/scylla-nightly', 'scylladb/scylla-enterprise-nightly'])
def test_get_specific_tag_of_docker_image(docker_repo):
assert get_specific_tag_of_docker_image(docker_repo=docker_repo) != 'latest'
@pytest.mark.parametrize("full_version,version,date,commit_id", (
("5.1.dev-0.20220713.15ed0a441e18", "5.1.dev", "20220713", "15ed0a441e18"),
("5.0.1-20220719.b177dacd3", "5.0.1", "20220719", "b177dacd3"),
("5.0.1-20220719.b177dacd3 with build-id 217f31634f8c8722cadcfe57ade8da58af05d415", "5.0.1", "20220719", "b177dacd3"),
("2022.1~rc5-20220515.6a1e89fbb", "2022.1~rc5", "20220515", "6a1e89fbb"),
("2022.2.dev-20220715.6fd8d82112e1", "2022.2.dev", "20220715", "6fd8d82112e1"),
("4.6.rc2-20220102.e8a1cfb6f", "4.6.rc2", "20220102", "e8a1cfb6f")
))
def test_scylla_version_grouped_regexp(full_version, version, date, commit_id):
parsed_version = SCYLLA_VERSION_GROUPED_RE.match(full_version)
assert parsed_version.group("version") == version
assert parsed_version.group("date") == date
assert parsed_version.group("commit_id") == commit_id
@pytest.mark.integration
@pytest.mark.need_network
@pytest.mark.parametrize("version, expected", (
("4.6.rc2-20220102.e8a1cfb6f", "scylladb/scylla:4.6.rc2"),
("5.0.1-0.20220719.b177dacd3", "scylladb/scylla:5.0.1"),
("5.1", "scylladb/scylla:5.1"),
("5.1.0~rc1", "scylladb/scylla:5.1.0-rc1"),
("5.0.1", "scylladb/scylla:5.0.1"),
("5.2.0~dev-0.20220824.6ce5e9079c1e", "scylladb/scylla-nightly:5.2.0-dev-0.20220824.6ce5e9079c1e"),
("5.1.0~dev-0.20220726.29c28dcb0c33", "scylladb/scylla-nightly:5.1.0-dev-0.20220726.29c28dcb0c33"),
("2022.2.dev-20220515.no_such_sha", "scylladb/scylla-enterprise:latest"),
("5.2.0~dev-20220515.no_such_sha", "scylladb/scylla:latest"),
))
def test_get_docker_image_by_version(version, expected):
assert get_docker_image_by_version(scylla_version=version) == expected
def test_get_docker_image_by_version_broken_string_version():
with pytest.raises(AssertionError):
get_docker_image_by_version(scylla_version="broken_version")
def test_get_docker_image_by_version_fallback_on_errors():
def mock_requests_factory(response_stub):
return mock.Mock(**{
'json.return_value': response_stub,
})
def raise_request_error(**kwargs):
raise requests.HTTPError()
non_existing_version = '5.2.0~dev-0.20221124.999b7f5d9b77'
expected_fallback = 'scylladb/scylla:latest'
with unittest.mock.patch("requests.get") as get_mock:
get_mock.side_effect = lambda **_: mock_requests_factory({})
assert get_docker_image_by_version(scylla_version=non_existing_version) == expected_fallback
get_mock.side_effect = lambda **_: mock_requests_factory({"results": [{'name': ''}, {}]})
assert get_docker_image_by_version(scylla_version=non_existing_version) == expected_fallback
get_mock.side_effect = raise_request_error
assert get_docker_image_by_version(scylla_version=non_existing_version) == expected_fallback
@pytest.mark.parametrize("version_string, expected", (
("5.1", (5, 1, 0, '', '')),
("5.1.0", (5, 1, 0, '', '')),
("5.1.1", (5, 1, 1, '', '')),
("5.1.0-rc1", (5, 1, 0, 'rc1', '')),
("5.1.0~rc1", (5, 1, 0, 'rc1', '')),
("5.1.rc1", (5, 1, 0, 'rc1', '')),
("2022.1.3-0.20220922.539a55e35", (2022, 1, 3, "dev-0.20220922", "539a55e35")),
("2022.1.3-0.20220922.539a55e35 with build-id d1fb2faafd95058a04aad30b675ff7d2b930278d",
(2022, 1, 3, "dev-0.20220922", "539a55e35")),
("2022.1.3-dev-0.20220922.539a55e35", (2022, 1, 3, "dev-0.20220922", "539a55e35")),
("5.2.0~rc1-0.20230207.8ff4717fd010", (5, 2, 0, "rc1-0.20230207", "8ff4717fd010")),
("5.2.0-dev-0.20230109.08b3a9c786d9", (5, 2, 0, "dev-0.20230109", "08b3a9c786d9")),
("5.2.0-dev-0.20230109.08b3a9c786d9-x86_64", (5, 2, 0, "dev-0.20230109", "08b3a9c786d9")),
("5.2.0-dev-0.20230109.08b3a9c786d9-aarch64", (5, 2, 0, "dev-0.20230109", "08b3a9c786d9")),
))
def test_comparable_scylla_version_init_positive(version_string, expected):
comparable_scylla_version = ComparableScyllaVersion(version_string)
assert comparable_scylla_version.v_major == expected[0]
assert comparable_scylla_version.v_minor == expected[1]
assert comparable_scylla_version.v_patch == expected[2]
assert comparable_scylla_version.v_pre_release == expected[3]
assert comparable_scylla_version.v_build == expected[4]
@pytest.mark.parametrize("version_string", (None, "", "5", "2023", "2023.dev"))
def test_comparable_scylla_versions_init_negative(version_string):
try:
ComparableScyllaVersion(version_string)
except ValueError:
pass
else:
assert False, (
f"'ComparableScyllaVersion' must raise a ValueError for the '{version_string}' "
"provided input")
def _compare_versions(version_string_left, version_string_right,
is_left_greater, is_equal, comparable_class):
comparable_version_left = comparable_class(version_string_left)
comparable_version_right = comparable_class(version_string_right)
compare_expected_result_err_msg = (
"One of 'is_left_greater' and 'is_equal' must be 'True' and another one must be 'False'")
assert is_left_greater or is_equal, compare_expected_result_err_msg
assert not (is_left_greater and is_equal)
if is_left_greater:
assert comparable_version_left > comparable_version_right
assert comparable_version_left >= comparable_version_right
assert comparable_version_left > version_string_right
assert comparable_version_left >= version_string_right
assert comparable_version_right < comparable_version_left
assert comparable_version_right <= comparable_version_left
assert comparable_version_right < version_string_left
assert comparable_version_right <= version_string_left
else:
assert comparable_version_left == comparable_version_right
assert comparable_version_left == version_string_right
assert comparable_version_left >= comparable_version_right
assert comparable_version_left >= version_string_right
assert comparable_version_right <= comparable_version_left
assert comparable_version_right <= version_string_left
@pytest.mark.parametrize(
"version_string_left, version_string_right, is_left_greater, is_equal, comparable_class", (
("5.2.2", "5.2.2", False, True, ComparableScyllaVersion),
("5.2.0", "5.1.2", True, False, ComparableScyllaVersion),
("5.2.1", "5.2.0", True, False, ComparableScyllaVersion),
("5.2.10", "5.2.9", True, False, ComparableScyllaVersion),
("5.2.0", "5.2.0~rc1-0.20230207.8ff4717fd010", True, False, ComparableScyllaVersion),
("5.2.0", "5.2.0-dev-0.20230109.08b3a9c786d9", True, False, ComparableScyllaVersion),
("2023.1.0", "2023.1.rc1", True, False, ComparableScyllaVersion),
("5.2.0", "5.1.rc1", True, False, ComparableScyllaVersion),
("5.2.0-dev-0.20230109.8ff4717fd010", "5.2.0-dev-0.20230109.08b3a9c786d9",
False, True, ComparableScyllaVersion),
))
def test_comparable_scylla_versions_compare(version_string_left, version_string_right,
is_left_greater, is_equal, comparable_class):
_compare_versions(
version_string_left, version_string_right, is_left_greater, is_equal, comparable_class)
@pytest.mark.parametrize("version_string_input, version_string_output", (
("5.2.2", "5.2.2"),
("2023.1.13", "2023.1.13"),
("5.2.0~rc0-0.20230207", "5.2.0-rc0-0.20230207"),
("5.2.0-rc1-0.20230207", "5.2.0-rc1-0.20230207"),
("5.2.0~dev-0.20230207.8ff4717fd010", "5.2.0-dev-0.20230207+8ff4717fd010"),
))
def test_comparable_scylla_versions_to_str(version_string_input, version_string_output):
assert str(ComparableScyllaVersion(version_string_input)) == version_string_output
@pytest.mark.parametrize("version_string, expected", (
("v1.8.0", (1, 8, 0, '', '')),
("1.8.0", (1, 8, 0, '', '')),
("1.8.0-rc.0", (1, 8, 0, 'rc.0', '')),
("1.9.0-alpha.1", (1, 9, 0, 'alpha.1', '')),
("1.9.0-alpha.1-nightly", (1, 9, 0, 'alpha.1', '')),
("1.9.0-alpha.1-2-g3321624", (1, 9, 0, 'alpha.1-2-g3321624', '')),
("1.9.0-alpha.1-2-g3321624-nightly", (1, 9, 0, 'alpha.1-2-g3321624', '')),
("v1.9.0-alpha.1-13-gc6a6e05", (1, 9, 0, 'alpha.1-13-gc6a6e05', '')),
("scylla-operator-1.8.0-beta.1", (1, 8, 0, 'beta.1', '')),
))
def test_comparable_scylla_operator_version_init_positive(version_string, expected):
comparable_scylla_operator_version = ComparableScyllaOperatorVersion(version_string)
assert comparable_scylla_operator_version.v_major == expected[0]
assert comparable_scylla_operator_version.v_minor == expected[1]
assert comparable_scylla_operator_version.v_patch == expected[2]
assert comparable_scylla_operator_version.v_pre_release == expected[3]
assert comparable_scylla_operator_version.v_build == expected[4]
@pytest.mark.parametrize("version_string", (None, "", "1", "1.alpha"))
def test_comparable_scylla_operator_versions_init_negative(version_string):
try:
ComparableScyllaOperatorVersion(version_string)
except ValueError:
pass
else:
assert False, (
f"'ComparableScyllaOperatorVersion' must raise a ValueError for the '{version_string}' "
"provided input")
@pytest.mark.parametrize(
"version_string_left, version_string_right, is_left_greater, is_equal, comparable_class", (
("v1.7.1", "1.7.0", True, False, ComparableScyllaOperatorVersion),
("1.7.1", "v1.7.0", True, False, ComparableScyllaOperatorVersion),
("1.8.0", "1.8.0-rc.0", True, False, ComparableScyllaOperatorVersion),
("1.8.0", "1.0.0-alpha.1", True, False, ComparableScyllaOperatorVersion),
("scylla-operator-v1.8.0-alpha.0-100-gf796b97", "1.8.0-alpha.0-99-g1234567",
True, False, ComparableScyllaOperatorVersion),
("scylla-operator-v1.8.0-alpha.0-10-gf796b97", "1.8.0-alpha.0-9-g1234567",
True, False, ComparableScyllaOperatorVersion),
("1.9.0-alpha.1-2-g3321624", "1.9.0-alpha.1-2-g3321624-nightly",
False, True, ComparableScyllaOperatorVersion),
("v1.8.0", "1.8.0", False, True, ComparableScyllaOperatorVersion),
("scylla-operator-1.8.0-beta.1", "1.8.0-beta.1",
False, True, ComparableScyllaOperatorVersion),
("scylla-manager-v1.8.0-alpha.0-100-gf796b97", "1.8.0-alpha.0-100-gf796b97",
False, True, ComparableScyllaOperatorVersion),
))
def test_comparable_scylla_operator_versions_compare(version_string_left, version_string_right,
is_left_greater, is_equal, comparable_class):
_compare_versions(
version_string_left, version_string_right, is_left_greater, is_equal, comparable_class)
@pytest.mark.parametrize("version_string_input, version_string_output", (
("scylla-operator-1.8.0-beta.1", "1.8.0-beta.1"),
("scylla-manager-1.8.0-beta.1", "1.8.0-beta.1"),
("scylla-1.8.0-beta.1", "1.8.0-beta.1"),
("scylla-operator-v1.8.0-alpha.0-100-gf796b97", "1.8.0-alpha.0-100-gf796b97"),
("scylla-manager-v1.8.0-alpha.0-100-gf796b97", "1.8.0-alpha.0-100-gf796b97"),
("scylla-v1.8.0-alpha.0-100-gf796b97", "1.8.0-alpha.0-100-gf796b97"),
("v1.8.1", "1.8.1"),
("1.8.1", "1.8.1"),
("1.8.0-rc.0", "1.8.0-rc.0"),
("1.9.0-alpha.1", "1.9.0-alpha.1"),
("1.9.0-alpha.1-nightly", "1.9.0-alpha.1"),
("1.9.0-alpha.1-2-g3321624", "1.9.0-alpha.1-2-g3321624"),
("1.9.0-alpha.1-2-g3321624-nightly", "1.9.0-alpha.1-2-g3321624"),
))
def test_comparable_scylla_operator_versions_to_str(version_string_input, version_string_output):
assert str(ComparableScyllaOperatorVersion(version_string_input)) == version_string_output