Skip to content
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: Make _should_wait_via_user_data() handle non-dict data #5976

Merged
merged 4 commits into from
Jan 15, 2025

Conversation

TheRealFalcon
Copy link
Member

@TheRealFalcon TheRealFalcon commented Jan 14, 2025

Proposed Commit Message

fix: Ensure _should_wait_via_user_data() handles all user data types

The function "_should_wait_via_user_data()" wasn't properly
handling user data that has a header that starts with
#cloud-config, but isn't cloud-config, like #cloud-config-archive

Fixes GH-5975

Additional Context

Test Steps

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>)

The function "_should_wait_via_user_data()" needs to be able to handle
non-dict data (i.e., #cloud-config-archive).

Fixes canonicalGH-5975
@@ -348,6 +348,9 @@ def _should_wait_via_user_data(
)
return True, "failed to parse user data as yaml"

if not isinstance(parsed_yaml, dict):
Copy link
Member

@holmanb holmanb Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but I think that this works around an existing bug rather than fixing it.

handlers.type_from_starts_with() only returned "text/cloud-config" because of a bug in the slicing on line 334. I'm guessing that slicing by the length of the longest value in INCLUSION_TYPES_MAP should do it.

As it is, either of the following types will incorrectly return text/cloud-config:

#cloud-config-archive
#cloud-config-jsonp

If I revert your change to main.py and then update the slice from 13 to 42, the test passes.

Aside: this logic feels out of place in main.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, you could also do .split(maxsplit=1)[0] to just get the first word

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kageurufu , thanks for the suggestion, but the goal of the slice was to avoid parsing processing the entire blob.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal of the slice was to avoid parsing processing the entire blob.

@kageurufu's suggestion would accomplish that: split on the first whitespace and return only the first value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holmanb I was more thinking about non-text binary data like some big gzipped blob.

@TheRealFalcon
Copy link
Member Author

@holmanb , I applied your suggestion but also kept my original change as I believe that it is also necessary.

@holmanb
Copy link
Member

holmanb commented Jan 14, 2025

@holmanb , I applied your suggestion but also kept my original change as I believe that it is also necessary.

When would it be necessary? This wouldn't be valid cloud-config, so cloud-init just spits warnings and doesn't configure the system at all - what is there to wait for?

Also, I think that @kageurufu's suggestion with .split() is more robust.

@TheRealFalcon
Copy link
Member Author

spits warnings

Spits tracebacks which we shouldn't allow intentionally.

@holmanb
Copy link
Member

holmanb commented Jan 15, 2025

spits warnings

Spits tracebacks which we shouldn't allow intentionally.

I was referring to the warnings due to it being an invalid configuration, but yes I see now that this would cause a traceback - makes sense to me.

Copy link
Member

@holmanb holmanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind documenting the "big gzipped blob" reasoning in a comment to explain the otherwise arbitrary-seeming magic variable?

Otherwise I'm satisifed with this logic, thanks!

@TheRealFalcon TheRealFalcon merged commit 65e9788 into canonical:main Jan 15, 2025
22 checks passed
@TheRealFalcon TheRealFalcon deleted the cloud-config-archive branch January 15, 2025 15:22
TheRealFalcon added a commit to TheRealFalcon/cloud-init that referenced this pull request Jan 15, 2025
…anonical#5976)

The function "_should_wait_via_user_data()" wasn't properly
handling user data that has a header that starts with
#cloud-config, but isn't cloud-config, like #cloud-config-archive

Fixes canonicalGH-5975
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.

3 participants