can change expiration_time in api

This commit is contained in:
2019-02-24 10:36:42 +01:00
parent 9812975aa7
commit f03394563c
5 changed files with 56 additions and 105 deletions

View File

@ -5,16 +5,12 @@ from py.test import raises
from .autopath import do_autopath
do_autopath()
from tiramisu import setting, value
setting.expires_time = 1
value.expires_time = 1
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, Leadership
from tiramisu import Config
from tiramisu.error import ConfigError, PropertiesOptionError
from tiramisu.setting import groups
from tiramisu import undefined, Params, ParamValue, ParamOption, \
list_sessions, default_storage, delete_session
from tiramisu.api import TIRAMISU_VERSION
def teardown_function(function):
@ -230,9 +226,6 @@ def test_reset_cache():
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
cfg.option('u1').value.get()
sleep(1)
cfg.option('u1').value.get()
sleep(1)
cfg.option('u2').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
@ -270,10 +263,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()
cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached()
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'])
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])
@ -283,20 +273,14 @@ def test_cache_leadership():
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])
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])
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0])
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
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()
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'])
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']
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
@ -307,10 +291,7 @@ def test_cache_leadership():
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])
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])
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, 1])
#DEL, insert, ...
@ -336,8 +317,6 @@ def test_cache_callback():
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig)
cfg.property.read_write()
if TIRAMISU_VERSION == 2:
cfg.property.pop('expire')
cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
@ -430,42 +409,27 @@ def test_cache_leader_and_followers():
val1_props = []
val1_val1_props = ['empty']
val1_val2_props = []
if TIRAMISU_VERSION == 2:
cfg.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)
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._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
else:
compare(cfg._config_bag.context.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)}})
# 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(cfg._config_bag.context.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)}})
# len is 0 so don't get any value
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.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() == {}
cfg.value.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), None: (set(), None)}
#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)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
@ -477,10 +441,7 @@ def test_cache_leader_and_followers():
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() == {}
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)}
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)},
# 'val1': {None: (val1_props, None)},
# 'val1.val1': {None: (val1_val1_props, None)},
@ -505,26 +466,15 @@ def test_cache_leader_callback():
val1_props = []
val1_val1_props = ['empty']
val1_val2_props = []
if TIRAMISU_VERSION == 2:
cfg.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._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
else:
compare(cfg._config_bag.context.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._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
global_props = frozenset(global_props)
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)},
'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)}})
cfg.option('val1.val1').value.set([undefined])
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
@ -544,19 +494,14 @@ def test_cache_requires():
od = OptionDescription('service', '', [a, b])
cfg = Config(od)
cfg.property.read_write()
if TIRAMISU_VERSION == 2:
cfg.property.pop('expire')
assert cfg._config_bag.context.cfgimpl_get_values()._p_.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)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
if TIRAMISU_VERSION == 2:
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
else:
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.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)},
'activate_service': {None: (set([]), None)},
@ -601,11 +546,8 @@ def test_cache_global_properties():
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
if TIRAMISU_VERSION == 2:
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
else:
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.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)},
@ -623,6 +565,7 @@ def test_callback_value_incr():
val2 = IntOption('val2', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
maconfig = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(maconfig)
cfg.cache.expiration_time(1)
cfg.property.read_write()
assert cfg.option('val1').value.get() == 1
sleep(1)