fix(operations.zypper): fix gpg validation, auto-import keys, and permissions
Description:
Fixes #1830 Fixes #1831 Fixes #1832
Description
This PR addresses three related issues with zypper and repository management to ensure repositories and packages deploy correctly out-of-the-box.
- GPG Key URL Validation (#1830):
ensure_yum_reponow parses thegpgkeyargument to ensure it's a valid URL (or an absolute local path). If someone passes invalid text (like"INVALID TEXT"), it throws anOperationValueErrorearly during the generation phase rather than failing silently during deployment. - Key Auto-Import for Non-Interactive Installs (#1831):
zypper --non-interactiveautomatically rejects unrecognized GPG keys by default. To fix failed package installations from new repositories, I added the--gpg-auto-import-keysflag toinstall_commandandupgrade_commandinzypper.packages(). Zypper will now correctly import valid keys instead of failing. - World-Readable
.repoFiles (#1832):files.putwas inheriting strict permissions from the internal string buffer, causing repo files to be created with restricted permissions (e.g.,0600). I addedmode="0644"to thefiles.putcall so that non-root users can correctly query and search repositories, matching native package manager defaults.
Testing
I updated the JSON test fixtures in accordance with Pyinfra's testing guidelines to verify all the changes:
-
Key Auto-Import Tests: Updated the expected command output in
tests/operations/zypper.packages/add_packages.json,install_with_args.json,install_with_global_args.json, andupdate_clean.jsonto explicitly ensure the--gpg-auto-import-keysflag is present during installs and updates. -
Validation Tests: Updated
tests/operations/dnf.repo/add.json,yum.repo/add.json, andzypper.repo/add.jsonto use a valid dummy URL (https://test/key) so they pass the new URL validation checks. -
Permissions Tests: Added the expected
chmod 644 /etc/.../somerepo.repocommand to the expected outputs of thednf.repo,yum.repo, andzypper.repotest fixtures to mathematically verify themode="0644"implementation. -
[x] Pull request is based on the default branch (
3.xat this time) -
[x] Pull request includes tests for any new/updated operations/facts
-
[x] Pull request includes documentation for any new/updated operations/facts
-
[x] Tests pass (see
scripts/dev-test.sh) -
[x] Type checking & code style passes (see
scripts/dev-lint.sh) -
[x] Pull request title follows the conventional commits format