Skip to content

Add logs to keystore-setup and fix password regex #10723

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

deajan
Copy link

@deajan deajan commented Apr 15, 2025

Description

This PR adds logging to the keystore-setup script, and fixes the regex to check old cloudstack-agent password.

When adding KVM hosts, the keystore-setup script may fail with 530: Failed to setup keystore on the KVM host). On the KVM host for various reasons (absence of keystore, malformatted agent.properties file, missing permissions...).

This adds logs to almost all actions, and also fixes the regex that gets the password from agent.properties in order to not fetch commented-out passwords.

Fixes #10703

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Script has been tested on two AlmaLinux 9.5 KVM hosts with a Cloudstack 4.20 management server.
Script has also been submitted to Shellcheck.

How did you try to break this feature and the system with this change?

Re-ran the tests on multiple hosts to validate that the script works ;)
Log function from the script has been tested on both RHEL and Debian systems.

Copy link

boring-cyborg bot commented Apr 15, 2025

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

ALIAS="cloud"
LIBVIRTD_FILE="/etc/libvirt/libvirtd.conf"

log() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if it installed by default on your host's OS, but there is a tool called logger to do this, no need for a script function.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

looks generally good, but i'd use a $LOGGER as log command and define it depending on availability as the native tool instead of the function.

@deajan
Copy link
Author

deajan commented Apr 16, 2025

The potential problem here is that if /usr/bin/logger does not exist on the target OS, the script must fallback to log() function which would require read command so it can accept getting stdout /stderr through pipes.
AFAIK read is a bash builtin, so the script would become interpreter dependant.

I tend to use that kind of log function so I always get my logs, regardless of the environment.

This would only be a problem of course if /usr/bin/logger is not present by default on all Cloudstack supported distros.
It is definitly on AlmaLinux 9.5. I can't say for the others.

@DaanHoogland So, do I switch to logger with a fallback to log() knowing this ?

@DaanHoogland
Copy link
Contributor

@deajan , I don’t see the need for read? you can test for [ -x $LOGGER ] or something of the likes right?

LOGGER=`type -p logger`
if [[ -x $LOGGER ]]
then
  # we are fine
else
  # use your method
fi

I am also only suggesting, I will not -1 without it.

@deajan
Copy link
Author

deajan commented Apr 17, 2025

The point is that the log function as for now works like log "something".
There are some lines in the script that are like keytool [args] >> LOG_FILE 2>&1 which would need to become keytool [args] 2>&1 | $LOGGER in which case, if /usr/bin/logger is not found, the log function will have to use read to capture the stdin.

It's just a detail, but I am not sure whether read builtin is present in dash used by default in Debian. I can check of course.

@deajan
Copy link
Author

deajan commented Apr 17, 2025

Update: Dash has builtin read. I'll make the necessary changes.

@deajan
Copy link
Author

deajan commented Apr 17, 2025

Updated the script. Let me run it on a couple of hosts to make sure everything works as expected.

@deajan deajan changed the title Add logs to keystore-setup and fix password regex WIP Add logs to keystore-setup and fix password regex Apr 17, 2025
@DaanHoogland
Copy link
Contributor

ok, i see @deajan , sorry to make your life so “exciting” . Nice solution!

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.31%. Comparing base (b2b2218) to head (d9a633e).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #10723   +/-   ##
=========================================
  Coverage     16.30%   16.31%           
- Complexity    13445    13447    +2     
=========================================
  Files          5676     5676           
  Lines        499241   499241           
  Branches      60377    60377           
=========================================
+ Hits          81408    81427   +19     
+ Misses       408767   408742   -25     
- Partials       9066     9072    +6     
Flag Coverage Δ
uitests 3.99% <ø> (ø)
unittests 17.17% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@deajan
Copy link
Author

deajan commented Apr 17, 2025

@DaanHoogland No worries, just wanted to make things right :)

Tested the script, logging works, registering computers works too (tested on two hosts)

@DaanHoogland DaanHoogland changed the title WIP Add logs to keystore-setup and fix password regex Add logs to keystore-setup and fix password regex Apr 17, 2025
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.

Missing logs when cloudstack-setup-agent is run with sudo
2 participants