Skip to content

Commit b05c07d

Browse files
authored
Merge pull request #48 from prilr/mysql-setup
Minor actor fixes and test adjustments
2 parents eccc558 + 5bfb2a4 commit b05c07d

4 files changed

Lines changed: 43 additions & 17 deletions

File tree

repos/system_upgrade/cloudlinux/actors/checkpanelmemory/libraries/checkpanelmemory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ def process():
5555
reporting.Title(title),
5656
reporting.Summary(summary),
5757
reporting.Severity(reporting.Severity.HIGH),
58-
reporting.Groups([reporting.Groups.SANITY]),
58+
reporting.Groups([reporting.Groups.SANITY, reporting.Groups.INHIBITOR]),
5959
]
6060
)
Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from leapp import reporting
2-
from leapp.libraries.actor import checkmemory
2+
from leapp.libraries.actor import checkpanelmemory
33
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked
44
from leapp.libraries.stdlib import api
55
from leapp.models import MemoryInfo, InstalledControlPanel
6+
from leapp.utils.report import is_inhibitor
67

78
from leapp.libraries.common.detectcontrolpanel import (
89
UNKNOWN_NAME,
@@ -12,31 +13,47 @@
1213

1314

1415
def test_check_memory_low(monkeypatch):
15-
minimum_req_error = []
1616
monkeypatch.setattr(api, "current_actor", CurrentActorMocked())
17-
minimum_req_error = checkmemory._check_memory(
18-
InstalledControlPanel(name=INTEGRATED_NAME), MemoryInfo(mem_total=1024)
17+
# _check_memory(panel_name, mem_info): panel must be string key for required_memory
18+
minimum_req_error = checkpanelmemory._check_memory(
19+
INTEGRATED_NAME, MemoryInfo(mem_total=1024)
1920
)
2021
assert minimum_req_error
2122

2223

2324
def test_check_memory_high(monkeypatch):
24-
minimum_req_error = []
2525
monkeypatch.setattr(api, "current_actor", CurrentActorMocked())
26-
minimum_req_error = checkmemory._check_memory(
27-
InstalledControlPanel(name=CPANEL_NAME), MemoryInfo(mem_total=16273492)
26+
minimum_req_error = checkpanelmemory._check_memory(
27+
CPANEL_NAME, MemoryInfo(mem_total=16273492)
2828
)
2929
assert not minimum_req_error
3030

3131

32+
def _mock_consume(panel_name, memory_info):
33+
"""Return a consume that yields the right model type for process()."""
34+
35+
def consume(model):
36+
if model is InstalledControlPanel:
37+
return iter([InstalledControlPanel(name=panel_name)])
38+
if model is MemoryInfo:
39+
return iter([memory_info])
40+
return iter([])
41+
42+
return consume
43+
44+
3245
def test_report(monkeypatch):
3346
title_msg = "Minimum memory requirements for panel {} are not met".format(
3447
UNKNOWN_NAME
3548
)
3649
monkeypatch.setattr(api, "current_actor", CurrentActorMocked())
37-
monkeypatch.setattr(api, "consume", lambda x: iter([MemoryInfo(mem_total=129)]))
50+
monkeypatch.setattr(
51+
api,
52+
"consume",
53+
_mock_consume(UNKNOWN_NAME, MemoryInfo(mem_total=129)),
54+
)
3855
monkeypatch.setattr(reporting, "create_report", create_report_mocked())
39-
checkmemory.process()
56+
checkpanelmemory.process()
4057
assert reporting.create_report.called
4158
assert title_msg == reporting.create_report.report_fields["title"]
42-
assert reporting.Flags.INHIBITOR in reporting.create_report.report_fields["flags"]
59+
assert is_inhibitor(reporting.create_report.report_fields)

repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/libraries/clmysql_upstream_mariadb.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _make_upgrade_mariadb_url(mariadb_url, source_major, target_major):
3232
We replace the parts of the URL to make them work with the target OS version.
3333
"""
3434
if not mariadb_url:
35+
api.current_logger().warning("Unsupported repository URL={}, skipping".format(mariadb_url))
3536
return None
3637
# Replace the first occurrence of source_major with target_major after 'yum'
3738
url_parts = mariadb_url.split("yum", 1)
@@ -43,10 +44,15 @@ def _make_upgrade_mariadb_url(mariadb_url, source_major, target_major):
4344
# Replace $releasever because upstream repos expect major version
4445
# and cloudlinux provides major.minor as $releasever
4546
url_parts[1] = url_parts[1].replace('$releasever', str(target_major))
46-
return "yum".join(url_parts)
47+
new_url = "yum".join(url_parts)
48+
# Treat as unsupported if no version replacement was made (e.g. "example.com/mariadb/yum")
49+
if new_url == mariadb_url and "/{}/".format(target_major) not in new_url:
50+
api.current_logger().warning("Unsupported repository URL={}, skipping".format(mariadb_url))
51+
return None
52+
return new_url
4753
else:
4854
api.current_logger().warning("Unsupported repository URL={}, skipping".format(mariadb_url))
49-
return
55+
return None
5056

5157

5258
def mariadb_process(lib, repofile_name, repofile_data):

repos/system_upgrade/cloudlinux/actors/scanrolloutrepositories/tests/test_releasever_replace.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from leapp.libraries.actor import scanrolloutrepositories
1+
from leapp.libraries.actor import scanrolloutrepositories
22
from leapp.libraries.common import cl_repofileutils
33
from leapp.libraries.common.testutils import produce_mocked
44
from leapp.libraries.stdlib import api
@@ -34,14 +34,17 @@ def __call__(self):
3434

3535

3636
def test_valid_repofile_exists(monkeypatch):
37-
def create_leapp_repofile_copy_mocked():
37+
def create_leapp_repofile_copy_mocked(*args, **kwargs):
3838
return "/leapp_copy_path/newrepo.repo"
3939

4040
monkeypatch.setattr(api, 'produce', produce_mocked())
41-
monkeypatch.setattr(cl_repofileutils, 'create_leapp_repofile_copy', create_leapp_repofile_copy_mocked)
41+
monkeypatch.setattr(
42+
scanrolloutrepositories, 'create_leapp_repofile_copy',
43+
create_leapp_repofile_copy_mocked,
44+
)
4245
monkeypatch.setattr(api, 'current_logger', LoggerMocked())
4346

44-
scanrolloutrepositories.process_repodata(_REPOFILE)
47+
scanrolloutrepositories.process_repodata(_REPOFILE, _REPOFILE.file)
4548

4649
assert api.produce.called == len(_REPODATA) + 1
4750

0 commit comments

Comments
 (0)