separate Cache from values and settings
This commit is contained in:
parent
c5ce9be699
commit
1691e38db5
16 changed files with 348 additions and 313 deletions
42
tests/config.py
Normal file
42
tests/config.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# from json import dumps, loads
|
||||||
|
try:
|
||||||
|
from tiramisu_json_api import Config
|
||||||
|
class TestConfig(Config):
|
||||||
|
def __init__(self,
|
||||||
|
config):
|
||||||
|
self.test_option = config.option
|
||||||
|
json = self.test_option.dict()
|
||||||
|
# assert json == loads(dumps(json))
|
||||||
|
super().__init__(json)
|
||||||
|
|
||||||
|
def send_data(self,
|
||||||
|
updates):
|
||||||
|
return self.updates_data(self.test_option.updates(updates))
|
||||||
|
PARAMS = ['tiramisu', 'tiramisu-api']
|
||||||
|
except:
|
||||||
|
PARAMS = ['tiramisu']
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def get_config(config, type, error=False):
|
||||||
|
if type == 'tiramisu':
|
||||||
|
return config
|
||||||
|
if error:
|
||||||
|
config.property.add('demoting_error_warning')
|
||||||
|
return TestConfig(config)
|
||||||
|
|
||||||
|
|
||||||
|
def value_list(values):
|
||||||
|
if values[0] == '':
|
||||||
|
del values[0]
|
||||||
|
return tuple(values)
|
||||||
|
|
||||||
|
|
||||||
|
def global_owner(config, config_type):
|
||||||
|
return config.owner.get()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=PARAMS)
|
||||||
|
def config_type(request):
|
||||||
|
return request.param
|
|
@ -54,16 +54,16 @@ def test_cache_config():
|
||||||
def test_cache():
|
def test_cache():
|
||||||
od1 = make_description()
|
od1 = make_description()
|
||||||
cfg = Config(od1)
|
cfg = Config(od1)
|
||||||
values = cfg._config_bag.context.cfgimpl_get_values()
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
settings = cfg._config_bag.context.cfgimpl_get_settings()
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.option('u2').value.get()
|
cfg.option('u2').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u2' in values._p_.get_cached()
|
assert 'u2' in values.get_cached()
|
||||||
assert 'u2' in settings._p_.get_cached()
|
assert 'u2' in settings.get_cached()
|
||||||
|
|
||||||
|
|
||||||
def test_cache_importation():
|
def test_cache_importation():
|
||||||
|
@ -105,171 +105,173 @@ def test_cache_importation_permissive():
|
||||||
def test_cache_reset():
|
def test_cache_reset():
|
||||||
od1 = make_description()
|
od1 = make_description()
|
||||||
cfg = Config(od1)
|
cfg = Config(od1)
|
||||||
values = cfg._config_bag.context.cfgimpl_get_values()
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
settings = cfg._config_bag.context.cfgimpl_get_settings()
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
#when change a value
|
#when change a value
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
cfg.option('u2').value.get()
|
cfg.option('u2').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u2' in values._p_.get_cached()
|
assert 'u2' in values.get_cached()
|
||||||
assert 'u2' in settings._p_.get_cached()
|
assert 'u2' in settings.get_cached()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
cfg.option('u2').value.set(1)
|
cfg.option('u2').value.set(1)
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u2' not in values._p_.get_cached()
|
assert 'u2' not in values.get_cached()
|
||||||
assert 'u2' not in settings._p_.get_cached()
|
assert 'u2' not in settings.get_cached()
|
||||||
#when remove a value
|
#when remove a value
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.option('u2').value.reset()
|
cfg.option('u2').value.reset()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u2' not in values._p_.get_cached()
|
assert 'u2' not in values.get_cached()
|
||||||
assert 'u2' not in settings._p_.get_cached()
|
assert 'u2' not in settings.get_cached()
|
||||||
#when add/del property
|
#when add/del property
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.option('u2').property.add('test')
|
cfg.option('u2').property.add('test')
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u2' not in values._p_.get_cached()
|
assert 'u2' not in values.get_cached()
|
||||||
assert 'u2' not in settings._p_.get_cached()
|
assert 'u2' not in settings.get_cached()
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.option('u2').property.pop('test')
|
cfg.option('u2').property.pop('test')
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u2' not in values._p_.get_cached()
|
assert 'u2' not in values.get_cached()
|
||||||
assert 'u2' not in settings._p_.get_cached()
|
assert 'u2' not in settings.get_cached()
|
||||||
#when enable/disabled property
|
#when enable/disabled property
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.property.add('test')
|
cfg.property.add('test')
|
||||||
assert 'u1' not in values._p_.get_cached()
|
assert 'u1' not in values.get_cached()
|
||||||
assert 'u1' not in settings._p_.get_cached()
|
assert 'u1' not in settings.get_cached()
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.property.pop('test')
|
cfg.property.pop('test')
|
||||||
assert 'u1' not in values._p_.get_cached()
|
assert 'u1' not in values.get_cached()
|
||||||
assert 'u1' not in settings._p_.get_cached()
|
assert 'u1' not in settings.get_cached()
|
||||||
|
|
||||||
|
|
||||||
def test_cache_reset_multi():
|
def test_cache_reset_multi():
|
||||||
od1 = make_description()
|
od1 = make_description()
|
||||||
cfg = Config(od1)
|
cfg = Config(od1)
|
||||||
values = cfg._config_bag.context.cfgimpl_get_values()
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
settings = cfg._config_bag.context.cfgimpl_get_settings()
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
cfg.option('u3').value.get()
|
cfg.option('u3').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u3' in values._p_.get_cached()
|
assert 'u3' in values.get_cached()
|
||||||
assert 'u3' in settings._p_.get_cached()
|
assert 'u3' in settings.get_cached()
|
||||||
#when change a value
|
#when change a value
|
||||||
cfg.option('u3').value.set([1])
|
cfg.option('u3').value.set([1])
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u3' not in values._p_.get_cached()
|
assert 'u3' not in values.get_cached()
|
||||||
assert 'u3' not in settings._p_.get_cached()
|
assert 'u3' not in settings.get_cached()
|
||||||
#when append value
|
#when append value
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
cfg.option('u3').value.get()
|
cfg.option('u3').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u3' in values._p_.get_cached()
|
assert 'u3' in values.get_cached()
|
||||||
assert 'u3' in settings._p_.get_cached()
|
assert 'u3' in settings.get_cached()
|
||||||
cfg.option('u3').value.set([1, 1])
|
cfg.option('u3').value.set([1, 1])
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u3' not in values._p_.get_cached()
|
assert 'u3' not in values.get_cached()
|
||||||
assert 'u3' not in settings._p_.get_cached()
|
assert 'u3' not in settings.get_cached()
|
||||||
#when pop value
|
#when pop value
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
cfg.option('u3').value.get()
|
cfg.option('u3').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u3' in values._p_.get_cached()
|
assert 'u3' in values.get_cached()
|
||||||
assert 'u3' in settings._p_.get_cached()
|
assert 'u3' in settings.get_cached()
|
||||||
cfg.option('u3').value.set([1])
|
cfg.option('u3').value.set([1])
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u3' not in values._p_.get_cached()
|
assert 'u3' not in values.get_cached()
|
||||||
assert 'u3' not in settings._p_.get_cached()
|
assert 'u3' not in settings.get_cached()
|
||||||
#when remove a value
|
#when remove a value
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.option('u3').value.reset()
|
cfg.option('u3').value.reset()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u3' not in values._p_.get_cached()
|
assert 'u3' not in values.get_cached()
|
||||||
assert 'u3' not in settings._p_.get_cached()
|
assert 'u3' not in settings.get_cached()
|
||||||
|
|
||||||
|
|
||||||
def test_reset_cache():
|
def test_reset_cache():
|
||||||
od1 = make_description()
|
od1 = make_description()
|
||||||
cfg = Config(od1)
|
cfg = Config(od1)
|
||||||
values = cfg._config_bag.context.cfgimpl_get_values()
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
settings = cfg._config_bag.context.cfgimpl_get_settings()
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
cfg.cache.reset()
|
cfg.cache.reset()
|
||||||
assert 'u1' not in values._p_.get_cached()
|
assert 'u1' not in values.get_cached()
|
||||||
assert 'u1' not in settings._p_.get_cached()
|
assert 'u1' not in settings.get_cached()
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
cfg.option('u2').value.get()
|
cfg.option('u2').value.get()
|
||||||
assert 'u1' in values._p_.get_cached()
|
assert 'u1' in values.get_cached()
|
||||||
assert 'u1' in settings._p_.get_cached()
|
assert 'u1' in settings.get_cached()
|
||||||
assert 'u2' in values._p_.get_cached()
|
assert 'u2' in values.get_cached()
|
||||||
assert 'u2' in settings._p_.get_cached()
|
assert 'u2' in settings.get_cached()
|
||||||
cfg.cache.reset()
|
cfg.cache.reset()
|
||||||
assert 'u1' not in values._p_.get_cached()
|
assert 'u1' not in values.get_cached()
|
||||||
assert 'u1' not in settings._p_.get_cached()
|
assert 'u1' not in settings.get_cached()
|
||||||
assert 'u2' not in values._p_.get_cached()
|
assert 'u2' not in values.get_cached()
|
||||||
assert 'u2' not in settings._p_.get_cached()
|
assert 'u2' not in settings.get_cached()
|
||||||
|
|
||||||
|
|
||||||
def test_cache_not_cache():
|
def test_cache_not_cache():
|
||||||
od1 = make_description()
|
od1 = make_description()
|
||||||
cfg = Config(od1)
|
cfg = Config(od1)
|
||||||
values = cfg._config_bag.context.cfgimpl_get_values()
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
settings = cfg._config_bag.context.cfgimpl_get_settings()
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
cfg.property.pop('cache')
|
cfg.property.pop('cache')
|
||||||
cfg.option('u1').value.get()
|
cfg.option('u1').value.get()
|
||||||
assert 'u1' not in values._p_.get_cached()
|
assert 'u1' not in values.get_cached()
|
||||||
assert 'u1' not in settings._p_.get_cached()
|
assert 'u1' not in settings.get_cached()
|
||||||
|
|
||||||
|
|
||||||
def test_cache_leadership():
|
def test_cache_leadership():
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
maconfig = OptionDescription('toto', '', [interface1])
|
od1 = OptionDescription('toto', '', [interface1])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(od1)
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
|
assert values.get_cached() == {}
|
||||||
|
#assert settings.get_cached() == {}
|
||||||
#
|
#
|
||||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||||
cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached()
|
cache = values.get_cached()
|
||||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2']
|
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2']
|
||||||
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
|
||||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||||
cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached()
|
cache = settings.get_cached()
|
||||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||||
|
@ -279,7 +281,7 @@ def test_cache_leadership():
|
||||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
||||||
cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached()
|
cache = values.get_cached()
|
||||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2', '192.168.1.1']
|
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2', '192.168.1.1']
|
||||||
|
@ -287,7 +289,7 @@ def test_cache_leadership():
|
||||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
|
||||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
|
||||||
cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached()
|
cache = settings.get_cached()
|
||||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||||
|
@ -314,83 +316,85 @@ def test_cache_callback():
|
||||||
val3 = StrOption('val3', "", callback=return_value, callback_params=Params((ParamValue('yes'),)))
|
val3 = StrOption('val3', "", callback=return_value, callback_params=Params((ParamValue('yes'),)))
|
||||||
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
||||||
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(kwargs={'value': ParamValue('yes')}), multi=True)
|
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(kwargs={'value': ParamValue('yes')}), multi=True)
|
||||||
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(od1)
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)}}
|
# 'val1': {None: (set([]), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)},
|
compare(values.get_cached(), {'val1': {None: ('val', None)},
|
||||||
'val2': {None: ('val', None)},
|
'val2': {None: ('val', None)},
|
||||||
'val3': {None: ('yes', None)},
|
'val3': {None: ('yes', None)},
|
||||||
'val4': {None: ('val', None)},
|
'val4': {None: ('val', None)},
|
||||||
'val5': {None: (['yes'], None)}})
|
'val5': {None: (['yes'], None)}})
|
||||||
cfg.option('val1').value.set('new')
|
cfg.option('val1').value.set('new')
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)}}
|
# 'val1': {None: (set([]), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)},
|
compare(values.get_cached(), {'val3': {None: ('yes', None)},
|
||||||
'val5': {None: (['yes'], None)}})
|
'val5': {None: (['yes'], None)}})
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)}}
|
# 'val1': {None: (set([]), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
compare(values.get_cached(), {'val1': {None: ('new', None)},
|
||||||
'val2': {None: ('new', None)},
|
'val2': {None: ('new', None)},
|
||||||
'val3': {None: ('yes', None)},
|
'val3': {None: ('yes', None)},
|
||||||
'val4': {None: ('new', None)},
|
'val4': {None: ('new', None)},
|
||||||
'val5': {None: (['yes'], None)}})
|
'val5': {None: (['yes'], None)}})
|
||||||
cfg.option('val3').value.set('new2')
|
cfg.option('val3').value.set('new2')
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)},
|
# 'val1': {None: (set([]), None)},
|
||||||
# 'val3': {None: (set([]), None)}}
|
# 'val3': {None: (set([]), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
compare(values.get_cached(), {'val1': {None: ('new', None)},
|
||||||
'val2': {None: ('new', None)},
|
'val2': {None: ('new', None)},
|
||||||
'val4': {None: ('new', None)},
|
'val4': {None: ('new', None)},
|
||||||
'val5': {None: (['yes'], None)}})
|
'val5': {None: (['yes'], None)}})
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)},
|
# 'val1': {None: (set([]), None)},
|
||||||
# 'val3': {None: (set([]), None)}}
|
# 'val3': {None: (set([]), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
compare(values.get_cached(), {'val1': {None: ('new', None)},
|
||||||
'val2': {None: ('new', None)},
|
'val2': {None: ('new', None)},
|
||||||
'val3': {None: ('new2', None)},
|
'val3': {None: ('new2', None)},
|
||||||
'val4': {None: ('new', None)},
|
'val4': {None: ('new', None)},
|
||||||
'val5': {None: (['yes'], None)}})
|
'val5': {None: (['yes'], None)}})
|
||||||
cfg.option('val4').value.set('new3')
|
cfg.option('val4').value.set('new3')
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)},
|
# 'val1': {None: (set([]), None)},
|
||||||
# 'val3': {None: (set([]), None)},
|
# 'val3': {None: (set([]), None)},
|
||||||
# 'val4': {None: (set([]), None)}}
|
# 'val4': {None: (set([]), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
compare(values.get_cached(), {'val1': {None: ('new', None)},
|
||||||
'val2': {None: ('new', None)},
|
'val2': {None: ('new', None)},
|
||||||
'val3': {None: ('new2', None)},
|
'val3': {None: ('new2', None)},
|
||||||
'val5': {None: (['yes'], None)}})
|
'val5': {None: (['yes'], None)}})
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)},
|
# 'val1': {None: (set([]), None)},
|
||||||
# 'val3': {None: (set([]), None)},
|
# 'val3': {None: (set([]), None)},
|
||||||
# 'val4': {None: (set([]), None)}}
|
# 'val4': {None: (set([]), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
compare(values.get_cached(), {'val1': {None: ('new', None)},
|
||||||
'val2': {None: ('new', None)},
|
'val2': {None: ('new', None)},
|
||||||
'val3': {None: ('new2', None)},
|
'val3': {None: ('new2', None)},
|
||||||
'val4': {None: ('new3', None)},
|
'val4': {None: ('new3', None)},
|
||||||
'val5': {None: (['yes'], None)}})
|
'val5': {None: (['yes'], None)}})
|
||||||
cfg.option('val5').value.set([undefined, 'new4'])
|
cfg.option('val5').value.set([undefined, 'new4'])
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)},
|
# 'val1': {None: (set([]), None)},
|
||||||
# 'val3': {None: (set([]), None)},
|
# 'val3': {None: (set([]), None)},
|
||||||
# 'val4': {None: (set([]), None)},
|
# 'val4': {None: (set([]), None)},
|
||||||
# 'val5': {None: (set(['empty']), None)}}
|
# 'val5': {None: (set(['empty']), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
compare(values.get_cached(), {'val1': {None: ('new', None)},
|
||||||
'val2': {None: ('new', None)},
|
'val2': {None: ('new', None)},
|
||||||
'val3': {None: ('new2', None)},
|
'val3': {None: ('new2', None)},
|
||||||
'val4': {None: ('new3', None)}})
|
'val4': {None: ('new3', None)}})
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#assert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)},
|
# 'val1': {None: (set([]), None)},
|
||||||
# 'val3': {None: (set([]), None)},
|
# 'val3': {None: (set([]), None)},
|
||||||
# 'val4': {None: (set([]), None)},
|
# 'val4': {None: (set([]), None)},
|
||||||
# 'val5': {None: (set(['empty']), None)}}
|
# 'val5': {None: (set(['empty']), None)}}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
compare(values.get_cached(), {'val1': {None: ('new', None)},
|
||||||
'val2': {None: ('new', None)},
|
'val2': {None: ('new', None)},
|
||||||
'val3': {None: ('new2', None)},
|
'val3': {None: ('new2', None)},
|
||||||
'val4': {None: ('new3', None)},
|
'val4': {None: ('new3', None)},
|
||||||
|
@ -401,8 +405,8 @@ def test_cache_leader_and_followers():
|
||||||
val1 = StrOption('val1', "", multi=True)
|
val1 = StrOption('val1', "", multi=True)
|
||||||
val2 = StrOption('val2', "", multi=True)
|
val2 = StrOption('val2', "", multi=True)
|
||||||
interface1 = Leadership('val1', '', [val1, val2])
|
interface1 = Leadership('val1', '', [val1, val2])
|
||||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(od1)
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
|
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
|
||||||
|
@ -415,42 +419,44 @@ def test_cache_leader_and_followers():
|
||||||
val1_val2_props = frozenset(val1_val2_props)
|
val1_val2_props = frozenset(val1_val2_props)
|
||||||
#None because no value
|
#None because no value
|
||||||
idx_val2 = None
|
idx_val2 = None
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
|
compare(settings.get_cached(), {None: {None: (global_props, None)},
|
||||||
'val1': {None: (val1_props, None)},
|
'val1': {None: (val1_props, None)},
|
||||||
'val1.val1': {None: (val1_val1_props, None)},
|
'val1.val1': {None: (val1_val1_props, None)},
|
||||||
'val1.val2': {idx_val2: (val1_val2_props, None)}})
|
'val1.val2': {idx_val2: (val1_val2_props, None)}})
|
||||||
# len is 0 so don't get any value
|
# len is 0 so don't get any value
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
|
compare(values.get_cached(), {'val1.val1': {None: ([], None)}})
|
||||||
#
|
#
|
||||||
cfg.option('val1.val1').value.set([undefined])
|
cfg.option('val1.val1').value.set([undefined])
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
|
compare(settings.get_cached(), {None: {None: (set(global_props), None)}})
|
||||||
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
|
assert values.get_cached() == {}
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
#has value
|
#has value
|
||||||
idx_val2 = 0
|
idx_val2 = 0
|
||||||
val_val2 = None
|
val_val2 = None
|
||||||
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)}
|
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)}
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
|
compare(settings.get_cached(), {None: {None: (global_props, None)},
|
||||||
'val1': {None: (val1_props, None)},
|
'val1': {None: (val1_props, None)},
|
||||||
'val1.val1': {None: (val1_val1_props, None)},
|
'val1.val1': {None: (val1_val1_props, None)},
|
||||||
'val1.val2': val_val2_props})
|
'val1.val2': val_val2_props})
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)},
|
compare(values.get_cached(), {'val1.val1': {None: ([None], None)},
|
||||||
'val1.val2': {idx_val2: (val_val2, None)}})
|
'val1.val2': {idx_val2: (val_val2, None)}})
|
||||||
cfg.option('val1.val1').value.set([undefined, undefined])
|
cfg.option('val1.val1').value.set([undefined, undefined])
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
cfg.option('val1.val2', 1).value.set('oui')
|
cfg.option('val1.val2', 1).value.set('oui')
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
|
||||||
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
|
assert values.get_cached() == {}
|
||||||
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
|
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
|
||||||
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
#assert settings.get_cached() == {None: {None: (global_props, None)},
|
||||||
# 'val1': {None: (val1_props, None)},
|
# 'val1': {None: (val1_props, None)},
|
||||||
# 'val1.val1': {None: (val1_val1_props, None)},
|
# 'val1.val1': {None: (val1_val1_props, None)},
|
||||||
# 'val1.val2': val1_val2_props}
|
# 'val1.val2': val1_val2_props}
|
||||||
#if TIRAMISU_VERSION == 2:
|
#if TIRAMISU_VERSION == 2:
|
||||||
# assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
# assert values.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||||
# 'val1.val2': {None: ([None, 'oui'], None)}}
|
# 'val1.val2': {None: ([None, 'oui'], None)}}
|
||||||
#else:
|
#else:
|
||||||
# assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
# assert values.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||||
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
|
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -458,8 +464,8 @@ def test_cache_leader_callback():
|
||||||
val1 = StrOption('val1', "", multi=True)
|
val1 = StrOption('val1', "", multi=True)
|
||||||
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
||||||
interface1 = Leadership('val1', '', [val1, val2])
|
interface1 = Leadership('val1', '', [val1, val2])
|
||||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(od1)
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
|
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
|
||||||
|
@ -470,19 +476,21 @@ def test_cache_leader_callback():
|
||||||
val1_props = frozenset(val1_props)
|
val1_props = frozenset(val1_props)
|
||||||
val1_val1_props = frozenset(val1_val1_props)
|
val1_val1_props = frozenset(val1_val1_props)
|
||||||
val1_val2_props = frozenset(val1_val2_props)
|
val1_val2_props = frozenset(val1_val2_props)
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
|
compare(settings.get_cached(), {None: {None: (global_props, None)},
|
||||||
'val1': {None: (val1_props, None)},
|
'val1': {None: (val1_props, None)},
|
||||||
'val1.val1': {None: (val1_val1_props, None)},
|
'val1.val1': {None: (val1_val1_props, None)},
|
||||||
'val1.val2': {None: (val1_val2_props, None)}})
|
'val1.val2': {None: (val1_val2_props, None)}})
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
|
compare(values.get_cached(), {'val1.val1': {None: ([], None)}})
|
||||||
cfg.option('val1.val1').value.set([undefined])
|
cfg.option('val1.val1').value.set([undefined])
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
|
compare(settings.get_cached(), {None: {None: (set(global_props), None)}})
|
||||||
|
|
||||||
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
|
assert values.get_cached() == {}
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
#FIXMEassert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
#FIXMEassert settings.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||||
# 'val1': {None: (set([]), None)}}
|
# 'val1': {None: (set([]), None)}}
|
||||||
#FIXMEassert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
#FIXMEassert values.get_cached() == {'val1.val1': {None: ([None], None)},
|
||||||
# 'val1.val2': {None: ([None], None)}
|
# 'val1.val2': {None: ([None], None)}
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
@ -494,43 +502,45 @@ def test_cache_requires():
|
||||||
od = OptionDescription('service', '', [a, b])
|
od = OptionDescription('service', '', [a, b])
|
||||||
cfg = Config(od)
|
cfg = Config(od)
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
|
assert values.get_cached() == {}
|
||||||
assert cfg.option('ip_address_service').value.get() == None
|
assert cfg.option('ip_address_service').value.get() == None
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)},
|
'activate_service': {None: (set([]), None)},
|
||||||
'ip_address_service': {None: (set([]), None)}})
|
'ip_address_service': {None: (set([]), None)}})
|
||||||
|
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
|
compare(values.get_cached(), {'ip_address_service': {None: (None, None)},
|
||||||
'activate_service': {None: (True, None)}})
|
'activate_service': {None: (True, None)}})
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)},
|
'activate_service': {None: (set([]), None)},
|
||||||
'ip_address_service': {None: (set([]), None)}})
|
'ip_address_service': {None: (set([]), None)}})
|
||||||
|
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
|
compare(values.get_cached(), {'ip_address_service': {None: (None, None)},
|
||||||
'activate_service': {None: (True, None)}})
|
'activate_service': {None: (True, None)}})
|
||||||
cfg.option('ip_address_service').value.set('1.1.1.1')
|
cfg.option('ip_address_service').value.set('1.1.1.1')
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)}})
|
'activate_service': {None: (set([]), None)}})
|
||||||
|
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}})
|
compare(values.get_cached(), {'activate_service': {None: (True, None)}})
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)},
|
'activate_service': {None: (set([]), None)},
|
||||||
'ip_address_service': {None: (set([]), None)}})
|
'ip_address_service': {None: (set([]), None)}})
|
||||||
|
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
|
compare(values.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
|
||||||
'activate_service': {None: (True, None)}})
|
'activate_service': {None: (True, None)}})
|
||||||
cfg.option('activate_service').value.set(False)
|
cfg.option('activate_service').value.set(False)
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
|
||||||
|
|
||||||
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
|
assert values.get_cached() == {}
|
||||||
cfg.value.dict()
|
cfg.value.dict()
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)},
|
'activate_service': {None: (set([]), None)},
|
||||||
'ip_address_service': {None: (set(['disabled']), None)}})
|
'ip_address_service': {None: (set(['disabled']), None)}})
|
||||||
|
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (False, None)}})
|
compare(values.get_cached(), {'activate_service': {None: (False, None)}})
|
||||||
|
|
||||||
|
|
||||||
def test_cache_global_properties():
|
def test_cache_global_properties():
|
||||||
|
@ -540,22 +550,24 @@ def test_cache_global_properties():
|
||||||
od = OptionDescription('service', '', [a, b])
|
od = OptionDescription('service', '', [a, b])
|
||||||
cfg = Config(od)
|
cfg = Config(od)
|
||||||
cfg.property.read_write()
|
cfg.property.read_write()
|
||||||
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
|
values = cfg._config_bag.context._impl_values_cache
|
||||||
|
settings = cfg._config_bag.context._impl_properties_cache
|
||||||
|
assert values.get_cached() == {}
|
||||||
assert cfg.option('ip_address_service').value.get() == None
|
assert cfg.option('ip_address_service').value.get() == None
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)},
|
'activate_service': {None: (set([]), None)},
|
||||||
'ip_address_service': {None: (set([]), None)}})
|
'ip_address_service': {None: (set([]), None)}})
|
||||||
|
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
|
compare(values.get_cached(), {'ip_address_service': {None: (None, None)},
|
||||||
'activate_service': {None: (True, None)}})
|
'activate_service': {None: (True, None)}})
|
||||||
cfg.property.pop('disabled')
|
cfg.property.pop('disabled')
|
||||||
assert cfg.option('ip_address_service').value.get() == None
|
assert cfg.option('ip_address_service').value.get() == None
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)},
|
'activate_service': {None: (set([]), None)},
|
||||||
'ip_address_service': {None: (set([]), None)}})
|
'ip_address_service': {None: (set([]), None)}})
|
||||||
cfg.property.add('test')
|
cfg.property.add('test')
|
||||||
assert cfg.option('ip_address_service').value.get() == None
|
assert cfg.option('ip_address_service').value.get() == None
|
||||||
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test', 'force_store_value']), None)},
|
compare(settings.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test', 'force_store_value']), None)},
|
||||||
'activate_service': {None: (set([]), None)},
|
'activate_service': {None: (set([]), None)},
|
||||||
'ip_address_service': {None: (set([]), None)}})
|
'ip_address_service': {None: (set([]), None)}})
|
||||||
|
|
||||||
|
@ -563,8 +575,8 @@ def test_cache_global_properties():
|
||||||
def test_callback_value_incr():
|
def test_callback_value_incr():
|
||||||
val1 = IntOption('val1', "", callback=return_incr, properties=('expire',))
|
val1 = IntOption('val1', "", callback=return_incr, properties=('expire',))
|
||||||
val2 = IntOption('val2', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
val2 = IntOption('val2', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
||||||
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
od1 = OptionDescription('rootconfig', '', [val1, val2])
|
||||||
cfg = Config(maconfig)
|
cfg = Config(od1)
|
||||||
assert cfg.cache.get_expiration_time() == 5
|
assert cfg.cache.get_expiration_time() == 5
|
||||||
cfg.cache.set_expiration_time(1)
|
cfg.cache.set_expiration_time(1)
|
||||||
assert cfg.cache.get_expiration_time() == 1
|
assert cfg.cache.get_expiration_time() == 1
|
||||||
|
|
|
@ -28,7 +28,7 @@ from .error import PropertiesOptionError, ConfigError, ConflictError, \
|
||||||
from .option import SynDynOptionDescription, DynOptionDescription, Leadership
|
from .option import SynDynOptionDescription, DynOptionDescription, Leadership
|
||||||
from .option.baseoption import BaseOption, valid_name
|
from .option.baseoption import BaseOption, valid_name
|
||||||
from .setting import OptionBag, ConfigBag, Settings, undefined
|
from .setting import OptionBag, ConfigBag, Settings, undefined
|
||||||
from .storage import get_storages, gen_storage_id, get_default_values_storages, list_sessions
|
from .storage import get_storages, gen_storage_id, get_default_values_storages, list_sessions, Cache
|
||||||
from .value import Values
|
from .value import Values
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
@ -104,8 +104,6 @@ class SubConfig(object):
|
||||||
|
|
||||||
def reset_one_option_cache(self,
|
def reset_one_option_cache(self,
|
||||||
desc,
|
desc,
|
||||||
values,
|
|
||||||
settings,
|
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
option_bag):
|
option_bag):
|
||||||
|
|
||||||
|
@ -127,8 +125,6 @@ class SubConfig(object):
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
option_bag.config_bag)
|
option_bag.config_bag)
|
||||||
self.reset_one_option_cache(desc,
|
self.reset_one_option_cache(desc,
|
||||||
values,
|
|
||||||
settings,
|
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
doption_bag)
|
doption_bag)
|
||||||
elif option.issubdyn():
|
elif option.issubdyn():
|
||||||
|
@ -146,8 +142,6 @@ class SubConfig(object):
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
option_bag.config_bag)
|
option_bag.config_bag)
|
||||||
self.reset_one_option_cache(desc,
|
self.reset_one_option_cache(desc,
|
||||||
values,
|
|
||||||
settings,
|
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
doption_bag)
|
doption_bag)
|
||||||
else:
|
else:
|
||||||
|
@ -158,14 +152,11 @@ class SubConfig(object):
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
option_bag.config_bag)
|
option_bag.config_bag)
|
||||||
self.reset_one_option_cache(desc,
|
self.reset_one_option_cache(desc,
|
||||||
values,
|
|
||||||
settings,
|
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
doption_bag)
|
doption_bag)
|
||||||
del option
|
del option
|
||||||
option_bag.option.reset_cache(option_bag.path,
|
option_bag.option.reset_cache(option_bag.path,
|
||||||
values,
|
option_bag.config_bag,
|
||||||
settings,
|
|
||||||
resetted_opts)
|
resetted_opts)
|
||||||
|
|
||||||
def cfgimpl_reset_cache(self,
|
def cfgimpl_reset_cache(self,
|
||||||
|
@ -178,18 +169,14 @@ class SubConfig(object):
|
||||||
|
|
||||||
context = self.cfgimpl_get_context()
|
context = self.cfgimpl_get_context()
|
||||||
desc = context.cfgimpl_get_description()
|
desc = context.cfgimpl_get_description()
|
||||||
values = context.cfgimpl_get_values()
|
|
||||||
settings = context.cfgimpl_get_settings()
|
|
||||||
|
|
||||||
if option_bag is not None:
|
if option_bag is not None:
|
||||||
self.reset_one_option_cache(desc,
|
self.reset_one_option_cache(desc,
|
||||||
values,
|
|
||||||
settings,
|
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
option_bag)
|
option_bag)
|
||||||
else:
|
else:
|
||||||
values._p_.reset_all_cache()
|
context._impl_values_cache.reset_all_cache()
|
||||||
settings._p_.reset_all_cache()
|
context._impl_properties_cache.reset_all_cache()
|
||||||
|
|
||||||
def cfgimpl_get_home_by_path(self,
|
def cfgimpl_get_home_by_path(self,
|
||||||
path,
|
path,
|
||||||
|
@ -608,7 +595,10 @@ class SubConfig(object):
|
||||||
class _CommonConfig(SubConfig):
|
class _CommonConfig(SubConfig):
|
||||||
"abstract base class for the Config, KernelGroupConfig and the KernelMetaConfig"
|
"abstract base class for the Config, KernelGroupConfig and the KernelMetaConfig"
|
||||||
__slots__ = ('_impl_values',
|
__slots__ = ('_impl_values',
|
||||||
|
'_impl_values_cache',
|
||||||
'_impl_settings',
|
'_impl_settings',
|
||||||
|
'_impl_properties_cache',
|
||||||
|
'_impl_permissives_cache',
|
||||||
'_impl_meta',
|
'_impl_meta',
|
||||||
'impl_type')
|
'impl_type')
|
||||||
|
|
||||||
|
@ -718,7 +708,8 @@ class KernelConfig(_CommonConfig):
|
||||||
"main configuration management entry"
|
"main configuration management entry"
|
||||||
__slots__ = ('__weakref__',
|
__slots__ = ('__weakref__',
|
||||||
'_impl_name',
|
'_impl_name',
|
||||||
'_display_name')
|
'_display_name',
|
||||||
|
'_impl_symlink')
|
||||||
impl_type = 'config'
|
impl_type = 'config'
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
|
@ -743,6 +734,7 @@ class KernelConfig(_CommonConfig):
|
||||||
:type persistent: `boolean`
|
:type persistent: `boolean`
|
||||||
"""
|
"""
|
||||||
self._impl_meta = None
|
self._impl_meta = None
|
||||||
|
self._impl_symlink = []
|
||||||
self._display_name = display_name
|
self._display_name = display_name
|
||||||
if isinstance(descr, Leadership):
|
if isinstance(descr, Leadership):
|
||||||
raise ConfigError(_('cannot set leadership object has root optiondescription'))
|
raise ConfigError(_('cannot set leadership object has root optiondescription'))
|
||||||
|
@ -754,7 +746,10 @@ class KernelConfig(_CommonConfig):
|
||||||
force_settings[1])
|
force_settings[1])
|
||||||
else:
|
else:
|
||||||
self._impl_settings = force_settings
|
self._impl_settings = force_settings
|
||||||
|
self._impl_permissives_cache = Cache()
|
||||||
|
self._impl_properties_cache = Cache()
|
||||||
self._impl_values = Values(force_values)
|
self._impl_values = Values(force_values)
|
||||||
|
self._impl_values_cache = Cache()
|
||||||
else:
|
else:
|
||||||
properties, permissives, values, session_id = get_storages(self,
|
properties, permissives, values, session_id = get_storages(self,
|
||||||
session_id,
|
session_id,
|
||||||
|
@ -764,7 +759,10 @@ class KernelConfig(_CommonConfig):
|
||||||
raise ValueError(_("invalid session ID: {0} for config").format(session_id))
|
raise ValueError(_("invalid session ID: {0} for config").format(session_id))
|
||||||
self._impl_settings = Settings(properties,
|
self._impl_settings = Settings(properties,
|
||||||
permissives)
|
permissives)
|
||||||
|
self._impl_permissives_cache = Cache()
|
||||||
|
self._impl_properties_cache = Cache()
|
||||||
self._impl_values = Values(values)
|
self._impl_values = Values(values)
|
||||||
|
self._impl_values_cache = Cache()
|
||||||
super().__init__(descr,
|
super().__init__(descr,
|
||||||
weakref.ref(self),
|
weakref.ref(self),
|
||||||
ConfigBag(self),
|
ConfigBag(self),
|
||||||
|
@ -982,7 +980,8 @@ class KernelGroupConfig(_CommonConfig):
|
||||||
|
|
||||||
|
|
||||||
class KernelMixConfig(KernelGroupConfig):
|
class KernelMixConfig(KernelGroupConfig):
|
||||||
__slots__ = ('_display_name',)
|
__slots__ = ('_display_name',
|
||||||
|
'_impl_symlink')
|
||||||
impl_type = 'mix'
|
impl_type = 'mix'
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
|
@ -995,15 +994,8 @@ class KernelMixConfig(KernelGroupConfig):
|
||||||
_duplicate=False):
|
_duplicate=False):
|
||||||
# FIXME _duplicate
|
# FIXME _duplicate
|
||||||
self._display_name = display_name
|
self._display_name = display_name
|
||||||
|
self._impl_symlink = []
|
||||||
for child in children:
|
for child in children:
|
||||||
if not isinstance(child, _CommonConfig):
|
|
||||||
try:
|
|
||||||
child = child._config
|
|
||||||
except:
|
|
||||||
raise TypeError(_("{}config's children "
|
|
||||||
"should be config, not {}"
|
|
||||||
).format(self.impl_type,
|
|
||||||
type(child)))
|
|
||||||
if not isinstance(child, (KernelConfig, KernelMixConfig)):
|
if not isinstance(child, (KernelConfig, KernelMixConfig)):
|
||||||
raise TypeError(_("child must be a Config, MixConfig or MetaConfig"))
|
raise TypeError(_("child must be a Config, MixConfig or MetaConfig"))
|
||||||
if child.cfgimpl_get_meta() is not None:
|
if child.cfgimpl_get_meta() is not None:
|
||||||
|
@ -1015,7 +1007,10 @@ class KernelMixConfig(KernelGroupConfig):
|
||||||
storage=storage)
|
storage=storage)
|
||||||
self._impl_settings = Settings(properties,
|
self._impl_settings = Settings(properties,
|
||||||
permissives)
|
permissives)
|
||||||
|
self._impl_permissives_cache = Cache()
|
||||||
|
self._impl_properties_cache = Cache()
|
||||||
self._impl_values = Values(values)
|
self._impl_values = Values(values)
|
||||||
|
self._impl_values_cache = Cache()
|
||||||
super().__init__(children,
|
super().__init__(children,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
_descr=optiondescription)
|
_descr=optiondescription)
|
||||||
|
@ -1199,13 +1194,17 @@ class KernelMixConfig(KernelGroupConfig):
|
||||||
config.cfgimpl_reset_cache(None, None)
|
config.cfgimpl_reset_cache(None, None)
|
||||||
|
|
||||||
def pop_config(self,
|
def pop_config(self,
|
||||||
session_id):
|
session_id,
|
||||||
|
config):
|
||||||
|
if session_id is not None:
|
||||||
for idx, child in enumerate(self._impl_children):
|
for idx, child in enumerate(self._impl_children):
|
||||||
if session_id == child.impl_getname():
|
if session_id == child.impl_getname():
|
||||||
child._impl_meta = None
|
child._impl_meta = None
|
||||||
child.cfgimpl_reset_cache(None, None)
|
child.cfgimpl_reset_cache(None, None)
|
||||||
return self._impl_children.pop(idx)
|
return self._impl_children.pop(idx)
|
||||||
raise ConfigError(_('cannot find the config {}').format(session_id))
|
raise ConfigError(_('cannot find the config {}').format(session_id))
|
||||||
|
if config is not None:
|
||||||
|
self._impl_children.pop(config)
|
||||||
|
|
||||||
|
|
||||||
class KernelMetaConfig(KernelMixConfig):
|
class KernelMetaConfig(KernelMixConfig):
|
||||||
|
@ -1236,14 +1235,6 @@ class KernelMetaConfig(KernelMixConfig):
|
||||||
children = new_children
|
children = new_children
|
||||||
descr = optiondescription
|
descr = optiondescription
|
||||||
for child in children:
|
for child in children:
|
||||||
if not isinstance(child, _CommonConfig):
|
|
||||||
try:
|
|
||||||
child = child._config
|
|
||||||
except Exception:
|
|
||||||
raise TypeError(_("{}config's children "
|
|
||||||
"should be config, not {}"
|
|
||||||
).format(self.impl_type,
|
|
||||||
type(child)))
|
|
||||||
if __debug__ and not isinstance(child, (KernelConfig,
|
if __debug__ and not isinstance(child, (KernelConfig,
|
||||||
KernelMetaConfig)):
|
KernelMetaConfig)):
|
||||||
raise TypeError(_("child must be a Config or MetaConfig"))
|
raise TypeError(_("child must be a Config or MetaConfig"))
|
||||||
|
@ -1286,7 +1277,7 @@ class KernelMetaConfig(KernelMixConfig):
|
||||||
display_name=self._display_name)
|
display_name=self._display_name)
|
||||||
# Copy context properties/permissives
|
# Copy context properties/permissives
|
||||||
if new:
|
if new:
|
||||||
config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(), config)
|
config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(config._impl_properties_cache), config)
|
||||||
config.cfgimpl_get_settings().set_context_permissives(self.cfgimpl_get_settings().get_context_permissives())
|
config.cfgimpl_get_settings().set_context_permissives(self.cfgimpl_get_settings().get_context_permissives())
|
||||||
config.cfgimpl_get_settings().ro_append = self.cfgimpl_get_settings().ro_append
|
config.cfgimpl_get_settings().ro_append = self.cfgimpl_get_settings().ro_append
|
||||||
config.cfgimpl_get_settings().rw_append = self.cfgimpl_get_settings().rw_append
|
config.cfgimpl_get_settings().rw_append = self.cfgimpl_get_settings().rw_append
|
||||||
|
|
|
@ -425,13 +425,13 @@ class BaseOption(Base):
|
||||||
|
|
||||||
def reset_cache(self,
|
def reset_cache(self,
|
||||||
path: str,
|
path: str,
|
||||||
values: Values,
|
config_bag: 'OptionBag',
|
||||||
settings: Settings,
|
|
||||||
resetted_opts: List[Base]) -> None:
|
resetted_opts: List[Base]) -> None:
|
||||||
settings._p_.delcache(path)
|
context = config_bag.context
|
||||||
settings._pp_.delcache(path)
|
context._impl_properties_cache.delcache(path)
|
||||||
|
context._impl_permissives_cache.delcache(path)
|
||||||
if not self.impl_is_optiondescription():
|
if not self.impl_is_optiondescription():
|
||||||
values._p_.delcache(path)
|
context._impl_values_cache.delcache(path)
|
||||||
|
|
||||||
def impl_is_symlinkoption(self) -> bool:
|
def impl_is_symlinkoption(self) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -182,36 +182,30 @@ class Leadership(OptionDescription):
|
||||||
|
|
||||||
def reset_cache(self,
|
def reset_cache(self,
|
||||||
path: str,
|
path: str,
|
||||||
values: Values,
|
config_bag: 'ConfigBag',
|
||||||
settings: Settings,
|
|
||||||
resetted_opts: List[Option]) -> None:
|
resetted_opts: List[Option]) -> None:
|
||||||
self._reset_cache(path,
|
self._reset_cache(path,
|
||||||
self.get_leader(),
|
self.get_leader(),
|
||||||
self.get_followers(),
|
self.get_followers(),
|
||||||
values,
|
config_bag,
|
||||||
settings,
|
|
||||||
resetted_opts)
|
resetted_opts)
|
||||||
|
|
||||||
def _reset_cache(self,
|
def _reset_cache(self,
|
||||||
path: str,
|
path: str,
|
||||||
leader: Option,
|
leader: Option,
|
||||||
followers: List[Option],
|
followers: List[Option],
|
||||||
values: Values,
|
config_bag: 'ConfigBag',
|
||||||
settings: Settings,
|
|
||||||
resetted_opts: List[Option]) -> None:
|
resetted_opts: List[Option]) -> None:
|
||||||
super().reset_cache(path,
|
super().reset_cache(path,
|
||||||
values,
|
config_bag,
|
||||||
settings,
|
|
||||||
resetted_opts)
|
resetted_opts)
|
||||||
leader.reset_cache(leader.impl_getpath(),
|
leader.reset_cache(leader.impl_getpath(),
|
||||||
values,
|
config_bag,
|
||||||
settings,
|
|
||||||
None)
|
None)
|
||||||
for follower in followers:
|
for follower in followers:
|
||||||
spath = follower.impl_getpath()
|
spath = follower.impl_getpath()
|
||||||
follower.reset_cache(spath,
|
follower.reset_cache(spath,
|
||||||
values,
|
config_bag,
|
||||||
settings,
|
|
||||||
None)
|
None)
|
||||||
resetted_opts.append(spath)
|
resetted_opts.append(spath)
|
||||||
|
|
||||||
|
|
|
@ -117,16 +117,14 @@ class SynDynLeadership(SynDynOptionDescription):
|
||||||
|
|
||||||
def reset_cache(self,
|
def reset_cache(self,
|
||||||
path: str,
|
path: str,
|
||||||
values: Values,
|
config_bag: 'ConfigBag',
|
||||||
settings: Settings,
|
|
||||||
resetted_opts: List[str]) -> None:
|
resetted_opts: List[str]) -> None:
|
||||||
leader = self.get_leader()
|
leader = self.get_leader()
|
||||||
followers = self.get_followers()
|
followers = self.get_followers()
|
||||||
self._reset_cache(path,
|
self._reset_cache(path,
|
||||||
leader,
|
leader,
|
||||||
followers,
|
followers,
|
||||||
values,
|
config_bag,
|
||||||
settings,
|
|
||||||
resetted_opts)
|
resetted_opts)
|
||||||
|
|
||||||
def pop(self,
|
def pop(self,
|
||||||
|
|
|
@ -196,7 +196,7 @@ class ConfigBag:
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
if key == 'properties':
|
if key == 'properties':
|
||||||
settings = self.context.cfgimpl_get_settings()
|
settings = self.context.cfgimpl_get_settings()
|
||||||
self.properties = settings.get_context_properties()
|
self.properties = settings.get_context_properties(self.context._impl_properties_cache)
|
||||||
return self.properties
|
return self.properties
|
||||||
if key == 'permissives':
|
if key == 'permissives':
|
||||||
settings = self.context.cfgimpl_get_settings()
|
settings = self.context.cfgimpl_get_settings()
|
||||||
|
@ -390,8 +390,9 @@ class Settings(object):
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
# get properties and permissive methods
|
# get properties and permissive methods
|
||||||
|
|
||||||
def get_context_properties(self):
|
def get_context_properties(self,
|
||||||
is_cached, props, validated = self._p_.getcache(None,
|
cache):
|
||||||
|
is_cached, props, validated = cache.getcache(None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
{},
|
{},
|
||||||
|
@ -400,7 +401,7 @@ class Settings(object):
|
||||||
if not is_cached:
|
if not is_cached:
|
||||||
props = self._p_.getproperties(None,
|
props = self._p_.getproperties(None,
|
||||||
self.default_properties)
|
self.default_properties)
|
||||||
self._p_.setcache(None,
|
cache.setcache(None,
|
||||||
None,
|
None,
|
||||||
props,
|
props,
|
||||||
{},
|
{},
|
||||||
|
@ -423,8 +424,9 @@ class Settings(object):
|
||||||
path = opt.impl_getpath()
|
path = opt.impl_getpath()
|
||||||
|
|
||||||
if apply_requires:
|
if apply_requires:
|
||||||
|
cache = config_bag.context._impl_properties_cache
|
||||||
props = config_bag.properties
|
props = config_bag.properties
|
||||||
is_cached, props, validated = self._p_.getcache(path,
|
is_cached, props, validated = cache.getcache(path,
|
||||||
config_bag.expiration_time,
|
config_bag.expiration_time,
|
||||||
index,
|
index,
|
||||||
props,
|
props,
|
||||||
|
@ -443,7 +445,7 @@ class Settings(object):
|
||||||
path)
|
path)
|
||||||
#if apply_requires and config_bag.properties == config_bag.true_properties:
|
#if apply_requires and config_bag.properties == config_bag.true_properties:
|
||||||
if apply_requires and not config_bag.is_unrestraint:
|
if apply_requires and not config_bag.is_unrestraint:
|
||||||
self._p_.setcache(path,
|
cache.setcache(path,
|
||||||
index,
|
index,
|
||||||
props,
|
props,
|
||||||
props,
|
props,
|
||||||
|
|
|
@ -31,6 +31,7 @@ from os.path import split
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from ..error import ConfigError
|
from ..error import ConfigError
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
|
from .util import Cache
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_STORAGE = MEMORY_STORAGE = 'dictionary'
|
DEFAULT_STORAGE = MEMORY_STORAGE = 'dictionary'
|
||||||
|
|
13
tiramisu/storage/cache/dictionary.py
vendored
13
tiramisu/storage/cache/dictionary.py
vendored
|
@ -16,26 +16,27 @@
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
class Cache(object):
|
class Cache:
|
||||||
__slots__ = ('_cache',)
|
__slots__ = ('_cache',)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
|
|
||||||
def _setcache(self, path, index, val, time, validated):
|
def setcache(self, path, index, val, time, validated):
|
||||||
self._cache.setdefault(path, {})[index] = (val, int(time), validated)
|
self._cache.setdefault(path, {})[index] = (val, int(time), validated)
|
||||||
|
|
||||||
def _getcache(self, path, index):
|
def getcache(self, path, index):
|
||||||
values = self._cache.get(path)
|
values = self._cache.get(path)
|
||||||
if values is None:
|
if values is None:
|
||||||
return
|
return
|
||||||
return values.get(index)
|
return values.get(index)
|
||||||
|
|
||||||
def _delcache(self, path):
|
def delcache(self, path):
|
||||||
|
if path in self._cache:
|
||||||
del self._cache[path]
|
del self._cache[path]
|
||||||
|
|
||||||
def _get_cached(self):
|
def get_cached(self):
|
||||||
return self._cache
|
return self._cache
|
||||||
|
|
||||||
def _reset_all_cache(self):
|
def reset_all_cache(self):
|
||||||
self._cache.clear()
|
self._cache.clear()
|
||||||
|
|
|
@ -16,19 +16,18 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from ..util import Cache
|
|
||||||
from ...log import log
|
from ...log import log
|
||||||
|
|
||||||
|
|
||||||
class Properties(Cache):
|
class Properties:
|
||||||
__slots__ = ('_properties',)
|
__slots__ = ('_properties',
|
||||||
|
'_storage')
|
||||||
|
|
||||||
def __init__(self, storage):
|
def __init__(self, storage):
|
||||||
# properties attribute: the name of a property enables this property
|
# properties attribute: the name of a property enables this property
|
||||||
# key is None for global properties
|
# key is None for global properties
|
||||||
self._properties = {}
|
self._properties = {}
|
||||||
# permissive properties
|
self._storage = storage
|
||||||
super(Properties, self).__init__(storage)
|
|
||||||
|
|
||||||
# properties
|
# properties
|
||||||
def setproperties(self, path, properties):
|
def setproperties(self, path, properties):
|
||||||
|
@ -55,13 +54,14 @@ class Properties(Cache):
|
||||||
self._properties = properties
|
self._properties = properties
|
||||||
|
|
||||||
|
|
||||||
class Permissives(Cache):
|
class Permissives:
|
||||||
__slots__ = ('_permissives',)
|
__slots__ = ('_permissives',
|
||||||
|
'_storage')
|
||||||
|
|
||||||
def __init__(self, storage):
|
def __init__(self, storage):
|
||||||
# permissive properties
|
# permissive properties
|
||||||
self._permissives = {}
|
self._permissives = {}
|
||||||
super(Permissives, self).__init__(storage)
|
self._storage = storage
|
||||||
|
|
||||||
def setpermissives(self, path, permissives):
|
def setpermissives(self, path, permissives):
|
||||||
log.debug('setpermissives %s %s', path, permissives)
|
log.debug('setpermissives %s %s', path, permissives)
|
||||||
|
|
|
@ -33,7 +33,7 @@ def list_sessions():
|
||||||
return _list_sessions
|
return _list_sessions
|
||||||
|
|
||||||
|
|
||||||
class Storage(object):
|
class Storage:
|
||||||
__slots__ = ('session_id', 'persistent')
|
__slots__ = ('session_id', 'persistent')
|
||||||
storage = 'dictionary'
|
storage = 'dictionary'
|
||||||
# if object could be serializable
|
# if object could be serializable
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
from ..util import Cache
|
|
||||||
from ...setting import undefined
|
from ...setting import undefined
|
||||||
from ...i18n import _
|
from ...i18n import _
|
||||||
from ...log import log
|
from ...log import log
|
||||||
|
@ -23,19 +22,18 @@ from ...log import log
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
|
||||||
class Values(Cache):
|
class Values:
|
||||||
__slots__ = ('_values',
|
__slots__ = ('_values',
|
||||||
'_informations',
|
'_informations',
|
||||||
|
'_storage',
|
||||||
'__weakref__')
|
'__weakref__')
|
||||||
|
|
||||||
def __init__(self, storage):
|
def __init__(self, storage):
|
||||||
"""init plugin means create values storage
|
"""init plugin means create values storage
|
||||||
"""
|
"""
|
||||||
#(('path1',), (index1,), (value1,), ('owner1'))
|
#(('path1',), (index1,), (value1,), ('owner1'))
|
||||||
self._values = ([], [], [], [])
|
self._values = ([], [], [], [])
|
||||||
self._informations = {}
|
self._informations = {}
|
||||||
# should init cache too
|
self._storage = storage
|
||||||
super(Values, self).__init__(storage)
|
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"sqlite3 cache"
|
"sqlite3"
|
||||||
# Copyright (C) 2013-2019 Team tiramisu (see AUTHORS for all contributors)
|
# Copyright (C) 2013-2019 Team tiramisu (see AUTHORS for all contributors)
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify it
|
# This program is free software: you can redistribute it and/or modify it
|
||||||
|
@ -19,14 +19,14 @@ try:
|
||||||
from cPickle import loads, dumps
|
from cPickle import loads, dumps
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from pickle import loads, dumps
|
from pickle import loads, dumps
|
||||||
from ..util import Cache
|
|
||||||
|
|
||||||
|
|
||||||
class Sqlite3DB(Cache):
|
class Sqlite3DB:
|
||||||
__slots__ = ('_session_id',)
|
__slots__ = ('_session_id',
|
||||||
|
'_storage')
|
||||||
def __init__(self, storage):
|
def __init__(self, storage):
|
||||||
self._session_id = storage.session_id
|
self._session_id = storage.session_id
|
||||||
super(Sqlite3DB, self).__init__(storage)
|
self._storage = storage
|
||||||
|
|
||||||
def _sqlite_decode_path(self, path):
|
def _sqlite_decode_path(self, path):
|
||||||
if path == '_none':
|
if path == '_none':
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"default plugin for cache: set it in a simple dictionary"
|
" with sqlite3 engine"
|
||||||
# Copyright (C) 2013-2019 Team tiramisu (see AUTHORS for all contributors)
|
# Copyright (C) 2013-2019 Team tiramisu (see AUTHORS for all contributors)
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify it
|
# This program is free software: you can redistribute it and/or modify it
|
||||||
|
|
|
@ -25,12 +25,6 @@ def _display_classname(obj): # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
class Cache(DictCache):
|
class Cache(DictCache):
|
||||||
__slots__ = ('_storage',)
|
|
||||||
|
|
||||||
def __init__(self, storage):
|
|
||||||
self._storage = storage
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
def setcache(self, path, index, val, self_props, props, validated):
|
def setcache(self, path, index, val, self_props, props, validated):
|
||||||
"""add val in cache for a specified path
|
"""add val in cache for a specified path
|
||||||
if follower, add index
|
if follower, add index
|
||||||
|
@ -38,7 +32,7 @@ class Cache(DictCache):
|
||||||
if 'cache' in props or 'cache' in self_props:
|
if 'cache' in props or 'cache' in self_props:
|
||||||
log.debug('setcache %s with index %s and value %s in %s (%s)',
|
log.debug('setcache %s with index %s and value %s in %s (%s)',
|
||||||
path, index, val, _display_classname(self), id(self))
|
path, index, val, _display_classname(self), id(self))
|
||||||
self._setcache(path, index, val, time(), validated)
|
super().setcache(path, index, val, time(), validated)
|
||||||
log.debug('not setcache %s with index %s and value %s and props %s and %s in %s (%s)',
|
log.debug('not setcache %s with index %s and value %s and props %s and %s in %s (%s)',
|
||||||
path, index, val, props, self_props, _display_classname(self), id(self))
|
path, index, val, props, self_props, _display_classname(self), id(self))
|
||||||
|
|
||||||
|
@ -51,7 +45,7 @@ class Cache(DictCache):
|
||||||
type_):
|
type_):
|
||||||
no_cache = False, None, False
|
no_cache = False, None, False
|
||||||
if 'cache' in props or type_ == 'context_props':
|
if 'cache' in props or type_ == 'context_props':
|
||||||
indexed = self._getcache(path, index)
|
indexed = super().getcache(path, index)
|
||||||
if indexed is None:
|
if indexed is None:
|
||||||
return no_cache
|
return no_cache
|
||||||
value, timestamp, validated = indexed
|
value, timestamp, validated = indexed
|
||||||
|
@ -89,18 +83,18 @@ class Cache(DictCache):
|
||||||
"""remove cache for a specified path
|
"""remove cache for a specified path
|
||||||
"""
|
"""
|
||||||
log.debug('delcache %s %s %s', path, _display_classname(self), id(self))
|
log.debug('delcache %s %s %s', path, _display_classname(self), id(self))
|
||||||
if path in self._cache:
|
super().delcache(path)
|
||||||
self._delcache(path)
|
|
||||||
|
|
||||||
def reset_all_cache(self):
|
def reset_all_cache(self):
|
||||||
"empty the cache"
|
"empty the cache"
|
||||||
log.debug('reset_all_cache %s %s', _display_classname(self), id(self))
|
log.debug('reset_all_cache %s %s', _display_classname(self), id(self))
|
||||||
self._reset_all_cache()
|
super().reset_all_cache()
|
||||||
|
|
||||||
def get_cached(self):
|
def get_cached(self):
|
||||||
"""return all values in a dictionary
|
"""return all values in a dictionary
|
||||||
please only use it in test purpose
|
please only use it in test purpose
|
||||||
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
|
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
|
||||||
"""
|
"""
|
||||||
log.debug('get_chached %s for %s (%s)', self._cache, _display_classname(self), id(self))
|
cache = super().get_cached()
|
||||||
return self._get_cached()
|
log.debug('get_chached %s for %s (%s)', cache, _display_classname(self), id(self))
|
||||||
|
return cache
|
||||||
|
|
|
@ -62,7 +62,8 @@ class Values(object):
|
||||||
"""
|
"""
|
||||||
# try to retrive value in cache
|
# try to retrive value in cache
|
||||||
setting_properties = option_bag.config_bag.properties
|
setting_properties = option_bag.config_bag.properties
|
||||||
is_cached, value, validated = self._p_.getcache(option_bag.path,
|
cache = option_bag.config_bag.context._impl_values_cache
|
||||||
|
is_cached, value, validated = cache.getcache(option_bag.path,
|
||||||
option_bag.config_bag.expiration_time,
|
option_bag.config_bag.expiration_time,
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
setting_properties,
|
setting_properties,
|
||||||
|
@ -79,7 +80,7 @@ class Values(object):
|
||||||
properties = option_bag.config_bag.properties
|
properties = option_bag.config_bag.properties
|
||||||
validator = 'validator' in properties and 'demoting_error_warning' not in properties
|
validator = 'validator' in properties and 'demoting_error_warning' not in properties
|
||||||
if not option_bag.fromconsistency and (not is_cached or validator):
|
if not option_bag.fromconsistency and (not is_cached or validator):
|
||||||
self._p_.setcache(option_bag.path,
|
cache.setcache(option_bag.path,
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
value,
|
value,
|
||||||
option_bag.properties,
|
option_bag.properties,
|
||||||
|
@ -175,7 +176,8 @@ class Values(object):
|
||||||
def _reset_cache(_value):
|
def _reset_cache(_value):
|
||||||
if not 'expire' in option_bag.properties:
|
if not 'expire' in option_bag.properties:
|
||||||
return
|
return
|
||||||
is_cache, cache_value, validated = self._p_.getcache(option_bag.path,
|
cache = option_bag.config_bag.context._impl_values_cache
|
||||||
|
is_cache, cache_value, validated = cache.getcache(option_bag.path,
|
||||||
None,
|
None,
|
||||||
option_bag.index,
|
option_bag.index,
|
||||||
option_bag.config_bag.properties,
|
option_bag.config_bag.properties,
|
||||||
|
|
Loading…
Reference in a new issue