tools: remove perl in mtx changer#1740
Conversation
|
I'm going to write a super-simple mockup-mtx and a systemtest to make sure this doesn't break. |
arogge
left a comment
There was a problem hiding this comment.
this looks pretty good. There's just one little bug the systemtest I added found.
| /^Data Transfer Element .*[0-9]:/ { | ||
| gsub("Data Transfer Element ","",$1) | ||
| gsub("Full .*",":F",$2) | ||
| gsub("Empty",":E",$2) | ||
| gsub("VolumeTag = ",":",$3) | ||
| print "D:" $1 $2 $3 | ||
| } |
There was a problem hiding this comment.
we still have a bug in here. The output for a drive with a volume loaded should look like this:
D:<drive>:F:<slot-currently-loaded>:<volume-tag>
e.g.
D:0:F:3:000003L8
for volume 000003L8 loaded from slot 3 into drive 0
There was a problem hiding this comment.
Ok seen, I've fixed that now with gensub
core/scripts/mtx-changer.in
Outdated
| awk_code=$( | ||
| cat << '_EOT_' | ||
| /^ .*Storage Element .*[0-9]:.*Full/ { | ||
| gsub("[ ].*Storage Element ","",$1) | ||
| gsub("VolumeTag=","",$3) | ||
| gsub(/ *$/, "", $3) | ||
| print $1 ":" $3 | ||
| } | ||
| _EOT_ | ||
| ) | ||
| awk -F ":" "$awk_code" "${TMPFILE}" |
There was a problem hiding this comment.
I just realized that this is way more complicated than needed.
We don't need to assign that to a variable, but can just make awk read the script from stdin like this:
| awk_code=$( | |
| cat << '_EOT_' | |
| /^ .*Storage Element .*[0-9]:.*Full/ { | |
| gsub("[ ].*Storage Element ","",$1) | |
| gsub("VolumeTag=","",$3) | |
| gsub(/ *$/, "", $3) | |
| print $1 ":" $3 | |
| } | |
| _EOT_ | |
| ) | |
| awk -F ":" "$awk_code" "${TMPFILE}" | |
| awk -f - -F ":" "${TMPFILE}" << '_EOT_' | |
| /^ .*Storage Element .*[0-9]:.*Full/ { | |
| gsub("[ ].*Storage Element ","",$1) | |
| gsub("VolumeTag=","",$3) | |
| gsub(/ *$/, "", $3) | |
| print $1 ":" $3 | |
| } | |
| _EOT_ |
That should work for all the other awk calls, too.
- add max_wait_drive variable with a default of 300s which can be extended in the mtx-changer.conf file to larger value (maybe needed for LTO9 drive due to calibration) - use awk expression if most cases - unify the way we use awk (-F, double quotes, etc) - shfmt -i2 -ci - shellcheck code - systemtests: add mtx-changer test - trim trailing whitespace on list cmd - improve readability of longer awk code use direct input in awk expression without variables Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
749426a to
64f747e
Compare
arogge
left a comment
There was a problem hiding this comment.
Of course, there is always a lot more stuff to optimize, but that's probably true for every shell-script we have.
This is really a huge improvement! Thank you!
This PR aims to cleanup our mtx-changer script.
We removed the perl dependency making it for friendly for containerized environment.
Some efforts have been put into reformatting sources and simplifying expression and usage.
Please check
If you have any questions or problems, please give a comment in the PR.
Helpful documentation and best practices
Checklist for the reviewer of the PR (will be processed by the Bareos team)
Make sure you check/merge the PR using
devtools/pr-toolto have some simple automated checks run and a proper changelog record added.General
Source code quality
Tests