test: add ShellSpec coverage for init-aks-custom-cloud.sh#8886
test: add ShellSpec coverage for init-aks-custom-cloud.sh#8886Devinwong wants to merge 11 commits into
Conversation
Resolves conflicts from PR #8692 after #8096 consolidated the four separate init-aks-custom-cloud scripts into one. Changes: - Restructure init-aks-custom-cloud.sh for source-safety: move all function definitions above a guard (following the localdns.sh pattern) so ShellSpec can Include the file and exercise functions directly. - Make repo-depot helper functions use env-var-overridable paths (APT_SOURCES_LIST_D_DIR, APT_KEYRINGS_DIR, etc.) for testability. - Remove misleading 'distribution is' log line. - Add __SOURCED__ guard for set -x to suppress trace noise in tests. - Merge spec file: keep grep-based ca-refresh wiring tests (from #8096) and add functional tests for init_ubuntu_main_repo_depot, init_ubuntu_pmc_repo_depot, and check_url. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR makes parts/linux/cloud-init/artifacts/init-aks-custom-cloud.sh safe to source (so ShellSpec can Include it) and adds ShellSpec coverage for key repo-depot and URL-checking helpers used in custom-cloud node boot.
Changes:
- Refactors
init-aks-custom-cloud.shto be source-safe by moving execution-only logic below an__SOURCED__guard and gatingset -xwhen sourced. - Makes several paths/env inputs overridable (e.g., apt sources/keyrings locations, wireserver endpoint) to enable hermetic tests.
- Adds/expands ShellSpec tests: keeps grep-based “wiring” checks and adds functional tests for
init_ubuntu_main_repo_depot,init_ubuntu_pmc_repo_depot, andcheck_url.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spec/parts/linux/cloud-init/artifacts/init_aks_custom_cloud_spec.sh | Adds wiring + functional ShellSpec coverage for repo-depot helpers and URL checking. |
| parts/linux/cloud-init/artifacts/init-aks-custom-cloud.sh | Refactors for source-safety and testability (guarded execution, env-overridable paths/endpoints). |
…ngs_dir Address review comment: variables in add_key_ubuntu are now declared local to prevent state leakage, arguments are properly quoted, and the unused keyrings_dir variable is removed (derive_key_paths has its own). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add tests covering different custom cloud scenarios per ADO#36479419: - determine_cert_endpoint_mode: parameterized tests for ussec, usnat (legacy), fairfax/mooncake/bleu (rcv1p), and empty location. - init_mariner_repo_depot: verifies repo creation and URL rewriting with a ussec-like endpoint. - init_azurelinux_repo_depot: verifies repo file generation for usnat and mooncake endpoints. - init_ubuntu_main_repo_depot: additional tests with fairfax, mooncake, and ussec endpoints. Production script changes (testability only): - Extract determine_cert_endpoint_mode() from inline case statement. - Make init_mariner_repo_depot and init_azurelinux_repo_depot use overridable YUM_REPOS_DIR (defaults to /etc/yum.repos.d). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| # Determines the certificate endpoint mode based on location. | ||
| # Returns "legacy" for ussec/usnat regions, "rcv1p" for all others. | ||
| # Usage: cert_endpoint_mode=$(determine_cert_endpoint_mode "$location") | ||
| function determine_cert_endpoint_mode { |
There was a problem hiding this comment.
The extracted determine_cert_endpoint_mode() function is the direct behavioral surface of RCV1P's cloud selection. It's now tested for 8 inputs (ussec, usnat, USSecWest, USNatEast, usgovvirginia, chinaeast2, francesouth, empty). However, there's no test that verifies the refresh_location env-var/arg2 handoff into it actually happens at the script top-level (grep-only). If someone in a future refactor accidentally passes $1 instead of $refresh_location to determine_cert_endpoint_mode , all unit tests still pass. Suggest adding a script-level ShellSpec that runs LOCATION=usseceast bash init-aks-custom-cloud.sh ca-refresh and asserts the emitted AKS.CSE.rcv1p.certEndpointMode event says mode=legacy . This locks the whole RCV1P mode-selection wiring, not just the isolated function.
Not sure if this is in scope of this PR though.
There was a problem hiding this comment.
This is a valid concern. But it seems it will need more changes. Let me follow up in a separate PR.
init_ubuntu_main_repo_depot templates the repodepot URL verbatim with no per-cloud branching, so the fairfax/mooncake/ussec cases exercised the same path as the generic placeholder test. Remove the redundant block; the generic repodepot.example.com test already covers the pass-through. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Neutralize enumerated cloud regions (ussec/usnat) to repodepot.example.com and collapse the redundant Azure Linux Mooncake case, matching the init_ubuntu_main_repo_depot cleanup. These functions template the repodepot URL verbatim with no per-cloud branching, so one placeholder test covers it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Harden WIRESERVER_ENDPOINT: only honor env override when sourced for tests - Create parent dirs for env-overridable paths (apt sources.list.d, yum.repos.d, OpenSSL cert target) so *_DIR test overrides are robust; no-op on prod defaults - OpenSSL bundle copy: warn on missing source, skip on same-file, no false success - Assert all 7 Azure Linux repo files in spec - Document the __SOURCED__ convention at top of file - Add wiring test pinning the determine_cert_endpoint_mode refresh_location handoff Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Set __SOURCED__=1 before Include so ShellSpec loads only the function
definitions. The script's ${__SOURCED__:+return 0} guard is a no-op when
__SOURCED__ is unset, so without this the Include could fall through into
the top-level provisioning path (wireserver calls, cron install, exit) and
cause side effects. Matches the sourcing convention documented in the
script header and used in cse_main_spec.sh.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… failure path Co-authored-by: Devinwong <13621569+Devinwong@users.noreply.github.com>
|
AgentBaker Linux gate detective RCA for failed run: https://msazure.visualstudio.com/CloudNativeCompute/_build/results?buildId=172266842
|
[No logic in init-aks-custom-cloud.sh is changed. Just make it testable]
Resolves conflicts from PR #8692 after #8096 consolidated the four separate init-aks-custom-cloud scripts into one.
Related: ADO#36479419
Changes
Script restructuring (init-aks-custom-cloud.sh) — testability only
Test Coverage Summary
Wiring tests (grep-based) — ca-refresh mode structural invariants
Verifies the script contains correct patterns for: action parsing (init/ca-refresh), location fallback from LOCATION, case-insensitive normalization, ussec/usnat to legacy mapping, refresh schedule gating, early exit in ca-refresh mode, and LOCATION passthrough to cron/systemd commands.
Functional tests — sourced and executed
Coverage: Ubuntu, Mariner, Azure Linux | All 5 custom clouds (bleu, fairfax, mooncake, ussec, usnat)
Supersedes