update to support consistently retrieving the last set configuration

This commit is contained in:
Blake J. Harnden 2018-06-08 13:53:16 -07:00
parent 52bfd1edf4
commit 044e7de5e3
2 changed files with 29 additions and 2 deletions

View file

@ -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())

View file

@ -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]