-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Ensure pre-24.2 custom modules work (#6034)
- Loading branch information
1 parent
c2778f0
commit ffd49b3
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
tests/integration_tests/assets/dropins/cc_custom_module_24_1.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,42 @@ | ||
# This file is part of cloud-init. See LICENSE file for license information. | ||
"""This was the canonical example module from 24.1 | ||
Ensure cloud-init still supports it.""" | ||
|
||
import logging | ||
|
||
from cloudinit.cloud import Cloud | ||
from cloudinit.config import Config | ||
from cloudinit.config.schema import MetaSchema, get_meta_doc | ||
from cloudinit.distros import ALL_DISTROS | ||
from cloudinit.settings import PER_INSTANCE | ||
|
||
MODULE_DESCRIPTION = """\ | ||
Description that will be used in module documentation. | ||
This will likely take multiple lines. | ||
""" | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
meta: MetaSchema = { | ||
"id": "cc_example", | ||
"name": "Example Module", | ||
"title": "Shows how to create a module", | ||
"description": MODULE_DESCRIPTION, | ||
"distros": [ALL_DISTROS], | ||
"frequency": PER_INSTANCE, | ||
"activate_by_schema_keys": ["example_key, example_other_key"], | ||
"examples": [ | ||
"example_key: example_value", | ||
"example_other_key: ['value', 2]", | ||
], | ||
} # type: ignore | ||
|
||
__doc__ = get_meta_doc(meta) | ||
|
||
|
||
def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: | ||
LOG.debug(f"Hi from module {name}") # noqa: G004 | ||
# Add one more line for easier testing | ||
print("Hello from module") |
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,28 @@ | ||
# This file is part of cloud-init. See LICENSE file for license information. | ||
|
||
import pytest | ||
|
||
from tests.integration_tests import releases | ||
from tests.integration_tests.instances import IntegrationInstance | ||
from tests.integration_tests.releases import IS_UBUNTU | ||
from tests.integration_tests.util import ASSETS_DIR | ||
|
||
|
||
@pytest.mark.skipif( | ||
not IS_UBUNTU, reason="module dir tested is ubuntu-specific" | ||
) | ||
def test_custom_module_24_1(client: IntegrationInstance): | ||
"""Ensure that modifications to cloud-init don't break old custom modules. | ||
24.1 had documentation that differs from current best practices. We want | ||
to ensure modules created from this documentation still work: | ||
https://docs.cloud-init.io/en/24.1/development/module_creation.html | ||
""" | ||
client.push_file( | ||
ASSETS_DIR / "dropins/cc_custom_module_24_1.py", | ||
"/usr/lib/python3/dist-packages/cloudinit/config/cc_custom_module_24_1.py", | ||
) | ||
output = client.execute("cloud-init single --name cc_custom_module_24_1") | ||
if releases.CURRENT_RELEASE >= releases.PLUCKY: | ||
assert "The 'get_meta_doc()' function is deprecated" in output | ||
assert "Hello from module" in output |