-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve handling of empty command lists in Autoinstall YAML #2072
base: main
Are you sure you want to change the base?
Conversation
5eb8382
to
433689d
Compare
What's the motivation for allowing an empty command list section? I would prefer it if we instead improved the validation error messaging by improving the json schema for the Unrelated to the code changes: Have you signed the Canonical CLA? The CLA bot says no but sometimes a manual nudge is necessary to get it happy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: we typically use conventional commits. e.g. "ci: add test case for empty cmdlist" or similar
@Chris-Peterson444 The reason is that the current behavior causes the installer to simply crash with an ugly backtrace that doesn't indicate anywhere in the output what line of the configuration file it is choking on or even that it was the autoinstall configuration. Even the validator does not tell you more than "NoneType is not an iterable" with no indication of what YAML key or line in the file was bad. That is a bad user experience that even a seasoned Linux veteran, which I consider myself, took more than an hour trying to figure out what was wrong. It was a simple fix, but this two-line addition to the logic makes it merely ignore those empty keys. Even if this isn't considered the correct fix, I would prefer a fix that at least indicated the line and/or key that is causing the validation to fail. I have tried to submit the CLA, but I don't know what to fill in for the field: "Please add the Canonical Project Manager or contact". It won't let me submit it without that value. What should I put in there? |
As a "new to Canonical" contributor, I am happy to accept nitpicks. I can update that commit message in my next rebase. |
If you do want this to be changed to a validation error, I can work on that. It will just take a little longer as I need to dig a little deeper into the guts of Subiquity. |
433689d
to
d88332e
Compare
Indeed, the error messaging isn't great yet and very non-obvious for some cases, such as this one. The validator needs some work and thank you for spending the time to track this down and make it better! I would suggest something like this: diff --git a/subiquity/server/controllers/cmdlist.py b/subiquity/server/controllers/cmdlist.py
index 2729da5c..4f77e7df 100644
--- a/subiquity/server/controllers/cmdlist.py
+++ b/subiquity/server/controllers/cmdlist.py
@@ -55,6 +55,7 @@ class CmdListController(NonInteractiveController):
"type": ["string", "array"],
"items": {"type": "string"},
},
+ "not": {},
}
builtin_cmds: Sequence[Command] = ()
cmds: Sequence[Command] = () which will at least result in providing the offending section. Using your CI autoinstall as an example:
or
There is perhaps a more elegant way to say "not empty" but this was my first approach.
I actually don't know to be honest. I suppose since you're contributing to subiquity you could put "subiquity" down, but I'm not sure this field matters for individual contributors. |
d88332e
to
0ec2a8e
Compare
I'll also add in the user experience that lead me to this issue. While attempting to automate my install process, I had a small autoinstall file with a single entry in late-commands. Something like this:
The exact command was different. I then made quite a number of changes including commenting out that command with a pound sign, but I did not comment out the key in front of it. After that, I found my installer was crashing and my initial suspicions were related to other changes I had made. It took me some time to realize that the crash was due to this file:
|
Thank you for sharing! This is exactly the kind of scenarios I want to avoid.
Yeah autoinstall errors can be elusive. We've done some work to make the runtime errors more obvious but the easiest ones to catch are ones like this where we can screen for them at validation time. |
Currently, an Autoinstall YAML with an empty command-list will cause the installer to crash or validate-autoinstall-user-data.py to exit without a clear error message indicating where the issue is or what the correct resolution might be.
This avoids a crash in both the installer and the validation script when a command list such as early-commands is provided in the Autoinstall YAML, but no entries are included. This causes the value of that key to be None instead of an empty list and triggers an exception in load_autoinstall_data(). Ignoring that value causes it to behave as if that command list was not provided at all.
0ec2a8e
to
dd305e0
Compare
For future note, I think that contact comes from this list: https://canonical.com/projects/directory. I have sent Matthieu an email. |
If you don't want to merge this until it's changed to a validation error, feel free to change it to a Draft PR. |
Sure, let's do that then. I think something along the lines I suggested would be the right direction. A change to the jsonschema along with some unittests to verify the behavior would be good. You can use the exact change I suggested, or something different if you prefer. Some tips: validation happens via a call to a controller's |
This fixes an issue with an Autoinstall user-data YAML such as the following:
This is being tracked in the following bug:
https://bugs.launchpad.net/subiquity/+bug/2078658
A test case was also added that demostrates the crash and verifies the fix.