separate Cache from values and settings

This commit is contained in:
Emmanuel Garette 2019-08-01 18:22:18 +02:00
parent c5ce9be699
commit 1691e38db5
16 changed files with 348 additions and 313 deletions

42
tests/config.py Normal file
View 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

View File

@ -54,16 +54,16 @@ def test_cache_config():
def test_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.option('u2').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' in values.get_cached()
assert 'u2' in settings.get_cached()
def test_cache_importation():
@ -105,171 +105,173 @@ def test_cache_importation_permissive():
def test_cache_reset():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
#when change a value
cfg.option('u1').value.get()
cfg.option('u2').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._p_.get_cached()
assert 'u1' in values._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' in values.get_cached()
assert 'u2' in settings.get_cached()
assert 'u1' in values.get_cached()
cfg.option('u2').value.set(1)
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
#when remove a value
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.option('u2').value.reset()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
#when add/del property
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.option('u2').property.add('test')
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.option('u2').property.pop('test')
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
#when enable/disabled property
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.property.add('test')
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.property.pop('test')
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
def test_cache_reset_multi():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
cfg.option('u1').value.get()
cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' in settings.get_cached()
#when change a value
cfg.option('u3').value.set([1])
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' not in values.get_cached()
assert 'u3' not in settings.get_cached()
#when append value
cfg.option('u1').value.get()
cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' in settings.get_cached()
cfg.option('u3').value.set([1, 1])
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' not in values.get_cached()
assert 'u3' not in settings.get_cached()
#when pop value
cfg.option('u1').value.get()
cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' in settings.get_cached()
cfg.option('u3').value.set([1])
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' not in values.get_cached()
assert 'u3' not in settings.get_cached()
#when remove a value
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.option('u3').value.reset()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' not in values.get_cached()
assert 'u3' not in settings.get_cached()
def test_reset_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
cfg.cache.reset()
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
cfg.option('u1').value.get()
cfg.option('u2').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._p_.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' in values.get_cached()
assert 'u2' in settings.get_cached()
cfg.cache.reset()
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
def test_cache_not_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
cfg.property.pop('cache')
cfg.option('u1').value.get()
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
def test_cache_leadership():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
od1 = OptionDescription('toto', '', [interface1])
cfg = Config(od1)
cfg.property.read_write()
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
values = cfg._config_bag.context._impl_values_cache
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.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['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
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 cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [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['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.netmask_admin_eth0', 0).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['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']
@ -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'][0][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['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'),)))
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)
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig)
od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(od1)
cfg.property.read_write()
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)}}
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)},
'val3': {None: ('yes', None)},
'val4': {None: ('val', None)},
'val5': {None: (['yes'], None)}})
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)}}
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)}})
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)}}
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)},
'val3': {None: ('yes', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
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)},
# '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)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
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)},
# '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)},
'val3': {None: ('new2', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
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)},
# 'val3': {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)},
'val3': {None: ('new2', None)},
'val5': {None: (['yes'], None)}})
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)},
# 'val3': {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)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
'val5': {None: (['yes'], None)}})
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)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), 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)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}})
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)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), 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)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
@ -401,8 +405,8 @@ def test_cache_leader_and_followers():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
od1 = OptionDescription('rootconfig', '', [interface1])
cfg = Config(od1)
cfg.property.read_write()
cfg.value.dict()
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)
#None because no value
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.val1': {None: (val1_val1_props, None)},
'val1.val2': {idx_val2: (val1_val2_props, None)}})
# 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])
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
compare(settings.get_cached(), {None: {None: (set(global_props), None)}})
assert values.get_cached() == {}
cfg.value.dict()
#has value
idx_val2 = 0
val_val2 = 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.val1': {None: (val1_val1_props, None)},
'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)}})
cfg.option('val1.val1').value.set([undefined, undefined])
cfg.value.dict()
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)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
assert values.get_cached() == {}
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.val1': {None: (val1_val1_props, None)},
# 'val1.val2': val1_val2_props}
#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)}}
#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)}}
@ -458,8 +464,8 @@ def test_cache_leader_callback():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
od1 = OptionDescription('rootconfig', '', [interface1])
cfg = Config(od1)
cfg.property.read_write()
cfg.value.dict()
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_val1_props = frozenset(val1_val1_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.val1': {None: (val1_val1_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])
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()
#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)}}
#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)}
# }
@ -494,43 +502,45 @@ def test_cache_requires():
od = OptionDescription('service', '', [a, b])
cfg = Config(od)
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
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)},
'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)}})
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)},
'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)}})
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)}})
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()
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)},
'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)}})
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()
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)},
'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():
@ -540,22 +550,24 @@ def test_cache_global_properties():
od = OptionDescription('service', '', [a, b])
cfg = Config(od)
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
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)},
'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)}})
cfg.property.pop('disabled')
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)},
'ip_address_service': {None: (set([]), None)}})
cfg.property.add('test')
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)},
'ip_address_service': {None: (set([]), None)}})
@ -563,8 +575,8 @@ def test_cache_global_properties():
def test_callback_value_incr():
val1 = IntOption('val1', "", callback=return_incr, properties=('expire',))
val2 = IntOption('val2', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
maconfig = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(maconfig)
od1 = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(od1)
assert cfg.cache.get_expiration_time() == 5
cfg.cache.set_expiration_time(1)
assert cfg.cache.get_expiration_time() == 1

View File

@ -28,7 +28,7 @@ from .error import PropertiesOptionError, ConfigError, ConflictError, \
from .option import SynDynOptionDescription, DynOptionDescription, Leadership
from .option.baseoption import BaseOption, valid_name
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 .i18n import _
@ -104,8 +104,6 @@ class SubConfig(object):
def reset_one_option_cache(self,
desc,
values,
settings,
resetted_opts,
option_bag):
@ -127,8 +125,6 @@ class SubConfig(object):
option_bag.index,
option_bag.config_bag)
self.reset_one_option_cache(desc,
values,
settings,
resetted_opts,
doption_bag)
elif option.issubdyn():
@ -146,8 +142,6 @@ class SubConfig(object):
option_bag.index,
option_bag.config_bag)
self.reset_one_option_cache(desc,
values,
settings,
resetted_opts,
doption_bag)
else:
@ -158,14 +152,11 @@ class SubConfig(object):
option_bag.index,
option_bag.config_bag)
self.reset_one_option_cache(desc,
values,
settings,
resetted_opts,
doption_bag)
del option
option_bag.option.reset_cache(option_bag.path,
values,
settings,
option_bag.config_bag,
resetted_opts)
def cfgimpl_reset_cache(self,
@ -178,18 +169,14 @@ class SubConfig(object):
context = self.cfgimpl_get_context()
desc = context.cfgimpl_get_description()
values = context.cfgimpl_get_values()
settings = context.cfgimpl_get_settings()
if option_bag is not None:
self.reset_one_option_cache(desc,
values,
settings,
resetted_opts,
option_bag)
else:
values._p_.reset_all_cache()
settings._p_.reset_all_cache()
context._impl_values_cache.reset_all_cache()
context._impl_properties_cache.reset_all_cache()
def cfgimpl_get_home_by_path(self,
path,
@ -608,7 +595,10 @@ class SubConfig(object):
class _CommonConfig(SubConfig):
"abstract base class for the Config, KernelGroupConfig and the KernelMetaConfig"
__slots__ = ('_impl_values',
'_impl_values_cache',
'_impl_settings',
'_impl_properties_cache',
'_impl_permissives_cache',
'_impl_meta',
'impl_type')
@ -718,7 +708,8 @@ class KernelConfig(_CommonConfig):
"main configuration management entry"
__slots__ = ('__weakref__',
'_impl_name',
'_display_name')
'_display_name',
'_impl_symlink')
impl_type = 'config'
def __init__(self,
@ -743,6 +734,7 @@ class KernelConfig(_CommonConfig):
:type persistent: `boolean`
"""
self._impl_meta = None
self._impl_symlink = []
self._display_name = display_name
if isinstance(descr, Leadership):
raise ConfigError(_('cannot set leadership object has root optiondescription'))
@ -754,7 +746,10 @@ class KernelConfig(_CommonConfig):
force_settings[1])
else:
self._impl_settings = force_settings
self._impl_permissives_cache = Cache()
self._impl_properties_cache = Cache()
self._impl_values = Values(force_values)
self._impl_values_cache = Cache()
else:
properties, permissives, values, session_id = get_storages(self,
session_id,
@ -764,7 +759,10 @@ class KernelConfig(_CommonConfig):
raise ValueError(_("invalid session ID: {0} for config").format(session_id))
self._impl_settings = Settings(properties,
permissives)
self._impl_permissives_cache = Cache()
self._impl_properties_cache = Cache()
self._impl_values = Values(values)
self._impl_values_cache = Cache()
super().__init__(descr,
weakref.ref(self),
ConfigBag(self),
@ -982,7 +980,8 @@ class KernelGroupConfig(_CommonConfig):
class KernelMixConfig(KernelGroupConfig):
__slots__ = ('_display_name',)
__slots__ = ('_display_name',
'_impl_symlink')
impl_type = 'mix'
def __init__(self,
@ -995,15 +994,8 @@ class KernelMixConfig(KernelGroupConfig):
_duplicate=False):
# FIXME _duplicate
self._display_name = display_name
self._impl_symlink = []
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)):
raise TypeError(_("child must be a Config, MixConfig or MetaConfig"))
if child.cfgimpl_get_meta() is not None:
@ -1015,7 +1007,10 @@ class KernelMixConfig(KernelGroupConfig):
storage=storage)
self._impl_settings = Settings(properties,
permissives)
self._impl_permissives_cache = Cache()
self._impl_properties_cache = Cache()
self._impl_values = Values(values)
self._impl_values_cache = Cache()
super().__init__(children,
session_id=session_id,
_descr=optiondescription)
@ -1199,13 +1194,17 @@ class KernelMixConfig(KernelGroupConfig):
config.cfgimpl_reset_cache(None, None)
def pop_config(self,
session_id):
session_id,
config):
if session_id is not None:
for idx, child in enumerate(self._impl_children):
if session_id == child.impl_getname():
child._impl_meta = None
child.cfgimpl_reset_cache(None, None)
return self._impl_children.pop(idx)
raise ConfigError(_('cannot find the config {}').format(session_id))
if config is not None:
self._impl_children.pop(config)
class KernelMetaConfig(KernelMixConfig):
@ -1236,14 +1235,6 @@ class KernelMetaConfig(KernelMixConfig):
children = new_children
descr = optiondescription
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,
KernelMetaConfig)):
raise TypeError(_("child must be a Config or MetaConfig"))
@ -1286,7 +1277,7 @@ class KernelMetaConfig(KernelMixConfig):
display_name=self._display_name)
# Copy context properties/permissives
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().ro_append = self.cfgimpl_get_settings().ro_append
config.cfgimpl_get_settings().rw_append = self.cfgimpl_get_settings().rw_append

View File

@ -425,13 +425,13 @@ class BaseOption(Base):
def reset_cache(self,
path: str,
values: Values,
settings: Settings,
config_bag: 'OptionBag',
resetted_opts: List[Base]) -> None:
settings._p_.delcache(path)
settings._pp_.delcache(path)
context = config_bag.context
context._impl_properties_cache.delcache(path)
context._impl_permissives_cache.delcache(path)
if not self.impl_is_optiondescription():
values._p_.delcache(path)
context._impl_values_cache.delcache(path)
def impl_is_symlinkoption(self) -> bool:
return False

View File

@ -182,36 +182,30 @@ class Leadership(OptionDescription):
def reset_cache(self,
path: str,
values: Values,
settings: Settings,
config_bag: 'ConfigBag',
resetted_opts: List[Option]) -> None:
self._reset_cache(path,
self.get_leader(),
self.get_followers(),
values,
settings,
config_bag,
resetted_opts)
def _reset_cache(self,
path: str,
leader: Option,
followers: List[Option],
values: Values,
settings: Settings,
config_bag: 'ConfigBag',
resetted_opts: List[Option]) -> None:
super().reset_cache(path,
values,
settings,
config_bag,
resetted_opts)
leader.reset_cache(leader.impl_getpath(),
values,
settings,
config_bag,
None)
for follower in followers:
spath = follower.impl_getpath()
follower.reset_cache(spath,
values,
settings,
config_bag,
None)
resetted_opts.append(spath)

View File

@ -117,16 +117,14 @@ class SynDynLeadership(SynDynOptionDescription):
def reset_cache(self,
path: str,
values: Values,
settings: Settings,
config_bag: 'ConfigBag',
resetted_opts: List[str]) -> None:
leader = self.get_leader()
followers = self.get_followers()
self._reset_cache(path,
leader,
followers,
values,
settings,
config_bag,
resetted_opts)
def pop(self,

View File

@ -196,7 +196,7 @@ class ConfigBag:
def __getattr__(self, key):
if key == 'properties':
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
if key == 'permissives':
settings = self.context.cfgimpl_get_settings()
@ -390,8 +390,9 @@ class Settings(object):
# ____________________________________________________________
# get properties and permissive methods
def get_context_properties(self):
is_cached, props, validated = self._p_.getcache(None,
def get_context_properties(self,
cache):
is_cached, props, validated = cache.getcache(None,
None,
None,
{},
@ -400,7 +401,7 @@ class Settings(object):
if not is_cached:
props = self._p_.getproperties(None,
self.default_properties)
self._p_.setcache(None,
cache.setcache(None,
None,
props,
{},
@ -423,8 +424,9 @@ class Settings(object):
path = opt.impl_getpath()
if apply_requires:
cache = config_bag.context._impl_properties_cache
props = config_bag.properties
is_cached, props, validated = self._p_.getcache(path,
is_cached, props, validated = cache.getcache(path,
config_bag.expiration_time,
index,
props,
@ -443,7 +445,7 @@ class Settings(object):
path)
#if apply_requires and config_bag.properties == config_bag.true_properties:
if apply_requires and not config_bag.is_unrestraint:
self._p_.setcache(path,
cache.setcache(path,
index,
props,
props,

View File

@ -31,6 +31,7 @@ from os.path import split
from typing import Dict
from ..error import ConfigError
from ..i18n import _
from .util import Cache
DEFAULT_STORAGE = MEMORY_STORAGE = 'dictionary'

View File

@ -16,26 +16,27 @@
# ____________________________________________________________
class Cache(object):
class Cache:
__slots__ = ('_cache',)
def __init__(self):
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)
def _getcache(self, path, index):
def getcache(self, path, index):
values = self._cache.get(path)
if values is None:
return
return values.get(index)
def _delcache(self, path):
def delcache(self, path):
if path in self._cache:
del self._cache[path]
def _get_cached(self):
def get_cached(self):
return self._cache
def _reset_all_cache(self):
def reset_all_cache(self):
self._cache.clear()

View File

@ -16,19 +16,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ____________________________________________________________
from copy import copy
from ..util import Cache
from ...log import log
class Properties(Cache):
__slots__ = ('_properties',)
class Properties:
__slots__ = ('_properties',
'_storage')
def __init__(self, storage):
# properties attribute: the name of a property enables this property
# key is None for global properties
self._properties = {}
# permissive properties
super(Properties, self).__init__(storage)
self._storage = storage
# properties
def setproperties(self, path, properties):
@ -55,13 +54,14 @@ class Properties(Cache):
self._properties = properties
class Permissives(Cache):
__slots__ = ('_permissives',)
class Permissives:
__slots__ = ('_permissives',
'_storage')
def __init__(self, storage):
# permissive properties
self._permissives = {}
super(Permissives, self).__init__(storage)
self._storage = storage
def setpermissives(self, path, permissives):
log.debug('setpermissives %s %s', path, permissives)

View File

@ -33,7 +33,7 @@ def list_sessions():
return _list_sessions
class Storage(object):
class Storage:
__slots__ = ('session_id', 'persistent')
storage = 'dictionary'
# if object could be serializable

View File

@ -15,7 +15,6 @@
# 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/>.
# ____________________________________________________________
from ..util import Cache
from ...setting import undefined
from ...i18n import _
from ...log import log
@ -23,19 +22,18 @@ from ...log import log
from copy import deepcopy
class Values(Cache):
class Values:
__slots__ = ('_values',
'_informations',
'_storage',
'__weakref__')
def __init__(self, storage):
"""init plugin means create values storage
"""
#(('path1',), (index1,), (value1,), ('owner1'))
self._values = ([], [], [], [])
self._informations = {}
# should init cache too
super(Values, self).__init__(storage)
self._storage = storage
def commit(self):
pass

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"sqlite3 cache"
"sqlite3"
# Copyright (C) 2013-2019 Team tiramisu (see AUTHORS for all contributors)
#
# This program is free software: you can redistribute it and/or modify it
@ -19,14 +19,14 @@ try:
from cPickle import loads, dumps
except ImportError:
from pickle import loads, dumps
from ..util import Cache
class Sqlite3DB(Cache):
__slots__ = ('_session_id',)
class Sqlite3DB:
__slots__ = ('_session_id',
'_storage')
def __init__(self, storage):
self._session_id = storage.session_id
super(Sqlite3DB, self).__init__(storage)
self._storage = storage
def _sqlite_decode_path(self, path):
if path == '_none':

View File

@ -1,5 +1,5 @@
# -*- 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)
#
# This program is free software: you can redistribute it and/or modify it

View File

@ -25,12 +25,6 @@ def _display_classname(obj): # pragma: no cover
class Cache(DictCache):
__slots__ = ('_storage',)
def __init__(self, storage):
self._storage = storage
super().__init__()
def setcache(self, path, index, val, self_props, props, validated):
"""add val in cache for a specified path
if follower, add index
@ -38,7 +32,7 @@ class Cache(DictCache):
if 'cache' in props or 'cache' in self_props:
log.debug('setcache %s with index %s and value %s in %s (%s)',
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)',
path, index, val, props, self_props, _display_classname(self), id(self))
@ -51,7 +45,7 @@ class Cache(DictCache):
type_):
no_cache = False, None, False
if 'cache' in props or type_ == 'context_props':
indexed = self._getcache(path, index)
indexed = super().getcache(path, index)
if indexed is None:
return no_cache
value, timestamp, validated = indexed
@ -89,18 +83,18 @@ class Cache(DictCache):
"""remove cache for a specified path
"""
log.debug('delcache %s %s %s', path, _display_classname(self), id(self))
if path in self._cache:
self._delcache(path)
super().delcache(path)
def reset_all_cache(self):
"empty the cache"
log.debug('reset_all_cache %s %s', _display_classname(self), id(self))
self._reset_all_cache()
super().reset_all_cache()
def get_cached(self):
"""return all values in a dictionary
please only use it in test purpose
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
"""
log.debug('get_chached %s for %s (%s)', self._cache, _display_classname(self), id(self))
return self._get_cached()
cache = super().get_cached()
log.debug('get_chached %s for %s (%s)', cache, _display_classname(self), id(self))
return cache

View File

@ -62,7 +62,8 @@ class Values(object):
"""
# try to retrive value in cache
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.index,
setting_properties,
@ -79,7 +80,7 @@ class Values(object):
properties = option_bag.config_bag.properties
validator = 'validator' in properties and 'demoting_error_warning' not in properties
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,
value,
option_bag.properties,
@ -175,7 +176,8 @@ class Values(object):
def _reset_cache(_value):
if not 'expire' in option_bag.properties:
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,
option_bag.index,
option_bag.config_bag.properties,