-
Notifications
You must be signed in to change notification settings - Fork 909
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
Fix mis-detecting network configuration in initramfs cmdline #844
Conversation
aba220c
to
b31d7a4
Compare
cloudinit/net/cmdline.py
Outdated
@@ -72,7 +73,7 @@ def is_applicable(self) -> bool: | |||
(ii) an open-iscsi interface file is present in the system | |||
""" | |||
if self._files: | |||
if 'ip=' in self._cmdline or 'ip6=' in self._cmdline: | |||
if re.search(r'(^|\s)ip[6]*=', self._cmdline): |
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.
I think [6]*
is slightly incorrect, it would match, e.g., ip666
(the addressing protocol of the beast); 6?
will match 0 or 1 "6"s. (Either way, the square brackets are superfluous: a character and a bracket expression containing only that character are equivalent.) This is borderline nit territory, but as regexes are hard enough to read at the best of times, I think it's worth being exact here.
I think we're also missing tests for the ^
choice of the subexpression here: nothing fails if I edit the regex to only have \s
there instead of the subexpression. Can you add a test for that?
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.
I'm just flying past here, but you should really "parse" the kernel cmdline with shlex.split, because that's essentially what the initramfs is doing. This regex would match something like the admittedly extremely contrived opt="bunch of stuff with spaces and ip=foo"
. Also the fewer regexes in the codebase the better!
@OddBloke Updated based on review comments. I attempted writing an integration test for this behavior, but I was unable to create one. It requires
#1 is doable but hacky. I can't figure out a way to do #2. Can you think of a realistic way to do #2? If not, are you ok having just unit test coverage for this one? |
5943ca2
to
e2c5027
Compare
klibc initramfs in debian allows the 'iscsi_target_ip=' cmdline parameter to specify an iscsi device attachment. This can cause cloud-init to mis-detect the cmdline paramter as a networking config. LP: #1919188
e2c5027
to
2cd6851
Compare
Updated (as a separate commit) to do this using shlex instead. |
Thanks, that makes me much less queasy :-) I think it would make sense to parse the kernel command line into a dict more generally but that's a much bigger change of course. |
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.
This LGTM, thanks! I wonder if we should add a test for quoted content (i.e. cmdline of foo="ip=shouldntbedetected"
); I'll let you decide and land this with or without it.
That looks good, no idea how I missed it first time through! |
Integration test still needs to be written
Proposed Commit Message
Additional Context
https://bugs.launchpad.net/cloud-init/+bug/1919188
Test Steps
Integration test still needs to be written
Checklist: