Skip to content

Commit 73099e2

Browse files
committed
Adjust crypto policies to run only on upgrade to 9+
Signed-off-by: Jakub Jelen <[email protected]>
1 parent c87d5a3 commit 73099e2

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

repos/system_upgrade/common/actors/cryptopoliciescheck/actor.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from leapp.actors import Actor
22
from leapp.libraries.actor import cryptopoliciescheck
3+
from leapp.libraries.common.config import version
34
from leapp.models import CryptoPolicyInfo, Report, TargetUserSpacePreupgradeTasks
45
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
56

@@ -21,4 +22,8 @@ class CryptoPoliciesCheck(Actor):
2122
tags = (IPUWorkflowTag, ChecksPhaseTag,)
2223

2324
def process(self):
25+
# there are no crypto policies in EL 7
26+
if int(version.get_target_major_version()) < 9:
27+
return
28+
2429
cryptopoliciescheck.process(self.consume(CryptoPolicyInfo))
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pytest
2+
3+
from leapp.libraries.common.config import version
14
from leapp.models import (
25
CopyFile,
36
CryptoPolicyInfo,
@@ -8,7 +11,13 @@
811
)
912

1013

11-
def test_actor_execution_default(current_actor_context):
14+
@pytest.mark.parametrize(('target_version', 'should_run'), [
15+
('8', False),
16+
('9', True),
17+
('10', True),
18+
])
19+
def test_actor_execution_default(monkeypatch, current_actor_context, target_version, should_run):
20+
monkeypatch.setattr(version, 'get_target_major_version', lambda: target_version)
1221
current_actor_context.feed(
1322
CryptoPolicyInfo(
1423
current_policy="DEFAULT",
@@ -17,10 +26,17 @@ def test_actor_execution_default(current_actor_context):
1726
)
1827
)
1928
current_actor_context.run()
20-
assert not current_actor_context.consume(TargetUserSpacePreupgradeTasks)
29+
if should_run:
30+
assert not current_actor_context.consume(TargetUserSpacePreupgradeTasks)
2131

2232

23-
def test_actor_execution_legacy(current_actor_context):
33+
@pytest.mark.parametrize(('target_version', 'should_run'), [
34+
('8', False),
35+
('9', True),
36+
('10', True),
37+
])
38+
def test_actor_execution_legacy(monkeypatch, current_actor_context, target_version, should_run):
39+
monkeypatch.setattr(version, 'get_target_major_version', lambda: target_version)
2440
current_actor_context.feed(
2541
CryptoPolicyInfo(
2642
current_policy="LEGACY",
@@ -30,15 +46,22 @@ def test_actor_execution_legacy(current_actor_context):
3046
)
3147
current_actor_context.run()
3248

33-
assert current_actor_context.consume(TargetUserSpacePreupgradeTasks)
34-
u = current_actor_context.consume(TargetUserSpacePreupgradeTasks)[0]
35-
assert u.install_rpms == ['crypto-policies-scripts']
36-
assert u.copy_files == []
49+
if should_run:
50+
assert current_actor_context.consume(TargetUserSpacePreupgradeTasks)
51+
u = current_actor_context.consume(TargetUserSpacePreupgradeTasks)[0]
52+
assert u.install_rpms == ['crypto-policies-scripts']
53+
assert u.copy_files == []
3754

38-
assert current_actor_context.consume(Report)
55+
assert current_actor_context.consume(Report)
3956

4057

41-
def test_actor_execution_custom(current_actor_context):
58+
@pytest.mark.parametrize(('target_version', 'should_run'), [
59+
('8', False),
60+
('9', True),
61+
('10', True),
62+
])
63+
def test_actor_execution_custom(monkeypatch, current_actor_context, target_version, should_run):
64+
monkeypatch.setattr(version, 'get_target_major_version', lambda: target_version)
4265
current_actor_context.feed(
4366
CryptoPolicyInfo(
4467
current_policy="CUSTOM:SHA2",
@@ -52,12 +75,13 @@ def test_actor_execution_custom(current_actor_context):
5275
)
5376
current_actor_context.run()
5477

55-
assert current_actor_context.consume(TargetUserSpacePreupgradeTasks)
56-
u = current_actor_context.consume(TargetUserSpacePreupgradeTasks)[0]
57-
assert u.install_rpms == ['crypto-policies-scripts']
58-
assert u.copy_files == [
59-
CopyFile(src='/etc/crypto-policies/policies/CUSTOM.pol'),
60-
CopyFile(src='/etc/crypto-policies/policies/modules/SHA2.pmod'),
61-
]
78+
if should_run:
79+
assert current_actor_context.consume(TargetUserSpacePreupgradeTasks)
80+
u = current_actor_context.consume(TargetUserSpacePreupgradeTasks)[0]
81+
assert u.install_rpms == ['crypto-policies-scripts']
82+
assert u.copy_files == [
83+
CopyFile(src='/etc/crypto-policies/policies/CUSTOM.pol'),
84+
CopyFile(src='/etc/crypto-policies/policies/modules/SHA2.pmod'),
85+
]
6286

63-
assert current_actor_context.consume(Report)
87+
assert current_actor_context.consume(Report)

repos/system_upgrade/common/actors/scancryptopolicies/actor.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from leapp.actors import Actor
22
from leapp.libraries.actor import scancryptopolicies
3+
from leapp.libraries.common.config import version
34
from leapp.models import CryptoPolicyInfo
45
from leapp.tags import FactsPhaseTag, IPUWorkflowTag
56

@@ -23,4 +24,8 @@ class ScanCryptoPolicies(Actor):
2324
tags = (IPUWorkflowTag, FactsPhaseTag)
2425

2526
def process(self):
27+
# there are no crypto policies in EL 7
28+
if int(version.get_target_major_version()) < 9:
29+
return
30+
2631
scancryptopolicies.process()
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import pytest
2+
3+
from leapp.libraries.common.config import version
14
from leapp.models import CryptoPolicyInfo
25

36

4-
def test_actor_execution(current_actor_context):
7+
@pytest.mark.parametrize(('target_version', 'should_run'), [
8+
('8', False),
9+
('9', True),
10+
('10', True),
11+
])
12+
def test_actor_execution(monkeypatch, current_actor_context, target_version, should_run):
13+
monkeypatch.setattr(version, 'get_target_major_version', lambda: target_version)
514
current_actor_context.run()
6-
assert current_actor_context.consume(CryptoPolicyInfo)
15+
if should_run:
16+
assert current_actor_context.consume(CryptoPolicyInfo)

0 commit comments

Comments
 (0)