-
Notifications
You must be signed in to change notification settings - Fork 911
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
testing: Add NoCloud setup for NoCloud test (SC-983) #1425
Conversation
37a3a3d
to
b235a3a
Compare
I'll fix the mypy issue, but should otherwise be reviewable |
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.
Thanks for this cleanup.
str(userdata_file), | ||
str(metadata_file), | ||
f"{instance.name}/var/lib/cloud/seed/nocloud-net/", | ||
"--create-dirs", |
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.
TIL about --create-dirs. Thanks.
def setup_nocloud(instance: LXDInstance): | ||
# On Jammy and above, LXD no longer uses NoCloud, so we need to set | ||
# it up manually | ||
if ImageSpecification.from_os_image().release in [ |
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 we probably can avoid coupling this implementation to specific series. Given that the underlying cause of the symptom is that LXD on jammy and later will no longer ship metadata templates for nocloud-net files, we can check that metadata and honor any image that doesn't contain these templates.
Here's an alternative suggestion which works on focal and jammy lxd_containers. I don't know if you find lxd config cmdline manipulation more busy than tempfile creation and lxc file push .
diff --git a/tests/integration_tests/datasources/test_nocloud.py b/tests/integration_tests/datasources/test_nocloud.py
index b496d5887..d9410410b 100644
--- a/tests/integration_tests/datasources/test_nocloud.py
+++ b/tests/integration_tests/datasources/test_nocloud.py
@@ -1,12 +1,8 @@
"""NoCloud datasource integration tests."""
-import tempfile
-from pathlib import Path
-
import pytest
from pycloudlib.lxd.instance import LXDInstance
from cloudinit.subp import subp
-from tests.integration_tests.clouds import ImageSpecification
from tests.integration_tests.instances import IntegrationInstance
VENDOR_DATA = """\
@@ -16,32 +12,49 @@ runcmd:
"""
+LXD_METADATA_NOCLOUD_SEED = """\
+ /var/lib/cloud/seed/nocloud-net/meta-data:
+ when:
+ - create
+ - copy
+ create_only: false
+ template: emptycfg.tpl
+ properties:
+ default: |
+ #cloud-config
+ {}
+ /var/lib/cloud/seed/nocloud-net/user-data:
+ when:
+ - create
+ - copy
+ create_only: false
+ template: emptycfg.tpl
+ properties:
+ default: |
+ #cloud-config
+ {}
+"""
+
+
def setup_nocloud(instance: LXDInstance):
# On Jammy and above, LXD no longer uses NoCloud, so we need to set
# it up manually
- if ImageSpecification.from_os_image().release in [
- "bionic",
- "focal",
- "impish",
- ]:
+ lxd_image_metadata = subp(
+ ["lxc", "config", "metadata", "show", instance.name]
+ )
+ if "/var/lib/cloud/seed/nocloud-net" in lxd_image_metadata.stdout:
return
- with tempfile.TemporaryDirectory() as tmpdir_str:
- tmpdir = Path(tmpdir_str)
- userdata_file = tmpdir / "user-data"
- metadata_file = tmpdir / "meta-data"
- userdata_file.touch()
- metadata_file.touch()
- subp(
- [
- "lxc",
- "file",
- "push",
- str(userdata_file),
- str(metadata_file),
- f"{instance.name}/var/lib/cloud/seed/nocloud-net/",
- "--create-dirs",
- ]
- )
+ subp(
+ ["lxc", "config", "template", "create", instance.name, "emptycfg.tpl"],
+ )
+ subp(
+ ["lxc", "config", "template", "edit", instance.name, "emptycfg.tpl"],
+ data="#cloud-config\n{}\n",
+ )
+ subp(
+ ["lxc", "config", "metadata", "edit", instance.name],
+ data=f"{lxd_image_metadata.stdout}{LXD_METADATA_NOCLOUD_SEED}",
+ )
# Only running on LXD container because we need NoCloud with custom setup
@@ -57,7 +70,6 @@ def test_nocloud_seedfrom_vendordata(client: IntegrationInstance):
seed_dir = "/var/tmp/test_seed_dir"
result = client.execute(
"mkdir {seed_dir} && "
- "mkdir -p /var/lib/cloud/seed/nocloud-net && "
"touch {seed_dir}/user-data && "
"touch {seed_dir}/meta-data && "
"echo 'seedfrom: {seed_dir}/' > "
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.
Thanks, I like your solution better. Pushed.
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.
Well I have to agree with this PR now. Thanks @TheRealFalcon
tests.integration_tests.bugs.test_gh570.test_nocloud_seedfrom_vendordata is currently failing on Jammy because Jammy no longer uses NoCloud and instead uses the LXD DataSource. This commit adds a NoCloud setup to the failing test so we can force the NoCloud datasource. Also, moved the test into a NoCloud specific file, so any other tests that need to be NoCloud specific can use the setup.
Proposed Commit Message
Additional Context
Review commits in order to see the actual changes
Failing test:
https://jenkins.canonical.com/server-team/view/cloud-init/job/cloud-init-integration-jammy-lxd_container/20/testReport/tests.integration_tests.bugs/test_gh570/test_nocloud_seedfrom_vendordata/