AppStreams promise type enhancements#136
Conversation
f73f03d to
8d34c03
Compare
03bec2e to
a6c0ca7
Compare
| self.log_error(f" Package {pkg} failed: {error}") | ||
|
|
||
| def _install_module(self, mpc, base, module_name, stream, profile): | ||
| def _apply_dnf_options(self, base, options): |
There was a problem hiding this comment.
This function seems to apply DNF configuration options at best effort. I.e., if it fails, it just logs a warning and continues. Is this the intention? If so, maybe you should rename the function to _try_apply_dnf_options?
There was a problem hiding this comment.
Yeah good point i was still thinking about this and maybe would be best to fail here.
| self.log_error( | ||
| f"Failed to verify module switch for {module_name}:{stream}/{profile}" | ||
| ) | ||
| return Result.NOT_KEPT |
There was a problem hiding this comment.
Maybe you can flatten this code to avoid too many nested if's. If you turn the conditions on their head you could get something like:
enabled_stream = mpc.getEnabledStream(module_name)
if enabled_stream != stream:
# Log error saying enabled stream was not equal to stream
return Result.NOT_KEPT
installed_profiles = mpc.getInstalledProfiles(module_name)
if profile not in installed_profiles:
# Log error saying profile not in installed_profiles
return Result.NOT_KEPT
# etc... and then eventually return REPAIREDIt's a little bit more readable in my opinion. But it's only an opinion. There is nothing wrong with the way you did it.
Yeah things were messy and eventually I gave up trying to have a logical commit order but I will give it another go to try and make it easier to follow. |
34ad32e to
aab1de7
Compare
Add an 'options' attribute that accepts a list of DNF configuration
options as "key=value" strings. Options are applied generically using
DNF's set_or_append_opt_value() API, enabling any DNF configuration
option without hardcoding specific cases.
Example usage:
appstreams:
"php"
state => "installed",
stream => "8.2",
options => { "install_weak_deps=false" };
The _try_apply_dnf_options() method applies options at best effort,
logging warnings for failures but continuing execution. This prevents
invalid options from blocking module operations.
Replace manual mpc.enable/install/save sequence with DNF's ModuleBase API (module_base.install()). This provides proper module context and ensures module-specific package versions are installed correctly.
Detect when a module is already installed with a different stream and
automatically switch to the requested stream using DNF's ModuleBase
switch_to() API. This enables both upgrades (e.g., php:8.1 → 8.2) and
downgrades (e.g., php:8.2 → 8.1) without manual intervention.
Stream switching is triggered when:
1. state => "installed" is requested
2. A module is already enabled with a different stream
3. The requested stream differs from the currently enabled stream
The _switch_module() method:
- Uses ModuleBase.switch_to() for proper DNF module transitions
- Downloads packages explicitly to avoid stale cache issues
- Verifies both stream and profile installation after switching
- Provides detailed error messages for each failure case
Example usage:
appstreams:
"php"
state => "installed",
stream => "8.2"; # Will switch from 8.1 if already installed
Mock dnf.module.module_base to support testing the ModuleBase API refactoring. Without this mock, the import sets dnf.module=None and tests fail when trying to access module_base.ModuleBase().
aab1de7 to
72c56c5
Compare
Invalid DNF options are configuration errors and should fail the promise as NOT_KEPT rather than logging warnings and continuing. Changes: - Renamed _try_apply_dnf_options -> _apply_dnf_options - Removed try/except wrapper inside _apply_dnf_options - Added try/except in callers to catch ConfigError and return NOT_KEPT - Added test_invalid_dnf_option_not_kept to verify behavior This aligns with strict configuration validation - if a user specifies an invalid option, it's a policy error that should be fixed.
72c56c5 to
b3364f5
Compare
|
Alright, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/13581/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-13581/ |
600330b to
10bcd44
Compare
Document the new features added in this PR: - Stream switching (automatic upgrades/downgrades) - Generic DNF options support - Audit trail attributes (handle, comment) Add usage examples for stream switching and DNF options.
10bcd44 to
fef723c
Compare
Generic DNF Options Support
Previously the appstreams promise type had no way to pass DNF configuration options. Users could not control behavior like weak dependency installation.
After adding support for
optionsthe module now accepts any DNF configuration option.Changes now log to dnf history. sys.argv is faked so that
dnf historywill output useful information in the prominent "Command Line" field.It's now possibly to easily switch streams. Previously, if a module was already enabled at one stream and you requested a different stream, the promise would report KEPT without making changes or would fail.
Promise would report KEPT because it detected the module was "installed", but didn't check if the stream matched. Now there is automatic detection and handling of stream changes (both upgrades and downgrades).
Same policy, same starting state:
DNF History shows:
And downgrades:
Result:
Fixed Package Versions installed by stream.
Previously packages might be installed from the wrong stream or default stream instead of the requested module stream.
Policy:
Result (with old mpc.enable/install API):
dnf history showed what we desired and what actually happened:
Now it uses the ModuleBase api and resolves versions from the module stream correctly:
Same policy:
Result:
DNF history:
optionsattribute