Skip to content

Commit 3cd9d16

Browse files
MDBF-1124 - Extend MTRTest _save_logs()
[1] compress core files generated by mtr [2] save mariadbd binary if core files were generated [3] save plugins .so files if core files were generated Note on [1]: By doing exec false, find will return non-0 on there being matches and then tar can save the plugins, de-referencing the list of symlinks make by mtr.
1 parent 059f607 commit 3cd9d16

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

  • configuration/steps/commands

configuration/steps/commands/mtr.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,36 @@ def _save_logs(self) -> str:
7070
logs = ["*.log", "*.err*", "core*"]
7171
patterns = " -o ".join([f'-iname "{log}"' for log in logs])
7272
return f"""
73-
echo "Saving MTR logs to persistent volume because some tests failed"
74-
cd {self.log_path}
75-
mkdir -p {self.save_logs_path}
76-
find . -type f \( {patterns} \) -print0 | rsync -a --files-from=- --from0 ./ {self.save_logs_path}/
77-
exit 1
73+
#!/bin/bash
74+
75+
script_dir=$(pwd) # Path where the test runner was invoked
76+
vardir="{self.log_path}"
77+
save_logs_path="{self.save_logs_path}"
78+
save_bin_path=$(dirname "$save_logs_path")
79+
file_patterns_to_save="{patterns}"
80+
81+
# MTR can run both from installed binaries or from build tree
82+
# Try to find mariadbd binary in both cases
83+
mariadbd_path=$(command -v mariadbd 2>/dev/null || ([ -x $script_dir/../sql/mariadbd ] && realpath $script_dir/../sql/mariadbd))
84+
85+
echo "Saving MTR logs"
86+
87+
# Staging path before files are moved to CI
88+
mkdir -p $save_logs_path
89+
90+
# Some core files are left uncompressed by MTR
91+
save_bin=0
92+
find $vardir -iregex ".*/core\(\.[0-9]+\)" -ls -exec gzip {{}} + -exec false {{}} + || save_bin=1
93+
94+
# Save plugins .so and mariadbd if core was generated
95+
if [[ $save_bin -ne 0 ]]; then
96+
tar -czvf "$save_bin_path/plugins.tar.gz" --dereference -C $vardir plugins
97+
gzip -c "$mariadbd_path" > "$save_bin_path/mariadbd.gz"
98+
fi
99+
100+
# Copy pattern matching files to staging
101+
cd "$vardir" && find . -type f \( $file_patterns_to_save \) -print0 | rsync -a --from0 --files-from=- ./ "$save_logs_path/"
102+
exit 1 # Script was invoked by an MTR failure so we must mark the step as failed
78103
"""
79104

80105

0 commit comments

Comments
 (0)