summaryrefslogtreecommitdiff
path: root/tests/unittests/config/test_cc_package_update_upgrade_install.py
blob: 07c5b93224c8fa4ab3a004abef67de2cf10a64a6 (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
51
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},
                (
                    "Cloud config schema deprecations: apt_update: "
                    "Default: ``false``. Deprecated in version 22.2. "
                    "Use ``package_update`` instead."
                ),
            ),
            (
                {"apt_upgrade": False},
                (
                    "Cloud config schema deprecations: apt_upgrade: "
                    "Default: ``false``. Deprecated in version 22.2. "
                    "Use ``package_upgrade`` instead."
                ),
            ),
            (
                {"apt_reboot_if_required": False},
                (
                    "Cloud config schema deprecations: "
                    "apt_reboot_if_required: Default: ``false``. "
                    "Deprecated in version 22.2. Use "
                    "``package_reboot_if_required`` instead."
                ),
            ),
        ],
    )
    @skipUnlessJsonSchema()
    def test_schema_validation(self, config, error_msg):
        with pytest.raises(SchemaValidationError, match=error_msg):
            validate_cloudconfig_schema(config, get_schema(), strict=True)