Merge branch 'master' into orm

Conflicts:
	test/test_option_consistency.py
	test/test_state.py
	tiramisu/option.py
This commit is contained in:
Emmanuel Garette 2014-02-06 22:21:22 +01:00
commit 21c8ed5d76
5 changed files with 469 additions and 412 deletions

View File

@ -5,7 +5,9 @@ from py.test import raises
from tiramisu.config import Config from tiramisu.config import Config
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \ from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \ BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \
PortOption, OptionDescription PortOption, NetworkOption, NetmaskOption, BroadcastOption, \
DomainnameOption, OptionDescription
from tiramisu.error import PropertiesOptionError
def make_description(): def make_description():
@ -212,6 +214,22 @@ def test_iter_all_prop():
assert list(config.iter_all()) == [('string2', 'string2')] assert list(config.iter_all()) == [('string2', 'string2')]
def test_impl_getpaths():
s = StrOption("string", "", default="string", properties=('disabled',))
s2 = StrOption("string2", "", default="string2")
s3 = StrOption("string3", "", default="string3")
s4 = StrOption("string4", "", default="string4", properties=('hidden',))
od = OptionDescription('od', '', [s3, s4])
descr = OptionDescription("options", "", [s, s2, od])
config = Config(descr)
assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
config.read_write()
raises(PropertiesOptionError, "config.od.string4")
assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
def test_invalid_option(): def test_invalid_option():
raises(TypeError, "ChoiceOption('a', '', [1, 2])") raises(TypeError, "ChoiceOption('a', '', [1, 2])")
raises(TypeError, "ChoiceOption('a', '', 1)") raises(TypeError, "ChoiceOption('a', '', 1)")
@ -225,3 +243,15 @@ def test_invalid_option():
raises(ValueError, "PortOption('a', '', 'string')") raises(ValueError, "PortOption('a', '', 'string')")
raises(ValueError, "PortOption('a', '', '11:12:13', allow_range=True)") raises(ValueError, "PortOption('a', '', '11:12:13', allow_range=True)")
raises(ValueError, "PortOption('a', '', 11111111111111111111)") raises(ValueError, "PortOption('a', '', 11111111111111111111)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=False)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=True, allow_registred=False, allow_private=True)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=False, allow_private=True)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=True)")
raises(ValueError, "PortOption('a', '', allow_zero=False, allow_wellknown=False, allow_registred=False, allow_private=False)")
raises(ValueError, "NetworkOption('a', '', 'string')")
raises(ValueError, "NetmaskOption('a', '', 'string')")
raises(ValueError, "BroadcastOption('a', '', 'string')")
raises(ValueError, "DomainnameOption('a', '', 'string')")
raises(ValueError, "DomainnameOption('a', '', type_='string')")
raises(ValueError, "DomainnameOption('a', '', allow_ip='string')")
raises(ValueError, "DomainnameOption('a', '', allow_without_dot='string')")

View File

@ -7,9 +7,9 @@ from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDesc
def test_domainname(): def test_domainname():
d = DomainnameOption('d', '') d = DomainnameOption('d', '')
e = DomainnameOption('e', '', "toto.com")
f = DomainnameOption('f', '', allow_without_dot=True) f = DomainnameOption('f', '', allow_without_dot=True)
od = OptionDescription('a', '', [d, f]) g = DomainnameOption('g', '', allow_ip=True)
od = OptionDescription('a', '', [d, f, g])
c = Config(od) c = Config(od)
c.read_write() c.read_write()
c.d = 'toto.com' c.d = 'toto.com'
@ -24,6 +24,12 @@ def test_domainname():
# #
c.f = 'toto.com' c.f = 'toto.com'
c.f = 'toto' c.f = 'toto'
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnameanditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnametoolongthathavemorethanmaximumsizeforatruedomainnameanditsnoteasytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowiendityeah'")
raises(ValueError, "c.f = 'd'")
#
c.g = 'toto.com'
c.g = '192.168.1.0'
c.g = '192.168.1.29'
def test_domainname_netbios(): def test_domainname_netbios():
@ -56,6 +62,7 @@ def test_email():
c.e = 'root@foo.com' c.e = 'root@foo.com'
raises(ValueError, "c.e = 'root'") raises(ValueError, "c.e = 'root'")
raises(ValueError, "c.e = 'root@domain'") raises(ValueError, "c.e = 'root@domain'")
raises(ValueError, "c.e = 'root[]@domain'")
def test_url(): def test_url():
@ -76,3 +83,4 @@ def test_url():
c.u = 'https://foo.com:8443' c.u = 'https://foo.com:8443'
c.u = 'https://foo.com:8443/' c.u = 'https://foo.com:8443/'
c.u = 'https://foo.com:8443/index.html' c.u = 'https://foo.com:8443/index.html'
raises(ValueError, "c.u = 'https://foo.com:84438989'")

