Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: remove perl in mtx changer #1740

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

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

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

None yet

4 participants