Skip to content

Commit 1856b55

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 1856b55

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

  • configuration/steps/commands

configuration/steps/commands/mtr.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,39 @@ 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+
plugins_dir=$( [ -d /usr/lib/mysql/plugin ] && echo /usr/lib/mysql/plugin || [ -d /usr/lib64/mysql/plugin ] && echo /usr/lib64/mysql/plugin || echo "$vardir/plugins" )
81+
82+
# MTR can run both from installed binaries or from build tree
83+
# Try to find mariadbd binary in both cases
84+
mariadbd_path=$(command -v mariadbd 2>/dev/null || ([ -x $script_dir/../sql/mariadbd ] && realpath $script_dir/../sql/mariadbd))
85+
86+
echo "Saving MTR logs"
87+
88+
# Staging path before files are moved to CI
89+
mkdir -p $save_logs_path
90+
91+
# Save plugins .so and mariadbd if core was generated
92+
save_bin=0
93+
find $vardir -name *core.* -exec false {{}} + || save_bin=1
94+
if [[ $save_bin -ne 0 ]]; then
95+
find -L "$plugins_dir" -maxdepth 1 -type f -name '*.so' -printf '%f\n' > $save_bin_path/plugins_list.txt
96+
tar -czvf "$save_bin_path/plugins.tar.gz" --dereference -C "$plugins_dir" -T $save_bin_path/plugins_list.txt
97+
gzip -c "$mariadbd_path" > "$save_bin_path/mariadbd.gz"
98+
fi
99+
100+
# Some core files are left uncompressed by MTR
101+
find $vardir -iregex ".*/core\(\.[0-9]+\)?" -ls -exec gzip {{}} +
102+
103+
# Copy pattern matching files to staging
104+
cd "$vardir" && find . -type f \( $file_patterns_to_save \) -print0 | rsync -a --from0 --files-from=- ./ "$save_logs_path/"
105+
exit 1 # Script was invoked by an MTR failure so we must mark the step as failed
78106
"""
79107

80108

0 commit comments

Comments
 (0)