View File

@ -186,6 +186,18 @@ def test_consistency_network_netmask():
raises(ValueError, "c.a = '192.168.1.1'") raises(ValueError, "c.a = '192.168.1.1'")
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)
c = Config(od)
c.a = '192.168.1.1'
c.b = '192.168.1.0'
raises(ConfigError, "c.c = '255.255.255.0'")
def test_consistency_ip_netmask_error_multi(): def test_consistency_ip_netmask_error_multi():
a = IPOption('a', '', multi=True) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '') b = NetmaskOption('b', '')
@ -234,6 +246,8 @@ def test_consistency_ip_netmask_multi_master():
c.b = ['255.255.255.255'] c.b = ['255.255.255.255']
c.b = ['255.255.255.0'] c.b = ['255.255.255.0']
raises(ValueError, "c.a = ['192.168.1.0']") raises(ValueError, "c.a = ['192.168.1.0']")
c.a = ['192.168.1.128']
raises(ValueError, "c.b = ['255.255.255.128']")
c.a = ['192.168.1.2', '192.168.1.3'] c.a = ['192.168.1.2', '192.168.1.3']
@ -277,6 +291,20 @@ def test_consistency_broadcast():
c.c[1] = '192.168.2.255' c.c[1] = '192.168.2.255'
def test_consistency_broadcast_error():
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
od = OptionDescription('a', '', [a, b, c])
od.impl_set_group_type(groups.master)
b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a)
c = Config(od)
c.a = ['192.168.1.0']
c.b = ['255.255.255.0']
raises(ConfigError, "c.c = ['192.168.1.255']")
def test_consistency_broadcast_default_1(): def test_consistency_broadcast_default_1():
a = NetworkOption('a', '', '192.168.1.0') a = NetworkOption('a', '', '192.168.1.0')
b = NetmaskOption('b', '', '255.255.255.128') b = NetmaskOption('b', '', '255.255.255.128')
@ -307,3 +335,14 @@ def test_consistency_not_all():
c.a = ['192.168.1.0'] c.a = ['192.168.1.0']
c.b = ['255.255.255.0'] c.b = ['255.255.255.0']
c.c = ['192.168.1.255'] c.c = ['192.168.1.255']
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)
c = Config(od)
c.cfgimpl_get_settings().setpermissive(('hidden',))
c.read_write()
c.a = 1

View File

