@@ -828,9 +828,10 @@ def prepare_scripts(self, guest: "tmt.steps.provision.Guest") -> None:
828
828
# Keep track of ScriptTemplate instances for later cleanup
829
829
templates_to_cleanup : list [ScriptTemplate ] = []
830
830
831
- for script in self .scripts :
832
- if not script .enabled (guest ):
833
- continue
831
+ try :
832
+ for script in self .scripts :
833
+ if not script .enabled (guest ):
834
+ continue
834
835
835
836
with script as source :
836
837
# If it's a template, prevent immediate cleanup and track it
@@ -869,42 +870,43 @@ def prepare_scripts(self, guest: "tmt.steps.provision.Guest") -> None:
869
870
scripts_by_target_dir [target_dir ] = []
870
871
scripts_by_target_dir [target_dir ].append (source_path )
871
872
872
- # Push script batches grouped by target directory
873
- for target_dir , source_paths in scripts_by_target_dir .items ():
874
- if not source_paths :
875
- continue
876
-
877
- self .debug (f"Pushing script batch ({ len (source_paths )} files) to { target_dir } " )
878
- guest .push (
879
- source = source_paths ,
880
- destination = target_dir ,
881
- options = ["-s" , "-p" , "--chmod=755" ],
882
- superuser = guest .facts .is_superuser is not True ,
883
- )
884
-
885
- # Create aliases on the guest (only within the default scripts_dest_dir)
886
- full_alias_command = ShellScript ("" ) # Start with an empty script
887
- alias_count = 0
888
- for target_path , aliases in aliases_to_create .items ():
889
- for alias in aliases :
890
- link_path = scripts_dest_dir / alias
891
- # Use absolute path for symlink target for simplicity/robustness
892
- single_alias_cmd = ShellScript (
893
- f"ln -sf { target_path .as_posix ()} { link_path .as_posix ()} "
873
+ # Push script batches grouped by target directory
874
+ for target_dir , source_paths in scripts_by_target_dir .items ():
875
+ if not source_paths :
876
+ continue
877
+
878
+ self .debug (f"Pushing script batch ({ len (source_paths )} files) to { target_dir } " )
879
+ guest .push (
880
+ source = source_paths ,
881
+ destination = target_dir ,
882
+ options = ["-s" , "-p" , "--chmod=755" ],
883
+ superuser = guest .facts .is_superuser is not True ,
894
884
)
895
- if alias_count == 0 :
896
- full_alias_command = single_alias_cmd
897
- else :
898
- full_alias_command &= single_alias_cmd # Use the '&' operator (__and__)
899
- alias_count += 1
900
885
901
- if alias_count > 0 :
902
- self .debug ("Creating script aliases on guest." )
903
- guest .execute (full_alias_command , friendly_command = "Create script aliases" )
904
-
905
- # Cleanup rendered templates now that they've been pushed
906
- for template_script in templates_to_cleanup :
907
- template_script .cleanup ()
886
+ # Create aliases on the guest (only within the default scripts_dest_dir)
887
+ full_alias_command = ShellScript ("" ) # Start with an empty script
888
+ alias_count = 0
889
+ for target_path , aliases in aliases_to_create .items ():
890
+ for alias in aliases :
891
+ link_path = scripts_dest_dir / alias
892
+ # Use absolute path for symlink target for simplicity/robustness
893
+ single_alias_cmd = ShellScript (
894
+ f"ln -sf { target_path .as_posix ()} { link_path .as_posix ()} "
895
+ )
896
+ if alias_count == 0 :
897
+ full_alias_command = single_alias_cmd
898
+ else :
899
+ full_alias_command &= single_alias_cmd # Use the '&' operator (__and__)
900
+ alias_count += 1
901
+
902
+ if alias_count > 0 :
903
+ self .debug ("Creating script aliases on guest." )
904
+ guest .execute (full_alias_command , friendly_command = "Create script aliases" )
905
+
906
+ finally :
907
+ # Cleanup rendered templates now that they've been pushed (or if an error occurred)
908
+ for template_script in templates_to_cleanup :
909
+ template_script .cleanup ()
908
910
909
911
def _tmt_report_results_filepath (self , invocation : TestInvocation ) -> Path :
910
912
"""
0 commit comments