In Config, name and session_id was quite equal, remove name
session_id is now validate set_value return Configs with error add new_config to MetaConfig
This commit is contained in:
parent
90a2072fc5
commit
be43c95ec0
|
@ -26,6 +26,22 @@ def return_error():
|
||||||
raise Exception('test')
|
raise Exception('test')
|
||||||
|
|
||||||
|
|
||||||
|
def test_choiceoption():
|
||||||
|
ch = ChoiceOption('ch', '', values=('val1', 'val2'))
|
||||||
|
od = OptionDescription('od', '', [ch])
|
||||||
|
cfg = Config(od)
|
||||||
|
cfg.read_write()
|
||||||
|
owner = cfg.cfgimpl_get_settings().getowner()
|
||||||
|
assert cfg.getowner(ch) == owners.default
|
||||||
|
cfg.ch = 'val1'
|
||||||
|
assert cfg.getowner(ch) == owner
|
||||||
|
del(cfg.ch)
|
||||||
|
assert cfg.getowner(ch) == owners.default
|
||||||
|
raises(ValueError, "cfg.ch='no'")
|
||||||
|
assert cfg.getowner(ch) == owners.default
|
||||||
|
assert ch.impl_get_values(cfg) == ('val1', 'val2')
|
||||||
|
|
||||||
|
|
||||||
def test_choiceoption_function():
|
def test_choiceoption_function():
|
||||||
ch = ChoiceOption('ch', '', values=return_list)
|
ch = ChoiceOption('ch', '', values=return_list)
|
||||||
od = OptionDescription('od', '', [ch])
|
od = OptionDescription('od', '', [ch])
|
||||||
|
|
|
@ -52,9 +52,9 @@ def make_description():
|
||||||
def test_base_config_name():
|
def test_base_config_name():
|
||||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||||
cfg = Config(descr, name='cfg')
|
cfg = Config(descr, session_id='cfg')
|
||||||
cfg.impl_getname() == 'cfg'
|
cfg.impl_getname() == 'cfg'
|
||||||
raises(ValueError, "Config(descr, name='unvalid name')")
|
raises(ValueError, "Config(descr, session_id='unvalid name')")
|
||||||
|
|
||||||
|
|
||||||
def test_not_config():
|
def test_not_config():
|
||||||
|
@ -403,6 +403,6 @@ def test_config_subconfig():
|
||||||
i4 = IntOption('i4', '', default=2)
|
i4 = IntOption('i4', '', default=2)
|
||||||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
conf1 = Config(od2, name='conf1')
|
conf1 = Config(od2, session_id='conf1')
|
||||||
conf1
|
conf1
|
||||||
raises(ConfigError, "conf2 = Config(od1, name='conf2')")
|
raises(ConfigError, "conf2 = Config(od1, session_id='conf2')")
|
||||||
|
|
|
@ -1306,9 +1306,9 @@ def test_state_config():
|
||||||
od = OptionDescription('od', '', [st])
|
od = OptionDescription('od', '', [st])
|
||||||
od2 = OptionDescription('od', '', [od, od1])
|
od2 = OptionDescription('od', '', [od, od1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(od2, persistent=True, session_id='29090938')
|
cfg = Config(od2, persistent=True, session_id='c29090938')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(od2, session_id='29090938')
|
cfg = Config(od2, session_id='c29090938')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
a = dumps(cfg)
|
a = dumps(cfg)
|
||||||
q = loads(a)
|
q = loads(a)
|
||||||
|
@ -1316,7 +1316,7 @@ def test_state_config():
|
||||||
_diff_conf(cfg, q)
|
_diff_conf(cfg, q)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090938')
|
delete_session('config', 'c29090938')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from py.test import raises
|
||||||
from tiramisu.setting import groups, owners
|
from tiramisu.setting import groups, owners
|
||||||
from tiramisu.config import Config, GroupConfig, MetaConfig
|
from tiramisu.config import Config, GroupConfig, MetaConfig
|
||||||
from tiramisu.option import IntOption, StrOption, NetworkOption, NetmaskOption, OptionDescription
|
from tiramisu.option import IntOption, StrOption, NetworkOption, NetmaskOption, OptionDescription
|
||||||
from tiramisu.error import ConfigError, ConflictError
|
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError
|
||||||
|
|
||||||
owners.addowner('meta')
|
owners.addowner('meta')
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ def make_description():
|
||||||
i6 = IntOption('i6', '', properties=('disabled',))
|
i6 = IntOption('i6', '', properties=('disabled',))
|
||||||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4, i5, i6])
|
od1 = OptionDescription('od1', '', [i1, i2, i3, i4, i5, i6])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
conf1 = Config(od2, name='conf1')
|
conf1 = Config(od2, session_id='conf3')
|
||||||
conf2 = Config(od2, name='conf2')
|
conf2 = Config(od2, session_id='conf4')
|
||||||
meta = MetaConfig([conf1, conf2], name='meta')
|
meta = MetaConfig([conf1, conf2], session_id='meta')
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
meta.cfgimpl_get_settings().setowner(owners.meta)
|
meta.cfgimpl_get_settings().setowner(owners.meta)
|
||||||
return meta
|
return meta
|
||||||
|
@ -184,28 +184,32 @@ def test_not_meta():
|
||||||
i1 = IntOption('i1', '')
|
i1 = IntOption('i1', '')
|
||||||
od1 = OptionDescription('od1', '', [i1])
|
od1 = OptionDescription('od1', '', [i1])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
conf1 = Config(od2, name='conf1')
|
conf1 = Config(od2, session_id='conf1')
|
||||||
conf2 = Config(od2, name='conf2')
|
conf2 = Config(od2, session_id='conf2')
|
||||||
conf3 = Config(od2)
|
conf3 = Config(od2)
|
||||||
conf4 = Config(od2, name='conf2')
|
try:
|
||||||
conf3, conf4
|
conf4 = Config(od2, session_id='conf2')
|
||||||
raises(ValueError, "GroupConfig(conf1)")
|
except ValueError:
|
||||||
#same name
|
pass
|
||||||
raises(ConflictError, "GroupConfig([conf2, conf4])")
|
else:
|
||||||
grp = GroupConfig([conf1, conf2])
|
conf3, conf4
|
||||||
raises(ConfigError, 'grp.od1.i1')
|
raises(ValueError, "GroupConfig(conf1)")
|
||||||
conf1, conf2 = grp.cfgimpl_get_children()
|
#same name
|
||||||
grp.set_value('od1.i1', 7)
|
raises(ConflictError, "GroupConfig([conf2, conf4])")
|
||||||
assert grp.conf1.od1.i1 == conf2.od1.i1 == 7
|
grp = GroupConfig([conf1, conf2])
|
||||||
assert grp.conf1.getowner(grp.conf1.unwrap_from_path('od1.i1')) is grp.conf2.getowner(grp.conf2.unwrap_from_path('od1.i1')) is owners.user
|
raises(ConfigError, 'grp.od1.i1')
|
||||||
|
conf1, conf2 = grp.cfgimpl_get_children()
|
||||||
|
grp.set_value('od1.i1', 7)
|
||||||
|
assert grp.conf1.od1.i1 == conf2.od1.i1 == 7
|
||||||
|
assert grp.conf1.getowner(grp.conf1.unwrap_from_path('od1.i1')) is grp.conf2.getowner(grp.conf2.unwrap_from_path('od1.i1')) is owners.user
|
||||||
|
|
||||||
|
|
||||||
def test_group_find_firsts():
|
def test_group_find_firsts():
|
||||||
i1 = IntOption('i1', '')
|
i1 = IntOption('i1', '')
|
||||||
od1 = OptionDescription('od1', '', [i1])
|
od1 = OptionDescription('od1', '', [i1])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
conf1 = Config(od2, name='conf1')
|
conf1 = Config(od2, session_id='conf1')
|
||||||
conf2 = Config(od2, name='conf2')
|
conf2 = Config(od2, session_id='conf2')
|
||||||
grp = GroupConfig([conf1, conf2])
|
grp = GroupConfig([conf1, conf2])
|
||||||
assert [conf1, conf2] == grp.find_firsts(byname='i1').cfgimpl_get_children()
|
assert [conf1, conf2] == grp.find_firsts(byname='i1').cfgimpl_get_children()
|
||||||
|
|
||||||
|
@ -214,15 +218,13 @@ def test_group_group():
|
||||||
i1 = IntOption('i1', '')
|
i1 = IntOption('i1', '')
|
||||||
od1 = OptionDescription('od1', '', [i1])
|
od1 = OptionDescription('od1', '', [i1])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
conf1 = Config(od2, name='conf1')
|
conf1 = Config(od2, session_id='conf9')
|
||||||
conf2 = Config(od2, name='conf2')
|
conf2 = Config(od2, session_id='conf10')
|
||||||
grp = GroupConfig([conf1, conf2])
|
|
||||||
raises(ValueError, "GroupConfig([grp])")
|
|
||||||
grp = GroupConfig([conf1, conf2], 'grp')
|
grp = GroupConfig([conf1, conf2], 'grp')
|
||||||
grp2 = GroupConfig([grp])
|
grp2 = GroupConfig([grp])
|
||||||
grp2.set_value('od1.i1', 2)
|
grp2.set_value('od1.i1', 2)
|
||||||
assert grp2.grp.conf1.od1.i1 == 2
|
assert grp2.grp.conf9.od1.i1 == 2
|
||||||
assert grp2.grp.conf1.getowner(i1) == owners.user
|
assert grp2.grp.conf9.getowner(i1) == owners.user
|
||||||
|
|
||||||
|
|
||||||
def test_meta_path():
|
def test_meta_path():
|
||||||
|
@ -239,10 +241,10 @@ def test_meta_unconsistent():
|
||||||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
od3 = OptionDescription('od3', '', [od1])
|
od3 = OptionDescription('od3', '', [od1])
|
||||||
conf1 = Config(od2, name='conf1')
|
conf1 = Config(od2, session_id='conf5')
|
||||||
conf2 = Config(od2, name='conf2')
|
conf2 = Config(od2, session_id='conf6')
|
||||||
conf3 = Config(od2, name='conf3')
|
conf3 = Config(od2, session_id='conf7')
|
||||||
conf4 = Config(od3, name='conf4')
|
conf4 = Config(od3, session_id='conf8')
|
||||||
conf3, conf4
|
conf3, conf4
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.cfgimpl_get_settings().setowner(owners.meta)
|
meta.cfgimpl_get_settings().setowner(owners.meta)
|
||||||
|
@ -251,7 +253,7 @@ def test_meta_unconsistent():
|
||||||
raises(ValueError, "MetaConfig([conf1, conf3])")
|
raises(ValueError, "MetaConfig([conf1, conf3])")
|
||||||
#not same descr
|
#not same descr
|
||||||
raises(ValueError, "MetaConfig([conf3, conf4])")
|
raises(ValueError, "MetaConfig([conf3, conf4])")
|
||||||
raises(ConfigError, "meta.conf1.read_only()")
|
raises(ConfigError, "meta.conf5.read_only()")
|
||||||
|
|
||||||
|
|
||||||
def test_meta_master_slaves():
|
def test_meta_master_slaves():
|
||||||
|
@ -259,8 +261,8 @@ def test_meta_master_slaves():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_only()
|
meta.read_only()
|
||||||
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0').cfgimpl_get_children()
|
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0').cfgimpl_get_children()
|
||||||
|
@ -277,8 +279,8 @@ def test_meta_master_slaves_value():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.conf1.ip_admin_eth0 = ['192.168.1.1']
|
meta.conf1.ip_admin_eth0 = ['192.168.1.1']
|
||||||
assert meta.conf1.netmask_admin_eth0 == [None]
|
assert meta.conf1.netmask_admin_eth0 == [None]
|
||||||
|
@ -299,8 +301,8 @@ def test_meta_master_slaves_value_default():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
assert meta.conf1.netmask_admin_eth0 == [None]
|
assert meta.conf1.netmask_admin_eth0 == [None]
|
||||||
meta.ip_admin_eth0 = ['192.168.1.1']
|
meta.ip_admin_eth0 = ['192.168.1.1']
|
||||||
|
@ -318,8 +320,8 @@ def test_meta_master_slaves_owners():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.cfgimpl_get_settings().setowner(owners.meta)
|
meta.cfgimpl_get_settings().setowner(owners.meta)
|
||||||
assert meta.conf1.getowner(ip_admin_eth0) == owners.default
|
assert meta.conf1.getowner(ip_admin_eth0) == owners.default
|
||||||
|
@ -349,9 +351,9 @@ def test_meta_force_default():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
@ -382,9 +384,9 @@ def test_meta_force_dont_change_value():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
@ -410,9 +412,9 @@ def test_meta_force_default_if_same():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
@ -452,9 +454,9 @@ def test_meta_force_default_if_same_and_dont_change():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
@ -494,9 +496,9 @@ def test_meta_force_default_and_dont_change():
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
@ -510,9 +512,9 @@ def test_meta_properties_meta():
|
||||||
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
@ -525,9 +527,9 @@ def test_meta_exception_meta():
|
||||||
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
||||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
@ -541,7 +543,7 @@ def test_meta_callback():
|
||||||
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
||||||
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)})
|
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)})
|
||||||
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
||||||
cfg = Config(maconfig, name='cfg')
|
cfg = Config(maconfig, session_id='cfg')
|
||||||
meta = MetaConfig([cfg])
|
meta = MetaConfig([cfg])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
assert meta.cfg.make_dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
|
assert meta.cfg.make_dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
|
||||||
|
@ -567,7 +569,7 @@ def test_meta_callback_slave():
|
||||||
interface1 = OptionDescription('val1', '', [val1, val3, val4])
|
interface1 = OptionDescription('val1', '', [val1, val3, val4])
|
||||||
interface1.impl_set_group_type(groups.master)
|
interface1.impl_set_group_type(groups.master)
|
||||||
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
||||||
cfg = Config(maconfig, name='cfg')
|
cfg = Config(maconfig, session_id='cfg')
|
||||||
meta = MetaConfig([cfg])
|
meta = MetaConfig([cfg])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
assert meta.cfg.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
assert meta.cfg.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||||
|
@ -599,3 +601,42 @@ def test_meta_callback_slave():
|
||||||
assert meta.cfg.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
assert meta.cfg.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
||||||
meta.val1.val1 = ['val4']
|
meta.val1.val1 = ['val4']
|
||||||
assert meta.cfg.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
assert meta.cfg.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_meta_properties_meta_set_value():
|
||||||
|
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||||
|
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
|
meta = MetaConfig([conf1, conf2])
|
||||||
|
meta.read_write()
|
||||||
|
assert conf1.make_dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
||||||
|
ret = meta.set_value('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
|
||||||
|
assert len(ret) == 2
|
||||||
|
assert isinstance(ret[0], PropertiesOptionError)
|
||||||
|
assert isinstance(ret[1], PropertiesOptionError)
|
||||||
|
ret = meta.set_value('netmask_admin_eth0', ['255.255.255.255'], force_default=True)
|
||||||
|
assert len(ret) == 1
|
||||||
|
assert isinstance(ret[0], PropertiesOptionError)
|
||||||
|
ret = meta.set_value('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True)
|
||||||
|
assert len(ret) == 3
|
||||||
|
assert isinstance(ret[0], PropertiesOptionError)
|
||||||
|
assert isinstance(ret[1], PropertiesOptionError)
|
||||||
|
assert isinstance(ret[2], PropertiesOptionError)
|
||||||
|
ret = meta.set_value('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True)
|
||||||
|
assert len(ret) == 1
|
||||||
|
assert isinstance(ret[0], PropertiesOptionError)
|
||||||
|
ret = meta.set_value('ip_admin_eth0', '255.255.255.255', only_config=True)
|
||||||
|
assert len(ret) == 2
|
||||||
|
assert isinstance(ret[0], ValueError)
|
||||||
|
assert isinstance(ret[1], ValueError)
|
||||||
|
ret = meta.set_value('ip_admin_eth0', '255.255.255.255', force_default=True)
|
||||||
|
assert len(ret) == 1
|
||||||
|
assert isinstance(ret[0], ValueError)
|
||||||
|
ret = meta.set_value('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True)
|
||||||
|
assert len(ret) == 1
|
||||||
|
assert isinstance(ret[0], ValueError)
|
||||||
|
ret = meta.set_value('ip_admin_eth0', '255.255.255.255', force_default_if_same=True)
|
||||||
|
assert len(ret) == 1
|
||||||
|
assert isinstance(ret[0], ValueError)
|
||||||
|
|
|
@ -207,6 +207,9 @@ def _diff_conf(cfg1, cfg2):
|
||||||
elif attr == '_impl_children':
|
elif attr == '_impl_children':
|
||||||
for index, _opt in enumerate(val1):
|
for index, _opt in enumerate(val1):
|
||||||
_diff_conf(_opt, val2[index])
|
_diff_conf(_opt, val2[index])
|
||||||
|
elif attr == '_impl_name':
|
||||||
|
#FIXME
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
assert val1 == val2
|
assert val1 == val2
|
||||||
|
|
||||||
|
@ -256,9 +259,9 @@ def test_diff_information_config():
|
||||||
o = OptionDescription('o', '', [b])
|
o = OptionDescription('o', '', [b])
|
||||||
o1 = OptionDescription('o1', '', [o])
|
o1 = OptionDescription('o1', '', [o])
|
||||||
try:
|
try:
|
||||||
cfg = Config(o1, persistent=True, session_id='29090938')
|
cfg = Config(o1, persistent=True, session_id='c29090938')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(o1, session_id='29090938')
|
cfg = Config(o1, session_id='c29090938')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
cfg.impl_set_information('info', 'oh')
|
cfg.impl_set_information('info', 'oh')
|
||||||
|
|
||||||
|
@ -269,7 +272,7 @@ def test_diff_information_config():
|
||||||
assert cfg.impl_get_information('info') == 'oh'
|
assert cfg.impl_get_information('info') == 'oh'
|
||||||
assert q.impl_get_information('info') == 'oh'
|
assert q.impl_get_information('info') == 'oh'
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090938')
|
delete_session('config', 'c29090938')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -341,16 +344,16 @@ def test_state_config():
|
||||||
val1 = BoolOption('val1', "")
|
val1 = BoolOption('val1', "")
|
||||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(maconfig, persistent=True, session_id='29090931')
|
cfg = Config(maconfig, persistent=True, session_id='c29090931')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(maconfig, session_id='29090931')
|
cfg = Config(maconfig, session_id='c29090931')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
a = dumps(cfg)
|
a = dumps(cfg)
|
||||||
q = loads(a)
|
q = loads(a)
|
||||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||||
_diff_conf(cfg, q)
|
_diff_conf(cfg, q)
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090931')
|
delete_session('config', 'c29090931')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -370,16 +373,16 @@ def test_state_config2():
|
||||||
od = OptionDescription('od', '', [st])
|
od = OptionDescription('od', '', [st])
|
||||||
od2 = OptionDescription('od', '', [od, od1])
|
od2 = OptionDescription('od', '', [od, od1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(od2, persistent=True, session_id='29090939')
|
cfg = Config(od2, persistent=True, session_id='c29090939')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(od2, session_id='29090939')
|
cfg = Config(od2, session_id='c29090939')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
a = dumps(cfg)
|
a = dumps(cfg)
|
||||||
q = loads(a)
|
q = loads(a)
|
||||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||||
_diff_conf(cfg, q)
|
_diff_conf(cfg, q)
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090939')
|
delete_session('config', 'c29090939')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -391,9 +394,9 @@ def test_diff_opt_value():
|
||||||
o = OptionDescription('o', '', [b, u, s])
|
o = OptionDescription('o', '', [b, u, s])
|
||||||
o1 = OptionDescription('o1', '', [o])
|
o1 = OptionDescription('o1', '', [o])
|
||||||
try:
|
try:
|
||||||
cfg = Config(o1, persistent=True, session_id='29090941')
|
cfg = Config(o1, persistent=True, session_id='c29090941')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(o1, session_id='29090941')
|
cfg = Config(o1, session_id='c29090941')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
|
|
||||||
a = dumps(cfg)
|
a = dumps(cfg)
|
||||||
|
@ -401,7 +404,7 @@ def test_diff_opt_value():
|
||||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||||
_diff_conf(cfg, q)
|
_diff_conf(cfg, q)
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090941')
|
delete_session('config', 'c29090941')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -416,9 +419,9 @@ def test_diff_opt_config():
|
||||||
o = OptionDescription('o', '', [b, u, s])
|
o = OptionDescription('o', '', [b, u, s])
|
||||||
o1 = OptionDescription('o1', '', [o])
|
o1 = OptionDescription('o1', '', [o])
|
||||||
try:
|
try:
|
||||||
cfg = Config(o1, persistent=True, session_id='29090940')
|
cfg = Config(o1, persistent=True, session_id='c29090940')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(o1, session_id='29090940')
|
cfg = Config(o1, session_id='c29090940')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
|
|
||||||
a = dumps(cfg)
|
a = dumps(cfg)
|
||||||
|
@ -426,7 +429,7 @@ def test_diff_opt_config():
|
||||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||||
_diff_conf(cfg, q)
|
_diff_conf(cfg, q)
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090940')
|
delete_session('config', 'c29090940')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -435,9 +438,9 @@ def test_state_properties():
|
||||||
val1 = BoolOption('val1', "")
|
val1 = BoolOption('val1', "")
|
||||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(maconfig, persistent=True, session_id='29090932')
|
cfg = Config(maconfig, persistent=True, session_id='c29090932')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(maconfig, session_id='29090932')
|
cfg = Config(maconfig, session_id='c29090932')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
cfg.read_write()
|
cfg.read_write()
|
||||||
cfg.cfgimpl_get_settings()[val1].append('test')
|
cfg.cfgimpl_get_settings()[val1].append('test')
|
||||||
|
@ -445,7 +448,7 @@ def test_state_properties():
|
||||||
q = loads(a)
|
q = loads(a)
|
||||||
_diff_conf(cfg, q)
|
_diff_conf(cfg, q)
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090932')
|
delete_session('config', 'c29090932')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -454,9 +457,9 @@ def test_state_values():
|
||||||
val1 = BoolOption('val1', "")
|
val1 = BoolOption('val1', "")
|
||||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(maconfig, persistent=True, session_id='29090933')
|
cfg = Config(maconfig, persistent=True, session_id='c29090933')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(maconfig, session_id='29090933')
|
cfg = Config(maconfig, session_id='c29090933')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
cfg.val1 = True
|
cfg.val1 = True
|
||||||
a = dumps(cfg)
|
a = dumps(cfg)
|
||||||
|
@ -466,7 +469,7 @@ def test_state_values():
|
||||||
assert cfg.val1 is True
|
assert cfg.val1 is True
|
||||||
assert q.val1 is False
|
assert q.val1 is False
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090933')
|
delete_session('config', 'c29090933')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -475,9 +478,9 @@ def test_state_values_owner():
|
||||||
val1 = BoolOption('val1', "")
|
val1 = BoolOption('val1', "")
|
||||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(maconfig, persistent=True, session_id='29090934')
|
cfg = Config(maconfig, persistent=True, session_id='c29090934')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
cfg = Config(maconfig, session_id='29090934')
|
cfg = Config(maconfig, session_id='c29090934')
|
||||||
cfg._impl_test = True
|
cfg._impl_test = True
|
||||||
owners.addowner('newowner')
|
owners.addowner('newowner')
|
||||||
cfg.cfgimpl_get_settings().setowner(owners.newowner)
|
cfg.cfgimpl_get_settings().setowner(owners.newowner)
|
||||||
|
@ -489,7 +492,7 @@ def test_state_values_owner():
|
||||||
nval1 = q.cfgimpl_get_description().val1
|
nval1 = q.cfgimpl_get_description().val1
|
||||||
assert q.getowner(nval1) == owners.newowner
|
assert q.getowner(nval1) == owners.newowner
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090934')
|
delete_session('config', 'c29090934')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -499,17 +502,17 @@ def test_state_metaconfig():
|
||||||
od1 = OptionDescription('od1', '', [i1])
|
od1 = OptionDescription('od1', '', [i1])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(od2, persistent=True, session_id='29090935')
|
cfg = Config(od2, persistent=True, session_id='c29090935')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
conf1 = Config(od2, session_id='29090935')
|
conf1 = Config(od2, session_id='c29090935')
|
||||||
conf1._impl_test = True
|
conf1._impl_test = True
|
||||||
conf2 = Config(od2, session_id='29090936')
|
conf2 = Config(od2, session_id='c29090936')
|
||||||
conf2._impl_test = True
|
conf2._impl_test = True
|
||||||
meta = MetaConfig([conf1, conf2], session_id='29090937')
|
meta = MetaConfig([conf1, conf2], session_id='c29090937')
|
||||||
meta._impl_test = True
|
meta._impl_test = True
|
||||||
raises(ConfigError, "dumps(meta)")
|
raises(ConfigError, "dumps(meta)")
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090935')
|
delete_session('config', 'c29090935')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -519,19 +522,19 @@ def test_state_groupconfig():
|
||||||
od1 = OptionDescription('od1', '', [i1])
|
od1 = OptionDescription('od1', '', [i1])
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
try:
|
try:
|
||||||
cfg = Config(od2, persistent=True, session_id='29090938')
|
cfg = Config(od2, persistent=True, session_id='c29090938')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
conf1 = Config(od2, session_id='29090938')
|
conf1 = Config(od2, session_id='c29090938')
|
||||||
conf1._impl_test = True
|
conf1._impl_test = True
|
||||||
conf2 = Config(od2, session_id='29090939')
|
conf2 = Config(od2, session_id='c29090939')
|
||||||
conf2._impl_test = True
|
conf2._impl_test = True
|
||||||
meta = GroupConfig([conf1, conf2], session_id='29090940')
|
meta = GroupConfig([conf1, conf2], session_id='c29090940')
|
||||||
meta._impl_test = True
|
meta._impl_test = True
|
||||||
a = dumps(meta)
|
a = dumps(meta)
|
||||||
q = loads(a)
|
q = loads(a)
|
||||||
_diff_conf(meta, q)
|
_diff_conf(meta, q)
|
||||||
try:
|
try:
|
||||||
delete_session('config', '29090938')
|
delete_session('config', 'c29090938')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -684,9 +684,9 @@ def test_submulti_unique():
|
||||||
def test_multi_submulti_meta():
|
def test_multi_submulti_meta():
|
||||||
multi = StrOption('multi', '', multi=submulti)
|
multi = StrOption('multi', '', multi=submulti)
|
||||||
od = OptionDescription('od', '', [multi])
|
od = OptionDescription('od', '', [multi])
|
||||||
conf1 = Config(od, name='conf1')
|
conf1 = Config(od, session_id='conf1')
|
||||||
conf1.read_write()
|
conf1.read_write()
|
||||||
conf2 = Config(od, name='conf2')
|
conf2 = Config(od, session_id='conf2')
|
||||||
conf2.read_write()
|
conf2.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.read_write()
|
meta.read_write()
|
||||||
|
|
|
@ -317,11 +317,13 @@ class SubConfig(object):
|
||||||
_commit=_commit)
|
_commit=_commit)
|
||||||
else:
|
else:
|
||||||
subpath = self._get_subpath(name)
|
subpath = self._get_subpath(name)
|
||||||
self.cfgimpl_get_values().setitem(child, value, subpath,
|
ret = self.cfgimpl_get_values().setitem(child, value, subpath,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
not_raises=not_raises, index=index,
|
not_raises=not_raises, index=index,
|
||||||
_setting_properties=_setting_properties,
|
_setting_properties=_setting_properties,
|
||||||
_commit=_commit)
|
_commit=_commit)
|
||||||
|
if ret is not None:
|
||||||
|
return ret
|
||||||
|
|
||||||
def __delattr__(self, name):
|
def __delattr__(self, name):
|
||||||
context = self._cfgimpl_get_context()
|
context = self._cfgimpl_get_context()
|
||||||
|
@ -781,8 +783,8 @@ class Config(_CommonConfig):
|
||||||
__slots__ = ('__weakref__', '_impl_test', '_impl_name')
|
__slots__ = ('__weakref__', '_impl_test', '_impl_name')
|
||||||
|
|
||||||
def __init__(self, descr, session_id=None, persistent=False,
|
def __init__(self, descr, session_id=None, persistent=False,
|
||||||
name=undefined, force_values=None, force_settings=None,
|
force_values=None, force_settings=None,
|
||||||
_duplicate=False, mandatory_name=False, _force_store_values=True):
|
_duplicate=False, _force_store_values=True):
|
||||||
""" Configuration option management master class
|
""" Configuration option management master class
|
||||||
|
|
||||||
:param descr: describes the configuration schema
|
:param descr: describes the configuration schema
|
||||||
|
@ -802,15 +804,9 @@ class Config(_CommonConfig):
|
||||||
self._impl_settings = force_settings
|
self._impl_settings = force_settings
|
||||||
self._impl_values = Values(self, force_values)
|
self._impl_values = Values(self, force_values)
|
||||||
else:
|
else:
|
||||||
properties, permissives, values = get_storages(self, session_id, persistent)
|
properties, permissives, values, session_id = get_storages(self, session_id, persistent)
|
||||||
if name is undefined:
|
if not valid_name(session_id): # pragma: optional cover
|
||||||
name = 'config'
|
raise ValueError(_("invalid session ID: {0} for config").format(session_id))
|
||||||
if session_id is not None:
|
|
||||||
name += session_id
|
|
||||||
if mandatory_name and name is None:
|
|
||||||
raise ValueError(_("name is mandatory for the config").format(name))
|
|
||||||
if name is not None and not valid_name(name): # pragma: optional cover
|
|
||||||
raise ValueError(_("invalid name: {0} for config").format(name))
|
|
||||||
self._impl_settings = Settings(self, properties, permissives)
|
self._impl_settings = Settings(self, properties, permissives)
|
||||||
self._impl_values = Values(self, values)
|
self._impl_values = Values(self, values)
|
||||||
super(Config, self).__init__(descr, weakref.ref(self))
|
super(Config, self).__init__(descr, weakref.ref(self))
|
||||||
|
@ -819,7 +815,7 @@ class Config(_CommonConfig):
|
||||||
self._impl_test = False
|
self._impl_test = False
|
||||||
if _duplicate is False and (force_settings is None or force_values is None):
|
if _duplicate is False and (force_settings is None or force_values is None):
|
||||||
self._impl_build_all_caches(_force_store_values)
|
self._impl_build_all_caches(_force_store_values)
|
||||||
self._impl_name = name
|
self._impl_name = session_id
|
||||||
|
|
||||||
def impl_getname(self):
|
def impl_getname(self):
|
||||||
return self._impl_name
|
return self._impl_name
|
||||||
|
@ -832,7 +828,7 @@ class GroupConfig(_CommonConfig):
|
||||||
__slots__ = ('__weakref__', '_impl_children', '_impl_name')
|
__slots__ = ('__weakref__', '_impl_children', '_impl_name')
|
||||||
|
|
||||||
def __init__(self, children, session_id=None, persistent=False,
|
def __init__(self, children, session_id=None, persistent=False,
|
||||||
_descr=None, name=undefined):
|
_descr=None):
|
||||||
if not isinstance(children, list):
|
if not isinstance(children, list):
|
||||||
raise ValueError(_("groupconfig's children must be a list"))
|
raise ValueError(_("groupconfig's children must be a list"))
|
||||||
names = []
|
names = []
|
||||||
|
@ -850,16 +846,14 @@ class GroupConfig(_CommonConfig):
|
||||||
raise ConflictError(_('config name must be uniq in '
|
raise ConflictError(_('config name must be uniq in '
|
||||||
'groupconfig for {0}').format(name))
|
'groupconfig for {0}').format(name))
|
||||||
self._impl_children = children
|
self._impl_children = children
|
||||||
properties, permissives, values = get_storages(self, session_id, persistent)
|
properties, permissives, values, session_id = get_storages(self, session_id, persistent)
|
||||||
self._impl_settings = Settings(self, properties, permissives)
|
self._impl_settings = Settings(self, properties, permissives)
|
||||||
self._impl_values = Values(self, values)
|
self._impl_values = Values(self, values)
|
||||||
super(GroupConfig, self).__init__(_descr, weakref.ref(self))
|
super(GroupConfig, self).__init__(_descr, weakref.ref(self))
|
||||||
self._impl_meta = None
|
self._impl_meta = None
|
||||||
#undocumented option used only in test script
|
#undocumented option used only in test script
|
||||||
self._impl_test = False
|
self._impl_test = False
|
||||||
if name is undefined:
|
self._impl_name = session_id
|
||||||
name = session_id
|
|
||||||
self._impl_name = name
|
|
||||||
|
|
||||||
def cfgimpl_get_children(self):
|
def cfgimpl_get_children(self):
|
||||||
return self._impl_children
|
return self._impl_children
|
||||||
|
@ -877,15 +871,19 @@ class GroupConfig(_CommonConfig):
|
||||||
def set_value(self, path, value, _commit=True):
|
def set_value(self, path, value, _commit=True):
|
||||||
"""Setattr not in current GroupConfig, but in each children
|
"""Setattr not in current GroupConfig, but in each children
|
||||||
"""
|
"""
|
||||||
|
ret = []
|
||||||
for child in self._impl_children:
|
for child in self._impl_children:
|
||||||
if isinstance(child, MetaConfig):
|
if isinstance(child, MetaConfig):
|
||||||
child.set_value(path, value, only_config=True, _commit=False)
|
ret.extend(child.set_value(path, value, only_config=True, _commit=False))
|
||||||
elif isinstance(child, GroupConfig):
|
elif isinstance(child, GroupConfig):
|
||||||
child.set_value(path, value, _commit=False)
|
ret.extend(child.set_value(path, value, _commit=False))
|
||||||
else:
|
else:
|
||||||
child.setattr(path, value, not_raises=True, _commit=False)
|
childret = child.setattr(path, value, not_raises=True, _commit=False)
|
||||||
|
if childret is not None:
|
||||||
|
ret.append(childret)
|
||||||
if _commit:
|
if _commit:
|
||||||
self.cfgimpl_get_values()._p_.commit()
|
self.cfgimpl_get_values()._p_.commit()
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def find_firsts(self, byname=None, bypath=undefined, byoption=undefined,
|
def find_firsts(self, byname=None, bypath=undefined, byoption=undefined,
|
||||||
|
@ -953,7 +951,7 @@ class MetaConfig(GroupConfig):
|
||||||
__slots__ = tuple()
|
__slots__ = tuple()
|
||||||
|
|
||||||
def __init__(self, children, session_id=None, persistent=False,
|
def __init__(self, children, session_id=None, persistent=False,
|
||||||
name=undefined, optiondescription=None):
|
optiondescription=None):
|
||||||
descr = None
|
descr = None
|
||||||
if optiondescription is not None:
|
if optiondescription is not None:
|
||||||
new_children = []
|
new_children = []
|
||||||
|
@ -977,7 +975,7 @@ class MetaConfig(GroupConfig):
|
||||||
child._impl_meta = weakref.ref(self)
|
child._impl_meta = weakref.ref(self)
|
||||||
|
|
||||||
super(MetaConfig, self).__init__(children, session_id, persistent,
|
super(MetaConfig, self).__init__(children, session_id, persistent,
|
||||||
descr, name)
|
descr)
|
||||||
|
|
||||||
def set_value(self, path, value, force_default=False,
|
def set_value(self, path, value, force_default=False,
|
||||||
force_dont_change_value=False, force_default_if_same=False,
|
force_dont_change_value=False, force_default_if_same=False,
|
||||||
|
@ -991,6 +989,7 @@ class MetaConfig(GroupConfig):
|
||||||
'force_dont_change_value cannot be set with'
|
'force_dont_change_value cannot be set with'
|
||||||
' only_config'))
|
' only_config'))
|
||||||
return super(MetaConfig, self).set_value(path, value, _commit=_commit)
|
return super(MetaConfig, self).set_value(path, value, _commit=_commit)
|
||||||
|
ret = []
|
||||||
if force_default or force_default_if_same or force_dont_change_value:
|
if force_default or force_default_if_same or force_dont_change_value:
|
||||||
if force_default and force_dont_change_value:
|
if force_default and force_dont_change_value:
|
||||||
raise ValueError(_('force_default and force_dont_change_value'
|
raise ValueError(_('force_default and force_dont_change_value'
|
||||||
|
@ -1005,18 +1004,40 @@ class MetaConfig(GroupConfig):
|
||||||
else:
|
else:
|
||||||
child_value = child.getattr(path)
|
child_value = child.getattr(path)
|
||||||
if force_default or value == child_value:
|
if force_default or value == child_value:
|
||||||
child.cfgimpl_get_values().reset(opt, path=path,
|
childret = child.cfgimpl_get_values().reset(opt, path=path,
|
||||||
validate=False,
|
validate=False,
|
||||||
_setting_properties=setting_properties,
|
_setting_properties=setting_properties,
|
||||||
_commit=False)
|
_commit=False)
|
||||||
|
if childret is not None:
|
||||||
|
ret.append(childret)
|
||||||
continue
|
continue
|
||||||
if force_dont_change_value:
|
if force_dont_change_value:
|
||||||
child_value = child.getattr(path, _setting_properties=setting_properties)
|
child_value = child.getattr(path, _setting_properties=setting_properties,
|
||||||
if value != child_value:
|
returns_raise=True)
|
||||||
child.setattr(path, child_value, _commit=False)
|
if isinstance(child_value, Exception):
|
||||||
|
ret.append(child_value)
|
||||||
|
elif value != child_value:
|
||||||
|
childret = child.setattr(path, child_value, _commit=False, not_raises=True)
|
||||||
|
if childret is not None:
|
||||||
|
ret.append(childret)
|
||||||
|
|
||||||
self.setattr(path, value, _commit=_commit)
|
setret = self.setattr(path, value, _commit=_commit, not_raises=True)
|
||||||
|
if setret is not None:
|
||||||
|
ret.append(setret)
|
||||||
|
return ret
|
||||||
|
|
||||||
def new_config(self, session_id=None, persistent=False, name=undefined):
|
def reset(self, path):
|
||||||
return Config(self._impl_descr, _duplicate=True, session_id=session_id, name=name,
|
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
|
||||||
persistent=persistent, mandatory_name=True)
|
setting_properties = self.cfgimpl_get_settings()._getproperties(read_write=False)
|
||||||
|
for child in self._impl_children:
|
||||||
|
child.cfgimpl_get_values().reset(opt, path=path,
|
||||||
|
validate=False,
|
||||||
|
_setting_properties=setting_properties,
|
||||||
|
_commit=False)
|
||||||
|
self.cfgimpl_get_values().reset(opt, path=path,
|
||||||
|
validate=False,
|
||||||
|
_setting_properties=setting_properties)
|
||||||
|
|
||||||
|
def new_config(self, session_id=None, persistent=False):
|
||||||
|
return Config(self._impl_descr, session_id=session_id,
|
||||||
|
persistent=persistent)
|
||||||
|
|
|
@ -34,6 +34,8 @@ def display_list(lst, separator='and'):
|
||||||
ret = str(ret)
|
ret = str(ret)
|
||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
|
if isinstance(lst, tuple):
|
||||||
|
lst = list(lst)
|
||||||
lst.sort()
|
lst.sort()
|
||||||
lst_ = []
|
lst_ = []
|
||||||
for l in lst[:-1]:
|
for l in lst[:-1]:
|
||||||
|
|
|
@ -42,7 +42,7 @@ if sys.version_info[0] >= 3: # pragma: no cover
|
||||||
|
|
||||||
StorageBase = get_storages_option('base')
|
StorageBase = get_storages_option('base')
|
||||||
submulti = 2
|
submulti = 2
|
||||||
name_regexp = re.compile(r'^[a-z][a-zA-Z\d\-_]*$')
|
name_regexp = re.compile(r'^[a-z][a-zA-Z\d_]*$')
|
||||||
forbidden_names = frozenset(['iter_all', 'iter_group', 'find', 'find_first',
|
forbidden_names = frozenset(['iter_all', 'iter_group', 'find', 'find_first',
|
||||||
'make_dict', 'unwrap_from_path', 'read_only',
|
'make_dict', 'unwrap_from_path', 'read_only',
|
||||||
'read_write', 'getowner', 'set_contexts'])
|
'read_write', 'getowner', 'set_contexts'])
|
||||||
|
|
|
@ -127,7 +127,7 @@ def get_storage(type_, session_id, persistent, test): # pragma: optional cover
|
||||||
|
|
||||||
def get_storages(context, session_id, persistent):
|
def get_storages(context, session_id, persistent):
|
||||||
def gen_id(config):
|
def gen_id(config):
|
||||||
return str(id(config)) + str(time()) + str(randint(0, 500))
|
return 'c' + str(id(config)) + str(int(time())) + str(randint(0, 500))
|
||||||
|
|
||||||
if session_id is None:
|
if session_id is None:
|
||||||
session_id = gen_id(context)
|
session_id = gen_id(context)
|
||||||
|
@ -136,7 +136,7 @@ def get_storages(context, session_id, persistent):
|
||||||
properties = imp.Properties(storage)
|
properties = imp.Properties(storage)
|
||||||
permissives = imp.Permissives(storage)
|
permissives = imp.Permissives(storage)
|
||||||
values = imp.Values(storage)
|
values = imp.Values(storage)
|
||||||
return properties, permissives, values
|
return properties, permissives, values, session_id
|
||||||
|
|
||||||
|
|
||||||
def get_storages_option(type_):
|
def get_storages_option(type_):
|
||||||
|
|
|
@ -93,7 +93,6 @@ class Storage(object):
|
||||||
self.execute(permissives_table)
|
self.execute(permissives_table)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
#print('ca commit')
|
|
||||||
self._conn.commit()
|
self._conn.commit()
|
||||||
|
|
||||||
def execute(self, sql, params=None, commit=True):
|
def execute(self, sql, params=None, commit=True):
|
||||||
|
|
|
@ -429,10 +429,12 @@ class Values(object):
|
||||||
session=session, not_raises=not_raises,
|
session=session, not_raises=not_raises,
|
||||||
index=index)
|
index=index)
|
||||||
if props and not_raises:
|
if props and not_raises:
|
||||||
return
|
return props
|
||||||
err = opt.impl_validate(value, fake_context, display_warnings=False, force_index=index,
|
err = opt.impl_validate(value, fake_context, display_warnings=False, force_index=index,
|
||||||
setting_properties=_setting_properties)
|
setting_properties=_setting_properties)
|
||||||
if err:
|
if err:
|
||||||
|
if not_raises:
|
||||||
|
return err
|
||||||
raise err
|
raise err
|
||||||
opt.impl_validate(value, fake_context, display_error=False,
|
opt.impl_validate(value, fake_context, display_error=False,
|
||||||
setting_properties=_setting_properties)
|
setting_properties=_setting_properties)
|
||||||
|
|
Loading…
Reference in New Issue