vm-host parameters help is wrong
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MAAS |
Fix Committed
|
Medium
|
Wyatt Rees |
Bug Description
$ maas root vm-host parameters
usage: maas root vm-host parameters [--help] [-d] [-k] id [data ...]
Obtain VM host parameters
...
Note: This method is reserved for admin users.
the following arguments are required: id, data
However data is not required, it is not even supposed to do anything
`vm-host parameters id` returns all parameters in one output
`vm-host parameters id certificate` says
'certificate' is not a name=value or name@=filename pair
Eithr parameter command needs to support data and return just that field from the output or help should be corrected to not suggest `data` is a valid argument or that it is required argument.
To be clear parameters -h shows `data` as argument and parameters without specifying id says id and data are required arguments
Related branches
- MAAS Lander: Approve
- Alexsander de Souza: Approve
-
Diff: 26 lines (+5/-2)1 file modifiedsrc/maascli/api.py (+5/-2)
- MAAS Lander: Approve
- Alexsander de Souza: Approve
-
Diff: 26 lines (+5/-2)1 file modifiedsrc/maascli/api.py (+5/-2)
- MAAS Lander: Approve
- Jack Lloyd-Walters: Approve
-
Diff: 107 lines (+55/-5)3 files modifiedsrc/maascli/api.py (+7/-3)
src/maascli/testing/config.py (+5/-1)
src/tests/maascli/test_api.py (+43/-1)
Changed in maas: | |
status: | New → Triaged |
importance: | Undecided → Medium |
milestone: | none → 3.5.0 |
Changed in maas: | |
milestone: | 3.5.0 → 3.5.x |
Changed in maas: | |
assignee: | nobody → Wyatt Rees (wyattrees) |
status: | Triaged → In Progress |
Changed in maas: | |
milestone: | 3.5.x → 3.6.0 |
Changed in maas: | |
status: | In Progress → Fix Committed |
We can fix this by changing how we add data to the argument parser. Currently, `data` is specified as a positional argument with `nargs="*"` and a custom type function. This forces `data` to be recognized as a required argument and specifies it as a list of key=value pairs: https:/ /git.launchpad. net/maas/ tree/src/ maascli/ api.py# n105
Unfortunately, argparse does not allow you to specify positional arguments as optional, unless you use `nargs="?"`. If we do use `nargs="?"`, the argument is no longer recognized as a list. However, we can then also modify the custom type converter (https:/ /git.launchpad. net/maas/ tree/src/ maascli/ api.py# n198) to convert a list of key=value pairs (rather than just one key=value pair, as is done now). This does remove "data" from the error message specifying required arguments, but has a side effect: whenever the `data` argument is presented for any command using it, it must be wrapped in quotes.
As a side-note: changing the API to actually use the `data` argument doesn't make a ton of sense, since the `data` argument must be presented as key=value pairs, but this specific action only requires a key.