summaryrefslogtreecommitdiff
path: root/tests/unittests/config/test_cc_package_update_upgrade_install.py
blob: e8fce98fcd60081b144b9ba217a15644f5dae4a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pytest

from cloudinit.config.schema import (
    SchemaValidationError,
    get_schema,
    validate_cloudconfig_schema,
)
from tests.unittests.helpers import skipUnlessJsonSchema


class TestPackageUpdateUpgradeSchema:
    @pytest.mark.parametrize(
        "config, error_msg",
        [
            # packages list with single entry (2 required)
            ({"packages": ["p1", ["p2"]]}, ""),
            # packages list with three entries (2 required)
            ({"packages": ["p1", ["p2", "p3", "p4"]]}, ""),
            # empty packages list
            ({"packages": []}, "is too short"),
            (
                {"apt_update": False},
                (
                    "deprecations: apt_update: DEPRECATED."
                    " Dropped after April 2027. Use ``package_update``."
                    " Default: ``false``"
                ),
            ),
            (
                {"apt_upgrade": False},
                (
                    "deprecations: apt_upgrade: DEPRECATED."
                    " Dropped after April 2027. Use ``package_upgrade``."
                    " Default: ``false``"
                ),
            ),
            (
                {"apt_reboot_if_required": False},
                (
                    "deprecations: apt_reboot_if_required: DEPRECATED."
                    " Dropped after April 2027."
                    " Use ``package_reboot_if_required``. Default: ``false``"
                ),
            ),
        ],
    )
    @skipUnlessJsonSchema()
    def test_schema_validation(self, config, error_msg):
        with pytest.raises(SchemaValidationError, match=error_msg):
            validate_cloudconfig_schema(config, get_schema(), strict=True)