Skip to content

Commit 9fb8938

Browse files
committed
Update checkpanelmemory to include the inhibitor flag and adjust tests
1 parent eccc558 commit 9fb8938

2 files changed

Lines changed: 28 additions & 11 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)

0 commit comments

Comments
 (0)