Exemple #1
0
    def test_should_not_concat_lists_by_default(self):
        """Should replace a list value by the new value."""
        dict_a = {1: "1a", 2: {3: ["a", "b"]}}
        dict_b = {1: "1b", 2: {3: ["c", "d"]}}

        result = dict_utils.deep_merge(dict_a, dict_b)

        self.assertEqual(dict_a, {1: "1a", 2: {3: ["a", "b"]}})
        self.assertEqual(dict_b, {1: "1b", 2: {3: ["c", "d"]}})
        self.assertEqual(result, {1: "1b", 2: {3: ["c", "d"]}})
Exemple #2
0
def get_deployments(project_config: dict) -> list:
    """Get the deployments configurations from the project configuration."""
    deployments = []
    for deployment in project_config["deployments"]:
        config = dict_utils.deep_merge(project_config, deployment)
        del config["deployments"]
        config = _resolve_variables_deep(config)
        deployments.append(config)

    return deployments
Exemple #3
0
    def test_should_concat_lists_if_specified(self):
        """Should concat the new list at the end of the original one."""
        dict_a = {1: "1a", 2: {3: ["a", "b"]}}
        dict_b = {1: "1b", 2: {3: ["c", "d"]}}

        result = dict_utils.deep_merge(dict_a, dict_b, concat_lists=True)

        self.assertEqual(dict_a, {1: "1a", 2: {3: ["a", "b"]}})
        self.assertEqual(dict_b, {1: "1b", 2: {3: ["c", "d"]}})
        self.assertEqual(result, {1: "1b", 2: {3: ["a", "b", "c", "d"]}})
def set_anti_affinity(deployment_config: dict, process_name: str,
                      resource: dict, templates: dict) -> None:
    """Attach the expected anti_affinity to the resource."""
    anti_affinity_node = get_anti_affinity_node(deployment_config,
                                                process_name, templates) or {}
    anti_affinity_zone = get_anti_affinity_zone(deployment_config,
                                                process_name, templates) or {}
    anti_affinity = dict_utils.deep_merge(anti_affinity_node,
                                          anti_affinity_zone,
                                          concat_lists=True)
    if len(anti_affinity) > 0:
        resource["spec"]["template"]["spec"]["affinity"] = anti_affinity
Exemple #5
0
def test_deep_merge_should_correctly_merge_nested_dicts():
    dict_a = {1: "1a", 2: {3: "3a", 4: "4a"}, 7: {8: "8a"}}
    dict_b = {2: {3: "3b", 5: "5b"}, 6: "6b", 9: {10: "10b"}}

    result = dict_utils.deep_merge(dict_a, dict_b)

    assert dict_a == {1: "1a", 2: {3: "3a", 4: "4a"}, 7: {8: "8a"}}
    assert dict_b == {2: {3: "3b", 5: "5b"}, 6: "6b", 9: {10: "10b"}}
    assert result == {
        1: "1a",
        2: {3: "3b", 4: "4a", 5: "5b"},
        6: "6b",
        7: {8: "8a"},
        9: {10: "10b"},
    }
Exemple #6
0
    def test_deep_merge_should_correctly_merge_nested_dicts(self):
        """Should correctly deep merge 2 dictionaries."""
        dict_a = {1: "1a", 2: {3: "3a", 4: "4a"}, 7: {8: "8a"}}
        dict_b = {2: {3: "3b", 5: "5b"}, 6: "6b", 9: {10: "10b"}}

        result = dict_utils.deep_merge(dict_a, dict_b)

        self.assertEqual(dict_a, {
            1: "1a",
            2: {
                3: "3a",
                4: "4a"
            },
            7: {
                8: "8a"
            }
        })
        self.assertEqual(dict_b, {
            2: {
                3: "3b",
                5: "5b"
            },
            6: "6b",
            9: {
                10: "10b"
            }
        })
        self.assertEqual(
            result, {
                1: "1a",
                2: {
                    3: "3b",
                    4: "4a",
                    5: "5b"
                },
                6: "6b",
                7: {
                    8: "8a"
                },
                9: {
                    10: "10b"
                }
            })
Exemple #7
0
def get_app_config(app_name: str) -> dict:
    """Load the configuration of an app"""
    app_config_path = os.path.join(
        Configuration.get_config_path(),
        Configuration.get_config_app_folder(),
        f"{app_name}.yaml",
    )
    if not io.exists(app_config_path):
        raise AppConfigurationNotFoundError(app_name)

    app_config = io.from_yaml(app_config_path)
    environment_config = get_project_config()

    config = dict_utils.deep_merge(environment_config, app_config)

    # Awaiting for implementation
    # validate configuration using nestor-config-validator

    return _resolve_variables_deep(config)