permissive only if needed + global properties are in metaconfig
This commit is contained in:
parent
dc9454be63
commit
7fb0ee2575
|
@ -26,9 +26,8 @@ def make_description():
|
||||||
od2 = OptionDescription('od2', '', [od1])
|
od2 = OptionDescription('od2', '', [od1])
|
||||||
conf1 = Config(od2, name='conf1')
|
conf1 = Config(od2, name='conf1')
|
||||||
conf2 = Config(od2, name='conf2')
|
conf2 = Config(od2, name='conf2')
|
||||||
conf1.read_write()
|
|
||||||
conf2.read_write()
|
|
||||||
meta = MetaConfig([conf1, conf2], name='meta')
|
meta = MetaConfig([conf1, conf2], name='meta')
|
||||||
|
meta.read_write()
|
||||||
meta.cfgimpl_get_settings().setowner(owners.meta)
|
meta.cfgimpl_get_settings().setowner(owners.meta)
|
||||||
return meta
|
return meta
|
||||||
|
|
||||||
|
@ -111,7 +110,7 @@ def test_find():
|
||||||
assert [i2] == meta.find(byname='i2')
|
assert [i2] == meta.find(byname='i2')
|
||||||
assert i2 == meta.find_first(byname='i2')
|
assert i2 == meta.find_first(byname='i2')
|
||||||
assert meta.make_dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
|
assert meta.make_dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
|
||||||
'od1.i2': 1, 'od1.i5': [2], 'od1.i6': None}
|
'od1.i2': 1, 'od1.i5': [2]}
|
||||||
|
|
||||||
|
|
||||||
def test_group_error():
|
def test_group_error():
|
||||||
|
@ -157,6 +156,7 @@ def test_meta_meta_set():
|
||||||
meta1 = make_description()
|
meta1 = make_description()
|
||||||
meta2 = MetaConfig([meta1])
|
meta2 = MetaConfig([meta1])
|
||||||
meta2.cfgimpl_get_settings().setowner(owners.meta)
|
meta2.cfgimpl_get_settings().setowner(owners.meta)
|
||||||
|
meta2.read_write()
|
||||||
conf1, conf2 = meta1.cfgimpl_get_children()
|
conf1, conf2 = meta1.cfgimpl_get_children()
|
||||||
meta2.set_value('od1.i1', 7, only_config=True)
|
meta2.set_value('od1.i1', 7, only_config=True)
|
||||||
meta2.set_value('od1.i6', 7, only_config=True)
|
meta2.set_value('od1.i6', 7, only_config=True)
|
||||||
|
@ -247,6 +247,7 @@ def test_meta_unconsistent():
|
||||||
raises(ValueError, "MetaConfig([conf1, conf3])")
|
raises(ValueError, "MetaConfig([conf1, conf3])")
|
||||||
#not same descr
|
#not same descr
|
||||||
raises(ValueError, "MetaConfig([conf3, conf4])")
|
raises(ValueError, "MetaConfig([conf3, conf4])")
|
||||||
|
raises(ConfigError, "meta.conf1.read_only()")
|
||||||
|
|
||||||
|
|
||||||
def test_meta_master_slaves():
|
def test_meta_master_slaves():
|
||||||
|
@ -257,19 +258,13 @@ def test_meta_master_slaves():
|
||||||
conf1 = Config(interface1, name='conf1')
|
conf1 = Config(interface1, name='conf1')
|
||||||
conf2 = Config(interface1, name='conf2')
|
conf2 = Config(interface1, name='conf2')
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2])
|
||||||
meta.conf1.read_only()
|
meta.read_only()
|
||||||
meta.conf2.read_only()
|
|
||||||
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0').cfgimpl_get_children()
|
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0').cfgimpl_get_children()
|
||||||
meta.conf1.read_write()
|
meta.read_write()
|
||||||
meta.conf2.read_only()
|
|
||||||
assert [conf2] == meta.find_firsts(byname='netmask_admin_eth0').cfgimpl_get_children()
|
|
||||||
meta.conf2.read_write()
|
|
||||||
raises(AttributeError, "meta.find_firsts(byname='netmask_admin_eth0')")
|
raises(AttributeError, "meta.find_firsts(byname='netmask_admin_eth0')")
|
||||||
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0',
|
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0',
|
||||||
check_properties=None).cfgimpl_get_children()
|
check_properties=None).cfgimpl_get_children()
|
||||||
meta.conf1.read_only()
|
meta.read_only()
|
||||||
meta.conf2.read_only()
|
|
||||||
meta.read_write()
|
|
||||||
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0').cfgimpl_get_children()
|
assert [conf1, conf2] == meta.find_firsts(byname='netmask_admin_eth0').cfgimpl_get_children()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,11 @@ class Settings(object):
|
||||||
else:
|
else:
|
||||||
is_cached = False
|
is_cached = False
|
||||||
if not is_cached or 'cache' not in props:
|
if not is_cached or 'cache' not in props:
|
||||||
|
meta = self._getcontext().cfgimpl_get_meta()
|
||||||
|
if meta is None:
|
||||||
props = self._p_.getproperties(path, default_properties)
|
props = self._p_.getproperties(path, default_properties)
|
||||||
|
else:
|
||||||
|
props = meta.cfgimpl_get_settings()._getproperties()
|
||||||
if 'cache' in props:
|
if 'cache' in props:
|
||||||
if 'expire' in props:
|
if 'expire' in props:
|
||||||
ntime = ntime + expires_time
|
ntime = ntime + expires_time
|
||||||
|
@ -446,6 +450,8 @@ class Settings(object):
|
||||||
"""save properties for specified path
|
"""save properties for specified path
|
||||||
(never save properties if same has option properties)
|
(never save properties if same has option properties)
|
||||||
"""
|
"""
|
||||||
|
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||||
|
raise ConfigError(_('cannot change global property with metaconfig'))
|
||||||
if not force:
|
if not force:
|
||||||
forbidden_properties = forbidden_set_properties & properties
|
forbidden_properties = forbidden_set_properties & properties
|
||||||
if forbidden_properties:
|
if forbidden_properties:
|
||||||
|
@ -503,14 +509,6 @@ class Settings(object):
|
||||||
properties = self._getproperties(opt_or_descr, path,
|
properties = self._getproperties(opt_or_descr, path,
|
||||||
setting_properties=setting_properties,
|
setting_properties=setting_properties,
|
||||||
index=index)
|
index=index)
|
||||||
# remove opt permissive
|
|
||||||
# permissive affect option's permission with or without permissive
|
|
||||||
# global property
|
|
||||||
properties -= self.getpermissive(setting_properties, path)
|
|
||||||
# remove global permissive if need
|
|
||||||
if force_permissive is True or 'permissive' in setting_properties:
|
|
||||||
properties -= self.getpermissive(setting_properties)
|
|
||||||
|
|
||||||
# calc properties
|
# calc properties
|
||||||
properties &= setting_properties
|
properties &= setting_properties
|
||||||
if not is_descr:
|
if not is_descr:
|
||||||
|
@ -531,6 +529,17 @@ class Settings(object):
|
||||||
properties.remove('frozen')
|
properties.remove('frozen')
|
||||||
if 'empty' in properties:
|
if 'empty' in properties:
|
||||||
properties.remove('empty')
|
properties.remove('empty')
|
||||||
|
|
||||||
|
# remove permissive properties
|
||||||
|
if properties != frozenset():
|
||||||
|
# remove opt permissive
|
||||||
|
# permissive affect option's permission with or without permissive
|
||||||
|
# global property
|
||||||
|
properties -= self.getpermissive(setting_properties, path)
|
||||||
|
# remove global permissive if need
|
||||||
|
if force_permissive is True or 'permissive' in setting_properties:
|
||||||
|
properties -= self.getpermissive(setting_properties)
|
||||||
|
|
||||||
# at this point an option should not remain in properties
|
# at this point an option should not remain in properties
|
||||||
if properties != frozenset():
|
if properties != frozenset():
|
||||||
props = list(properties)
|
props = list(properties)
|
||||||
|
|
Loading…
Reference in New Issue