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, PathConfig, \ Params, ParamOption, ParamValue from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, SlaveError, APIError from tiramisu.storage import list_sessions owners.addowner('path1') owners.addowner('path2') def teardown_function(function): assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__) 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_description1(): 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_description2(): 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_description3(): 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_pathconfig(double=False): od1 = make_description() od2 = make_description1() od3 = make_description2() conf1 = Config(od1, session_id='conf1') conf2 = Config(od2, session_id='conf2') path = PathConfig(od3, [conf1, conf2], session_id='path') if double: od4 = make_description3() path.owner.set(owners.path2) path = PathConfig(od4, [path], session_id='doublepath') path.property.read_write() path.owner.set(owners.path1) return path def test_unknown_config(): path = make_pathconfig() raises(ConfigError, "path.config('unknown')") def test_none(): path = make_pathconfig() assert path.option('od1.i3').value.get() is path.config('conf1').option('od1.i3').value.get() is path.config('conf2').option('od1.i3').value.get() is None assert path.option('od1.i3').owner.get() is path.config('conf1').option('od1.i3').owner.get() is path.config('conf2').option('od1.i3').owner.get() is owners.default # path.option('od1.i3').value.set(3) assert path.option('od1.i3').value.get() == path.config('conf1').option('od1.i3').value.get() == path.config('conf2').option('od1.i3').value.get() == 3 assert path.option('od1.i3').owner.get() is path.config('conf1').option('od1.i3').owner.get() is path.config('conf2').option('od1.i3').owner.get() is owners.path1 # path.config('conf1').option('od1.i3').value.set(2) assert path.option('od1.i3').value.get() == path.config('conf2').option('od1.i3').value.get() == 3 assert path.config('conf1').option('od1.i3').value.get() == 2 assert path.option('od1.i3').owner.get() is path.config('conf2').option('od1.i3').owner.get() is owners.path1 assert path.config('conf1').option('od1.i3').owner.get() is owners.user # path.option('od1.i3').value.set(4) assert path.option('od1.i3').value.get() == path.config('conf2').option('od1.i3').value.get() == 4 assert path.config('conf1').option('od1.i3').value.get() == 2 assert path.option('od1.i3').owner.get() is path.config('conf2').option('od1.i3').owner.get() is owners.path1 assert path.config('conf1').option('od1.i3').owner.get() is owners.user # path.option('od1.i3').value.reset() assert path.option('od1.i3').value.get() is path.config('conf2').option('od1.i3').value.get() is None assert path.config('conf1').option('od1.i3').value.get() == 2 assert path.option('od1.i3').owner.get() is path.config('conf2').option('od1.i3').owner.get() is owners.default assert path.config('conf1').option('od1.i3').owner.get() is owners.user # path.config('conf1').option('od1.i3').value.reset() assert path.option('od1.i3').value.get() is path.config('conf1').option('od1.i3').value.get() is path.config('conf2').option('od1.i3').value.get() is None assert path.option('od1.i3').owner.get() is path.config('conf1').option('od1.i3').owner.get() is path.config('conf2').option('od1.i3').owner.get() is owners.default # assert path.config(None).config.name() == path.config.name() def test_reset(): path = make_pathconfig() assert path.option('od1.i2').value.get() == 1 path.option('od1.i2').value.set(2) path.config('conf1').option('od1.i2').value.set(3) assert path.option('od1.i2').value.get() == 2 assert path.config('conf1').option('od1.i2').value.get() == 3 assert path.config('conf2').option('od1.i2').value.get() == 2 path.config.reset() assert path.option('od1.i2').value.get() == 1 assert path.config('conf1').option('od1.i2').value.get() == 3 assert path.config('conf2').option('od1.i2').value.get() == 1 def test_default(): path = make_pathconfig() assert path.option('od1.i2').value.get() == path.config('conf1').option('od1.i2').value.get() == path.config('conf2').option('od1.i2').value.get() == 1 assert path.option('od1.i2').owner.get() is path.config('conf1').option('od1.i2').owner.get() is path.config('conf2').option('od1.i2').owner.get() is owners.default # path.option('od1.i2').value.set(3) assert path.option('od1.i2').value.get() == path.config('conf1').option('od1.i2').value.get() == path.config('conf2').option('od1.i2').value.get() == 3 assert path.option('od1.i2').owner.get() is path.config('conf1').option('od1.i2').owner.get() is path.config('conf2').option('od1.i2').owner.get() is owners.path1 # path.config('conf1').option('od1.i2').value.set(2) assert path.option('od1.i2').value.get() == path.config('conf2').option('od1.i2').value.get() == 3 assert path.config('conf1').option('od1.i2').value.get() == 2 assert path.option('od1.i2').owner.get() is path.config('conf2').option('od1.i2').owner.get() is owners.path1 assert path.config('conf1').option('od1.i2').owner.get() is owners.user # path.option('od1.i2').value.set(4) assert path.option('od1.i2').value.get() == path.config('conf2').option('od1.i2').value.get() == 4 assert path.config('conf1').option('od1.i2').value.get() == 2 assert path.option('od1.i2').owner.get() is path.config('conf2').option('od1.i2').owner.get() is owners.path1 assert path.config('conf1').option('od1.i2').owner.get() is owners.user # path.option('od1.i2').value.reset() assert path.option('od1.i2').value.get() == path.config('conf2').option('od1.i2').value.get() == 1 assert path.config('conf1').option('od1.i2').value.get() == 2 assert path.option('od1.i2').owner.get() is path.config('conf2').option('od1.i2').owner.get() is owners.default assert path.config('conf1').option('od1.i2').owner.get() is owners.user # path.config('conf1').option('od1.i2').value.reset() assert path.option('od1.i2').value.get() == path.config('conf1').option('od1.i2').value.get() == path.config('conf2').option('od1.i2').value.get() == 1 assert path.option('od1.i2').owner.get() is path.config('conf1').option('od1.i2').owner.get() is path.config('conf2').option('od1.i2').owner.get() is owners.default def test_contexts(): path = make_pathconfig() errors = path.value.set('od1.i2', 6, only_config=True) assert path.option('od1.i2').value.get() == 1 assert path.option('od1.i2').owner.get() == owners.default assert path.config('conf1').option('od1.i2').value.get() == path.config('conf1').option('od1.i2').value.get() == 6 assert path.config('conf1').option('od1.i2').owner.get() == path.config('conf1').option('od1.i2').owner.get() is owners.user assert len(errors) == 0 def test_find(): path = make_pathconfig() ret = list(path.option.find('i2')) assert len(ret) == 1 assert 1 == ret[0].value.get() assert 1 == path.option.find('i2', first=True).value.get() assert path.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None, 'od1.i2': 1, 'od1.i5': [2]} def test_path_path(): path = make_pathconfig(double=True) assert path.option('od1.i2').value.get() == path.config('path').option('od1.i2').value.get() == path.config('path.conf1').option('od1.i2').value.get() == path.config('path.conf2').option('od1.i2').value.get() == 1 assert path.option('od1.i2').owner.get() is path.config('path').option('od1.i2').owner.get() is path.config('path.conf1').option('od1.i2').owner.get() is path.config('path.conf2').option('od1.i2').owner.get() is owners.default # path.option('od1.i2').value.set(3) assert path.option('od1.i2').value.get() == path.config('path').option('od1.i2').value.get() == path.config('path.conf1').option('od1.i2').value.get() == path.config('path.conf2').option('od1.i2').value.get() == 3 assert path.option('od1.i2').owner.get() is path.config('path').option('od1.i2').owner.get() is path.config('path.conf1').option('od1.i2').owner.get() is path.config('path.conf2').option('od1.i2').owner.get() is owners.path1 # path.config('path.conf1').option('od1.i2').value.set(2) assert path.option('od1.i2').value.get() == path.config('path').option('od1.i2').value.get() == path.config('path.conf2').option('od1.i2').value.get() == 3 assert path.config('path.conf1').option('od1.i2').value.get() == 2 assert path.option('od1.i2').owner.get() is path.config('path').option('od1.i2').owner.get() is path.config('path.conf2').option('od1.i2').owner.get() is owners.path1 assert path.config('path.conf1').option('od1.i2').owner.get() is owners.user # path.config('path').option('od1.i2').value.set(4) assert path.option('od1.i2').value.get() == 3 assert path.config('path').option('od1.i2').value.get() == path.config('path.conf2').option('od1.i2').value.get() == 4 assert path.config('path.conf1').option('od1.i2').value.get() == 2 assert path.option('od1.i2').owner.get() is owners.path1 assert path.config('path').option('od1.i2').owner.get() is path.config('path.conf2').option('od1.i2').owner.get() is owners.path2 assert path.config('path.conf1').option('od1.i2').owner.get() is owners.user # path.config('path').option('od1.i2').value.reset() assert path.option('od1.i2').value.get() == path.config('path').option('od1.i2').value.get() == path.config('path.conf2').option('od1.i2').value.get() == 3 assert path.config('path.conf1').option('od1.i2').value.get() == 2 assert path.option('od1.i2').owner.get() is path.config('path').option('od1.i2').owner.get() is path.config('path.conf2').option('od1.i2').owner.get() is owners.path1 assert path.config('path.conf1').option('od1.i2').owner.get() is owners.user # path.option('od1.i2').value.reset() assert path.option('od1.i2').value.get() == path.config('path').option('od1.i2').value.get() == path.config('path.conf2').option('od1.i2').value.get() == 1 assert path.config('path.conf1').option('od1.i2').value.get() == 2 assert path.option('od1.i2').owner.get() is path.config('path').option('od1.i2').owner.get() is path.config('path.conf2').option('od1.i2').owner.get() is owners.default assert path.config('path.conf1').option('od1.i2').owner.get() is owners.user # path.config('path.conf1').option('od1.i2').value.reset() assert path.option('od1.i2').value.get() == path.config('path').option('od1.i2').value.get() == path.config('path.conf1').option('od1.i2').value.get() == path.config('path.conf2').option('od1.i2').value.get() == 1 assert path.option('od1.i2').owner.get() is path.config('path').option('od1.i2').owner.get() is path.config('path.conf1').option('od1.i2').owner.get() is path.config('path.conf2').option('od1.i2').owner.get() is owners.default def test_path_path_set(): path = make_pathconfig(double=True) errors1 = path.value.set('od1.i1', 7, only_config=True) errors2 = path.value.set('od1.i6', 7, only_config=True) assert len(errors1) == 0 assert len(errors2) == 2 conf1 = path.config('path.conf1')._config_bag.context conf2 = path.config('path.conf2')._config_bag.context assert path.config('path.conf1').option('od1.i1').value.get() == path.config('path.conf2').option('od1.i1').value.get() == 7 # dconfigs = [] for conf in path.config.find('i1', value=7).config.list(): dconfigs.append(conf._config_bag.context) assert [conf1, conf2] == dconfigs path.config('path.conf1').option('od1.i1').value.set(8) # dconfigs = [] for conf in path.config.find('i1').config.list(): dconfigs.append(conf._config_bag.context) assert [conf1, conf2] == dconfigs assert conf2 == list(path.config.find('i1', value=7).config.list())[0]._config_bag.context assert conf1 == list(path.config.find('i1', value=8).config.list())[0]._config_bag.context # dconfigs = [] for conf in path.config.find('i5', value=2).config.list(): dconfigs.append(conf._config_bag.context) assert [conf1, conf2] == dconfigs # raises(AttributeError, "path.config.find('i1', value=10)") raises(AttributeError, "path.config.find('not', value=10)") raises(AttributeError, "path.config.find('i6')") raises(ValueError, "path.value.set('od1.i6', 7, only_config=True, force_default=True)") raises(ValueError, "path.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)") raises(ValueError, "path.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)") def test_not_path(): 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(APIError, "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 grp.option('od1.i1').value.reset() assert grp.config('conf1').option('od1.i1').owner.get() is grp.config('conf2').option('od1.i1').owner.get() is owners.default 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').config.list() conf1._config_bag.context == next(itr)._config_bag.context conf2._config_bag.context == next(itr)._config_bag.context try: next(itr) except StopIteration: pass except: raise Exception('no') else: raise Exception('no') 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_path_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') path = PathConfig(od2, [conf1, conf2]) path.owner.set(owners.path1) raises(TypeError, 'PathConfig(od2, "string")') # same descr but conf1 already in path raises(ValueError, "PathConfig(od2, [conf1, conf3])") # not same descr PathConfig(od2, [conf3, conf4]) def test_path_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') path = PathConfig(od, [conf1, conf2]) path.property.read_only() itr = path.config.find('ip_admin_eth0').config.list() assert conf1._config_bag.context == next(itr)._config_bag.context assert conf2._config_bag.context == next(itr)._config_bag.context itr = path.config.find('netmask_admin_eth0').config.list() assert conf1._config_bag.context == next(itr)._config_bag.context assert conf2._config_bag.context == next(itr)._config_bag.context path.property.read_write() raises(AttributeError, "path.config.find('netmask_admin_eth0')") itr = path.unrestraint.config.find('netmask_admin_eth0').config.list() assert conf1._config_bag.context == next(itr)._config_bag.context assert conf2._config_bag.context == next(itr)._config_bag.context path.property.read_only() itr = path.config.find('netmask_admin_eth0').config.list() assert conf1._config_bag.context == next(itr)._config_bag.context assert conf2._config_bag.context == next(itr)._config_bag.context def test_path_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') path = PathConfig(od, [conf1, conf2], session_id="path") path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8']) assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None #FIXME devrait raise ! assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset() # path.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None path.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' path.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None def test_path_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') path = PathConfig(od, [conf1, conf2]) assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None # path.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None # path.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' # path.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None def test_path_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') path = PathConfig(od, [conf1, conf2]) path.owner.set(owners.path1) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() raises(SlaveError, "path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()") # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset() assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() # path.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.path1 assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() # path.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.path1 assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.path1 # path.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0') assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.path1 assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.path1 # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user assert path.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default def test_path_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') path = PathConfig(od, [conf1, conf2]) path.property.read_write() path.owner.set('path1') assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] # errors = path.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1']) assert len(errors) == 0 assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] # errors = path.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3']) assert len(errors) == 0 assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] # errors = path.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True) assert len(errors) == 0 assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] def test_path_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') path = PathConfig(od, [conf1, conf2]) path.property.read_write() path.owner.set('path1') assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() errors = path.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True) assert len(errors) == 0 assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user def test_path_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') path = PathConfig(od, [conf1, conf2]) path.property.read_write() path.owner.set('path1') # assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() errors = path.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True) assert len(errors) == 0 assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.path1 assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.path1 # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.path1 errors = path.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True) assert len(errors) == 0 assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.path1 def test_path_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') path = PathConfig(od, [conf1, conf2]) path.property.read_write() path.owner.set('path1') # assert path.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() errors = path.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 path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.path1 assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user # path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3']) assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user errors = path.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 path.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5'] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3'] assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert path.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user assert path.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user def test_path_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') path = PathConfig(od, [conf1, conf2]) path.property.read_write() path.owner.set('path1') raises(ValueError, "path.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True)") def test_path_properties_path(): 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') conf1.property.read_write() conf2.property.read_write() path = PathConfig(od, [conf1, conf2]) path.property.read_write() assert path.config('conf1').value.dict() == {} def test_path_exception_path(): 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') path = PathConfig(od, [conf1, conf2]) path.property.read_write() raises(Exception, "conf1.make_dict()") def test_path_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') path = PathConfig(maconfig, [cfg]) path.property.read_write() assert path.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'} path.config('cfg').option('val1').value.set('new') assert path.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} path.config('cfg').option('val1').value.reset() path.option('val1').value.set('new') assert path.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} path.config('cfg').option('val4').value.set('new1') assert path.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} path.config('cfg').option('val4').value.reset() path.option('val4').value.set('new1') assert path.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} path.option('val4').value.reset() def test_path_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') path = PathConfig(maconfig, [cfg]) path.property.read_write() assert path.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} path.config('cfg1').option('val').value.set('val1') assert path.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'} path.config('cfg1').option('val').value.reset() path.option('val').value.set('val1') assert path.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'} path.option('val').value.reset() path.config('cfg1').option('val1.val2', 0).value.set('val2') assert path.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} path.config('cfg1').option('val1.val2', 0).value.reset() assert path.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} path.option('val1.val2', 0).value.set('val2') assert path.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} path.config('cfg1').option('val1.val3', 0).value.set('val6') assert path.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'} path.option('val1.val2', 0).value.reset() path.config('cfg1').option('val1.val3', 0).value.reset() path.config('cfg1').option('val1.val1').value.set(['val3']) assert path.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'} path.config('cfg1').option('val1.val1').value.reset() assert path.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'} path.option('val1.val1').value.set(['val3']) assert path.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'} path.config('cfg1').option('val1.val2', 0).value.set('val2') assert path.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'} path.option('val1.val1').value.set(['val3', 'rah']) assert path.config('cfg1').value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'} path.option('val1.val1').value.pop(1) path.option('val1.val1').value.set(['val4']) assert path.config('cfg1').value.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]) od0 = OptionDescription('root', '', [interface1]) 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]) od1 = OptionDescription('root', '', [interface1]) 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]) od2 = OptionDescription('root', '', [interface1]) conf1 = Config(od0, session_id='conf1') conf2 = Config(od1, session_id='conf2') meta = PathConfig(od2, [conf1, conf2]) meta.property.read_write() meta.owner.set('path1') 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.option('ip_admin_eth0.ip_admin_eth0').value.reset(children=True) 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_path_properties_path_copy(): 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',)) interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) 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]) 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',)) interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) conf1 = Config(interface0, session_id='conf1') conf2 = Config(interface1, session_id='conf2') conf1.property.read_write() conf2.property.read_write() path = PathConfig(interface2, [conf1, conf2], session_id='path1') path.property.read_write() conf3 = path.config('conf1').config.copy(session_id='conf3') path2 = conf3.config.metaconfig() assert path.config.name() == path2.config.name() assert path.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert path.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert path.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} path.option('ip_admin_eth0').value.set(['192.168.1.2']) assert path.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert path.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert path.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.2']} ret = path.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) assert path.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert path.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert path.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.3']} def test_path_properties_path_deepcopy(): 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',)) interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) 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]) 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',)) interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) conf1 = Config(interface0, session_id='conf1') conf2 = Config(interface1, session_id='conf2') conf1.property.read_write() conf2.property.read_write() path = PathConfig(interface2, [conf1, conf2]) path.permissive.set(frozenset({'hidden'})) path.property.read_write() path2 = path.config('conf1').config.deepcopy(session_id='conf3') assert path != path2 assert path.permissive.get() == path2.permissive.get() assert path.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert path.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} assert path2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} path.option('ip_admin_eth0').value.set(['192.168.1.2']) assert path.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert path.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']} assert path2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} path.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True) assert path.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert path.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']} assert path2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} def test_path_properties_subpath_deepcopy(): 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',)) interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) 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]) 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',)) interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) conf1 = Config(interface0, session_id='conf1') conf1.property.read_write() path1 = PathConfig(interface1, [conf1], session_id='path1') path2 = PathConfig(interface2, [path1], session_id='path2') path_copy = conf1.config.deepcopy(session_id='conf2', metaconfig_prefix='copy_') assert path_copy.config.name() == 'copy_path2' assert path_copy.config('copy_path1').config.name() == 'copy_path1' assert path_copy.config('copy_path1').config('conf2').config.name() == 'conf2' def test_path_properties_subpath_deepcopy_owner(): ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") netmask_admin_eth0 = NetmaskOption('netmask_admin_eth1', "mask") interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip") netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip") netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask") interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) conf1 = Config(interface0, session_id='conf1') conf1.owner.set('conf1_user') conf1.property.read_write() path1 = PathConfig(interface1, [conf1], session_id='path1') path1.owner.set('path1_user') path2 = PathConfig(interface2, [path1], session_id='path2') path2.owner.set('path2_user') # conf1.option('ip_admin_eth0').value.set('192.168.0.1') assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user' path2.option('ip_admin_eth0').value.set('192.168.0.3') assert path2.option('ip_admin_eth0').owner.get() == 'path2_user' # path2_copy = conf1.config.deepcopy(session_id='conf2', metaconfig_prefix='copy_') path2_copy.option('netmask_admin_eth0').value.set('255.255.255.255') assert path2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3' assert path2_copy.option('ip_admin_eth0').owner.get() == 'path2_user' assert path2_copy.option('netmask_admin_eth0').owner.get() == 'path2_user' # path1_copy = path2_copy.config('copy_path1') path1_copy.option('netmask_admin_eth0').value.set('255.255.255.255') # conf2 = path1_copy.config('conf2') conf2.owner.set('conf2_user') conf2.option('netmask_admin_eth1').value.set('255.255.255.255') assert conf2.option('netmask_admin_eth1').owner.get() == 'conf2_user' assert conf2.option('ip_admin_eth0').value.get() == '192.168.0.1' assert conf2.option('ip_admin_eth0').owner.get() == 'conf1_user' def test_path_properties_path_set_value(): ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.1']) netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',)) interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) netmask_admin_eth0 = NetmaskOption('netmask_admin_eth1', "mask", multi=True, properties=('disabled',)) interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) 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',)) interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) conf1 = Config(interface0, session_id='conf1') conf2 = Config(interface1, session_id='conf2') conf1.property.read_write() conf2.property.read_write() path = PathConfig(interface2, [conf1, conf2]) path.property.read_write() assert path.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} ret = path.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], AttributeError) del ret[1] del ret[0] del ret ret = path.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True) assert len(ret) == 2 assert isinstance(ret[0], AttributeError) assert isinstance(ret[1], PropertiesOptionError) del ret[1] del ret[0] del ret ret = path.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], AttributeError) assert isinstance(ret[2], PropertiesOptionError) del ret[2] del ret[1] del ret[0] del ret ret = path.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True) assert len(ret) == 2 assert isinstance(ret[0], AttributeError) assert isinstance(ret[1], PropertiesOptionError) del ret[1] del ret[0] del ret ret = path.value.set('ip_admin_eth0', '255.255.255.255', only_config=True) assert len(ret) == 2 assert isinstance(ret[0], AttributeError) assert isinstance(ret[1], ValueError) del ret[1] del ret[0] del ret ret = path.value.set('ip_admin_eth0', '255.255.255.255', force_default=True) assert len(ret) == 2 assert isinstance(ret[0], AttributeError) assert isinstance(ret[1], ValueError) del ret[1] del ret[0] del ret ret = path.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True) assert len(ret) == 2 assert isinstance(ret[0], AttributeError) assert isinstance(ret[1], ValueError) del ret[1] del ret[0] del ret ret = path.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True) assert len(ret) == 2 assert isinstance(ret[0], AttributeError) assert isinstance(ret[1], ValueError) del ret[1] del ret[0] del ret def test_path_different_default(): ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1']) interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2']) interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.3']) interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.4']) ip_admin_eth1 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.5']) interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1]) ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6']) interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0]) conf1 = Config(interface0, session_id='conf1') conf1.property.read_write() conf2 = Config(interface1, session_id='conf2') conf2.property.read_write() path = PathConfig(interface2, [conf1, conf2], session_id='subpath1') path = PathConfig(interface3, [path], session_id='subpath2') path = PathConfig(interface4, [path]) path.property.read_write() path.value.dict() == {'ip_admin_eth0': ['192.168.1.6']} path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']} path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']} path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']} path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']} # path.option('ip_admin_eth0').value.set(['192.168.1.7']) assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.7'], 'ip_admin_eth1': ['192.168.1.5']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.7']} # path.config('subpath2').option('ip_admin_eth0').value.set(['192.168.1.8']) assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']} # raises(AttributeError, "path.config('subpath2.subpath1').option('ip_admin_eth0').value.set(['192.168.1.9'])") assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']} # raises(AttributeError, "path.config('subpath2.subpath1.conf2').option('ip_admin_eth0').value.set(['192.168.1.9'])") assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']} # path.config('subpath2.subpath1.conf1').option('ip_admin_eth0').value.set(['192.168.1.9']) assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']} # raises(AttributeError, "path.option('ip_admin_eth1').value.set(['192.168.1.10'])") assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']} # path.config('subpath2').option('ip_admin_eth1').value.set(['192.168.1.10']) assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.10']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.10']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']} # path.config('subpath2.subpath1').option('ip_admin_eth1').value.set(['192.168.1.11']) assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.11']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']} # path.config('subpath2.subpath1.conf2').option('ip_admin_eth1').value.set(['192.168.1.12']) assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']} # raises(AttributeError, "path.config('subpath2.subpath1.conf1').option('ip_admin_eth1').value.set(['192.168.1.13'])") assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']} assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']} assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']} assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']} assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}