@@ -133,6 +133,43 @@ def pull(
133
133
extend_options : Optional [list [str ]] = None ) -> None :
134
134
""" Nothing to be done to pull workdir """
135
135
136
+ def acquire_log (self , log_name : str ) -> Optional [str ]:
137
+ """fetch and return content of a requested log"""
138
+ if log_name == 'dmesg' :
139
+ return self .execute (Command ('dmesg' )).stdout
140
+ return None
141
+
142
+ def store_log (
143
+ self ,
144
+ log_name : Optional [str ],
145
+ log_path : Optional [Path ],
146
+ log_content : str ) -> None :
147
+ """save log content and return the path"""
148
+ if log_path and log_name :
149
+ # if log_path contains log file name
150
+ if log_path .name == log_name :
151
+ log_path .write_text (log_content )
152
+ else :
153
+ (log_path / log_name ).write_text (log_content )
154
+ elif log_path and not log_name :
155
+ log_path .write_text (log_content )
156
+ elif log_name and not log_path :
157
+ self .info ('no log_path provided,store log to current dir' )
158
+ (Path .cwd () / log_name ).write_text (log_content )
159
+ else :
160
+ self .warn ('log_name and log_path cannot both be None' )
161
+
162
+ def handle_guest_logs (self , logs : Optional [list [str ]] = None ) -> None :
163
+ """get log content and save it to the workdir/provision/,
164
+ list the log dir in guests.yaml"""
165
+ logs = logs or []
166
+ for log_name in logs :
167
+ log_content = self .acquire_log (log_name )
168
+ if log_content :
169
+ self .store_log (log_name , self .workdir , log_content )
170
+ else :
171
+ self .debug (f'no content in { log_name } ' )
172
+
136
173
137
174
@tmt .steps .provides_method ('local' )
138
175
class ProvisionLocal (tmt .steps .provision .ProvisionPlugin [ProvisionLocalData ]):
0 commit comments