generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 6
fix: __MOCK_SKU is uninitialised when run from init services #74
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
dgchinner
wants to merge
1
commit into
linux-system-roles:main
Choose a base branch
from
dgchinner:sku-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts SKU customisation scripts to safely handle an optionally undefined __MOCK_SKU under strict shell settings, ensures topology runtime directory exists, and clarifies test behaviour in the SKU test harness. Sequence diagram for __MOCK_SKU initialisation and SKU lookupsequenceDiagram
actor Systemd
participant Script as setup_sku_customisations_sh
participant Env as Environment
participant Metadata as AzureMetadataService
Systemd ->> Script: Start sku_customisation.service
Script ->> Script: Set topology env vars
Script ->> Script: mkdir -p TOPOLOGY_RUNTIME_DIR
Script ->> Env: Read __MOCK_SKU
alt __MOCK_SKU undefined in Env
Script ->> Script: Parameter expansion ${__MOCK_SKU:=}
Script ->> Env: Set __MOCK_SKU to empty string
else __MOCK_SKU defined (possibly empty)
Script ->> Script: Keep existing __MOCK_SKU
end
Script ->> Script: Test -z "$__MOCK_SKU"
alt __MOCK_SKU empty
Script ->> Metadata: HTTP GET /metadata/instance
Metadata -->> Script: SKU from metadata
Script ->> Script: Apply SKU customisations
else __MOCK_SKU nonempty (test harness)
Script ->> Script: Use mocked SKU from Env
Script ->> Script: Apply SKU customisations
end
Script -->> Systemd: Exit status 0 (on success)
Flow diagram for SKU resolution logic in setup_sku_customisations.shflowchart TD
A_start[Start setup_sku_customisations.sh] --> B_set_dirs[Set topology environment variables]
B_set_dirs --> C_mkdir[Create TOPOLOGY_RUNTIME_DIR with mkdir -p]
C_mkdir --> D_init_mock_sku[Initialise __MOCK_SKU with parameter expansion]
D_init_mock_sku --> E_check_mock_sku{Is __MOCK_SKU empty?}
E_check_mock_sku -->|Yes| F_use_metadata[Call Azure metadata endpoint to fetch SKU]
E_check_mock_sku -->|No| G_use_mock_sku[Use __MOCK_SKU from environment or tests]
F_use_metadata --> H_apply_customisations[Apply SKU specific customisations]
G_use_mock_sku --> H_apply_customisations
H_apply_customisations --> I_end[End script]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- In
test-sku-setup.sh, the change from__MOCK_SKU="$sku {{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"to__MOCK_SKU="$sku" "{{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"alters the command invocation semantics; if the intent is to set__MOCK_SKUin the environment while runningsetup_sku_customisations.sh, consider using__MOCK_SKU="$sku" "{{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"(single command line) or__MOCK_SKU="$sku" bash "{{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"to preserve the original behavior more explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `test-sku-setup.sh`, the change from `__MOCK_SKU="$sku {{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"` to `__MOCK_SKU="$sku" "{{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"` alters the command invocation semantics; if the intent is to set `__MOCK_SKU` in the environment while running `setup_sku_customisations.sh`, consider using `__MOCK_SKU="$sku" "{{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"` (single command line) or `__MOCK_SKU="$sku" bash "{{ __hpc_azure_resource_dir }}/bin/setup_sku_customisations.sh"` to preserve the original behavior more explicitly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This results in a failure due to the '-eu' flags the shell is running under like this: systemd[1]: Starting Customisations based on SKU... setup_sku_customisations.sh[1343]: /opt/hpc/azure/bin/setup_sku_customisations.sh: line 29: __MOCK_SKU: unbound variable systemd[1]: sku_customisation.service: Main process exited, code=exited, status=1/FAILURE The test code can validly set __MOCK_SKU to an empty string to test fetching the SKU from the azure infrastructure. Hence we need to have both a defined, empty string and an undefined environment variable work correct. This is how the "-z $__MOCK_SKU" check is defined to work, but we have to work around linter requirements for avoiding use of undefined variables. Hence using 'test -v __MOCK_SKU' to detect if the variable is undefined is insufficient to trigger auto-test behaviour as it does not capture the defined-but-empty case described above. As such, use the bash conditional variable init construct that initialises __MOCK_SKU to an empty string if and only if the variable is not already defined by the environment. Also clean up a couple of other minor issues that were also introduced when satisfying linters found whilst testing the above fix. Signed-off-by: Dave Chinner <dchinner@redhat.com>
richm
reviewed
Feb 11, 2026
richm
approved these changes
Feb 11, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This results in a failure due to the '-eu' flags the shell is running under like this:
systemd[1]: Starting Customisations based on SKU...
setup_sku_customisations.sh[1343]: /opt/hpc/azure/bin/setup_sku_customisations.sh: line 29: __MOCK_SKU: unbound variable
systemd[1]: sku_customisation.service: Main process exited, code=exited, status=1/FAILURE
The test code can validly set __MOCK_SKU to an
empty string to test fetching the SKU from the azure infrastructure. Hence we need to have both a defined, empty string and an undefined environment variable work correct. This is how the "-z $__MOCK_SKU" check is defined to work, but we have to work around linter requirements for avoiding use of undefined variables.
Hence using 'test -v __MOCK_SKU' to detect if the variable is undefined is insufficient to trigger auto-test behaviour as it does not capture the defined-but-empty case described above. As such, use the bash conditional variable init construct that initialises __MOCK_SKU to an empty string if and only if the variable is not already defined by the environment.
Also clean up a couple of other minor issues that were also introduced when satisfying linters found whilst testing the above fix.
Issue Tracker Tickets (Jira or BZ if any): RHELHPC-152
Summary by Sourcery
Ensure SKU customisation script handles undefined or empty __MOCK_SKU correctly while keeping tests compatible with strict shell settings.
Bug Fixes:
Enhancements: