Skip to content

Improve ubuntu upgrade bash scripts#2142

Open
jovial wants to merge 1 commit intostackhpc/2024.1from
2024.1/ubuntu-upgrade-script-bash
Open

Improve ubuntu upgrade bash scripts#2142
jovial wants to merge 1 commit intostackhpc/2024.1from
2024.1/ubuntu-upgrade-script-bash

Conversation

@jovial
Copy link
Contributor

@jovial jovial commented Feb 6, 2026

  • Fix checking of undefined variables
  • More quoting

Concrete issue was that it failed to correctly check KAYOBE_PATH was set.

- Fix checking of undefined variables
- More quoting
@jovial jovial requested a review from a team as a code owner February 6, 2026 18:44
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the robustness of the Ubuntu upgrade scripts by fixing checks for undefined variables and adding quoting, which are great improvements. The changes correctly address the issues described.

I've added a couple of suggestions on tools/ubuntu-upgrade-infra-vm.sh to make the scripts even more concise and maintainable by using more idiomatic bash constructs. These suggestions also apply to the other scripts (ubuntu-upgrade-overcloud.sh, ubuntu-upgrade-seed-hypervisor.sh, ubuntu-upgrade-seed.sh) as they share similar code blocks. Applying these changes across all scripts would reduce code duplication and improve overall consistency.

Comment on lines +10 to 18
if [[ -z "$KAYOBE_PATH" ]]; then
echo "Environment variable \$KAYOBE_PATH is not defined"
exit 2
fi

if [[ ! $KAYOBE_CONFIG_PATH ]]; then
if [[ -z "$KAYOBE_CONFIG_PATH" ]]; then
echo "Environment variable \$KAYOBE_CONFIG_PATH is not defined"
exit 2
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For checking required environment variables, you can use parameter expansion to make the code more concise and idiomatic. This will check if the variable is set and not empty, and if not, it will print the error message to stderr and exit the script due to set -e. This pattern can be applied to the other scripts as well.

Suggested change
if [[ -z "$KAYOBE_PATH" ]]; then
echo "Environment variable \$KAYOBE_PATH is not defined"
exit 2
fi
if [[ ! $KAYOBE_CONFIG_PATH ]]; then
if [[ -z "$KAYOBE_CONFIG_PATH" ]]; then
echo "Environment variable \$KAYOBE_CONFIG_PATH is not defined"
exit 2
fi
: "${KAYOBE_PATH:?Environment variable KAYOBE_PATH is not defined}"
: "${KAYOBE_CONFIG_PATH:?Environment variable KAYOBE_CONFIG_PATH is not defined}"

Comment on lines +20 to 28
if [[ -z "$ANSIBLE_ROLES_PATH" ]]; then
set -x
export ANSIBLE_ROLES_PATH=$KAYOBE_PATH/ansible/roles
export ANSIBLE_ROLES_PATH="$KAYOBE_PATH/ansible/roles"
set +x
else
set -x
export ANSIBLE_ROLES_PATH=$ANSIBLE_ROLES_PATH:$KAYOBE_PATH/ansible/roles
export ANSIBLE_ROLES_PATH="$ANSIBLE_ROLES_PATH:$KAYOBE_PATH/ansible/roles"
set +x
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic for setting ANSIBLE_ROLES_PATH can be simplified to be less repetitive. By preparing the new value in a temporary variable, you can avoid duplicating the set -x/export/set +x block. This refactoring improves readability and maintainability, and can be applied to the other scripts as well.

Suggested change
if [[ -z "$ANSIBLE_ROLES_PATH" ]]; then
set -x
export ANSIBLE_ROLES_PATH=$KAYOBE_PATH/ansible/roles
export ANSIBLE_ROLES_PATH="$KAYOBE_PATH/ansible/roles"
set +x
else
set -x
export ANSIBLE_ROLES_PATH=$ANSIBLE_ROLES_PATH:$KAYOBE_PATH/ansible/roles
export ANSIBLE_ROLES_PATH="$ANSIBLE_ROLES_PATH:$KAYOBE_PATH/ansible/roles"
set +x
fi
if [[ -z "$ANSIBLE_ROLES_PATH" ]]; then
ANSIBLE_ROLES_PATH_NEW="$KAYOBE_PATH/ansible/roles"
else
ANSIBLE_ROLES_PATH_NEW="$ANSIBLE_ROLES_PATH:$KAYOBE_PATH/ansible/roles"
fi
set -x
export ANSIBLE_ROLES_PATH="$ANSIBLE_ROLES_PATH_NEW"
set +x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant