739 lines
43 KiB
Python
739 lines
43 KiB
Python
from .autopath import do_autopath
|
|
do_autopath()
|
|
|
|
from py.test import raises
|
|
|
|
from tiramisu.setting import groups, owners
|
|
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
|
|
OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \
|
|
Params, ParamOption, ParamValue
|
|
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, SlaveError
|
|
|
|
owners.addowner('meta1')
|
|
owners.addowner('meta2')
|
|
|
|
|
|
def return_value(value=None):
|
|
return value
|
|
|
|
|
|
def raise_exception():
|
|
raise Exception('test')
|
|
|
|
|
|
def make_description():
|
|
i1 = IntOption('i1', '')
|
|
i2 = IntOption('i2', '', default=1)
|
|
i3 = IntOption('i3', '')
|
|
i4 = IntOption('i4', '', default=2)
|
|
i5 = IntOption('i5', '', default=[2], multi=True)
|
|
i6 = IntOption('i6', '', properties=('disabled',))
|
|
od1 = OptionDescription('od1', '', [i1, i2, i3, i4, i5, i6])
|
|
od2 = OptionDescription('od2', '', [od1])
|
|
return od2
|
|
|
|
|
|
def make_metaconfig(double=False):
|
|
od2 = make_description()
|
|
conf1 = Config(od2, session_id='conf1')
|
|
conf2 = Config(od2, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2], session_id='meta')
|
|
if double:
|
|
meta.owner.set(owners.meta2)
|
|
meta = MetaConfig([meta], session_id='doublemeta')
|
|
meta.property.read_write()
|
|
meta.owner.set(owners.meta1)
|
|
return meta
|
|
|
|
|
|
def test_unknown_config():
|
|
meta = make_metaconfig()
|
|
raises(ConfigError, "meta.config('unknown')")
|
|
|
|
|
|
#FIXME ne pas mettre 2 meta dans une config
|
|
#FIXME ne pas mettre 2 OD differents dans un meta
|
|
def test_none():
|
|
meta = make_metaconfig()
|
|
assert meta.option('od1.i3').value.get() is meta.config('conf1').option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None
|
|
assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default
|
|
#
|
|
meta.option('od1.i3').value.set(3)
|
|
assert meta.option('od1.i3').value.get() == meta.config('conf1').option('od1.i3').value.get() == meta.config('conf2').option('od1.i3').value.get() == 3
|
|
assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.meta1
|
|
#
|
|
meta.config('conf1').option('od1.i3').value.set(2)
|
|
assert meta.option('od1.i3').value.get() == meta.config('conf2').option('od1.i3').value.get() == 3
|
|
assert meta.config('conf1').option('od1.i3').value.get() == 2
|
|
assert meta.option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.meta1
|
|
assert meta.config('conf1').option('od1.i3').owner.get() is owners.user
|
|
#
|
|
meta.option('od1.i3').value.set(4)
|
|
assert meta.option('od1.i3').value.get() == meta.config('conf2').option('od1.i3').value.get() == 4
|
|
assert meta.config('conf1').option('od1.i3').value.get() == 2
|
|
assert meta.option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.meta1
|
|
assert meta.config('conf1').option('od1.i3').owner.get() is owners.user
|
|
#
|
|
meta.option('od1.i3').value.reset()
|
|
assert meta.option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None
|
|
assert meta.config('conf1').option('od1.i3').value.get() == 2
|
|
assert meta.option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default
|
|
assert meta.config('conf1').option('od1.i3').owner.get() is owners.user
|
|
#
|
|
meta.config('conf1').option('od1.i3').value.reset()
|
|
assert meta.option('od1.i3').value.get() is meta.config('conf1').option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None
|
|
assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default
|
|
|
|
|
|
def test_default():
|
|
meta = make_metaconfig()
|
|
assert meta.option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 1
|
|
assert meta.option('od1.i2').owner.get() is meta.config('conf1').option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.default
|
|
#
|
|
meta.option('od1.i2').value.set(3)
|
|
assert meta.option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 3
|
|
assert meta.option('od1.i2').owner.get() is meta.config('conf1').option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.meta1
|
|
#
|
|
meta.config('conf1').option('od1.i2').value.set(2)
|
|
assert meta.option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 3
|
|
assert meta.config('conf1').option('od1.i2').value.get() == 2
|
|
assert meta.option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.meta1
|
|
assert meta.config('conf1').option('od1.i2').owner.get() is owners.user
|
|
#
|
|
meta.option('od1.i2').value.set(4)
|
|
assert meta.option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 4
|
|
assert meta.config('conf1').option('od1.i2').value.get() == 2
|
|
assert meta.option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.meta1
|
|
assert meta.config('conf1').option('od1.i2').owner.get() is owners.user
|
|
#
|
|
meta.option('od1.i2').value.reset()
|
|
assert meta.option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 1
|
|
assert meta.config('conf1').option('od1.i2').value.get() == 2
|
|
assert meta.option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.default
|
|
assert meta.config('conf1').option('od1.i2').owner.get() is owners.user
|
|
#
|
|
meta.config('conf1').option('od1.i2').value.reset()
|
|
assert meta.option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 1
|
|
assert meta.option('od1.i2').owner.get() is meta.config('conf1').option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.default
|
|
|
|
|
|
def test_contexts():
|
|
meta = make_metaconfig()
|
|
errors = meta.value.set('od1.i2', 6, only_config=True)
|
|
assert meta.option('od1.i2').value.get() == 1
|
|
assert meta.option('od1.i2').owner.get() == owners.default
|
|
assert meta.config('conf1').option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == 6
|
|
assert meta.config('conf1').option('od1.i2').owner.get() == meta.config('conf1').option('od1.i2').owner.get() is owners.user
|
|
assert len(errors) == 0
|
|
|
|
|
|
def test_find():
|
|
meta = make_metaconfig()
|
|
ret = meta.option.find('i2')
|
|
assert len(ret) == 1
|
|
assert 1 == ret[0].value.get()
|
|
assert 1 == meta.option.find('i2', first=True).value.get()
|
|
assert meta.option.make_dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
|
|
'od1.i2': 1, 'od1.i5': [2]}
|
|
|
|
|
|
def test_meta_meta():
|
|
meta = make_metaconfig(double=True)
|
|
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf1').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 1
|
|
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf1').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.default
|
|
#
|
|
meta.option('od1.i2').value.set(3)
|
|
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf1').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 3
|
|
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf1').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
|
|
#
|
|
meta.config('meta.conf1').option('od1.i2').value.set(2)
|
|
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 3
|
|
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
|
|
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
|
|
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
|
#
|
|
meta.config('meta').option('od1.i2').value.set(4)
|
|
assert meta.option('od1.i2').value.get() == 3
|
|
assert meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 4
|
|
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
|
|
assert meta.option('od1.i2').owner.get() is owners.meta1
|
|
assert meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta2
|
|
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
|
#
|
|
meta.config('meta').option('od1.i2').value.reset()
|
|
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 3
|
|
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
|
|
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
|
|
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
|
#
|
|
meta.option('od1.i2').value.reset()
|
|
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 1
|
|
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
|
|
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.default
|
|
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
|
|
#
|
|
meta.config('meta.conf1').option('od1.i2').value.reset()
|
|
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf1').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 1
|
|
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf1').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.default
|
|
|
|
|
|
def test_meta_new_config():
|
|
od = make_description()
|
|
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
|
|
assert len(list(meta.config.list())) == 2
|
|
meta.config.new('newconf1')
|
|
assert len(list(meta.config.list())) == 3
|
|
|
|
|
|
def test_meta_new_config_wrong_name():
|
|
od = make_description()
|
|
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
|
|
assert len(list(meta.config.list())) == 2
|
|
raises(ConflictError, "meta.config.new('name1')")
|
|
assert len(list(meta.config.list())) == 2
|
|
|
|
|
|
def test_meta_meta_set():
|
|
meta = make_metaconfig(double=True)
|
|
errors1 = meta.value.set('od1.i1', 7, only_config=True)
|
|
errors2 = meta.value.set('od1.i6', 7, only_config=True)
|
|
assert len(errors1) == 0
|
|
assert len(errors2) == 2
|
|
conf1 = meta.config('meta.conf1')._config.context
|
|
conf2 = meta.config('meta.conf2')._config.context
|
|
assert meta.config('meta.conf1').option('od1.i1').value.get() == meta.config('meta.conf2').option('od1.i1').value.get() == 7
|
|
#
|
|
dconfigs = []
|
|
for conf in meta.config.find('i1', value=7, first=True).config.list():
|
|
dconfigs.append(conf._config)
|
|
assert [conf1, conf2] == dconfigs
|
|
meta.config('meta.conf1').option('od1.i1').value.set(8)
|
|
#
|
|
dconfigs = []
|
|
for conf in meta.config.find('i1', first=True).config.list():
|
|
dconfigs.append(conf._config)
|
|
assert [conf1, conf2] == dconfigs
|
|
assert conf2 == list(meta.config.find('i1', value=7, first=True).config.list())[0]._config
|
|
assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config
|
|
#
|
|
dconfigs = []
|
|
for conf in meta.config.find('i5', value=2, first=True).config.list():
|
|
dconfigs.append(conf._config)
|
|
assert [conf1, conf2] == dconfigs
|
|
#
|
|
raises(AttributeError, "meta.config.find('i1', value=10, first=True)")
|
|
raises(AttributeError, "meta.config.find('not', value=10, first=True)")
|
|
raises(AttributeError, "meta.config.find('i6', first=True)")
|
|
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_default=True)")
|
|
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)")
|
|
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)")
|
|
|
|
|
|
def test_not_meta():
|
|
i1 = IntOption('i1', '')
|
|
od1 = OptionDescription('od1', '', [i1])
|
|
od2 = OptionDescription('od2', '', [od1])
|
|
conf1 = Config(od2, session_id='conf1')
|
|
conf2 = Config(od2, session_id='conf2')
|
|
conf3 = Config(od2)
|
|
conf4 = Config(od2, session_id='conf4')
|
|
raises(TypeError, "GroupConfig(conf1)")
|
|
#same name
|
|
raises(ConflictError, "GroupConfig([conf2, conf4], session_id='conf2')")
|
|
raises(ConflictError, "GroupConfig([conf2, conf2], session_id='conf8')")
|
|
grp = GroupConfig([conf1, conf2])
|
|
raises(ConfigError, "grp.option('od1.i1').value.get()")
|
|
conf1, conf2 = grp.config.list()
|
|
errors = grp.value.set('od1.i1', 7)
|
|
assert len(errors) == 0
|
|
assert grp.config('conf1').option('od1.i1').value.get() == grp.config('conf2').option('od1.i1').value.get() == 7
|
|
assert grp.config('conf1').option('od1.i1').owner.get() is grp.config('conf2').option('od1.i1').owner.get() is owners.user
|
|
|
|
|
|
def test_group_find_firsts():
|
|
i1 = IntOption('i1', '')
|
|
od1 = OptionDescription('od1', '', [i1])
|
|
od2 = OptionDescription('od2', '', [od1])
|
|
conf1 = Config(od2, session_id='conf1')
|
|
conf2 = Config(od2, session_id='conf2')
|
|
grp = GroupConfig([conf1, conf2])
|
|
itr = grp.config.find('i1', first=True).config.list()
|
|
conf1._config == next(itr)._config
|
|
conf2._config == next(itr)._config
|
|
|
|
|
|
def test_group_group():
|
|
i1 = IntOption('i1', '')
|
|
od1 = OptionDescription('od1', '', [i1])
|
|
od2 = OptionDescription('od2', '', [od1])
|
|
conf1 = Config(od2, session_id='conf9')
|
|
conf2 = Config(od2, session_id='conf10')
|
|
grp = GroupConfig([conf1, conf2], 'grp')
|
|
grp2 = GroupConfig([grp])
|
|
errors = grp2.value.set('od1.i1', 2)
|
|
assert len(errors) == 0
|
|
assert grp2.config('grp.conf9').option('od1.i1').value.get() == 2
|
|
assert grp2.config('grp.conf9').option('od1.i1').owner.get() is owners.user
|
|
|
|
|
|
def test_meta_unconsistent():
|
|
i1 = IntOption('i1', '')
|
|
i2 = IntOption('i2', '', default=1)
|
|
i3 = IntOption('i3', '')
|
|
i4 = IntOption('i4', '', default=2)
|
|
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
|
od2 = OptionDescription('od2', '', [od1])
|
|
od3 = OptionDescription('od3', '', [od1])
|
|
conf1 = Config(od2, session_id='conf1')
|
|
conf2 = Config(od2, session_id='conf2')
|
|
conf3 = Config(od2, session_id='conf3')
|
|
conf4 = Config(od3, session_id='conf4')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.owner.set(owners.meta1)
|
|
raises(TypeError, 'MetaConfig("string")')
|
|
#same descr but conf1 already in meta
|
|
raises(ValueError, "MetaConfig([conf1, conf3])")
|
|
#not same descr
|
|
raises(ValueError, "MetaConfig([conf3, conf4])")
|
|
raises(ConfigError, "meta.config('conf1').property.read_only()")
|
|
|
|
|
|
def test_meta_master_slaves():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_only()
|
|
itr = meta.config.find('ip_admin_eth0', first=True).config.list()
|
|
assert conf1._config == next(itr)._config
|
|
assert conf2._config == next(itr)._config
|
|
itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
|
|
assert conf1._config == next(itr)._config
|
|
assert conf2._config == next(itr)._config
|
|
meta.property.read_write()
|
|
raises(AttributeError, "meta.config.find('netmask_admin_eth0', first=True)")
|
|
itr = meta.unrestraint.config.find('netmask_admin_eth0', first=True).config.list()
|
|
assert conf1._config == next(itr)._config
|
|
assert conf2._config == next(itr)._config
|
|
meta.property.read_only()
|
|
itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
|
|
assert conf1._config == next(itr)._config
|
|
assert conf2._config == next(itr)._config
|
|
|
|
|
|
def test_meta_master_slaves_value2():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2], session_id="meta")
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
#FIXME devrait raise ! assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
|
#
|
|
meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
|
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
|
|
|
|
def test_meta_master_slaves_value_default():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
#
|
|
meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
#
|
|
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
|
|
#
|
|
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
|
|
|
|
|
def test_meta_master_slaves_owners():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.owner.set(owners.meta1)
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
|
raises(SlaveError, "meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()")
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
|
#
|
|
meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
|
#
|
|
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
|
|
#
|
|
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
|
|
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
|
|
|
|
|
def test_meta_force_default():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
meta.owner.set('meta1')
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
#
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
#
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3'])
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
|
#
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True)
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
|
|
|
|
def test_meta_force_dont_change_value():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
meta.owner.set('meta1')
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True)
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
|
|
|
|
def test_meta_force_default_if_same():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
meta.owner.set('meta1')
|
|
#
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True)
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True)
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
|
|
|
|
|
def test_meta_force_default_if_same_and_dont_change():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
meta.owner.set('meta1')
|
|
#
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True)
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
#
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True)
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
|
|
|
|
|
|
def test_meta_force_default_and_dont_change():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='rconf1')
|
|
conf2 = Config(od, session_id='rconf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
meta.owner.set('meta1')
|
|
raises(ValueError, "meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True)")
|
|
|
|
|
|
def test_meta_properties_meta():
|
|
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',))
|
|
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
assert meta.config('conf1').option.make_dict() == {}
|
|
|
|
|
|
def test_meta_exception_meta():
|
|
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, callback=raise_exception)
|
|
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
raises(Exception, "conf1.make_dict()")
|
|
|
|
|
|
def test_meta_callback():
|
|
val1 = StrOption('val1', "", 'val')
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
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')}))
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
|
cfg = Config(maconfig, session_id='cfg')
|
|
meta = MetaConfig([cfg])
|
|
meta.property.read_write()
|
|
assert meta.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
|
|
meta.config('cfg').option('val1').value.set('new')
|
|
#assert meta.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
|
|
#meta.config('cfg').option('val1').value.reset()
|
|
#meta.option('val1').value.set('new')
|
|
#assert meta.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
|
|
#meta.config('cfg').option('val4').value.set('new1')
|
|
#assert meta.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
|
|
#meta.config('cfg').option('val4').value.reset()
|
|
#meta.option('val4').value.set('new1')
|
|
#assert meta.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
|
|
#meta.option('val4').value.reset()
|
|
|
|
|
|
def test_meta_callback_slave():
|
|
val = StrOption('val', "", default='val')
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val)))
|
|
val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
|
|
od = OptionDescription('root', '', [interface1])
|
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
|
cfg = Config(maconfig, session_id='cfg1')
|
|
meta = MetaConfig([cfg])
|
|
meta.property.read_write()
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
|
meta.config('cfg1').option('val').value.set('val1')
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
|
meta.config('cfg1').option('val').value.reset()
|
|
meta.option('val').value.set('val1')
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
|
meta.option('val').value.reset()
|
|
meta.config('cfg1').option('val1.val2', 0).value.set('val2')
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
|
meta.config('cfg1').option('val1.val2', 0).value.reset()
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
|
meta.option('val1.val2', 0).value.set('val2')
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
|
meta.config('cfg1').option('val1.val3', 0).value.set('val6')
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
|
|
meta.option('val1.val2', 0).value.reset()
|
|
meta.config('cfg1').option('val1.val3', 0).value.reset()
|
|
meta.config('cfg1').option('val1.val1').value.set(['val3'])
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
|
meta.config('cfg1').option('val1.val1').value.reset()
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
|
meta.option('val1.val1').value.set(['val3'])
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
|
meta.config('cfg1').option('val1.val2', 0).value.set('val2')
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
|
meta.option('val1.val1').value.set(['val3', 'rah'])
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
|
meta.option('val1.val1').value.pop(1)
|
|
meta.option('val1.val1').value.set(['val4'])
|
|
assert meta.config('cfg1').option.make_dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
|
|
|
|
|
|
def test_meta_reset():
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
|
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
od = OptionDescription('root', '', [interface1])
|
|
conf1 = Config(od, session_id='conf1')
|
|
conf2 = Config(od, session_id='conf2')
|
|
meta = MetaConfig([conf1, conf2])
|
|
meta.property.read_write()
|
|
meta.owner.set('meta1')
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
|
|
assert len(errors) == 0
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
|
|
meta.value.reset('ip_admin_eth0.ip_admin_eth0')
|
|
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
|
|
|
|
|
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.property.read_write()
|
|
assert meta.config('conf1').option.make_dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
|
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
|
|
assert len(ret) == 2
|
|
assert isinstance(ret[0], PropertiesOptionError)
|
|
assert isinstance(ret[1], PropertiesOptionError)
|
|
del(ret)
|
|
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True)
|
|
assert len(ret) == 1
|
|
assert isinstance(ret[0], PropertiesOptionError)
|
|
del(ret)
|
|
ret = meta.value.set('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)
|
|
del(ret)
|
|
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True)
|
|
assert len(ret) == 1
|
|
assert isinstance(ret[0], PropertiesOptionError)
|
|
del(ret)
|
|
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', only_config=True)
|
|
assert len(ret) == 2
|
|
assert isinstance(ret[0], ValueError)
|
|
assert isinstance(ret[1], ValueError)
|
|
del(ret)
|
|
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default=True)
|
|
assert len(ret) == 1
|
|
assert isinstance(ret[0], ValueError)
|
|
del(ret)
|
|
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True)
|
|
assert len(ret) == 1
|
|
assert isinstance(ret[0], ValueError)
|
|
del(ret)
|
|
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True)
|
|
assert len(ret) == 1
|
|
assert isinstance(ret[0], ValueError)
|
|
del(ret)
|