@ -1,362 +1,368 @@
#from tiramisu.option import BoolOption, UnicodeOption, SymLinkOption, \ import autopath
# IntOption, OptionDescription
#from tiramisu.config import Config, GroupConfig, MetaConfig from tiramisu.option import BoolOption, UnicodeOption, SymLinkOption, \
#from tiramisu.setting import owners IntOption, OptionDescription
#from tiramisu.storage import delete_session from tiramisu.config import Config, GroupConfig, MetaConfig
#from tiramisu.error import ConfigError from tiramisu.setting import owners
#from pickle import dumps, loads from tiramisu.storage import delete_session
#from py.test import raises from tiramisu.error import ConfigError
# from pickle import dumps, loads
# from py.test import raises
#def return_value(value=None):
# return value
# def return_value(value=None):
# return value
#def _get_slots(opt):
# slots = set()
# for subclass in opt.__class__.__mro__: def _get_slots(opt):
# if subclass is not object: slots = set()
# slots.update(subclass.__slots__) for subclass in opt.__class__.__mro__:
# return slots if subclass is not object:
# slots.update(subclass.__slots__)
# return slots
#def _no_state(opt):
# for attr in _get_slots(opt):
# if 'state' in attr: def _no_state(opt):
# try: for attr in _get_slots(opt):
# getattr(opt, attr) if 'state' in attr:
# except: try:
# pass getattr(opt, attr)
# else: except:
# raise Exception('opt should have already attribute {0}'.format(attr)) pass
# else:
# raise Exception('opt should have already attribute {0}'.format(attr))
#def _diff_opt(opt1, opt2):
# attr1 = set(_get_slots(opt1))
# attr2 = set(_get_slots(opt2)) def _diff_opt(opt1, opt2):
# diff1 = attr1 - attr2 attr1 = set(_get_slots(opt1))
# diff2 = attr2 - attr1 attr2 = set(_get_slots(opt2))
# if diff1 != set(): diff1 = attr1 - attr2
# raise Exception('more attribute in opt1 {0}'.format(list(diff1))) diff2 = attr2 - attr1
# if diff2 != set(): if diff1 != set():
# raise Exception('more attribute in opt2 {0}'.format(list(diff2))) raise Exception('more attribute in opt1 {0}'.format(list(diff1)))
# for attr in attr1: if diff2 != set():
# if attr in ['_cache_paths', '_cache_consistencies']: raise Exception('more attribute in opt2 {0}'.format(list(diff2)))
# continue for attr in attr1:
# err1 = False if attr in ['_cache_paths', '_cache_consistencies']:
# err2 = False continue
# val1 = None err1 = False
# val2 = None err2 = False
# try: val1 = None
# val1 = getattr(opt1, attr) val2 = None
# except: try:
# err1 = True val1 = getattr(opt1, attr)
# except:
# try: err1 = True
# val2 = getattr(opt2, attr)
# except: try:
# err2 = True val2 = getattr(opt2, attr)
# assert err1 == err2 except:
# if val1 is None: err2 = True
# assert val1 == val2 assert err1 == err2
# elif attr == '_children': if val1 is None:
# assert val1[0] == val2[0] assert val1 == val2
# for index, _opt in enumerate(val1[1]): elif attr == '_children':
# assert _opt._name == val2[1][index]._name assert val1[0] == val2[0]
# elif attr == '_requires': for index, _opt in enumerate(val1[1]):
# assert val1[0][0][0]._name == val2[0][0][0]._name assert _opt._name == val2[1][index]._name
# assert val1[0][0][1:] == val2[0][0][1:] elif attr == '_requires':
# elif attr == '_opt': assert val1[0][0][0]._name == val2[0][0][0]._name
# assert val1._name == val2._name assert val1[0][0][1:] == val2[0][0][1:]
# elif attr == '_consistencies': elif attr == '_opt':
# # dict is only a cache assert val1._name == val2._name
# if isinstance(val1, list): elif attr == '_consistencies':
# for index, consistency in enumerate(val1): # dict is only a cache
# assert consistency[0] == val2[index][0] if isinstance(val1, list):
# for idx, opt in enumerate(consistency[1]): for index, consistency in enumerate(val1):
# assert opt._name == val2[index][1][idx]._name assert consistency[0] == val2[index][0]
# elif attr == '_callback': for idx, opt in enumerate(consistency[1]):
# assert val1[0] == val2[0] assert opt._name == val2[index][1][idx]._name
# if val1[1] is not None: elif attr == '_callback':
# for key, values in val1[1].items(): assert val1[0] == val2[0]
# for idx, value in enumerate(values): if val1[1] is not None:
# if isinstance(value, tuple): for key, values in val1[1].items():
# assert val1[1][key][idx][0]._name == val2[1][key][idx][0]._name for idx, value in enumerate(values):
# assert val1[1][key][idx][1] == val2[1][key][idx][1] if isinstance(value, tuple):
# else: assert val1[1][key][idx][0]._name == val2[1][key][idx][0]._name
# assert val1[1][key][idx] == val2[1][key][idx] assert val1[1][key][idx][1] == val2[1][key][idx][1]
# else: else:
# assert val1[1] == val2[1] assert val1[1][key][idx] == val2[1][key][idx]
# else: else:
# assert val1 == val2 assert val1[1] == val2[1]
# else:
# assert val1 == val2
#def _diff_conf(cfg1, cfg2):
# attr1 = set(_get_slots(cfg1))
# attr2 = set(_get_slots(cfg2)) def _diff_conf(cfg1, cfg2):
# diff1 = attr1 - attr2 attr1 = set(_get_slots(cfg1))
# diff2 = attr2 - attr1 attr2 = set(_get_slots(cfg2))
# if diff1 != set(): diff1 = attr1 - attr2
# raise Exception('more attribute in cfg1 {0}'.format(list(diff1))) diff2 = attr2 - attr1
# if diff2 != set(): if diff1 != set():
# raise Exception('more attribute in cfg2 {0}'.format(list(diff2))) raise Exception('more attribute in cfg1 {0}'.format(list(diff1)))
# for attr in attr1: if diff2 != set():
# if attr in ('_impl_context', '__weakref__'): raise Exception('more attribute in cfg2 {0}'.format(list(diff2)))
# continue for attr in attr1:
# err1 = False if attr in ('_impl_context', '__weakref__'):
# err2 = False continue
# val1 = None err1 = False
# val2 = None err2 = False
# try: val1 = None
# val1 = getattr(cfg1, attr) val2 = None
# except: try:
# err1 = True val1 = getattr(cfg1, attr)
# except:
# try: err1 = True
# val2 = getattr(cfg2, attr)
# except: try:
# err2 = True val2 = getattr(cfg2, attr)
# assert err1 == err2 except:
# if val1 is None: err2 = True
# assert val1 == val2 assert err1 == err2
# elif attr == '_impl_values': if val1 is None:
# assert cfg1.cfgimpl_get_values().get_modified_values() == cfg2.cfgimpl_get_values().get_modified_values() assert val1 == val2
# elif attr == '_impl_settings': elif attr == '_impl_values':
# assert cfg1.cfgimpl_get_settings().get_modified_properties() == cfg2.cfgimpl_get_settings().get_modified_properties() assert cfg1.cfgimpl_get_values().get_modified_values() == cfg2.cfgimpl_get_values().get_modified_values()
# assert cfg1.cfgimpl_get_settings().get_modified_permissives() == cfg2.cfgimpl_get_settings().get_modified_permissives() elif attr == '_impl_settings':
# elif attr == '_impl_descr': assert cfg1.cfgimpl_get_settings().get_modified_properties() == cfg2.cfgimpl_get_settings().get_modified_properties()
# _diff_opt(cfg1.cfgimpl_get_description(), cfg2.cfgimpl_get_description()) assert cfg1.cfgimpl_get_settings().get_modified_permissives() == cfg2.cfgimpl_get_settings().get_modified_permissives()
# else: elif attr == '_impl_descr':
# assert val1 == val2 _diff_opt(cfg1.cfgimpl_get_description(), cfg2.cfgimpl_get_description())
# else:
# assert val1 == val2
#def test_diff_opt():
# b = BoolOption('b', '')
# u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}]) def test_diff_opt():
# #u.impl_add_consistency('not_equal', b) b = BoolOption('b', '')
# s = SymLinkOption('s', u) u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
# o = OptionDescription('o', '', [b, u, s]) s = SymLinkOption('s', u)
# o1 = OptionDescription('o1', '', [o]) o = OptionDescription('o', '', [b, u, s])
# o1 = OptionDescription('o1', '', [o])
# a = dumps(o1)
# q = loads(a) a = dumps(o1)
# _diff_opt(o1, q) q = loads(a)
# _diff_opt(o1.o, q.o) _diff_opt(o1, q)
# _diff_opt(o1.o.b, q.o.b) _diff_opt(o1.o, q.o)
# _diff_opt(o1.o.u, q.o.u) _diff_opt(o1.o.b, q.o.b)
# _diff_opt(o1.o.s, q.o.s) _diff_opt(o1.o.u, q.o.u)
# _diff_opt(o1.o.s, q.o.s)
#
#def test_diff_opt_cache():
# b = BoolOption('b', '') def test_only_optiondescription():
# u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}]) b = BoolOption('b', '')
# u.impl_add_consistency('not_equal', b) raises(SystemError, "a = dumps(b)")
# s = SymLinkOption('s', u)
# o = OptionDescription('o', '', [b, u, s])
# o1 = OptionDescription('o1', '', [o]) def test_diff_opt_cache():
# o1.impl_build_cache() b = BoolOption('b', '')
# u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
# a = dumps(o1) u.impl_add_consistency('not_equal', b)
# q = loads(a) s = SymLinkOption('s', u)
# _diff_opt(o1, q) o = OptionDescription('o', '', [b, u, s])
# _diff_opt(o1.o, q.o) o1 = OptionDescription('o1', '', [o])
# _diff_opt(o1.o.b, q.o.b) o1.impl_build_cache()
# _diff_opt(o1.o.u, q.o.u)
# _diff_opt(o1.o.s, q.o.s) a = dumps(o1)
# q = loads(a)
# _diff_opt(o1, q)
#def test_diff_opt_callback(): _diff_opt(o1.o, q.o)
# b = BoolOption('b', '', callback=return_value) _diff_opt(o1.o.b, q.o.b)
# b2 = BoolOption('b2', '', callback=return_value, callback_params={'': ('yes',)}) _diff_opt(o1.o.u, q.o.u)
# b3 = BoolOption('b3', '', callback=return_value, callback_params={'': ('yes', (b, False)), 'value': ('no',)}) _diff_opt(o1.o.s, q.o.s)
# o = OptionDescription('o', '', [b, b2, b3])
# o1 = OptionDescription('o1', '', [o])
# o1.impl_build_cache() def test_diff_opt_callback():
# b = BoolOption('b', '', callback=return_value)
# a = dumps(o1) b2 = BoolOption('b2', '', callback=return_value, callback_params={'': ('yes',)})
# q = loads(a) b3 = BoolOption('b3', '', callback=return_value, callback_params={'': ('yes', (b, False)), 'value': ('no',)})
# _diff_opt(o1, q) o = OptionDescription('o', '', [b, b2, b3])
# _diff_opt(o1.o, q.o) o1 = OptionDescription('o1', '', [o])
# _diff_opt(o1.o.b, q.o.b) o1.impl_build_cache()
# _diff_opt(o1.o.b2, q.o.b2)
# _diff_opt(o1.o.b3, q.o.b3) a = dumps(o1)
# q = loads(a)
# _diff_opt(o1, q)
#def test_no_state_attr(): _diff_opt(o1.o, q.o)
# # all _state_xxx attributes should be deleted _diff_opt(o1.o.b, q.o.b)
# b = BoolOption('b', '') _diff_opt(o1.o.b2, q.o.b2)
# u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}]) _diff_opt(o1.o.b3, q.o.b3)
# s = SymLinkOption('s', u)
# o = OptionDescription('o', '', [b, u, s])
# o1 = OptionDescription('o1', '', [o]) def test_no_state_attr():
# # all _state_xxx attributes should be deleted
# a = dumps(o1) b = BoolOption('b', '')
# q = loads(a) u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
# _no_state(q) s = SymLinkOption('s', u)
# _no_state(q.o) o = OptionDescription('o', '', [b, u, s])
# _no_state(q.o.b) o1 = OptionDescription('o1', '', [o])
# _no_state(q.o.u)
# _no_state(q.o.s) a = dumps(o1)
# q = loads(a)
# _no_state(q)
#def test_state_config(): _no_state(q.o)
# val1 = BoolOption('val1', "") _no_state(q.o.b)
# maconfig = OptionDescription('rootconfig', '', [val1]) _no_state(q.o.u)
# try: _no_state(q.o.s)
# cfg = Config(maconfig, persistent=True, session_id='29090931')
# except ValueError:
# cfg = Config(maconfig, session_id='29090931') def test_state_config():
# cfg._impl_test = True val1 = BoolOption('val1', "")
# a = dumps(cfg) maconfig = OptionDescription('rootconfig', '', [val1])
# q = loads(a) try:
# _diff_conf(cfg, q) cfg = Config(maconfig, persistent=True, session_id='29090931')
# try: except ValueError:
# delete_session('29090931') cfg = Config(maconfig, session_id='29090931')
# except ConfigError: cfg._impl_test = True
# pass a = dumps(cfg)
# q = loads(a)
# _diff_conf(cfg, q)
#def test_state_properties(): try:
# val1 = BoolOption('val1', "") delete_session('29090931')
# maconfig = OptionDescription('rootconfig', '', [val1]) except ConfigError:
# try: pass
# cfg = Config(maconfig, persistent=True, session_id='29090932')
# except ValueError:
# cfg = Config(maconfig, session_id='29090932') def test_state_properties():
# cfg._impl_test = True val1 = BoolOption('val1', "")
# cfg.read_write() maconfig = OptionDescription('rootconfig', '', [val1])
# cfg.cfgimpl_get_settings()[val1].append('test') try:
# a = dumps(cfg) cfg = Config(maconfig, persistent=True, session_id='29090932')
# q = loads(a) except ValueError:
# _diff_conf(cfg, q) cfg = Config(maconfig, session_id='29090932')
# try: cfg._impl_test = True
# delete_session('29090932') cfg.read_write()
# except ConfigError: cfg.cfgimpl_get_settings()[val1].append('test')
# pass a = dumps(cfg)
# q = loads(a)
# _diff_conf(cfg, q)
#def test_state_values(): try:
# val1 = BoolOption('val1', "") delete_session('29090932')
# maconfig = OptionDescription('rootconfig', '', [val1]) except ConfigError:
# try: pass
# cfg = Config(maconfig, persistent=True, session_id='29090933')
# except ValueError:
# cfg = Config(maconfig, session_id='29090933') def test_state_values():
# cfg._impl_test = True val1 = BoolOption('val1', "")
# cfg.val1 = True maconfig = OptionDescription('rootconfig', '', [val1])
# a = dumps(cfg) try:
# q = loads(a) cfg = Config(maconfig, persistent=True, session_id='29090933')
# _diff_conf(cfg, q) except ValueError:
# q.val1 = False cfg = Config(maconfig, session_id='29090933')
# #assert cfg.val1 is True cfg._impl_test = True
# assert q.val1 is False cfg.val1 = True
# try: a = dumps(cfg)
# delete_session('29090933') q = loads(a)
# except ConfigError: _diff_conf(cfg, q)
# pass q.val1 = False
# #assert cfg.val1 is True
# assert q.val1 is False
#def test_state_values_owner(): try:
# val1 = BoolOption('val1', "") delete_session('29090933')
# maconfig = OptionDescription('rootconfig', '', [val1]) except ConfigError:
# try: pass
# cfg = Config(maconfig, persistent=True, session_id='29090934')
# except ValueError:
# cfg = Config(maconfig, session_id='29090934') def test_state_values_owner():
# cfg._impl_test = True val1 = BoolOption('val1', "")
# owners.addowner('newowner') maconfig = OptionDescription('rootconfig', '', [val1])
# cfg.cfgimpl_get_settings().setowner(owners.newowner) try:
# cfg.val1 = True cfg = Config(maconfig, persistent=True, session_id='29090934')
# a = dumps(cfg) except ValueError:
# q = loads(a) cfg = Config(maconfig, session_id='29090934')
# _diff_conf(cfg, q) cfg._impl_test = True
# q.val1 = False owners.addowner('newowner')
# nval1 = q.cfgimpl_get_description().val1 cfg.cfgimpl_get_settings().setowner(owners.newowner)
# assert q.getowner(nval1) == owners.newowner cfg.val1 = True
# try: a = dumps(cfg)
# delete_session('29090934') q = loads(a)
# except ConfigError: _diff_conf(cfg, q)
# pass q.val1 = False
# nval1 = q.cfgimpl_get_description().val1
# assert q.getowner(nval1) == owners.newowner
#def test_state_metaconfig(): try:
# i1 = IntOption('i1', '') delete_session('29090934')
# od1 = OptionDescription('od1', '', [i1]) except ConfigError:
# od2 = OptionDescription('od2', '', [od1]) pass
# conf1 = Config(od2, session_id='29090935')
# conf1._impl_test = True
# conf2 = Config(od2, session_id='29090936') def test_state_metaconfig():
# conf2._impl_test = True i1 = IntOption('i1', '')
# meta = MetaConfig([conf1, conf2], session_id='29090937') od1 = OptionDescription('od1', '', [i1])
# meta._impl_test = True od2 = OptionDescription('od2', '', [od1])
# raises(ConfigError, "dumps(meta)") conf1 = Config(od2, session_id='29090935')
# try: conf1._impl_test = True
# delete_session('29090935') conf2 = Config(od2, session_id='29090936')
# delete_session('29090936') conf2._impl_test = True
# delete_session('29090937') meta = MetaConfig([conf1, conf2], session_id='29090937')
# except ConfigError: meta._impl_test = True
# pass raises(ConfigError, "dumps(meta)")
# try:
# delete_session('29090935')
#def test_state_groupconfig(): delete_session('29090936')
# i1 = IntOption('i1', '') delete_session('29090937')
# od1 = OptionDescription('od1', '', [i1]) except ConfigError:
# od2 = OptionDescription('od2', '', [od1]) pass
# conf1 = Config(od2, session_id='29090935')
# conf1._impl_test = True
# conf2 = Config(od2, session_id='29090936') def test_state_groupconfig():
# conf2._impl_test = True i1 = IntOption('i1', '')
# meta = GroupConfig([conf1, conf2], session_id='29090937') od1 = OptionDescription('od1', '', [i1])
# meta._impl_test = True od2 = OptionDescription('od2', '', [od1])
# a = dumps(meta) conf1 = Config(od2, session_id='29090935')
# q = loads(a) conf1._impl_test = True
# _diff_conf(meta, q) conf2 = Config(od2, session_id='29090936')
# try: conf2._impl_test = True
# delete_session('29090935') meta = GroupConfig([conf1, conf2], session_id='29090937')
# delete_session('29090936') meta._impl_test = True
# delete_session('29090937') a = dumps(meta)
# except ConfigError: q = loads(a)
# pass _diff_conf(meta, q)
# try:
# delete_session('29090935')
#def test_state_unkown_setting_owner(): delete_session('29090936')
# """load an unknow _owner, should create it""" delete_session('29090937')
# assert not 'supernewuser' in owners.__dict__ except ConfigError:
# loads("""ccopy_reg pass
#_reconstructor
#p0
#(ctiramisu.setting def test_state_unkown_setting_owner():
#Settings """load an unknow _owner, should create it"""
#p1 assert not 'supernewuser' in owners.__dict__
#c__builtin__ loads("""ccopy_reg
#object _reconstructor
#p2 p0
#Ntp3 (ctiramisu.setting
#Rp4 Settings
#(dp5 p1
#S'_owner' c__builtin__
#p6 object
#S'supernewuser' p2
#p7 Ntp3
#sS'_p_' Rp4
#p8 (dp5
#g0 S'_owner'
#(ctiramisu.storage.dictionary.setting p6
#Settings S'supernewuser'
#p9 p7
#g2 sS'_p_'
#Ntp10 p8
#Rp11 g0
#(dp12 (ctiramisu.storage.dictionary.setting
#S'_cache' Settings
#p13 p9
#(dp14 g2
#sS'_permissives' Ntp10
#p15 Rp11
#(dp16 (dp12
#sS'_properties' S'_cache'
#p17 p13
#(dp18 (dp14
#sbsb. sS'_permissives'
#.""") p15
# assert 'supernewuser' in owners.__dict__ (dp16
sS'_properties'
p17
(dp18
sbsb.
.""")
assert 'supernewuser' in owners.__dict__

View File

@ -400,9 +400,6 @@ class Option(OnlyOption):
""" """
if context is not None: if context is not None:
descr = context.cfgimpl_get_description() descr = context.cfgimpl_get_description()
#option is also in all_cons_opts
if option not in all_cons_opts:
raise ConfigError(_('option not in all_cons_opts'))
all_cons_vals = [] all_cons_vals = []
for opt in all_cons_opts: for opt in all_cons_opts:
@ -413,7 +410,8 @@ class Option(OnlyOption):
#if context, calculate value, otherwise get default value #if context, calculate value, otherwise get default value
if context is not None: if context is not None:
opt_value = context._getattr( opt_value = context._getattr(
descr.impl_get_path_by_opt(opt), validate=False) descr.impl_get_path_by_opt(opt), validate=False,
force_permissive=True)
else: else:
opt_value = opt.impl_getdefault() opt_value = opt.impl_getdefault()
@ -641,7 +639,6 @@ class Option(OnlyOption):
consistencies = self._state_consistencies consistencies = self._state_consistencies
else: else:
consistencies = self._consistencies consistencies = self._consistencies
if isinstance(consistencies, list):
new_value = [] new_value = []
for consistency in consistencies: for consistency in consistencies:
values = [] values = []
@ -651,21 +648,6 @@ class Option(OnlyOption):
else: else:
values.append(descr.impl_get_path_by_opt(obj)) values.append(descr.impl_get_path_by_opt(obj))
new_value.append((consistency[0], tuple(values))) new_value.append((consistency[0], tuple(values)))
else:
new_value = {}
for key, _consistencies in consistencies.items():
new_value[key] = []
for key_cons, _cons in _consistencies:
_list_cons = []
for _con in _cons:
if load:
_list_cons.append(
descr.impl_get_opt_by_path(_con))
else:
_list_cons.append(
descr.impl_get_path_by_opt(_con))
new_value[key].append((key_cons, tuple(_list_cons)))
if load: if load:
del(self._state_consistencies) del(self._state_consistencies)
self._consistencies = new_value self._consistencies = new_value
@ -921,8 +903,8 @@ class PortOption(Option):
for val in value: for val in value:
try: try:
if not self._extra['_min_value'] <= int(val) <= self._extra['_max_value']: if not self._extra['_min_value'] <= int(val) <= self._extra['_max_value']:
raise ValueError('invalid port, must be an between {0} ' raise ValueError(_('invalid port, must be an between {0} '
'and {1}'.format( 'and {1}').format(
self._extra['_min_value'], self._extra['_min_value'],
self._extra['_max_value'])) self._extra['_max_value']))
except ValueError: except ValueError:
@ -979,19 +961,14 @@ class NetmaskOption(Option):
IP('{0}/{1}'.format(val_ipnetwork, val_netmask), IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
make_net=not make_net) make_net=not make_net)
except ValueError: except ValueError:
if not make_net: pass
msg = _("invalid network {0} ({1}) "
"with netmask {2},"
" this network is an IP")
else: else:
if make_net: if make_net:
msg = _("invalid IP {0} ({1}) with netmask {2}," msg = _("invalid IP {0} ({1}) with netmask {2},"
" this IP is a network") " this IP is a network")
except ValueError: except ValueError:
if make_net: if not make_net:
msg = _('invalid IP {0} ({1}) with netmask {2}')
else:
msg = _('invalid network {0} ({1}) with netmask {2}') msg = _('invalid network {0} ({1}) with netmask {2}')
if msg is not None: if msg is not None:
raise ValueError(msg.format(val_ipnetwork, opts[1].impl_getname(), raise ValueError(msg.format(val_ipnetwork, opts[1].impl_getname(),
@ -1338,13 +1315,10 @@ class OptionDescription(BaseOption, StorageOptionDescription):
if consistencies is not None: if consistencies is not None:
for func, all_cons_opts in consistencies: for func, all_cons_opts in consistencies:
#all_cons_opts[0] is the option where func is set #all_cons_opts[0] is the option where func is set
ret = all_cons_opts[0]._launch_consistency(func, option, all_cons_opts[0]._launch_consistency(func, option,
value, value,
context, index, context, index,
all_cons_opts) all_cons_opts)
if ret is False:
return False
return True
# ____________________________________________________________ # ____________________________________________________________
# serialize object # serialize object