-
Notifications
You must be signed in to change notification settings - Fork 908
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
TheRealFalcon
merged 4 commits into
canonical:main
from
TheRealFalcon:cloud-config-archive
Jan 15, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/integration_tests/modules/test_cloud_config_archive.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
from tests.integration_tests.instances import IntegrationInstance | ||
from tests.integration_tests.util import verify_clean_boot, verify_clean_log | ||
|
||
USER_DATA = """\ | ||
#cloud-config-archive | ||
- type: "text/cloud-boothook" | ||
content: | | ||
#!/bin/sh | ||
echo "this is from a boothook." > /var/tmp/boothook.txt | ||
- type: "text/cloud-config" | ||
content: | | ||
bootcmd: | ||
- echo "this is from a cloud-config." > /var/tmp/bootcmd.txt | ||
""" | ||
|
||
|
||
@pytest.mark.ci | ||
@pytest.mark.user_data(USER_DATA) | ||
def test_cloud_config_archive(client: IntegrationInstance): | ||
"""Basic correctness test for #cloud-config-archive.""" | ||
log = client.read_from_file("/var/log/cloud-init.log") | ||
assert "this is from a boothook." in client.read_from_file( | ||
"/var/tmp/boothook.txt" | ||
) | ||
assert "this is from a cloud-config." in client.read_from_file( | ||
"/var/tmp/bootcmd.txt" | ||
) | ||
verify_clean_log(log) | ||
verify_clean_boot(client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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 inINCLUSION_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
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.
As an alternative, you could also do
.split(maxsplit=1)[0]
to just get the first wordThere 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.
@kageurufu , thanks for the suggestion, but the goal of the slice was to avoid parsing processing the entire blob.
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.
@kageurufu's suggestion would accomplish that: split on the first whitespace and return only the first value
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.
@holmanb I was more thinking about non-text binary data like some big gzipped blob.