2013-08-24 22:32:54 +02:00
|
|
|
# coding: utf-8
|
2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
2013-06-13 22:07:58 +02:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import BoolOption, StrOption, SymLinkOption, \
|
|
|
|
OptionDescription, MasterSlaves, Config, getapi
|
|
|
|
from tiramisu.error import PropertiesOptionError, ConfigError
|
2013-06-13 22:07:58 +02:00
|
|
|
from tiramisu.setting import groups, owners
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu.api import TIRAMISU_VERSION
|
2013-06-13 22:07:58 +02:00
|
|
|
|
|
|
|
from py.test import raises
|
|
|
|
|
|
|
|
|
2017-01-26 21:55:10 +01:00
|
|
|
def return_value():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2013-06-13 22:07:58 +02:00
|
|
|
#____________________________________________________________
|
|
|
|
def test_symlink_option():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.option('s1.b').value.get() is False
|
|
|
|
api.option("s1.b").value.set(True)
|
|
|
|
api.option("s1.b").value.set(False)
|
|
|
|
assert api.option('s1.b').value.get() is False
|
|
|
|
assert api.option('c').value.get() is False
|
|
|
|
api.option('s1.b').value.set(True)
|
|
|
|
assert api.option('s1.b').value.get() is True
|
|
|
|
assert api.option('c').value.get() is True
|
|
|
|
api.option('s1.b').value.set(False)
|
|
|
|
assert api.option('s1.b').value.get() is False
|
|
|
|
assert api.option('c').value.get() is False
|
2013-06-13 22:07:58 +02:00
|
|
|
|
|
|
|
|
2018-04-10 12:33:51 +02:00
|
|
|
def test_symlink_assign_option():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
raises(ConfigError, "api.option('c').value.set(True)")
|
|
|
|
|
|
|
|
|
|
|
|
def test_symlink_del_option():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
raises(TypeError, "api.option('c').value.reset()")
|
|
|
|
|
|
|
|
|
2018-04-11 16:36:15 +02:00
|
|
|
def test_symlink_addproperties():
|
|
|
|
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(TypeError, "api.option('c').property.add('new')")
|
|
|
|
raises(TypeError, "api.option('c').property.reset()")
|
|
|
|
|
|
|
|
|
|
|
|
def test_symlink_addpermissive():
|
|
|
|
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(TypeError, "api.option('c').permissive.set(frozenset(['new']))")
|
|
|
|
raises(TypeError, "api.option('c').permissive.reset()")
|
|
|
|
|
|
|
|
|
2017-01-26 21:55:10 +01:00
|
|
|
def test_symlink_getproperties():
|
|
|
|
boolopt = BoolOption('b', '', default=True, properties=('test',))
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
|
|
|
|
else:
|
|
|
|
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
|
2017-01-26 21:55:10 +01:00
|
|
|
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False
|
|
|
|
|
|
|
|
|
|
|
|
def test_symlink_getcallback():
|
|
|
|
boolopt = BoolOption('b', '', callback=return_value)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription('opt', '', [boolopt, linkopt])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
2017-01-26 21:55:10 +01:00
|
|
|
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
|
|
|
|
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, {})
|
|
|
|
|
|
|
|
|
2013-06-13 22:07:58 +02:00
|
|
|
def test_symlink_requires():
|
|
|
|
boolopt = BoolOption('b', '', default=True)
|
2013-06-29 18:41:14 +02:00
|
|
|
stropt = StrOption('s', '', requires=[{'option': boolopt,
|
|
|
|
'expected': False,
|
|
|
|
'action': 'disabled'}])
|
2013-06-13 22:07:58 +02:00
|
|
|
linkopt = SymLinkOption("c", stropt)
|
|
|
|
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('b').value.get() is True
|
|
|
|
assert api.option('s').value.get() is None
|
|
|
|
assert api.option('c').value.get() is None
|
|
|
|
api.option('b').value.set(False)
|
2013-06-13 22:07:58 +02:00
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('s').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 22:07:58 +02:00
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert props == ['disabled']
|
|
|
|
else:
|
|
|
|
assert props == {'disabled'}
|
2013-06-13 22:07:58 +02:00
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('c').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 22:07:58 +02:00
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert props == ['disabled']
|
|
|
|
else:
|
|
|
|
assert props == {'disabled'}
|
2013-06-13 22:07:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_symlink_multi():
|
|
|
|
boolopt = BoolOption("b", "", default=[False], multi=True)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.option('s1.b').value.get() == [False]
|
|
|
|
assert api.option('c').value.get() == [False]
|
|
|
|
api.option('s1.b').value.set([True])
|
|
|
|
assert api.option('s1.b').value.get() == [True]
|
|
|
|
assert api.option('c').value.get() == [True]
|
|
|
|
api.option('s1.b').value.set([False])
|
|
|
|
assert api.option('s1.b').value.get() == [False]
|
|
|
|
assert api.option('c').value.get() == [False]
|
|
|
|
api.option('s1.b').value.set([False, True])
|
|
|
|
assert api.option('s1.b').value.get() == [False, True]
|
|
|
|
assert api.option('c').value.get() == [False, True]
|
2013-06-13 22:07:58 +02:00
|
|
|
assert boolopt.impl_is_multi() is True
|
|
|
|
assert linkopt.impl_is_multi() is True
|
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
def test_symlink_assign():
|
|
|
|
if TIRAMISU_VERSION != 2:
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
raises(ConfigError, "api.option('c').value.set(True)")
|
|
|
|
|
|
|
|
|
2013-06-13 22:07:58 +02:00
|
|
|
def test_symlink_owner():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.option('s1.b').owner.isdefault()
|
|
|
|
assert api.option('c').owner.isdefault()
|
|
|
|
api.option('s1.b').value.set(True)
|
|
|
|
assert not api.option('s1.b').owner.isdefault()
|
|
|
|
assert not api.option('c').owner.isdefault()
|
2013-06-13 22:07:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_symlink_get_information():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
boolopt.impl_set_information('test', 'test')
|
|
|
|
assert boolopt.impl_get_information('test') == 'test'
|
|
|
|
assert linkopt.impl_get_information('test') == 'test'
|
|
|
|
boolopt.impl_set_information('test', 'test2')
|
|
|
|
assert boolopt.impl_get_information('test') == 'test2'
|
|
|
|
assert linkopt.impl_get_information('test') == 'test2'
|
|
|
|
|
|
|
|
|
|
|
|
def test_symlink_master():
|
|
|
|
a = StrOption('a', "", multi=True)
|
|
|
|
ip_admin_eth0 = SymLinkOption('ip_admin_eth0', a)
|
|
|
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "", multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
|
2013-06-13 22:07:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_symlink_slaves():
|
|
|
|
a = StrOption('a', "", multi=True)
|
2013-08-28 11:33:43 +02:00
|
|
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
2013-06-13 22:07:58 +02:00
|
|
|
netmask_admin_eth0 = SymLinkOption('netmask_admin_eth0', a)
|
2017-10-14 13:33:25 +02:00
|
|
|
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
|
2017-09-17 15:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
#____________________________________________________________
|
|
|
|
def test_symlink_dependency():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
linkopt = SymLinkOption("c", boolopt)
|
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.option('s1.b').option.has_dependency() is False
|
|
|
|
assert api.option('c').option.has_dependency() is True
|
|
|
|
assert api.option('s1.b').option.has_dependency(False) is True
|
|
|
|
assert api.option('c').option.has_dependency(False) is False
|