Skip to content

tools: remove perl in mtx changer#1740

Merged
BareosBot merged 3 commits intobareos:masterfrom
bruno-at-bareos:dev/bruno/master/remove-perl-in-mtx-changer
May 15, 2024
Merged

tools: remove perl in mtx changer#1740
BareosBot merged 3 commits intobareos:masterfrom
bruno-at-bareos:dev/bruno/master/remove-perl-in-mtx-changer

Conversation

@bruno-at-bareos
Copy link
Contributor

@bruno-at-bareos bruno-at-bareos commented Mar 18, 2024

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.

  • additionally we request python3 in webui selenium testing

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

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-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Check backport line
  • Required backport PRs have been created
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR
Tests
  • Decision taken that a test is required (if not, then remove this paragraph)
  • The choice of the type of test (unit test or systemtest) is reasonable
  • Testname matches exactly what is being tested
  • On a fail, output of the test leads quickly to the origin of the fault

@arogge
Copy link
Member

arogge commented Apr 19, 2024

I'm going to write a super-simple mockup-mtx and a systemtest to make sure this doesn't break.

Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks pretty good. There's just one little bug the systemtest I added found.

Comment on lines +288 to +277
/^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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok seen, I've fixed that now with gensub

@bruno-at-bareos bruno-at-bareos requested a review from arogge April 22, 2024 14:41
Comment on lines +229 to +239
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}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bruno-at-bareos bruno-at-bareos requested a review from arogge April 30, 2024 08:29
- 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>
@bruno-at-bareos bruno-at-bareos force-pushed the dev/bruno/master/remove-perl-in-mtx-changer branch from 749426a to 64f747e Compare May 15, 2024 07:38
@bruno-at-bareos bruno-at-bareos requested a review from sebsura May 15, 2024 07:39
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@BareosBot BareosBot merged commit 155d77f into bareos:master May 15, 2024
@bruno-at-bareos bruno-at-bareos deleted the dev/bruno/master/remove-perl-in-mtx-changer branch November 25, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants