Exemple #1
0
def migrate(settings: dict) -> dict:
    """
    Migration of the settings ``settings`` to the V3.0.0 settings

    :param settings: The settings dict to migrate
    :return: The migrated dict
    """
    # rename keys and update their value
    old_setting = helper.Setting("default_kickstart",
                                 "/var/lib/cobbler/kickstarts/default.ks")
    new_setting = helper.Setting(
        "default_autoinstall",
        "/var/lib/cobbler/autoinstall_templates/default.ks")
    helper.key_rename(old_setting, "default_autoinstall", settings)
    helper.key_set_value(new_setting, settings)

    old_setting = helper.Setting("snippetsdir", "/var/lib/cobbler/snippets")
    new_setting = helper.Setting("autoinstall_snippets_dir",
                                 "/var/lib/cobbler/snippets")
    helper.key_rename(old_setting, "autoinstall_snippets_dir", settings)
    helper.key_set_value(new_setting, settings)

    # add missing keys
    # name - value pairs
    missing_keys = {
        'autoinstall_templates_dir': "/var/lib/cobbler/templates",
        'boot_loader_conf_template_dir': "/etc/cobbler/boot_loader_conf",
        'default_name_servers_search': [],
        'include': ["/etc/cobbler/settings.d/*.settings"],
        'nopxe_with_triggers': 1,
        'scm_push_script': "/bin/true",
        'scm_track_author': "cobbler <cobbler@localhost>",
        'tftpboot_location': "/srv/tftpboot",
        'webdir_whitelist': []
    }
    for (key, value) in missing_keys.items():
        new_setting = helper.Setting(key, value)
        helper.key_add(new_setting, settings)

    # delete removed keys
    deleted_keys = [
        "consoles", "func_auto_setup", "func_master", "kernel_options_s390x",
        "pxe_template_dir", "redhat_management_type",
        "template_remote_kickstarts"
    ]
    for key in deleted_keys:
        helper.key_delete(key, settings)

    # TODO: v2 to v3 script
    if not validate(settings):
        raise SchemaError("V3.0.0: Schema error while validating")
    return normalize(settings)
Exemple #2
0
def migrate(settings: dict) -> dict:
    """
    Migration of the settings ``settings`` to version V3.3.1 settings

    :param settings: The settings dict to migrate
    :return: The migrated dict
    """

    # rename keys and update their value
    # add missing keys
    # name - value pairs
    missing_keys = {
        'auto_migrate_settings': True,
        'ldap_tls_cacertdir': "",
        'ldap_tls_reqcert': "hard",
        'ldap_tls_cipher_suite': "",
        'bootloaders_shim_folder': "@@shim_folder@@",
        'bootloaders_shim_file': "@@shim_file@@",
        'bootloaders_ipxe_folder': "@@ipxe_folder@@",
        'syslinux_memdisk_folder': "@@memdisk_folder@@",
        'syslinux_pxelinux_folder': "@@pxelinux_folder@@",
    }
    for (key, value) in missing_keys.items():
        new_setting = helper.Setting(key, value)
        helper.key_add(new_setting, settings)

    # delete removed keys

    if not validate(settings):
        raise SchemaError("V3.3.1: Schema error while validating")
    return normalize(settings)
Exemple #3
0
def test_key_get(example_dict):
    # Arrange
    expected_result = helper.Setting("b.u", 1)
    # Act
    result = helper.key_get("b.u", example_dict)

    # Assert
    assert expected_result == result
Exemple #4
0
def test_key_set_value(example_dict):
    # Arrange
    new = helper.Setting("b.u", 5)

    # Act
    helper.key_set_value(new, example_dict)

    # Assert
    assert example_dict["b"]["u"] == 5
Exemple #5
0
def test_key_add(example_dict):
    # Arrange
    new = helper.Setting("c.a", 5)

    # Act
    helper.key_add(new, example_dict)

    # Assert
    assert example_dict["c"]["a"] == 5
Exemple #6
0
def test_key_rename(example_dict):
    # Arrange
    rename = helper.Setting("b.u", 1)
    # Act
    helper.key_rename(rename, "a", example_dict)

    # Assert
    print(example_dict)
    assert example_dict["b"].get("u") is None
    assert example_dict["b"]["a"] == 1
Exemple #7
0
def test_key_move(example_dict):
    # Arrange
    move = helper.Setting("b.u", 1)

    # Act
    helper.key_move(move, ["a", "a"], example_dict)

    # Assert
    assert example_dict["b"].get("u") is None
    assert example_dict["a"]["a"] == 1
Exemple #8
0
def migrate(settings: dict) -> dict:
    """
    Migration of the settings ``settings`` to the V3.2.0 settings

    :param settings: The settings dict to migrate
    :return: The migrated dict
    """
    # add missing keys
    # name - value pairs
    missing_keys = {
        'cache_enabled': 1,
        'reposync_rsync_flags': "-rltDv --copy-unsafe-links"
    }
    for (key, value) in missing_keys.items():
        new_setting = helper.Setting(key, value)
        helper.key_add(new_setting, settings)

    if not validate(settings):
        raise SchemaError("V3.2.0: Schema error while validating")
    return normalize(settings)
Exemple #9
0
def migrate(settings: dict) -> dict:
    """
    Migration of the settings ``settings`` to version V3.3.0 settings

    :param settings: The settings dict to migrate
    :return: The migrated dict
    """

    # migrate gpxe -> ipxe
    if "enable_gpxe" in settings:
        gpxe = helper.key_get("enable_gpxe", settings)
        helper.key_rename(gpxe, "enable_ipxe", settings)

    # rename keys and update their value
    old_setting = helper.Setting(
        "default_autoinstall",
        "/var/lib/cobbler/autoinstall_templates/default.ks")
    new_setting = helper.Setting("autoinstall", "default.ks")
    helper.key_rename(old_setting, "autoinstall", settings)
    helper.key_set_value(new_setting, settings)

    old_setting = helper.Setting("next_server", "127.0.0.1")
    new_setting = helper.Setting("next_server_v4", "127.0.0.1")
    helper.key_rename(old_setting, "next_server_v4", settings)
    helper.key_set_value(new_setting, settings)

    # add missing keys
    # name - value pairs
    missing_keys = {
        'auto_migrate_settings':
        True,
        'bind_zonefile_path':
        "@@bind_zonefiles@@",
        'bootloaders_formats': {
            "aarch64": {
                "binary_name": "grubaa64.efi"
            },
            "arm": {
                "binary_name": "bootarm.efi"
            },
            "arm64-efi": {
                "binary_name": "grubaa64.efi",
                "extra_modules": ["efinet"]
            },
            "i386": {
                "binary_name": "bootia32.efi"
            },
            "i386-pc-pxe": {
                "binary_name": "grub.0",
                "mod_dir": "i386-pc",
                "extra_modules": ["chain", "pxe", "biosdisk"]
            },
            "i686": {
                "binary_name": "bootia32.efi"
            },
            "IA64": {
                "binary_name": "bootia64.efi"
            },
            "powerpc-ieee1275": {
                "binary_name": "grub.ppc64le",
                "extra_modules": ["net", "ofnet"],
            },
            "x86_64-efi": {
                "binary_name": "grubx86.efi",
                "extra_modules": ["chain", "efinet"]
            }
        },
        'bootloaders_modules': [
            "btrfs", "ext2", "xfs", "jfs", "reiserfs", "all_video", "boot",
            "cat", "configfile", "echo", "fat", "font", "gfxmenu", "gfxterm",
            "gzio", "halt", "iso9660", "jpeg", "linux", "loadenv", "minicmd",
            "normal", "part_apple", "part_gpt", "part_msdos",
            "password_pbkdf2", "png", "reboot", "search", "search_fs_file",
            "search_fs_uuid", "search_label", "sleep", "test", "true", "video",
            "mdraid09", "mdraid1x", "lvm", "serial", "regexp", "tr", "tftp",
            "http", "luks", "gcry_rijndael", "gcry_sha1", "gcry_sha256"
        ],
        'grub2_mod_dir':
        "/usr/share/grub2",
        'manage_dhcp_v4':
        False,
        'manage_dhcp_v6':
        False,
        'next_server_v6':
        "::1",
        'syslinux_dir':
        "/usr/share/syslinux"
    }
    for (key, value) in missing_keys.items():
        new_setting = helper.Setting(key, value)
        helper.key_add(new_setting, settings)

    # delete removed keys
    helper.key_delete("cache_enabled", settings)

    if not validate(settings):
        raise SchemaError("V3.3.0: Schema error while validating")
    return normalize(settings)