@@ -625,6 +625,11 @@ def is_ready(self) -> bool:
625
625
626
626
raise NotImplementedError
627
627
628
+ @property
629
+ def logs (self ) -> list [str ]:
630
+
631
+ raise NotImplementedError
632
+
628
633
@classmethod
629
634
def options (cls , how : Optional [str ] = None ) -> list [tmt .options .ClickOptionDecoratorType ]:
630
635
""" Prepare command line options related to guests """
@@ -1103,6 +1108,42 @@ def requires(cls) -> list['tmt.base.Dependency']:
1103
1108
""" All requirements of the guest implementation """
1104
1109
return []
1105
1110
1111
+ def acquire_log (self , log_name : str ) -> Optional [str ]:
1112
+ """fetch and return content of a requested log"""
1113
+ raise NotImplementedError
1114
+
1115
+ def store_log (
1116
+ self ,
1117
+ log_path : Path ,
1118
+ log_content : str ,
1119
+ log_name : Optional [str ] = None ) -> None :
1120
+ """save log content and return the path"""
1121
+ if log_name :
1122
+ # if log_path contains log file name
1123
+ if log_path .is_dir ():
1124
+ log_path .write_text (log_content )
1125
+ else :
1126
+ (log_path / log_name ).write_text (log_content )
1127
+ else :
1128
+ log_path .write_text (log_content )
1129
+
1130
+ def handle_guest_logs (self ,
1131
+ log_path : Optional [Path ] = None ,
1132
+ logs : Optional [list [str ]] = None ) -> None :
1133
+ """get log content and save it to the workdir/provision/,
1134
+ list the log dir in guests.yaml"""
1135
+ logs = logs or []
1136
+ log_path = log_path or self .workdir
1137
+ for log_name in logs :
1138
+ log_content = self .acquire_log (log_name )
1139
+ if log_content :
1140
+ if log_path :
1141
+ self .store_log (log_path , log_content , log_name )
1142
+ else :
1143
+ self .store_log (Path .cwd (), log_content , log_name )
1144
+ else :
1145
+ self .debug (f'no content in { log_name } ' )
1146
+
1106
1147
1107
1148
@dataclasses .dataclass
1108
1149
class GuestSshData (GuestData ):
0 commit comments