2013-04-20 17:30:05 +02:00
|
|
|
# coding: utf-8
|
2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
|
|
|
|
2017-07-04 19:59:42 +02:00
|
|
|
from tiramisu import setting, value
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.expires_time = 1
|
2017-07-04 19:59:42 +02:00
|
|
|
value.expires_time = 1
|
2017-10-14 13:33:25 +02:00
|
|
|
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, MasterSlaves
|
2013-04-20 17:30:05 +02:00
|
|
|
from tiramisu.config import Config
|
2017-09-22 19:51:26 +02:00
|
|
|
from tiramisu.error import ConfigError, PropertiesOptionError
|
2015-11-29 23:03:08 +01:00
|
|
|
from tiramisu.setting import groups
|
2018-04-15 21:13:16 +02:00
|
|
|
from tiramisu import getapi, undefined, Params, ParamValue, ParamOption
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu.api import TIRAMISU_VERSION
|
2014-03-09 20:22:29 +01:00
|
|
|
|
|
|
|
|
2013-09-07 17:25:22 +02:00
|
|
|
from time import sleep, time
|
2014-03-09 20:22:29 +01:00
|
|
|
from py.test import raises
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
2017-09-17 15:55:32 +02:00
|
|
|
global incr
|
2018-03-31 23:09:40 +02:00
|
|
|
incr = -1
|
2017-09-17 15:55:32 +02:00
|
|
|
def return_incr():
|
|
|
|
global incr
|
|
|
|
incr += 1
|
2018-03-31 23:09:40 +02:00
|
|
|
return int(incr/2) + 1
|
2017-09-17 15:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def return_value(val):
|
|
|
|
return val
|
|
|
|
|
|
|
|
|
2013-04-20 17:30:05 +02:00
|
|
|
def make_description():
|
|
|
|
u1 = IntOption('u1', '', multi=True)
|
|
|
|
u2 = IntOption('u2', '')
|
|
|
|
u3 = IntOption('u3', '', multi=True)
|
|
|
|
return OptionDescription('od1', '', [u1, u2, u3])
|
|
|
|
|
|
|
|
|
2014-11-10 21:00:30 +01:00
|
|
|
def test_cache_config():
|
|
|
|
od1 = make_description()
|
2015-07-24 17:54:10 +02:00
|
|
|
assert od1.impl_already_build_caches() is False
|
2014-11-10 21:00:30 +01:00
|
|
|
c = Config(od1)
|
2015-07-24 17:54:10 +02:00
|
|
|
assert od1.impl_already_build_caches() is True
|
|
|
|
c
|
2014-11-10 21:00:30 +01:00
|
|
|
|
|
|
|
|
2013-04-20 17:30:05 +02:00
|
|
|
def test_cache():
|
|
|
|
od1 = make_description()
|
|
|
|
c = Config(od1)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(c)
|
2013-04-20 17:30:05 +02:00
|
|
|
values = c.cfgimpl_get_values()
|
|
|
|
settings = c.cfgimpl_get_settings()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2013-09-07 17:25:22 +02:00
|
|
|
|
|
|
|
|
2018-04-27 14:20:12 +02:00
|
|
|
def test_cache_importation():
|
|
|
|
od1 = make_description()
|
|
|
|
api = getapi(Config(od1))
|
|
|
|
api.option('u2').value.set(1)
|
|
|
|
export = api.value.exportation()
|
|
|
|
assert api.option.make_dict() == {'u1': [], 'u2': 1, 'u3': []}
|
|
|
|
api.option('u2').value.set(2)
|
|
|
|
assert api.option.make_dict() == {'u1': [], 'u2': 2, 'u3': []}
|
|
|
|
api.value.importation(export)
|
|
|
|
assert api.option.make_dict() == {'u1': [], 'u2': 1, 'u3': []}
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_importation_property():
|
|
|
|
od1 = make_description()
|
|
|
|
api = getapi(Config(od1))
|
|
|
|
api.option('u2').property.add('prop')
|
|
|
|
export = api.property.exportation()
|
|
|
|
assert api.option('u2').property.get() == {'prop'}
|
|
|
|
api.option('u2').property.add('prop2')
|
|
|
|
assert api.option('u2').property.get() == {'prop', 'prop2'}
|
|
|
|
api.property.importation(export)
|
|
|
|
assert api.option('u2').property.get() == {'prop'}
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_importation_permissive():
|
|
|
|
od1 = make_description()
|
|
|
|
api = getapi(Config(od1))
|
|
|
|
api.option('u2').permissive.set(frozenset(['prop']))
|
|
|
|
export = api.permissive.exportation()
|
|
|
|
assert api.option('u2').permissive.get() == {'prop'}
|
|
|
|
api.option('u2').permissive.set(frozenset(['prop', 'prop2']))
|
|
|
|
assert api.option('u2').permissive.get() == {'prop', 'prop2'}
|
|
|
|
api.permissive.importation(export)
|
|
|
|
assert api.option('u2').permissive.get() == {'prop'}
|
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
#def test_get_cache():
|
|
|
|
# # force a value in cache, try if reget corrupted value
|
|
|
|
# od1 = make_description()
|
|
|
|
# c = Config(od1)
|
|
|
|
# api = getapi(c)
|
|
|
|
# values = c.cfgimpl_get_values()
|
|
|
|
# settings = c.cfgimpl_get_settings()
|
|
|
|
# ntime = time() + 1
|
|
|
|
# settings._p_.setcache('u1', set(['inject']), ntime, None)
|
|
|
|
# assert 'inject' in settings[od1.u1]
|
|
|
|
# values._p_.setcache('u1', 100, ntime, None)
|
|
|
|
# assert api.option('u1').value.get() == [100]
|
|
|
|
|
|
|
|
|
|
|
|
#def test_get_cache_no_expire():
|
|
|
|
# # force a value in cache, try if reget corrupted value
|
|
|
|
# od1 = make_description()
|
|
|
|
# c = Config(od1)
|
|
|
|
# api = getapi(c)
|
|
|
|
# values = c.cfgimpl_get_values()
|
|
|
|
# settings = c.cfgimpl_get_settings()
|
|
|
|
# settings._p_.setcache('u1', set(['inject2']), None, None)
|
|
|
|
# assert 'inject2' in settings[od1.u1]
|
|
|
|
# values._p_.setcache('u1', 200, None, None)
|
|
|
|
# assert api.option('u1').value.get() == [200]
|
2013-09-07 22:37:13 +02:00
|
|
|
|
|
|
|
|
2013-04-20 17:30:05 +02:00
|
|
|
def test_cache_reset():
|
|
|
|
od1 = make_description()
|
|
|
|
c = Config(od1)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(c)
|
2013-04-20 17:30:05 +02:00
|
|
|
values = c.cfgimpl_get_values()
|
|
|
|
settings = c.cfgimpl_get_settings()
|
|
|
|
#when change a value
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
|
|
|
api.option('u2').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2018-03-19 08:33:53 +01:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
api.option('u2').value.set(1)
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
|
|
|
assert 'u2' not in values._p_.get_cached()
|
2017-11-03 21:52:13 +01:00
|
|
|
assert 'u2' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
#when remove a value
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').value.reset()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
|
|
|
assert 'u2' not in values._p_.get_cached()
|
2017-11-03 21:52:13 +01:00
|
|
|
assert 'u2' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
#when add/del property
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').property.add('test')
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').property.pop('test')
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2013-04-20 17:30:05 +02:00
|
|
|
#when enable/disabled property
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.add('test')
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' not in values._p_.get_cached()
|
|
|
|
assert 'u1' not in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
|
|
|
assert 'u1' in values._p_.get_cached()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.pop('test')
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' not in values._p_.get_cached()
|
|
|
|
assert 'u1' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_reset_multi():
|
|
|
|
od1 = make_description()
|
|
|
|
c = Config(od1)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(c)
|
2013-04-20 17:30:05 +02:00
|
|
|
values = c.cfgimpl_get_values()
|
|
|
|
settings = c.cfgimpl_get_settings()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
|
|
|
api.option('u3').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2017-07-08 15:59:56 +02:00
|
|
|
#when change a value
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u3').value.set([1])
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
|
|
|
assert 'u3' not in values._p_.get_cached()
|
2017-11-03 21:52:13 +01:00
|
|
|
assert 'u3' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
#when append value
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
|
|
|
api.option('u3').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u3').value.set([1, 1])
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
|
|
|
assert 'u3' not in values._p_.get_cached()
|
2017-11-03 21:52:13 +01:00
|
|
|
assert 'u3' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
#when pop value
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
|
|
|
api.option('u3').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u3').value.set([1])
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
|
|
|
assert 'u3' not in values._p_.get_cached()
|
2017-11-03 21:52:13 +01:00
|
|
|
assert 'u3' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
#when remove a value
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u3').value.reset()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
|
|
|
assert 'u3' not in values._p_.get_cached()
|
2017-11-03 21:52:13 +01:00
|
|
|
assert 'u3' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_reset_cache():
|
|
|
|
od1 = make_description()
|
|
|
|
c = Config(od1)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(c)
|
2013-04-20 17:30:05 +02:00
|
|
|
values = c.cfgimpl_get_values()
|
|
|
|
settings = c.cfgimpl_get_settings()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' in values._p_.get_cached()
|
|
|
|
assert 'u1' in settings._p_.get_cached()
|
2018-04-09 21:37:49 +02:00
|
|
|
c.cfgimpl_reset_cache(None, None, None)
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' not in values._p_.get_cached()
|
|
|
|
assert 'u1' not in settings._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-09-07 17:25:22 +02:00
|
|
|
sleep(1)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-04-20 17:30:05 +02:00
|
|
|
sleep(1)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2018-04-09 21:37:49 +02:00
|
|
|
c.cfgimpl_reset_cache(None, None, None)
|
2017-09-22 08:26:11 +02:00
|
|
|
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()
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
#def test_reset_cache_subconfig():
|
|
|
|
# od1 = make_description()
|
|
|
|
# od2 = OptionDescription('od2', '', [od1])
|
|
|
|
# c = Config(od2)
|
|
|
|
# api = getapi(c)
|
|
|
|
# values = c.cfgimpl_get_values()
|
|
|
|
# api.option('od1.u1').value.get()
|
|
|
|
# assert 'od1.u1' in values._p_.get_cached()
|
2018-04-09 21:37:49 +02:00
|
|
|
# c.od1.cfgimpl_reset_cache(None, None, None)
|
2018-03-19 08:33:53 +01:00
|
|
|
# assert 'od1.u1' not in values._p_.get_cached()
|
2013-08-24 21:26:10 +02:00
|
|
|
|
|
|
|
|
2018-04-09 21:37:49 +02:00
|
|
|
#def test_reset_cache_only_expired():
|
|
|
|
# od1 = make_description()
|
|
|
|
# c = Config(od1)
|
|
|
|
# api = getapi(c)
|
|
|
|
# api.property.add('expire')
|
|
|
|
# values = c.cfgimpl_get_values()
|
|
|
|
# settings = c.cfgimpl_get_settings()
|
|
|
|
# api.option('u1').value.get()
|
|
|
|
# assert 'u1' in values._p_.get_cached()
|
|
|
|
# assert 'u1' in settings._p_.get_cached()
|
|
|
|
# c.cfgimpl_reset_cache(True)
|
|
|
|
# assert 'u1' in values._p_.get_cached()
|
|
|
|
# assert 'u1' in settings._p_.get_cached()
|
|
|
|
# sleep(1)
|
|
|
|
# api.option('u1').value.get()
|
|
|
|
# sleep(1)
|
|
|
|
# api.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()
|
|
|
|
# c.cfgimpl_reset_cache(True)
|
|
|
|
# assert 'u1' not in values._p_.get_cached()
|
|
|
|
# assert 'u1' not in settings._p_.get_cached()
|
|
|
|
# assert 'u2' in values._p_.get_cached()
|
|
|
|
# assert 'u2' in settings._p_.get_cached()
|
2013-09-07 17:25:22 +02:00
|
|
|
|
|
|
|
|
2018-04-09 21:37:49 +02:00
|
|
|
#def test_cache_not_expire():
|
|
|
|
# od1 = make_description()
|
|
|
|
# c = Config(od1)
|
|
|
|
# api = getapi(c)
|
|
|
|
# values = c.cfgimpl_get_values()
|
|
|
|
# settings = c.cfgimpl_get_settings()
|
|
|
|
# #api.property.pop('expire')
|
|
|
|
# api.option('u1').value.get()
|
|
|
|
# assert 'u1' in values._p_.get_cached()
|
|
|
|
# assert 'u1' in settings._p_.get_cached()
|
|
|
|
# c.cfgimpl_reset_cache(True)
|
|
|
|
# assert 'u1' in values._p_.get_cached()
|
|
|
|
# assert 'u1' in settings._p_.get_cached()
|
|
|
|
# sleep(1)
|
|
|
|
# api.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()
|
|
|
|
# c.cfgimpl_reset_cache(True)
|
|
|
|
# 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()
|
2013-09-07 17:25:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_not_cache():
|
|
|
|
od1 = make_description()
|
|
|
|
c = Config(od1)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(c)
|
2013-09-07 17:25:22 +02:00
|
|
|
values = c.cfgimpl_get_values()
|
|
|
|
settings = c.cfgimpl_get_settings()
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.pop('cache')
|
|
|
|
api.option('u1').value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert 'u1' not in values._p_.get_cached()
|
|
|
|
assert 'u1' not in settings._p_.get_cached()
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
#def test_reset_cache_only():
|
|
|
|
# od1 = make_description()
|
|
|
|
# c = Config(od1)
|
|
|
|
# api = getapi(c)
|
|
|
|
# values = c.cfgimpl_get_values()
|
|
|
|
# settings = c.cfgimpl_get_settings()
|
|
|
|
# api.option('u1').value.get()
|
|
|
|
# assert 'u1' in values._p_.get_cached()
|
|
|
|
# assert 'u1' in settings._p_.get_cached()
|
|
|
|
# c.cfgimpl_reset_cache(only=('values',))
|
|
|
|
# assert 'u1' not in values._p_.get_cached()
|
|
|
|
# assert 'u1' in settings._p_.get_cached()
|
|
|
|
# api.option('u1').value.get()
|
|
|
|
# assert 'u1' in values._p_.get_cached()
|
|
|
|
# assert 'u1' in settings._p_.get_cached()
|
|
|
|
# c.cfgimpl_reset_cache(only=('settings',))
|
|
|
|
# assert 'u1' in values._p_.get_cached()
|
|
|
|
# assert 'u1' not in settings._p_.get_cached()
|
|
|
|
|
|
|
|
|
|
|
|
#def test_force_cache():
|
|
|
|
# u1 = IntOption('u1', '', multi=True)
|
|
|
|
# u2 = IntOption('u2', '')
|
|
|
|
# u3 = IntOption('u3', '', multi=True)
|
|
|
|
# u4 = IntOption('u4', '', properties=('disabled',))
|
|
|
|
# od = OptionDescription('od1', '', [u1, u2, u3, u4])
|
|
|
|
# c = Config(od)
|
|
|
|
# api = getapi(c)
|
|
|
|
# api.property.read_write()
|
|
|
|
# api.property.pop('expire')
|
|
|
|
# api.property.pop('disabled')
|
|
|
|
#
|
|
|
|
# c.cfgimpl_get_values().force_cache()
|
2018-06-25 21:40:16 +02:00
|
|
|
# compare(c.cfgimpl_get_values()._p_.get_cached(), {'u1': {None: ([], None)},
|
|
|
|
# 'u2': {None: (None, None)},
|
|
|
|
# 'u3': {None: ([], None)},
|
|
|
|
# 'u4': {None: (None, None)}})
|
|
|
|
# compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'u1': {None: (set(['empty']), None)},
|
|
|
|
# 'u2': {None: (set([]), None)},
|
|
|
|
# 'u3': {None: (set(['empty']), None)},
|
|
|
|
# 'u4': {None: (set(['disabled']), None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
# api.property.read_only()
|
|
|
|
#
|
|
|
|
# c.cfgimpl_get_values().force_cache()
|
2018-06-25 21:40:16 +02:00
|
|
|
# compare(c.cfgimpl_get_values()._p_.get_cached(), {'u1': {None: ([], None)},
|
|
|
|
# 'u2': {None: (None, None)},
|
|
|
|
# 'u3': {None: ([], None)}})
|
|
|
|
# compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'empty', 'everything_frozen', 'frozen', 'mandatory', 'validator', 'warnings']), None)},
|
|
|
|
# 'u1': {None: (set(['empty']), None)},
|
|
|
|
# 'u2': {None: (set([]), None)},
|
|
|
|
# 'u3': {None: (set(['empty']), None)},
|
|
|
|
# 'u4': {None: (set(['disabled']), None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
#
|
|
|
|
# c.cfgimpl_get_settings().remove('cache')
|
|
|
|
# raises(ConfigError, "c.cfgimpl_get_values().force_cache()")
|
2015-11-29 23:03:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_master_slave():
|
|
|
|
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)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2015-11-29 23:03:08 +01:00
|
|
|
maconfig = OptionDescription('toto', '', [interface1])
|
|
|
|
cfg = Config(maconfig)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(cfg)
|
|
|
|
api.property.read_write()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
2018-03-19 08:33:53 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
2015-11-29 23:03:08 +01:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
|
|
|
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
|
|
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
|
|
|
else:
|
|
|
|
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
2015-11-29 23:03:08 +01:00
|
|
|
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']
|
2018-03-19 08:33:53 +01:00
|
|
|
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
|
|
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
|
2017-09-22 19:51:26 +02:00
|
|
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
2017-09-22 08:26:11 +02:00
|
|
|
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
2017-07-13 22:04:06 +02:00
|
|
|
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
2015-11-29 23:03:08 +01:00
|
|
|
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
|
|
|
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0])
|
|
|
|
else:
|
|
|
|
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0])
|
2015-11-29 23:03:08 +01:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
|
|
|
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
|
|
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
|
|
|
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
2017-09-22 08:26:11 +02:00
|
|
|
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
|
|
|
else:
|
|
|
|
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
2015-11-29 23:03:08 +01:00
|
|
|
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']
|
2018-03-19 08:33:53 +01:00
|
|
|
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
|
|
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
|
2017-09-22 19:51:26 +02:00
|
|
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
|
|
|
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
|
2017-09-22 08:26:11 +02:00
|
|
|
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
2017-07-13 22:04:06 +02:00
|
|
|
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
2015-11-29 23:03:08 +01:00
|
|
|
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
|
|
|
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0, 1])
|
|
|
|
else:
|
|
|
|
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, 1])
|
2015-11-29 23:03:08 +01:00
|
|
|
#DEL, insert, ...
|
2017-07-08 15:59:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
def return_value(value=None):
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2018-06-25 21:40:16 +02:00
|
|
|
def compare(calculated, expected):
|
|
|
|
assert set(calculated.keys()) == set(expected.keys())
|
|
|
|
for calculated_key in calculated:
|
|
|
|
assert set(calculated[calculated_key].keys()) == set(expected[calculated_key].keys())
|
|
|
|
for calculated_subkey in calculated[calculated_key]:
|
|
|
|
# do not check timestamp
|
|
|
|
assert calculated[calculated_key][calculated_subkey][0] == expected[calculated_key][calculated_subkey][0]
|
|
|
|
|
|
|
|
|
2017-07-08 15:59:56 +02:00
|
|
|
def test_cache_callback():
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
2018-04-15 21:13:16 +02:00
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params=Params((ParamOption(val1),)), properties=('mandatory',))
|
|
|
|
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)
|
2017-07-08 15:59:56 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
|
|
|
cfg = Config(maconfig)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(cfg)
|
|
|
|
api.property.read_write()
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
api.property.pop('expire')
|
|
|
|
api.option.make_dict()
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)},
|
|
|
|
'val2': {None: ('val', None)},
|
|
|
|
'val3': {None: ('yes', None)},
|
|
|
|
'val4': {None: ('val', None)},
|
|
|
|
'val5': {None: (['yes'], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1').value.set('new')
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)},
|
|
|
|
'val5': {None: (['yes'], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
|
|
|
'val2': {None: ('new', None)},
|
|
|
|
'val3': {None: ('yes', None)},
|
|
|
|
'val4': {None: ('new', None)},
|
|
|
|
'val5': {None: (['yes'], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val3').value.set('new2')
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)},
|
|
|
|
# 'val3': {None: (set([]), None)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
|
|
|
'val2': {None: ('new', None)},
|
|
|
|
'val4': {None: ('new', None)},
|
|
|
|
'val5': {None: (['yes'], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)},
|
|
|
|
# 'val3': {None: (set([]), None)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
|
|
|
'val2': {None: ('new', None)},
|
|
|
|
'val3': {None: ('new2', None)},
|
|
|
|
'val4': {None: ('new', None)},
|
|
|
|
'val5': {None: (['yes'], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val4').value.set('new3')
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)},
|
|
|
|
# 'val3': {None: (set([]), None)},
|
|
|
|
# 'val4': {None: (set([]), None)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
|
|
|
'val2': {None: ('new', None)},
|
|
|
|
'val3': {None: ('new2', None)},
|
|
|
|
'val5': {None: (['yes'], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)},
|
|
|
|
# 'val3': {None: (set([]), None)},
|
|
|
|
# 'val4': {None: (set([]), None)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
|
|
|
'val2': {None: ('new', None)},
|
|
|
|
'val3': {None: ('new2', None)},
|
|
|
|
'val4': {None: ('new3', None)},
|
|
|
|
'val5': {None: (['yes'], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val5').value.set([undefined, 'new4'])
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.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)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
|
|
|
'val2': {None: ('new', None)},
|
|
|
|
'val3': {None: ('new2', None)},
|
|
|
|
'val4': {None: ('new3', None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2017-11-03 21:52:13 +01:00
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.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)}}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
|
|
|
|
'val2': {None: ('new', None)},
|
|
|
|
'val3': {None: ('new2', None)},
|
|
|
|
'val4': {None: ('new3', None)},
|
|
|
|
'val5': {None: (['yes', 'new4'], None)}})
|
2017-07-08 15:59:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_master_and_slaves_master():
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2017-07-08 15:59:56 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(maconfig)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(cfg)
|
|
|
|
api.property.read_write()
|
|
|
|
api.option.make_dict()
|
|
|
|
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
|
|
|
val1_props = []
|
|
|
|
val1_val1_props = ['empty']
|
|
|
|
val1_val2_props = []
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
api.property.pop('expire')
|
|
|
|
global_props = set(global_props)
|
|
|
|
val1_props = set(val1_props)
|
|
|
|
val1_val1_props = set(val1_val1_props)
|
|
|
|
val1_val2_props = set(val1_val2_props)
|
|
|
|
else:
|
|
|
|
global_props = frozenset(global_props)
|
|
|
|
val1_props = frozenset(val1_props)
|
|
|
|
val1_val1_props = frozenset(val1_val1_props)
|
|
|
|
val1_val2_props = frozenset(val1_val2_props)
|
|
|
|
#None because no value
|
|
|
|
idx_val2 = None
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
|
|
|
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
|
|
|
else:
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_settings()._p_.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)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
# len is 0 so don't get any value
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
#
|
|
|
|
api.option('val1.val1').value.set([undefined])
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'val1': {None: (set([]), None)}})
|
2017-09-22 08:26:11 +02:00
|
|
|
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
val_val2 = [None]
|
|
|
|
val_val2_props = {None: (set(), None), 0: (set(), None)}
|
|
|
|
else:
|
|
|
|
#has value
|
|
|
|
idx_val2 = 0
|
|
|
|
val_val2 = None
|
|
|
|
val_val2_props = {idx_val2: (val1_val2_props, None)}
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_settings()._p_.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.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)},
|
|
|
|
'val1.val2': {idx_val2: (val_val2, None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set([undefined, undefined])
|
|
|
|
api.option.make_dict()
|
|
|
|
api.option('val1.val2', 1).value.set('oui')
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'val1': {None: (set([]), None)}})
|
2017-09-22 08:26:11 +02:00
|
|
|
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}
|
|
|
|
else:
|
|
|
|
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
|
|
|
|
#assert cfg.cfgimpl_get_settings()._p_.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.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
|
|
|
# 'val1.val2': {None: ([None, 'oui'], None)}}
|
|
|
|
#else:
|
|
|
|
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
|
|
|
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
|
2017-07-08 15:59:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_master_callback():
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
2018-04-15 21:13:16 +02:00
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2017-07-08 15:59:56 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(maconfig)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(cfg)
|
|
|
|
api.property.read_write()
|
|
|
|
api.option.make_dict()
|
|
|
|
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
|
|
|
val1_props = []
|
|
|
|
val1_val1_props = ['empty']
|
|
|
|
val1_val2_props = []
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
api.property.pop('expire')
|
|
|
|
global_props = set(global_props)
|
|
|
|
val1_props = set(val1_props)
|
|
|
|
val1_val1_props = set(val1_val1_props)
|
|
|
|
val1_val2_props = set(val1_val2_props)
|
|
|
|
else:
|
|
|
|
global_props = frozenset(global_props)
|
|
|
|
val1_props = frozenset(val1_props)
|
|
|
|
val1_val1_props = frozenset(val1_val1_props)
|
|
|
|
val1_val2_props = frozenset(val1_val2_props)
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
|
|
|
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
|
|
|
else:
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_settings()._p_.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.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set([undefined])
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(cfg.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'val1': {None: (set([]), None)}})
|
2017-11-03 21:52:13 +01:00
|
|
|
|
2017-09-22 08:26:11 +02:00
|
|
|
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2017-11-03 21:52:13 +01:00
|
|
|
#FIXMEassert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'val1': {None: (set([]), None)}}
|
|
|
|
#FIXMEassert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
|
|
|
# 'val1.val2': {None: ([None], None)}
|
|
|
|
# }
|
|
|
|
|
2017-07-08 15:59:56 +02:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
#def test_cache_master_slave_different():
|
|
|
|
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
|
|
|
# c = StrOption('str', 'Test string option', multi=True)
|
|
|
|
# d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
|
|
|
# descr = MasterSlaves("int", "", [b, c, d])
|
|
|
|
# #descr.impl_set_group_type(groups.master)
|
|
|
|
# cfg = Config(descr)
|
|
|
|
# api = getapi(cfg)
|
|
|
|
# api.property.read_write()
|
|
|
|
# api.property.pop('expire')
|
|
|
|
# api.option.make_dict()
|
2018-06-25 21:40:16 +02:00
|
|
|
# compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'int': {None: ([0], None)},
|
|
|
|
# 'str': {None: ([None], None)},
|
|
|
|
# 'str1': {None: ([None], None)}})
|
|
|
|
# conver(cfg.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'int': {None: (set(['empty']), None)},
|
|
|
|
# 'str': {None: (set([]), None), 0: (set([]), None)},
|
|
|
|
# 'str1': {None: (set([]), None), 0: (set([]), None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
# api.option('int').value.set([0, 1])
|
|
|
|
# api.option.make_dict()
|
2018-06-25 21:40:16 +02:00
|
|
|
# compare(cfg.cfgimpl_get_values()._p_.get_cached(), {'int': {None: ([0, 1], None)},
|
2018-03-19 08:33:53 +01:00
|
|
|
# 'str': {None: ([None, None], None)},
|
2018-06-25 21:40:16 +02:00
|
|
|
# 'str1': {None: ([None, None], None)}})
|
|
|
|
# compare(cfg.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
2018-03-19 08:33:53 +01:00
|
|
|
# 'int': {None: (set(['empty']), None)},
|
|
|
|
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
2018-06-25 21:40:16 +02:00
|
|
|
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
#
|
|
|
|
# api.option('str', 1).value.set('1')
|
|
|
|
# api.option.make_dict()
|
|
|
|
# assert set(cfg.cfgimpl_get_values()._p_.get_cached().keys()) == set(['int', 'str', 'str1'])
|
2018-06-25 21:40:16 +02:00
|
|
|
# compare(cfg.cfgimpl_get_values()._p_.get_cached()['int'], {None: ([0, 1], None)})
|
|
|
|
# compare(cfg.cfgimpl_get_values()._p_.get_cached()['str'], {None: ([None, '1'], None)})
|
2018-03-19 08:33:53 +01:00
|
|
|
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][0] == None
|
|
|
|
# raises(PropertiesOptionError, "cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][1]")
|
|
|
|
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][1] == None
|
2018-06-25 21:40:16 +02:00
|
|
|
# compare(cfg.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
# 'int': {None: (set(['empty']), None)},
|
|
|
|
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
|
|
|
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
# api.property.read_only()
|
|
|
|
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
|
|
|
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
|
|
|
# api.option.make_dict()
|
|
|
|
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
|
|
|
# 'str': {None: ([None, '1'], None)},
|
|
|
|
# 'str1': {None: ([None, None], None)}}
|
|
|
|
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'everything_frozen', 'validator', 'warnings', 'empty', 'mandatory', ]), None)},
|
|
|
|
# 'int': {None: (set(['empty']), None)},
|
|
|
|
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
|
|
|
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
2017-09-22 19:51:26 +02:00
|
|
|
|
|
|
|
|
2017-07-08 15:59:56 +02:00
|
|
|
def test_cache_requires():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(c)
|
|
|
|
api.property.read_write()
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
api.property.pop('expire')
|
2017-09-22 08:26:11 +02:00
|
|
|
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('ip_address_service').value.get() == None
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'activate_service': {None: (set([]), None)},
|
|
|
|
'ip_address_service': {None: (set([]), None)}})
|
2017-07-08 15:59:56 +02:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
|
|
|
else:
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
|
|
|
|
'activate_service': {None: (True, None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'activate_service': {None: (set([]), None)},
|
|
|
|
'ip_address_service': {None: (set([]), None)}})
|
2017-07-08 15:59:56 +02:00
|
|
|
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
|
|
|
|
'activate_service': {None: (True, None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('ip_address_service').value.set('1.1.1.1')
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'activate_service': {None: (set([]), None)}})
|
2017-07-08 15:59:56 +02:00
|
|
|
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'activate_service': {None: (set([]), None)},
|
|
|
|
'ip_address_service': {None: (set([]), None)}})
|
2017-07-08 15:59:56 +02:00
|
|
|
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
|
|
|
|
'activate_service': {None: (True, None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('activate_service').value.set(False)
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
|
2017-07-08 15:59:56 +02:00
|
|
|
|
2017-09-22 08:26:11 +02:00
|
|
|
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option.make_dict()
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'activate_service': {None: (set([]), None)},
|
|
|
|
'ip_address_service': {None: (set(['disabled']), None)}})
|
2017-07-08 15:59:56 +02:00
|
|
|
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (False, None)}})
|
2017-07-13 22:04:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_global_properties():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(c)
|
|
|
|
api.property.read_write()
|
2017-09-22 08:26:11 +02:00
|
|
|
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('ip_address_service').value.get() == None
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
2017-07-13 22:04:06 +02:00
|
|
|
'activate_service': {None: (set([]), None)},
|
2018-06-25 21:40:16 +02:00
|
|
|
'ip_address_service': {None: (set([]), None)}})
|
2017-07-13 22:04:06 +02:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
|
|
|
else:
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
|
|
|
|
'activate_service': {None: (True, None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.pop('disabled')
|
|
|
|
assert api.option('ip_address_service').value.get() == None
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
|
|
|
'activate_service': {None: (set([]), None)},
|
|
|
|
'ip_address_service': {None: (set([]), None)}})
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.add('test')
|
|
|
|
assert api.option('ip_address_service').value.get() == None
|
2018-06-25 21:40:16 +02:00
|
|
|
compare(c.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)},
|
|
|
|
'activate_service': {None: (set([]), None)},
|
|
|
|
'ip_address_service': {None: (set([]), None)}})
|
2017-09-17 15:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_incr():
|
2018-03-31 23:09:40 +02:00
|
|
|
val1 = IntOption('val1', "", callback=return_incr, properties=('expire',))
|
2018-04-15 21:13:16 +02:00
|
|
|
val2 = IntOption('val2', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
2017-09-17 15:55:32 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
cfg = Config(maconfig)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(cfg)
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == 1
|
2017-09-17 15:55:32 +02:00
|
|
|
sleep(1)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('val2').value.get() == 1
|
2017-09-17 15:55:32 +02:00
|
|
|
sleep(1)
|
2018-03-31 23:09:40 +02:00
|
|
|
assert api.option('val1').value.get() == 1
|
|
|
|
assert api.option('val2').value.get() == 1
|
|
|
|
sleep(2)
|
|
|
|
assert api.option('val1').value.get() == 2
|
|
|
|
assert api.option('val2').value.get() == 2
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('val1').value.get() == 2
|
|
|
|
assert api.option('val2').value.get() == 2
|