Skip to content

automatic: Support --dump-config option - #3089

Open
jelly wants to merge 1 commit into
rpm-software-management:mainfrom
jelly:dnf5-automatic-config
Open

jelly wants to merge 1 commit into
rpm-software-management:mainfrom
jelly:dnf5-automatic-config

Conversation

@jelly

@jelly jelly commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Support dumping the dnf automatic configuration of all merged configuration files. This is useful for Cockpit to discover what configuration settings are applied and if a dropin file needs to be created.


One discussion topic might be that this dumps in toml while dnf --dump-main-config dumps without showing the sections

@jelly
jelly requested a review from a team as a code owner December 2, 2026 17:58
@jelly
jelly requested review from fhbash and removed request for a team December 2, 2026 17:58
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

automatic: Support --dump-config option

✨ Enhancement 🧪 Tests 🕐 10-20 Minutes


AI Description

• Adds a dnf automatic --dump-config flag that prints the merged automatic.conf settings and
 exits.
• Dumps each config section (commands, emitters, command, command_email, email, base) as key = value
 pairs.
• Adds a behave integration test covering override precedence and the dump output; documents the
 option in the man page.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • This is one bounded end-to-end behavior: an automatic-command invocation resolves its automatic configuration and presents it to the invoking operator.
  • The propagation path is direct from the new command behavior to that single output capability; the documentation and integration test do not create separate production capabilities.
Behavioral complexity 🟢 Low 🧩 Straightforward

  • The change adds a gated, direct serialization rule over existing Config opt_binds and then performs an early successful exit.
  • It reuses established option parsing and value-string conversion; it does not introduce new state coordination, ordering, concurrency, persistence, or downstream contracts.
  • The catch only changes formatting for an OptionError by printing the key without a value.
Sources

