2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
2013-05-10 22:32:42 +02:00
|
|
|
from tiramisu.setting import owners, groups
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
|
|
|
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\
|
2018-08-14 23:07:07 +02:00
|
|
|
Config, undefined, Params, ParamOption
|
2014-12-01 22:58:53 +01:00
|
|
|
from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu.api import TIRAMISU_VERSION
|
2014-03-12 21:56:53 +01:00
|
|
|
import warnings
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2016-11-20 18:02:10 +01:00
|
|
|
def return_value(value=None):
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2013-12-09 18:56:29 +01:00
|
|
|
def test_consistency():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
#consistency to itself
|
|
|
|
raises(ConfigError, "a.impl_add_consistency('not_equal', a)")
|
|
|
|
|
|
|
|
|
2014-10-25 22:47:40 +02:00
|
|
|
def test_consistency_not_exists():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
2015-11-24 10:58:19 +01:00
|
|
|
a, b
|
2014-10-25 22:47:40 +02:00
|
|
|
raises(ConfigError, "a.impl_add_consistency('not_exists', b)")
|
|
|
|
|
|
|
|
|
2014-12-01 22:58:53 +01:00
|
|
|
def test_consistency_unknown_params():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
2015-11-24 10:58:19 +01:00
|
|
|
a, b
|
2014-12-01 22:58:53 +01:00
|
|
|
raises(ValueError, "a.impl_add_consistency('not_equal', b, unknown=False)")
|
|
|
|
|
|
|
|
|
2015-11-24 10:58:19 +01:00
|
|
|
def test_consistency_warnings_only_default():
|
|
|
|
a = IntOption('a', '', 1)
|
|
|
|
b = IntOption('b', '', 1)
|
|
|
|
warnings.simplefilter("always", ValueWarning)
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
|
|
|
assert w != []
|
|
|
|
|
|
|
|
|
2014-03-12 21:56:53 +01:00
|
|
|
def test_consistency_warnings_only():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set(1)
|
2014-03-12 21:56:53 +01:00
|
|
|
warnings.simplefilter("always", ValueWarning)
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('b').value.set(1)
|
2014-03-12 21:56:53 +01:00
|
|
|
assert w != []
|
|
|
|
|
|
|
|
|
2016-10-10 21:41:22 +02:00
|
|
|
def test_consistency_warnings_only_more_option():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
d = IntOption('d', '')
|
|
|
|
od = OptionDescription('od', '', [a, b, d])
|
|
|
|
a.impl_add_consistency('not_equal', b, d, warnings_only=True)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set(1)
|
2016-10-10 21:41:22 +02:00
|
|
|
warnings.simplefilter("always", ValueWarning)
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('b').value.set(1)
|
2016-10-10 21:41:22 +02:00
|
|
|
assert w != []
|
2016-11-20 18:02:10 +01:00
|
|
|
assert len(w) == 1
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('d').value.get()
|
2016-11-20 18:02:10 +01:00
|
|
|
assert w != []
|
|
|
|
assert len(w) == 1
|
2016-10-10 21:41:22 +02:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('d').value.set(1)
|
2016-10-10 21:41:22 +02:00
|
|
|
assert w != []
|
2016-11-20 18:02:10 +01:00
|
|
|
assert len(w) == 1
|
2016-10-10 21:41:22 +02:00
|
|
|
|
|
|
|
|
2018-09-04 08:36:02 +02:00
|
|
|
def test_consistency_warnings_only_option():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '', warnings_only=True)
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
api = Config(od)
|
|
|
|
api.option('a').value.set(1)
|
|
|
|
warnings.simplefilter("always", ValueWarning)
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
api.option('b').value.set(1)
|
|
|
|
assert w != []
|
|
|
|
api.option('a').value.reset()
|
|
|
|
api.option('b').value.set(1)
|
|
|
|
raises(ValueError, "api.option('a').value.set(1)")
|
|
|
|
|
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
def test_consistency_not_equal():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a').value.get() is None
|
|
|
|
assert api.option('b').value.get() is None
|
|
|
|
api.option('a').value.set(1)
|
|
|
|
api.option('a').value.reset()
|
|
|
|
api.option('a').value.set(1)
|
|
|
|
raises(ValueError, "api.option('b').value.set(1)")
|
|
|
|
api.option('b').value.set(2)
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2013-09-28 17:05:01 +02:00
|
|
|
def test_consistency_not_equal_many_opts():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
c = IntOption('c', '')
|
|
|
|
d = IntOption('d', '')
|
|
|
|
e = IntOption('e', '')
|
|
|
|
f = IntOption('f', '')
|
|
|
|
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
|
|
|
a.impl_add_consistency('not_equal', b, c, d, e, f)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a').value.get() is None
|
|
|
|
assert api.option('b').value.get() is None
|
2013-09-28 17:05:01 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set(1)
|
|
|
|
api.option('a').value.reset()
|
2013-09-28 17:05:01 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set(1)
|
|
|
|
raises(ValueError, "api.option('b').value.set(1)")
|
2013-09-28 17:05:01 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('b').value.set(2)
|
|
|
|
raises(ValueError, "api.option('f').value.set(2)")
|
|
|
|
raises(ValueError, "api.option('f').value.set(1)")
|
2013-09-28 17:05:01 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('d').value.set(3)
|
|
|
|
raises(ValueError, "api.option('f').value.set(3)")
|
|
|
|
raises(ValueError, "api.option('a').value.set(3)")
|
|
|
|
api.option('d').value.set(3)
|
|
|
|
raises(ValueError, "api.option('c').value.set(3)")
|
|
|
|
raises(ValueError, "api.option('e').value.set(3)")
|
2013-09-28 17:05:01 +02:00
|
|
|
|
|
|
|
|
2016-10-12 21:58:37 +02:00
|
|
|
def test_consistency_not_equal_many_opts_one_disabled():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
c = IntOption('c', '')
|
|
|
|
d = IntOption('d', '')
|
|
|
|
e = IntOption('e', '')
|
|
|
|
f = IntOption('f', '')
|
|
|
|
g = IntOption('g', '', properties=('disabled',))
|
|
|
|
od = OptionDescription('od', '', [a, b, c, d, e, f, g])
|
|
|
|
a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('a').value.get() is None
|
|
|
|
assert api.option('b').value.get() is None
|
2016-10-12 21:58:37 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set(1)
|
|
|
|
api.option('a').value.reset()
|
2016-10-12 21:58:37 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set(1)
|
|
|
|
raises(ValueError, "api.option('b').value.set(1)")
|
2016-10-12 21:58:37 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('b').value.set(2)
|
|
|
|
raises(ValueError, "api.option('f').value.set(2)")
|
|
|
|
raises(ValueError, "api.option('f').value.set(1)")
|
2016-10-12 21:58:37 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('d').value.set(3)
|
|
|
|
raises(ValueError, "api.option('f').value.set(3)")
|
|
|
|
raises(ValueError, "api.option('a').value.set(3)")
|
|
|
|
raises(ValueError, "api.option('c').value.set(3)")
|
|
|
|
raises(ValueError, "api.option('e').value.set(3)")
|
2016-10-12 21:58:37 +02:00
|
|
|
|
|
|
|
|
2013-11-23 23:34:17 +01:00
|
|
|
def test_consistency_not_in_config_1():
|
2013-09-28 17:05:01 +02:00
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
od1 = OptionDescription('od1', '', [a])
|
|
|
|
od = OptionDescription('root', '', [od1])
|
2015-11-24 10:58:19 +01:00
|
|
|
od
|
2013-09-28 17:05:01 +02:00
|
|
|
raises(ConfigError, "Config(od)")
|
2013-11-23 23:34:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_in_config_2():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
od1 = OptionDescription('od1', '', [a])
|
|
|
|
od2 = OptionDescription('od2', '', [b])
|
2013-09-28 17:05:01 +02:00
|
|
|
od = OptionDescription('root', '', [od1, od2])
|
|
|
|
Config(od)
|
2013-11-23 23:34:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_in_config_3():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
od1 = OptionDescription('od1', '', [a])
|
|
|
|
od2 = OptionDescription('od2', '', [b])
|
|
|
|
od = OptionDescription('root', '', [od1, od2])
|
2015-11-24 10:58:19 +01:00
|
|
|
od
|
2013-09-28 17:05:01 +02:00
|
|
|
#with subconfig
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(ConfigError, "Config(od1)")
|
2013-09-28 17:05:01 +02:00
|
|
|
|
|
|
|
|
2013-11-23 23:34:17 +01:00
|
|
|
def test_consistency_after_config():
|
2013-09-28 17:05:01 +02:00
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
od1 = OptionDescription('od1', '', [a])
|
|
|
|
od2 = OptionDescription('od2', '', [b])
|
|
|
|
od = OptionDescription('root', '', [od1, od2])
|
|
|
|
Config(od)
|
2014-01-30 22:55:15 +01:00
|
|
|
raises(AttributeError, "a.impl_add_consistency('not_equal', b)")
|
2013-09-28 17:05:01 +02:00
|
|
|
|
|
|
|
|
2013-09-03 22:41:18 +02:00
|
|
|
def test_consistency_not_equal_symlink():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
c = SymLinkOption('c', a)
|
|
|
|
od = OptionDescription('od', '', [a, b, c])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2013-09-28 17:05:01 +02:00
|
|
|
assert set(od._cache_consistencies.keys()) == set([a, b])
|
2013-09-03 22:41:18 +02:00
|
|
|
|
|
|
|
|
2015-11-24 10:58:19 +01:00
|
|
|
def test_consistency_not_equal_submulti():
|
|
|
|
a = IntOption('a', '', multi=submulti)
|
|
|
|
b = IntOption('b', '', multi=submulti)
|
2016-01-03 13:23:15 +01:00
|
|
|
od = OptionDescription('a', '', [a, b])
|
|
|
|
raises(ConfigError, 'a.impl_add_consistency("not_equal", b)')
|
2015-11-24 10:58:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal_default_submulti():
|
|
|
|
a = IntOption('a', '', [[1, 2]], multi=submulti)
|
|
|
|
b = IntOption('b', '', [[1]], multi=submulti)
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
od
|
2016-01-03 13:23:15 +01:00
|
|
|
raises(ConfigError, "a.impl_add_consistency('not_equal', b)")
|
2015-11-24 10:58:19 +01:00
|
|
|
|
|
|
|
|
2016-11-16 22:31:42 +01:00
|
|
|
def test_consistency_not_equal_masterslave():
|
2013-05-10 15:10:06 +02:00
|
|
|
a = IntOption('a', '', multi=True)
|
|
|
|
b = IntOption('b', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('b', '', [od])
|
2017-10-14 13:33:25 +02:00
|
|
|
#od.impl_set_group_type(groups.master)
|
2013-05-10 15:10:06 +02:00
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a.a').value.get() == []
|
|
|
|
api.option('a.a').value.set([1])
|
|
|
|
api.option('a.a').value.reset()
|
|
|
|
api.option('a.a').value.set([1])
|
|
|
|
raises(ValueError, "api.option('a.b', 0).value.set(1)")
|
|
|
|
api.option('a.b', 0).value.set(2)
|
|
|
|
api.option('a.a').value.reset()
|
|
|
|
api.option('a.a').value.set([1])
|
2018-08-23 23:14:22 +02:00
|
|
|
api.config.dict()
|
2013-05-10 15:10:06 +02:00
|
|
|
|
|
|
|
|
2017-07-21 18:03:34 +02:00
|
|
|
def test_consistency_not_equal_masterslave_error_multi1():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
c = NetmaskOption('c', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2017-07-21 18:03:34 +02:00
|
|
|
od2 = OptionDescription('b', '', [od, c])
|
|
|
|
c.impl_add_consistency('ip_netmask', a)
|
|
|
|
raises(ConfigError, "Config(od2)")
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal_masterslave_error_multi2():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
c = IPOption('c', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2017-07-21 18:03:34 +02:00
|
|
|
od2 = OptionDescription('b', '', [od, c])
|
|
|
|
b.impl_add_consistency('ip_netmask', c)
|
|
|
|
raises(ConfigError, "Config(od2)")
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal_masterslave_error_othermaster():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
c = IPOption('c', '', multi=True)
|
|
|
|
d = NetmaskOption('d', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
|
|
|
od2 = MasterSlaves('c', '', [c, d])
|
|
|
|
#od2.impl_set_group_type(groups.master)
|
2017-07-21 18:03:34 +02:00
|
|
|
od3 = OptionDescription('b', '', [od, od2])
|
|
|
|
d.impl_add_consistency('ip_netmask', a)
|
|
|
|
raises(ConfigError, "Config(od2)")
|
|
|
|
|
|
|
|
|
2016-11-16 22:31:42 +01:00
|
|
|
def test_consistency_not_equal_masterslaves_default():
|
2015-11-24 10:58:19 +01:00
|
|
|
a = IntOption('a', '', multi=True)
|
|
|
|
b = IntOption('b', '', multi=True, default_multi=1)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('a', '', [od])
|
2017-10-14 13:33:25 +02:00
|
|
|
#od.impl_set_group_type(groups.master)
|
2015-11-24 10:58:19 +01:00
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a.a').value.get() == []
|
|
|
|
raises(ValueError, "api.option('a.a').value.set([1])")
|
|
|
|
api.option('a.a').value.set([2])
|
|
|
|
api.option('a.a').value.reset()
|
2015-11-24 10:58:19 +01:00
|
|
|
|
|
|
|
|
2016-11-16 22:31:42 +01:00
|
|
|
def test_consistency_not_equal_multi():
|
|
|
|
a = IntOption('a', '', multi=True)
|
|
|
|
b = IntOption('b', '', multi=True)
|
|
|
|
od = OptionDescription('a', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a').value.get() == []
|
|
|
|
assert api.option('b').value.get() == []
|
|
|
|
api.option('a').value.set([1])
|
|
|
|
api.option('a').value.reset()
|
|
|
|
api.option('a').value.set([1])
|
|
|
|
raises(ValueError, "api.option('b').value.set([1])")
|
|
|
|
api.option('a').value.set([2])
|
|
|
|
raises(ValueError, "api.option('b').value.set([2, 1])")
|
|
|
|
api.option('a').value.set([2, 3])
|
|
|
|
raises(ValueError, "api.option('a').value.set([2, 3, 3])")
|
|
|
|
raises(ValueError, "api.option('b').value.set([2, 3])")
|
2016-11-16 22:31:42 +01:00
|
|
|
|
|
|
|
|
2018-06-02 08:35:05 +02:00
|
|
|
def test_consistency_not_equal_multi_default1():
|
2016-11-16 22:31:42 +01:00
|
|
|
a = IntOption('a', '', multi=True, default=[1])
|
2018-06-02 08:35:05 +02:00
|
|
|
b = IntOption('b', '', multi=True, default=[3, 1])
|
2016-11-16 22:31:42 +01:00
|
|
|
od = OptionDescription('a', '', [a, b])
|
2018-06-02 08:35:05 +02:00
|
|
|
raises(ValueError, "b.impl_add_consistency('not_equal', a)")
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal_multi_default2():
|
|
|
|
a = IntOption('a', '', multi=True, default=[1])
|
|
|
|
b = IntOption('b', '', multi=True, default_multi=1)
|
|
|
|
od = OptionDescription('a', '', [a, b])
|
|
|
|
#default_multi not tested now
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal_master_default():
|
|
|
|
a = IntOption('a', '', multi=True, default=[2, 1])
|
|
|
|
b = IntOption('b', '', multi=True, default_multi=1)
|
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
od2 = OptionDescription('a', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-06-02 08:35:05 +02:00
|
|
|
# default_multi not tested
|
|
|
|
raises(ValueError, "api.option('a.b', 0).value.get()")
|
|
|
|
api.option('a.b', 0).value.set(3)
|
|
|
|
api.option('a.b', 1).value.set(3)
|
|
|
|
assert api.option('a.b', 1).value.get() == 3
|
2016-11-16 22:31:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal_multi_default_modif():
|
|
|
|
a = IntOption('a', '', multi=True)
|
|
|
|
b = IntOption('b', '', multi=True, default=[1, 2])
|
|
|
|
od = OptionDescription('a', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a').value.get() == []
|
|
|
|
assert api.option('b').value.get() == [1, 2]
|
|
|
|
raises(ValueError, "api.option('a').value.set([1])")
|
|
|
|
raises(ValueError, "api.option('b').value.set([1, 2, 1])")
|
2016-11-16 22:31:42 +01:00
|
|
|
|
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
def test_consistency_default():
|
|
|
|
a = IntOption('a', '', 1)
|
|
|
|
b = IntOption('b', '', 1)
|
2015-11-24 10:58:19 +01:00
|
|
|
a, b
|
2013-05-10 15:10:06 +02:00
|
|
|
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2013-09-28 17:05:01 +02:00
|
|
|
def test_consistency_default_multi():
|
|
|
|
a = IntOption('a', '', [2, 1], multi=True)
|
|
|
|
b = IntOption('b', '', [1, 1], multi=True)
|
|
|
|
c = IntOption('c', '', [1, 2], multi=True)
|
2015-11-24 10:58:19 +01:00
|
|
|
b
|
2013-09-28 17:05:01 +02:00
|
|
|
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION != 2:
|
|
|
|
raises(ValueError, "a.impl_add_consistency('not_equal', c)")
|
2013-09-28 17:05:01 +02:00
|
|
|
|
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
def test_consistency_default_diff():
|
|
|
|
a = IntOption('a', '', 3)
|
|
|
|
b = IntOption('b', '', 1)
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(ValueError, "api.option('a').value.set(1)")
|
|
|
|
api.option('a').value.set(2)
|
|
|
|
api.option('b').value.set(3)
|
|
|
|
owner = api.owner.get()
|
|
|
|
assert api.option('a').owner.get() == owner
|
|
|
|
raises(ValueError, "api.option('a').value.reset()")
|
|
|
|
assert api.option('a').owner.get() == owner
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_ip_netmask():
|
|
|
|
a = IPOption('a', '')
|
|
|
|
b = NetmaskOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
b.impl_add_consistency('ip_netmask', a)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set('192.168.1.1')
|
|
|
|
api.option('b').value.set('255.255.255.0')
|
|
|
|
api.option('a').value.set('192.168.1.2')
|
|
|
|
api.option('b').value.set('255.255.255.255')
|
|
|
|
api.option('b').value.set('255.255.255.0')
|
|
|
|
raises(ValueError, "api.option('a').value.set('192.168.1.0')")
|
|
|
|
raises(ValueError, "api.option('a').value.set('192.168.1.255')")
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_network_netmask():
|
|
|
|
a = NetworkOption('a', '')
|
|
|
|
b = NetmaskOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set('192.168.1.1')
|
|
|
|
api.option('b').value.set('255.255.255.255')
|
|
|
|
api.option('b').value.reset()
|
|
|
|
api.option('a').value.set('192.168.1.0')
|
|
|
|
api.option('b').value.set('255.255.255.0')
|
|
|
|
raises(ValueError, "api.option('a').value.set('192.168.1.1')")
|
2013-05-10 15:10:06 +02:00
|
|
|
|
|
|
|
|
2014-03-11 18:57:19 +01:00
|
|
|
def test_consistency_ip_in_network():
|
|
|
|
a = NetworkOption('a', '')
|
|
|
|
b = NetmaskOption('b', '')
|
|
|
|
c = IPOption('c', '')
|
2015-11-24 10:58:19 +01:00
|
|
|
d = IPOption('d', '')
|
|
|
|
od = OptionDescription('od', '', [a, b, c, d])
|
2014-03-11 18:57:19 +01:00
|
|
|
c.impl_add_consistency('in_network', a, b)
|
2015-11-24 10:58:19 +01:00
|
|
|
d.impl_add_consistency('in_network', a, b, warnings_only=True)
|
|
|
|
warnings.simplefilter("always", ValueWarning)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set('192.168.1.0')
|
|
|
|
api.option('b').value.set('255.255.255.0')
|
|
|
|
api.option('c').value.set('192.168.1.1')
|
|
|
|
raises(ValueError, "api.option('c').value.set('192.168.2.1')")
|
|
|
|
raises(ValueError, "api.option('c').value.set('192.168.1.0')")
|
|
|
|
raises(ValueError, "api.option('c').value.set('192.168.1.255')")
|
2015-11-24 10:58:19 +01:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('d').value.set('192.168.2.1')
|
2015-11-24 10:58:19 +01:00
|
|
|
assert len(w) == 1
|
2014-03-11 18:57:19 +01:00
|
|
|
|
|
|
|
|
2018-06-02 08:35:05 +02:00
|
|
|
# needs 3 arguments, not 2
|
|
|
|
#def test_consistency_ip_in_network_len_error():
|
|
|
|
# a = NetworkOption('a', '')
|
|
|
|
# b = NetmaskOption('b', '')
|
|
|
|
# c = IPOption('c', '')
|
|
|
|
# od = OptionDescription('od', '', [a, b, c])
|
|
|
|
# raises(ConfigError, "c.impl_add_consistency('in_network', a)")
|
|
|
|
|
|
|
|
|
|
|
|
# needs 2 arguments, not 3
|
|
|
|
#def test_consistency_ip_netmask_network_error():
|
|
|
|
# a = IPOption('a', '')
|
|
|
|
# b = NetworkOption('b', '')
|
|
|
|
# c = NetmaskOption('c', '')
|
|
|
|
# od = OptionDescription('od', '', [a, b, c])
|
|
|
|
# c.impl_add_consistency('ip_netmask', a, b)
|
2018-08-14 23:07:07 +02:00
|
|
|
# api = Config(od)
|
2018-06-02 08:35:05 +02:00
|
|
|
# api.option('a').value.set('192.168.1.1')
|
|
|
|
# api.option('b').value.set('192.168.1.0')
|
|
|
|
# raises(ConfigError, "api.option('c').value.set('255.255.255.0')")
|
2014-02-06 22:17:20 +01:00
|
|
|
|
|
|
|
|
2013-05-10 22:32:42 +02:00
|
|
|
def test_consistency_ip_netmask_error_multi():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '')
|
2015-11-24 10:58:19 +01:00
|
|
|
OptionDescription('od', '', [a, b])
|
2013-09-28 17:05:01 +02:00
|
|
|
raises(ConfigError, "b.impl_add_consistency('ip_netmask', a)")
|
2013-05-10 22:32:42 +02:00
|
|
|
|
|
|
|
|
2013-05-10 15:10:06 +02:00
|
|
|
def test_consistency_ip_netmask_multi():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
b.impl_add_consistency('ip_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.1'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.a').value.set(['192.168.1.2'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.255')
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
|
2013-05-10 15:10:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_network_netmask_multi():
|
|
|
|
a = NetworkOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.1'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.255')
|
|
|
|
api.option('a.b', 0).value.reset()
|
|
|
|
api.option('a.a').value.set(['192.168.1.0'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
2013-05-10 22:32:42 +02:00
|
|
|
|
|
|
|
|
2016-10-10 21:41:22 +02:00
|
|
|
def test_consistency_network_netmask_multi_slave_default_multi():
|
|
|
|
a = NetworkOption('a', '', default_multi=u'192.168.1.0', multi=True, properties=('mandatory',))
|
|
|
|
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2017-10-14 13:33:25 +02:00
|
|
|
#od.impl_set_group_type(groups.master)
|
2016-10-10 21:41:22 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
api.option('a.a').value.set([undefined])
|
|
|
|
assert api.option('a.a').value.get() == ['192.168.1.0']
|
|
|
|
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
2016-10-10 21:41:22 +02:00
|
|
|
|
|
|
|
|
2014-12-07 14:39:23 +01:00
|
|
|
def test_consistency_network_netmask_multi_slave_default():
|
|
|
|
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
|
|
|
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2014-12-07 14:39:23 +01:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
api.property.pop('cache')
|
|
|
|
assert api.option('a.a').value.get() == []
|
|
|
|
api.option('a.a').value.set(['192.168.1.0'])
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
|
|
|
assert api.option('a.b', 0).value.get() == u'255.255.255.0'
|
|
|
|
api.property.read_write()
|
|
|
|
raises(ValueError, "api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
|
|
|
|
api.option('a.a').value.set(['192.168.1.0', undefined])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.b', 1).value.set('255.255.255.255')
|
|
|
|
api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])
|
2015-03-08 12:03:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
def return_netmask(*args, **kwargs):
|
|
|
|
return u'255.255.255.0'
|
|
|
|
|
|
|
|
|
2015-04-18 22:53:45 +02:00
|
|
|
def return_netmask2(master):
|
|
|
|
if master is not None:
|
|
|
|
if master.endswith('2.1'):
|
|
|
|
return u'255.255.255.0'
|
|
|
|
if not master.endswith('.0'):
|
|
|
|
return u'255.255.255.255'
|
|
|
|
return u'255.255.255.0'
|
|
|
|
|
|
|
|
|
2015-03-08 12:03:49 +01:00
|
|
|
def test_consistency_network_netmask_multi_slave_callback():
|
|
|
|
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
|
|
|
b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2015-03-08 12:03:49 +01:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
api.property.pop('cache')
|
|
|
|
assert api.option('a.a').value.get() == []
|
|
|
|
api.option('a.a').value.set(['192.168.1.0'])
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
|
|
|
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
|
|
|
api.property.read_write()
|
|
|
|
raises(ValueError, "assert api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
|
|
|
|
api.option('a.a').value.set(['192.168.1.0', undefined])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.b', 1).value.set('255.255.255.255')
|
|
|
|
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
|
2014-12-07 14:39:23 +01:00
|
|
|
|
|
|
|
|
2015-04-18 22:53:45 +02:00
|
|
|
def test_consistency_network_netmask_multi_slave_callback_value():
|
|
|
|
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
2018-04-15 21:13:16 +02:00
|
|
|
b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(a)), multi=True, properties=('mandatory',))
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2015-04-18 22:53:45 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
api.property.pop('cache')
|
|
|
|
assert api.option('a.a').value.get() == []
|
|
|
|
api.option('a.a').value.set(['192.168.1.0'])
|
|
|
|
assert api.option('a.a').value.get() == ['192.168.1.0']
|
|
|
|
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])")
|
|
|
|
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
|
|
|
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['192.168.2.1'])")
|
|
|
|
assert api.option('a.a').value.get() == [u'192.168.1.0']
|
|
|
|
assert api.option('a.b', 0).value.get() == '255.255.255.0'
|
|
|
|
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.b', 1).value.set('255.255.255.255')
|
2015-04-18 22:53:45 +02:00
|
|
|
|
|
|
|
|
2013-05-10 22:32:42 +02:00
|
|
|
def test_consistency_ip_netmask_multi_master():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2013-05-10 22:32:42 +02:00
|
|
|
b.impl_add_consistency('ip_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.1'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.a').value.set(['192.168.1.2'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.255')
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])")
|
|
|
|
api.option('a.a').value.set(['192.168.1.128'])
|
|
|
|
raises(ValueError, "api.option('a.b', 0).value.set('255.255.255.128')")
|
|
|
|
api.option('a.a').value.set(['192.168.1.2', '192.168.1.3'])
|
2013-05-10 22:32:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_network_netmask_multi_master():
|
|
|
|
a = NetworkOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2013-05-10 22:32:42 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.1'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.255')
|
|
|
|
api.option('a.b', 0).value.reset()
|
|
|
|
api.option('a.a').value.set(['192.168.1.0'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
2013-09-27 23:26:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_broadcast():
|
|
|
|
a = NetworkOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
c = BroadcastOption('c', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b, c])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2013-09-27 23:26:10 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
|
|
|
c.impl_add_consistency('broadcast', a, b)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2013-09-28 17:05:01 +02:00
|
|
|
#first, test network_netmask
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.128'])
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['255.255.255.0'])")
|
2013-09-28 17:05:01 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.0'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.c', 0).value.set('192.168.1.255')
|
|
|
|
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])")
|
2013-09-28 17:05:01 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.0', '192.168.2.128'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.b', 1).value.set('255.255.255.128')
|
|
|
|
api.option('a.c', 0).value.set('192.168.1.255')
|
|
|
|
api.option('a.c', 1).value.set('192.168.2.255')
|
|
|
|
raises(ValueError, "api.option('a.c', 1).value.set('192.168.2.128')")
|
|
|
|
api.option('a.c', 1).value.set('192.168.2.255')
|
2013-09-28 17:05:01 +02:00
|
|
|
|
|
|
|
|
2014-02-06 22:17:20 +01:00
|
|
|
def test_consistency_broadcast_error():
|
|
|
|
a = NetworkOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
c = BroadcastOption('c', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b, c])
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2014-02-06 22:17:20 +01:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
|
|
|
c.impl_add_consistency('broadcast', a)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(ConfigError, "api.option('a.a').value.set(['192.168.1.0'])")
|
2014-02-06 22:17:20 +01:00
|
|
|
|
|
|
|
|
2016-10-14 21:31:39 +02:00
|
|
|
def test_consistency_broadcast_warnings():
|
|
|
|
warnings.simplefilter("always", ValueWarning)
|
|
|
|
a = NetworkOption('a', '', properties=('mandatory', 'disabled'))
|
|
|
|
b = NetmaskOption('b', '', properties=('mandatory', 'disabled'))
|
|
|
|
c = NetmaskOption('c', '', properties=('mandatory', 'disabled'))
|
|
|
|
od = OptionDescription('a', '', [a, b, c])
|
|
|
|
b.impl_add_consistency('network_netmask', a, warnings_only=True)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2016-10-14 21:31:39 +02:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set('192.168.1.4')
|
|
|
|
api.option('b').value.set('255.255.255.0')
|
2016-10-14 21:31:39 +02:00
|
|
|
assert len(w) == 1
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
2016-10-14 21:31:39 +02:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
list(api.value.mandatory_warnings())
|
2016-10-14 21:31:39 +02:00
|
|
|
assert len(w) == 0
|
|
|
|
|
|
|
|
|
2013-11-23 23:34:17 +01:00
|
|
|
def test_consistency_broadcast_default_1():
|
2013-09-28 17:05:01 +02:00
|
|
|
a = NetworkOption('a', '', '192.168.1.0')
|
|
|
|
b = NetmaskOption('b', '', '255.255.255.128')
|
|
|
|
c = BroadcastOption('c', '', '192.168.2.127')
|
|
|
|
od = OptionDescription('a', '', [a, b, c])
|
2015-11-24 10:58:19 +01:00
|
|
|
od
|
2013-09-28 17:05:01 +02:00
|
|
|
raises(ValueError, "c.impl_add_consistency('broadcast', a, b)")
|
2013-11-23 23:34:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_broadcast_default_2():
|
|
|
|
a = NetworkOption('a', '', '192.168.1.0')
|
|
|
|
b = NetmaskOption('b', '', '255.255.255.128')
|
|
|
|
d = BroadcastOption('d', '', '192.168.1.127')
|
2013-09-28 17:05:01 +02:00
|
|
|
od2 = OptionDescription('a', '', [a, b, d])
|
2015-11-24 10:58:19 +01:00
|
|
|
od2
|
2013-09-28 17:05:01 +02:00
|
|
|
d.impl_add_consistency('broadcast', a, b)
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_all():
|
|
|
|
#_cache_consistencies is not None by not options has consistencies
|
|
|
|
a = NetworkOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
c = BroadcastOption('c', '', multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b, c])
|
|
|
|
#od.impl_set_group_type(groups.master)
|
2013-09-28 17:05:01 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a.a').value.set(['192.168.1.0'])
|
|
|
|
api.option('a.b', 0).value.set('255.255.255.0')
|
|
|
|
api.option('a.c', 0).value.set('192.168.1.255')
|
2014-02-06 19:19:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_permissive():
|
|
|
|
a = IntOption('a', '', 1)
|
|
|
|
b = IntOption('b', '', 2, properties=('hidden',))
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
api.permissive.set(frozenset(['hidden']))
|
|
|
|
api.option('a').value.set(1)
|
2014-03-12 16:44:48 +01:00
|
|
|
|
|
|
|
|
2014-12-01 22:58:53 +01:00
|
|
|
def test_consistency_disabled():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '', properties=('disabled',))
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('a').value.set(1)")
|
2014-12-01 22:58:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_disabled_transitive():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '', properties=('disabled',))
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b, transitive=False)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
api.option('a').value.set(1)
|
2014-12-01 22:58:53 +01:00
|
|
|
|
|
|
|
|
2014-12-01 23:02:55 +01:00
|
|
|
def test_consistency_disabled_transitive_2():
|
|
|
|
a = IPOption('a', '')
|
|
|
|
b = IPOption('b', '')
|
|
|
|
c = NetworkOption('c', '', default='192.168.1.0')
|
|
|
|
d = NetmaskOption('d', '', default='255.255.255.0', properties=('disabled',))
|
|
|
|
od = OptionDescription('od', '', [a, b, c, d])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
a.impl_add_consistency('in_network', c, d, transitive=False)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_write()
|
|
|
|
api.option('a').value.set('192.168.1.1')
|
|
|
|
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
|
|
|
|
api.option('a').value.set('192.168.2.1')
|
2014-12-01 23:02:55 +01:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('a').value.set('192.168.1.1')
|
|
|
|
api.property.pop('disabled')
|
|
|
|
raises(ValueError, "api.option('a').value.set('192.168.2.1')")
|
2014-12-01 23:02:55 +01:00
|
|
|
|
|
|
|
|
2014-03-12 16:44:48 +01:00
|
|
|
def return_val(*args, **kwargs):
|
|
|
|
return '192.168.1.1'
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_with_callback():
|
|
|
|
a = NetworkOption('a', '', default='192.168.1.0')
|
|
|
|
b = NetmaskOption('b', '', default='255.255.255.0')
|
2018-04-15 21:13:16 +02:00
|
|
|
c = IPOption('c', '', callback=return_val, callback_params=Params(ParamOption(a)))
|
2014-03-12 16:44:48 +01:00
|
|
|
od = OptionDescription('od', '', [a, b, c])
|
|
|
|
c.impl_add_consistency('in_network', a, b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('c').value.get()
|
2016-11-20 14:32:06 +01:00
|
|
|
|
|
|
|
|
2018-09-04 08:36:02 +02:00
|
|
|
def test_consistency_warnings_only_options():
|
|
|
|
a = IPOption('a', '', warnings_only=True)
|
|
|
|
b = IPOption('b', '')
|
|
|
|
c = NetworkOption('c', '', default='192.168.1.0')
|
|
|
|
d = NetmaskOption('d', '', default='255.255.255.0', properties=('disabled',))
|
|
|
|
od = OptionDescription('od', '', [a, b, c, d])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
a.impl_add_consistency('in_network', c, d, transitive=False)
|
|
|
|
api = Config(od)
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('a').value.set('192.168.1.1')
|
|
|
|
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
|
|
|
|
api.option('a').value.set('192.168.2.1')
|
|
|
|
#
|
|
|
|
api.option('a').value.set('192.168.1.1')
|
|
|
|
api.property.pop('disabled')
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
api.option('a').value.set('192.168.2.1')
|
|
|
|
assert len(w) == 1
|
|
|
|
|
|
|
|
|
|
|
|
#def test_consistency_warnings_only_options_callback():
|
|
|
|
# a = IPOption('a', '', warnings_only=True)
|
|
|
|
# b = IPOption('b', '')
|
|
|
|
# c = NetworkOption('c', '', default='192.168.1.0')
|
|
|
|
# d = NetmaskOption('d', '', callback=return_netmask2, callback_params=Params(ParamOption(a)))
|
|
|
|
# od = OptionDescription('od', '', [a, b, c, d])
|
|
|
|
# a.impl_add_consistency('not_equal', b)
|
|
|
|
# a.impl_add_consistency('in_network', c, d, transitive=False)
|
|
|
|
# api = Config(od)
|
|
|
|
# api.property.read_write()
|
|
|
|
# api.option('a').value.set('192.168.1.1')
|
|
|
|
# raises(ValueError, "api.option('b').value.set('192.168.1.1')")
|
|
|
|
# api.option('a').value.set('192.168.2.1')
|
|
|
|
# #
|
|
|
|
# api.option('a').value.set('192.168.1.1')
|
|
|
|
# api.property.pop('disabled')
|
|
|
|
# with warnings.catch_warnings(record=True) as w:
|
|
|
|
# api.option('a').value.set('192.168.2.1')
|
|
|
|
# assert len(w) == 1
|
|
|
|
|
|
|
|
|
2016-11-20 14:32:06 +01:00
|
|
|
def test_consistency_double_warnings():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '', 1)
|
|
|
|
c = IntOption('c', '', 1)
|
|
|
|
od = OptionDescription('od', '', [a, b, c])
|
|
|
|
warnings.simplefilter("always", ValueWarning)
|
|
|
|
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
|
|
|
a.impl_add_consistency('not_equal', c, warnings_only=True)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2016-11-20 14:32:06 +01:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('od.a').value.set(1)
|
2016-11-20 14:32:06 +01:00
|
|
|
assert w != []
|
|
|
|
assert len(w) == 2
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('od.c').value.set(2)
|
2018-09-04 08:36:02 +02:00
|
|
|
assert len(w) == 0
|
2016-11-20 14:32:06 +01:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('od.a').value.set(2)
|
2016-11-20 14:32:06 +01:00
|
|
|
assert w != []
|
|
|
|
assert len(w) == 1
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.pop('warnings')
|
2016-11-20 14:32:06 +01:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('od.a').value.set(1)
|
2016-11-20 14:32:06 +01:00
|
|
|
assert w == []
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_warnings_error():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '', 1)
|
|
|
|
c = IntOption('c', '', 1)
|
|
|
|
od = OptionDescription('od', '', [a, b, c])
|
|
|
|
warnings.simplefilter("always", ValueWarning)
|
|
|
|
a.impl_add_consistency('not_equal', b, warnings_only=True)
|
|
|
|
a.impl_add_consistency('not_equal', c)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2016-11-20 14:32:06 +01:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(ValueError, "api.option('a').value.set(1)")
|
2016-11-20 14:32:06 +01:00
|
|
|
assert w == []
|
2016-12-07 17:28:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_network_netmask_mandatory():
|
|
|
|
a = NetworkOption('a', '', multi=True, properties=('mandatory',), default=[u'0.0.0.0'])
|
|
|
|
b = NetmaskOption('b', '', multi=True, properties=('mandatory',), default_multi=u'0.0.0.0')
|
2017-10-14 13:33:25 +02:00
|
|
|
od = MasterSlaves('a', '', [a, b])
|
2016-12-07 17:28:31 +01:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2018-03-19 08:33:53 +01:00
|
|
|
od2 = OptionDescription('od2', '', [od])
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od2)
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.read_only()
|
|
|
|
api.property.pop('mandatory')
|
2018-08-23 23:14:22 +02:00
|
|
|
api.config.dict()
|
2017-09-17 15:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_has_dependency():
|
|
|
|
a = IPOption('a', '')
|
|
|
|
b = NetmaskOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
b.impl_add_consistency('ip_netmask', a)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a').option.has_dependency() is True
|
|
|
|
assert api.option('b').option.has_dependency() is True
|
|
|
|
assert api.option('a').option.has_dependency(False) is True
|
|
|
|
assert api.option('b').option.has_dependency(False) is True
|
2017-09-17 15:55:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal_has_dependency():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
2018-08-14 23:07:07 +02:00
|
|
|
api = Config(od)
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('a').option.has_dependency() is False
|
|
|
|
assert api.option('b').option.has_dependency() is False
|
|
|
|
assert api.option('a').option.has_dependency(False) is True
|
|
|
|
assert api.option('b').option.has_dependency(False) is True
|