@@ -38,6 +38,22 @@ def _provides_feature(feature_cls: FeatureClass) -> FeatureClass:
38
38
return _provides_feature
39
39
40
40
41
+ def find_plugin (name : str ) -> 'FeatureClass' :
42
+ """
43
+ Find a plugin by its name.
44
+
45
+ :raises GeneralError: when the plugin does not exist.
46
+ """
47
+
48
+ plugin = _FEATURE_PLUGIN_REGISTRY .get_plugin (name )
49
+
50
+ if plugin is None :
51
+ raise tmt .utils .GeneralError (
52
+ f"Feature plugin '{ name } ' was not found in feature registry." )
53
+
54
+ return plugin
55
+
56
+
41
57
class Feature (tmt .utils .Common ):
42
58
""" Base class for ``feature`` prepare plugin implementations """
43
59
@@ -54,28 +70,37 @@ def __init__(
54
70
55
71
self .guest = guest
56
72
57
- def enable (self ) -> None :
73
+ @classmethod
74
+ def enable (cls , guest : Guest , logger : tmt .log .Logger ) -> None :
58
75
raise NotImplementedError
59
76
60
- def disable (self ) -> None :
77
+ @classmethod
78
+ def disable (cls , guest : Guest , logger : tmt .log .Logger ) -> None :
61
79
raise NotImplementedError
62
80
63
- def _find_playbook (self , filename : str ) -> Optional [Path ]:
81
+ @classmethod
82
+ def _find_playbook (cls , filename : str , logger : tmt .log .Logger ) -> Optional [Path ]:
64
83
filepath = FEATURE_PLAYEBOOK_DIRECTORY / filename
65
84
if filepath .exists ():
66
85
return filepath
67
86
68
- self . warn (f"Cannot find any suitable playbook for '{ filename } '." )
87
+ logger . warning (f"Cannot find any suitable playbook for '{ filename } '." , 0 )
69
88
return None
70
89
71
- def _run_playbook (self , op : str , playbook_filename : str ) -> None :
72
- playbook_path = self ._find_playbook (playbook_filename )
90
+ @classmethod
91
+ def _run_playbook (
92
+ cls ,
93
+ op : str ,
94
+ playbook_filename : str ,
95
+ guest : Guest ,
96
+ logger : tmt .log .Logger ) -> None :
97
+ playbook_path = cls ._find_playbook (playbook_filename , logger )
73
98
if not playbook_path :
74
99
raise tmt .utils .GeneralError (
75
- f"{ op .capitalize ()} { self .NAME .upper ()} is not supported on this guest." )
100
+ f"{ op .capitalize ()} { cls .NAME .upper ()} is not supported on this guest." )
76
101
77
- self .info (f'{ op .capitalize ()} { self .NAME .upper ()} ' )
78
- self . guest .ansible (playbook_path )
102
+ logger .info (f'{ op .capitalize ()} { cls .NAME .upper ()} ' )
103
+ guest .ansible (playbook_path )
79
104
80
105
81
106
@dataclasses .dataclass
@@ -125,27 +150,20 @@ def go(
125
150
if self .opt ('dry' ):
126
151
return []
127
152
128
- print ("### DEBUG IZMI ###" )
129
- print (f"obsah registru: { list (_FEATURE_PLUGIN_REGISTRY .iter_plugins ())} " )
130
- print_value = cast (Optional [str ], getattr (self .data , "epel" , None ))
131
- print (f"obsah value: { print_value } " )
132
-
133
153
for feature_id in _FEATURE_PLUGIN_REGISTRY .iter_plugin_ids ():
134
- feature = _FEATURE_PLUGIN_REGISTRY .get_plugin (feature_id )
135
-
136
- assert feature is not None # narrow type
154
+ feature = find_plugin (feature_id )
137
155
138
156
value = cast (Optional [str ], getattr (self .data , feature .NAME , None ))
139
157
if value is None :
140
158
continue
141
- if isinstance ( feature , Feature ):
142
- value = value .lower ()
143
- if value == 'enabled' :
144
- feature .enable ()
145
- elif value == 'disabled' :
146
- feature .disable ()
147
- else :
148
- raise tmt .utils .GeneralError (f"Unknown feature setting '{ value } '." )
159
+
160
+ value = value .lower ()
161
+ if value == 'enabled' :
162
+ feature .enable (guest , logger )
163
+ elif value == 'disabled' :
164
+ feature .disable (guest , logger )
165
+ else :
166
+ raise tmt .utils .GeneralError (f"Unknown feature setting '{ value } '." )
149
167
150
168
return results
151
169
0 commit comments