dnf5-plugins/automatic_plugin/automatic.cpp[278-282]

    dump_config = std::make_unique<libdnf5::cli::session::BoolOption>(
        *this,
        "dump-config",
        '\0',
        _("Print dnf-automatic configuration values, excluding the main [base] configuration, to stdout."),
Potential damage 🟢 Low 🩹 Reversible

  • If the dump capability regresses, an operator may receive missing, misleading, or unavailable configuration output and must inspect configuration another way.
  • The path exits before update processing, so this behavior does not itself modify packages, persistent state, or external notification systems.
  • Reverting the code restores the prior command behavior; no dump-specific persistent state or external effect requires repair.
Sources

dnf5-plugins/automatic_plugin/automatic.cpp[278-282]

    dump_config = std::make_unique<libdnf5::cli::session::BoolOption>(
        *this,
        "dump-config",
        '\0',
        _("Print dnf-automatic configuration values, excluding the main [base] configuration, to stdout."),
Assessed commit b9e1978
Diagram

graph TD
    CLI["dnf automatic --dump-config"] --> PRE["pre_configure()"] --> LOAD["load config files"] --> DUMP["dump_section() x6"] --> EXIT["SilentCommandExitError(0)"]
    LOAD -. "automatic.conf + conf.d" .-> CONF[("ConfigAutomatic")]
    DUMP -. "reads options" .-> CONF
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Machine-readable JSON output (--dump-config=json or a separate flag)
  • ➕ Cockpit can parse it without a hand-written INI/TOML parser
  • ➕ Avoids ambiguity from keys printed without values when unset
  • ➕ Easier to extend with metadata such as the source file for each value
  • ➖ Diverges from the text format of dnf --dump-main-config
  • ➖ Adds a second output format to maintain and document
2. Reuse dnf --dump-main-config style (no section headers, flat key = value)
  • ➕ Consistent with existing dnf dump behavior
  • ➕ Simpler output
  • ➖ Loses section context, which Cockpit needs to decide which drop-in file to create
  • ➖ Key names collide across sections such as email_host and base options

Recommendation: The PR's approach is reasonable for the stated goal: it reuses the existing option binds, runs after all drop-ins are merged, and exits before any side effects. Section headers are needed for Cockpit to map a setting to its drop-in section. The main open question is format. The output is INI-style, not strict TOML, though it is valid INI-like syntax. If Cockpit will parse it programmatically, a JSON option would be more robust. Keeping plain text is acceptable if the format is documented as a stable contract. The PR should state which choice it makes.

Files changed (4) +83 / -0

Enhancement (2) +25 / -0
automatic.cppAdd dump_section helper and --dump-config early exit +24/-0

Add dump_section helper and --dump-config early exit

• Adds a dump_section() helper that prints a [section] header and each option as key = value, falling back to a bare key when the value cannot be read. Registers the dump-config BoolOption and, in pre_configure(), dumps six config sections and throws SilentCommandExitError(0) before timer, download, or apply logic runs.

dnf5-plugins/automatic_plugin/automatic.cpp

automatic.hppDeclare dump_config option member +1/-0

Declare dump_config option member

• Adds a unique_ptr<BoolOption> member named dump_config next to the existing timer option.

dnf5-plugins/automatic_plugin/automatic.hpp

Tests (1) +55 / -0
dump-config.featureAdd behave test for dumped automatic configuration +55/-0

Add behave test for dumped automatic configuration

• Creates a distribution automatic.conf and a local drop-in with overlapping keys, runs automatic --dump-config --installupdates, and checks that the local overrides and CLI flag appear in the expected sections and that no transaction output is printed.

integration-tests/dnf-behave-tests/dnf/dnf-automatic/dump-config.feature

Documentation (1) +3 / -0
automatic.8.rstDocument --dump-config in automatic man page +3/-0

Document --dump-config in automatic man page

• Adds a --dump-config entry to the Options section describing that it prints configuration values to stdout.

doc/dnf5_plugins/automatic.8.rst

@m-blaha

m-blaha commented Dec 3, 2026

Copy link
Copy Markdown
Member

Nice! What is expected to be printed in the [base] section? Currently it prints full ConfigMain (beware that the print is called from pre_configure hook, which means that the /etc/dnf/dnf.conf overrides are not applied yet). According to the test, only automatic overrides are expected (that would require comparing the option priority with libdnf5::Option::Priority::AUTOMATICCONFIG before printing). If we need full config, that either moving printing to the top of configure(), or calling base.load_config() just before printing should help.
There is one more subtlety - dirs (reposdir, logdir,...) are prepended by installroot even later (during base.setup() called between pre_configure and configure). So if we print in pre_configure, raw config values, as used in config files, are printed (without installroot). If we print later, the actual values for the run (installroot applied, variables expanded) are printed. The same for variables substitution. I would lean towards printing configured values, not resolved ones - thus stay in pre_configure().

@jelly

jelly commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Nice! What is expected to be printed in the [base] section? Currently it prints full ConfigMain (beware that the print is called from pre_configure hook, which means that the /etc/dnf/dnf.conf overrides are not applied yet). According to the test, only automatic overrides are expected (that would require comparing the option priority with libdnf5::Option::Priority::AUTOMATICCONFIG before printing). If we need full config, that either moving printing to the top of configure(), or calling base.load_config() just before printing should help. There is one more subtlety - dirs (reposdir, logdir,...) are prepended by installroot even later (during base.setup() called between pre_configure and configure). So if we print in pre_configure, raw config values, as used in config files, are printed (without installroot). If we print later, the actual values for the run (installroot applied, variables expanded) are printed. The same for variables substitution. I would lean towards printing configured values, not resolved ones - thus stay in pre_configure().

I have to admit that I didn't fully graps the implications here, the main motivation is to print the automatic config so I'd say we can drop the main config.

@jelly
jelly force-pushed the dnf5-automatic-config branch 2 times, most recently from e9aff3b to 012d025 Compare December 4, 2026 11:39
Support dumping the dnf automatic configuration of all merged
configuration files. This is useful for Cockpit to discover what
configuration settings are applied and if a drop-in file needs to be
created.
The [base] section, which overrides options from the main DNF
configuration, is excluded from the output.
@jelly
jelly force-pushed the dnf5-automatic-config branch from 012d025 to b9e1978 Compare December 4, 2026 13:36
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.

2 participants