Skip to content

Commit

Permalink
test: Ensure pre-24.2 custom modules work (#6034)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealFalcon authored Feb 19, 2025
1 parent c2778f0 commit ffd49b3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/integration_tests/assets/dropins/cc_custom_module_24_1.py
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")
28 changes: 28 additions & 0 deletions tests/integration_tests/dropins/test_custom_modules.py
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

0 comments on commit ffd49b3

Please sign in to comment.