6
6
from leapp .models import TargetInitramfsTasks , UpgradeInitramfsTasks
7
7
8
8
DRACUT_MOD_DIR = '/usr/lib/dracut/modules.d/'
9
- SUMMARY_DRACUT_FMT = (
10
- 'The requested dracut modules for the initramfs are in conflict.'
11
- ' At least one dracut module is specified to be installed from'
12
- ' multiple paths. The list of conflicting dracut module names'
13
- ' with paths is listed below: {}'
9
+ SUMMARY_FMT = (
10
+ 'The requested {kind} modules for the initramfs are in conflict.'
11
+ ' At least one {kind} module is specified to be installed from'
12
+ ' multiple paths. The list of conflicting {kind} module names'
13
+ ' with paths is listed below: {conflicts }'
14
14
)
15
15
16
16
@@ -22,51 +22,72 @@ def _printable_modules(conflicts):
22
22
return '' .join (output )
23
23
24
24
25
- def _treat_path (dmodule ):
25
+ def _treat_path_dracut (dmodule ):
26
26
"""
27
27
In case the path is not set, set the expected path of the dracut module.
28
28
"""
29
+
29
30
if not dmodule .module_path :
30
31
return os .path .join (DRACUT_MOD_DIR , dmodule .name )
31
32
return dmodule .module_path
32
33
33
34
34
- def _detect_dracut_modules_conflicts (msgtype ):
35
+ def _treat_path_kernel (kmodule ):
36
+ """
37
+ In case the path of a kernel module is not set, indicate that the module is
38
+ taken from the current system.
39
+ """
40
+
41
+ if not kmodule .module_path :
42
+ return kmodule .name + ' (system)'
43
+ return kmodule .module_path
44
+
45
+
46
+ def _detect_modules_conflicts (msgtype , kind ):
35
47
"""
36
48
Return dict of modules with conflicting tasks
37
49
38
- In this case when a dracut module should be applied but different
39
- sources are specified. E.g.:
40
- include dracut modules X where,
50
+ In this case when a module should be applied but different sources are
51
+ specified. E.g.:
52
+ include modules X where,
41
53
msg A) X
42
54
msg B) X from custom path
43
55
"""
44
- dracut_modules = defaultdict (set )
56
+
57
+ modules_map = {
58
+ 'dracut' : {
59
+ 'msgattr' : 'include_dracut_modules' ,
60
+ 'treat_path_fn' : _treat_path_dracut ,
61
+ },
62
+ 'kernel' : {
63
+ 'msgattr' : 'include_kernel_modules' ,
64
+ 'treat_path_fn' : _treat_path_kernel
65
+ },
66
+ }
67
+
68
+ modules = defaultdict (set )
45
69
for msg in api .consume (msgtype ):
46
- for dmodule in msg .include_dracut_modules :
47
- dracut_modules [dmodule .name ].add (_treat_path (dmodule ))
48
- return {key : val for key , val in dracut_modules .items () if len (val ) > 1 }
70
+ for module in getattr (msg , modules_map [kind ]['msgattr' ]):
71
+ treat_path_fn = modules_map [kind ]['treat_path_fn' ]
72
+ modules [module .name ].add (treat_path_fn (module ))
73
+ return {key : val for key , val in modules .items () if len (val ) > 1 }
74
+
75
+
76
+ def report_conflicts (msgname , kind , msgtype ):
77
+ conflicts = _detect_modules_conflicts (msgtype , kind )
78
+ if not conflicts :
79
+ return
80
+ report = [
81
+ reporting .Title ('Conflicting requirements of {kind} modules for the {msgname} initramfs' .format (
82
+ kind = kind , msgname = msgname )),
83
+ reporting .Summary (SUMMARY_FMT .format (kind = kind , conflicts = _printable_modules (conflicts ))),
84
+ reporting .Severity (reporting .Severity .HIGH ),
85
+ reporting .Groups ([reporting .Groups .SANITY , reporting .Groups .INHIBITOR ]),
86
+ ]
87
+ reporting .create_report (report )
49
88
50
89
51
90
def process ():
52
- conflicts = _detect_dracut_modules_conflicts (UpgradeInitramfsTasks )
53
- if conflicts :
54
- report = [
55
- reporting .Title ('Conflicting requirements of dracut modules for the upgrade initramfs' ),
56
- reporting .Summary (SUMMARY_DRACUT_FMT .format (_printable_modules (conflicts ))),
57
- reporting .Severity (reporting .Severity .HIGH ),
58
- reporting .Groups ([reporting .Groups .SANITY ]),
59
- reporting .Groups ([reporting .Groups .INHIBITOR ]),
60
- ]
61
- reporting .create_report (report )
62
-
63
- conflicts = _detect_dracut_modules_conflicts (TargetInitramfsTasks )
64
- if conflicts :
65
- report = [
66
- reporting .Title ('Conflicting requirements of dracut modules for the target initramfs' ),
67
- reporting .Summary (SUMMARY_DRACUT_FMT .format (_printable_modules (conflicts ))),
68
- reporting .Severity (reporting .Severity .HIGH ),
69
- reporting .Groups ([reporting .Groups .SANITY ]),
70
- reporting .Groups ([reporting .Groups .INHIBITOR ]),
71
- ]
72
- reporting .create_report (report )
91
+ report_conflicts ('upgrade' , 'kernel' , UpgradeInitramfsTasks )
92
+ report_conflicts ('upgrade' , 'dracut' , UpgradeInitramfsTasks )
93
+ report_conflicts ('target' , 'dracut' , TargetInitramfsTasks )
0 commit comments