Skip to content

fix(hotplug-hook): accept --subsystem after the hotplug action - #7122

Closed
wak327 wants to merge 1 commit into
canonical:mainfrom
wak327:fix/hotplug-hook-subsystem-arg
Closed

wak327 wants to merge 1 commit into
canonical:mainfrom
wak327:fix/hotplug-hook-subsystem-arg

Conversation

@wak327

@wak327 wak327 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Proposed Commit Message

fix(hotplug-hook): accept --subsystem after the hotplug action

--subsystem was only an option of `cloud-init devel hotplug-hook`
itself, so it had to come before the hotplug action:
`hotplug-hook query -s net` failed as if --subsystem was missing, and
`hotplug-hook query --help` did not mention it.

Also accept --subsystem after the query, handle and enable actions, so
it shows in their help, while the form used by tools/hook-hotplug
(`--subsystem=net handle ...`) keeps working. As argparse can no longer
require it on either parser, handle_args() reports it when missing.

Fixes GH-4826
Fixes GH-4827

Additional Context

Fixes #4826
Fixes #4827

--subsystem is now accepted both before and after the hotplug action. The leading form keeps working unchanged. That includes the --subsystem=net handle --devpath=... --udevaction=... arguments that tools/hook-hotplug passes to cloud-init-hotplugd.

The query, handle and enable parsers get their own -s/--subsystem with default=argparse.SUPPRESS, so an action given without it can't overwrite a value parsed before the action. argparse can't require an option that may appear on either parser, so handle_args() now makes that check. It uses argparse's usual message and exit code 2, and it runs before Init is created, so a missing option still has no side effects.

Command Before After
hotplug-hook -s net query accepted accepted
hotplug-hook query -s net error: the following arguments are required: -s/--subsystem accepted
hotplug-hook handle -d PATH -u add -s net same error accepted
hotplug-hook query --help lists only -h also lists -s, --subsystem {net}
hotplug-hook query exit 2, -s/--subsystem required exit 2, -s/--subsystem required

The new TestGetParser tests cover these cases. Verified with the pinned black, isort, ruff, pylint and mypy, and the full unit suite passes (5,787 tests).

Test Steps

cloud-init devel hotplug-hook query --help
cloud-init devel hotplug-hook query -s net
cloud-init devel hotplug-hook -s net query
cloud-init devel hotplug-hook query  # exit 2: -s/--subsystem is required
tox -e py3 -- tests/unittests/cmd/devel/test_hotplug_hook.py

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

--subsystem was only an option of `cloud-init devel hotplug-hook`
itself, so it had to come before the hotplug action:
`hotplug-hook query -s net` failed as if --subsystem was missing, and
`hotplug-hook query --help` did not mention it.

Also accept --subsystem after the query, handle and enable actions, so
it shows in their help, while the form used by tools/hook-hotplug
(`--subsystem=net handle ...`) keeps working. As argparse can no longer
require it on either parser, handle_args() reports it when missing.

Fixes canonicalGH-4826
Fixes canonicalGH-4827
@holmanb

holmanb commented Oct 7, 2026

Copy link
Copy Markdown
Member

Thanks for this, @wak327. I don't think that the extra parser complexity is warranted here. This is not intended to be a user-facing command. I just closed #4826.

@wak327 wak327 closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants