def test_merge_with_empty(self):
        self.assertEqual(self.dict2, dict_util.merge_dicts({}, self.dict2,
                                                           True))
        self.assertEqual(self.dict2, dict_util.merge_dicts({}, self.dict2))

        self.assertEqual(self.dict2,
                         dict_util.merge_dicts(self.dict2, {}, True))
        self.assertEqual(self.dict2, dict_util.merge_dicts(self.dict2, {}))
def apply_service_defaults(subliminal, superliminal):
    """ Apply defaults services
        :param subliminal: subliminal config
        :param superliminal: superliminal config
        :returns: enriched services with superliminal.service_defaults & subliminal.service_defaults
    """
    keyword = "service_defaults"
    superliminal_service_defaults = superliminal.get(keyword, {})
    subliminal_service_defaults = subliminal.get(keyword, {})

    merged_service_defaults = merge_dicts(subliminal_service_defaults,
                                          superliminal_service_defaults,
                                          recursive=True)

    return [merge_dicts(service, merged_service_defaults, True) for service in
            subliminal.get(__SERVICES, {})]
def __enrich_tasks(sub_tasks, super_before_tasks, super_after_tasks, task_defaults):
    merged_tasks = super_before_tasks + sub_tasks + super_after_tasks

    return [
        merge_dicts(task, task_defaults.get(task.get('type', ''), {}), recursive=True)
        for task in merged_tasks
    ]
 def test_recursive_merge_dicts(self):
     expected = {
         "env": "env1",
         "env4": "env4",
         "env_dict": {
             "env2": "env2",
             "env3": "env3"
         }
     }
     self.assertEqual(expected,
                      dict_util.merge_dicts(self.dict1, self.dict2, True))
    def test_merge_dicts(self):
        expected = {
            "env": "env1",
            "env4": "env4",
            "env_dict": {
                "env2": "env2"
            }
        }

        self.assertEqual(expected,
                         dict_util.merge_dicts(self.dict1, self.dict2))
def apply_pipeline_defaults(subliminal, superliminal, pipeline):
    """Apply defaults values on given pipeline
    :param subliminal: subliminal config
    :param superliminal: superliminal config
    :param  pipeline: to apply defaults on

    :returns: enriched pipeline with superliminal.pipeline_defaults & subliminal.pipeline_defaults
    """
    keyword = "pipeline_defaults"
    superliminal_pipe_defaults = superliminal.get(keyword, {}).copy()
    subliminal_pipe_defaults = subliminal.get(keyword, {}).copy()
    superliminal_before_tasks = superliminal_pipe_defaults.pop(__BEFORE_TASKS, [])
    superliminal_after_tasks = superliminal_pipe_defaults.pop(__AFTER_TASKS, [])
    merged_pipeline_defaults = merge_dicts(subliminal_pipe_defaults, superliminal_pipe_defaults,
                                           True)
    pipeline = merge_dicts(pipeline, merged_pipeline_defaults, True)

    return apply_task_defaults(subliminal, superliminal, pipeline,
                               superliminal_before_tasks=superliminal_before_tasks,
                               superliminal_after_tasks=superliminal_after_tasks)
def __apply_task_defaults(subliminal,
                          superliminal,
                          subliminal_tasks,
                          superliminal_before_tasks,
                          superliminal_after_tasks):
    keyword = "task_defaults"
    subliminal_tasks_defaults = subliminal.get(keyword, {})
    superliminal_tasks_defaults = superliminal.get(keyword, {})
    merged_task_defaults = merge_dicts(subliminal_tasks_defaults, superliminal_tasks_defaults,
                                       recursive=True)

    return __enrich_tasks(subliminal_tasks, superliminal_before_tasks, superliminal_after_tasks,
                          merged_task_defaults)
Пример #8
0
    def __deep_list_keyword_merge(unique_key_name, subliminal_list_conf,
                                  superliminal_list_conf):
        subliminal_key_map = {
            item[unique_key_name]: item
            for item in subliminal_list_conf
        }
        superliminal_key_map = {
            item[unique_key_name]: item
            for item in superliminal_list_conf
        }

        return list(
            dict_util.merge_dicts(superliminal_key_map,
                                  subliminal_key_map,
                                  recursive=True).values())
Пример #9
0
    def __merge_superliminals(self, super1, super2):
        super1_pipeline_defaults = super1.get(self.__PIPELINE_DEFAULTS,
                                              {}).copy()
        super2_pipeline_defaults = super2.get(self.__PIPELINE_DEFAULTS,
                                              {}).copy()

        super1[self.__PIPELINE_DEFAULTS][self.__BEFORE_TASKS] = \
            super2_pipeline_defaults.pop(self.__BEFORE_TASKS, []) + super1_pipeline_defaults.pop(
                self.__BEFORE_TASKS, [])

        super1[self.__PIPELINE_DEFAULTS][self.__AFTER_TASKS] = \
            super1_pipeline_defaults.pop(self.__AFTER_TASKS, []) + super2_pipeline_defaults.pop(
                self.__AFTER_TASKS, [])

        # merge supers tasks
        return dict_util.merge_dicts(super1, super2, True)
Пример #10
0
    def __merge_sub_and_super(self, sub, supr, is_render_variables):
        merged_pipelines = list()

        for pipeline in sub.get(self.__PIPELINES, {}):
            final_pipeline = self.__apply_pipeline_defaults(
                sub, supr, pipeline)
            merged_pipelines.append(final_pipeline)

        sub[self.__PIPELINES] = merged_pipelines
        sub[self.__SERVICES] = default_configs.apply_service_defaults(
            sub, supr)

        sub = dict_util.merge_dicts(supr.copy(), sub)

        return default_configs.apply_variable_substitution(
            sub, supr, is_render_variables)
Пример #11
0
def apply_variable_substitution(subliminal, superliminal, is_render_variables=False):
    """
     if is_render_variables is True
        Replace all {{variable.key}} in subliminal with variable.value variable in
        subliminal.variables + superliminal.variables
     else
        merge subliminal.variables with superliminal.variables without replace
        placeholders
     """
    keyword = "variables"
    merged_variables = dict_util.merge_dicts(subliminal.get(keyword, {}),
                                             superliminal.get(keyword, {}), True)
    if is_render_variables:
        for k, v in merged_variables.items():
            if isinstance(v, str) or (not isinstance(v, dict) and not isinstance(v, list)):
                merged_variables[k] = dict_util.replace_placholders_in_string(str(v),
                                                                              merged_variables)

        merged_variables = dict_util.replace_placeholders(merged_variables, merged_variables)
        return dict_util.replace_placeholders(subliminal, merged_variables)
    else:
        subliminal[keyword] = merged_variables
        return subliminal