diff --git a/daemon/core/conf.py b/daemon/core/conf.py index bba983c7..988225e1 100644 --- a/daemon/core/conf.py +++ b/daemon/core/conf.py @@ -154,6 +154,8 @@ class ConfigurableManager(object): def set_configs(self, config, node_id=_default_node, config_type=_default_type): logger.debug("setting config for node(%s) type(%s): %s", node_id, config_type, config) node_configs = self.get_all_configs(node_id) + if config_type in node_configs: + node_configs.pop(config_type) node_configs[config_type] = config def get_config(self, _id, node_id=_default_node, config_type=_default_type): @@ -168,4 +170,4 @@ class ConfigurableManager(object): def get_all_configs(self, node_id=_default_node): logger.debug("getting all configs for node(%s)", node_id) - return self._configuration_maps.setdefault(node_id, {}) + return self._configuration_maps.setdefault(node_id, OrderedDict()) diff --git a/daemon/tests/test_conf.py b/daemon/tests/test_conf.py index 0d56ce3f..2849f6ec 100644 --- a/daemon/tests/test_conf.py +++ b/daemon/tests/test_conf.py @@ -1,4 +1,10 @@ -from core.conf import ConfigurableManager, ConfigurableOptions, Configuration +from random import shuffle + +import pytest + +from core.conf import ConfigurableManager +from core.conf import ConfigurableOptions +from core.conf import Configuration from core.enumerations import ConfigDataTypes @@ -148,3 +154,22 @@ class TestConf: assert len(node_all_configs) == 2 assert config_one in node_all_configs assert config_two in node_all_configs + + @pytest.mark.parametrize("_", xrange(10)) + def test_config_last_key(self, _): + # given + config_manager = ConfigurableManager() + config = {1: 2} + node_id = 1 + config_types = [1, 2, 3] + shuffle(config_types) + config_manager.set_configs(config, node_id=node_id, config_type=config_types[0]) + config_manager.set_configs(config, node_id=node_id, config_type=config_types[1]) + config_manager.set_configs(config, node_id=node_id, config_type=config_types[2]) + + # when + keys = config_manager.get_all_configs(node_id=node_id).keys() + + # then + assert keys + assert keys[-1] == config_types[2]