copy context owner when user copied a config/metaconfig
Context owner is now in values (no more in settings). The context owner is set in storage. So when copy/deepcopy a config, owner is copied to. For user, when export values, context owner is not returned by default.
This commit is contained in:
parent
e021e26d5a
commit
87594307c9
|
@ -185,6 +185,15 @@ def test_meta_new_config():
|
||||||
assert len(list(meta.config.list())) == 3
|
assert len(list(meta.config.list())) == 3
|
||||||
|
|
||||||
|
|
||||||
|
def test_meta_new_metaconfig():
|
||||||
|
od = make_description()
|
||||||
|
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
|
||||||
|
meta.config.new('newconf1', type='metaconfig')
|
||||||
|
meta.config('newconf1').config.new('newconf2', type='metaconfig')
|
||||||
|
meta.config('newconf1').config('newconf2').config.new('newconf3')
|
||||||
|
assert meta.config('newconf1').config('newconf2').config('newconf3').config.name() == 'newconf3'
|
||||||
|
|
||||||
|
|
||||||
def test_meta_pop_config():
|
def test_meta_pop_config():
|
||||||
od = make_description()
|
od = make_description()
|
||||||
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
|
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
|
||||||
|
@ -777,6 +786,46 @@ def test_meta_properties_submeta_deepcopy():
|
||||||
assert meta_copy.config('copy_meta1').config('conf2').config.name() == 'conf2'
|
assert meta_copy.config('copy_meta1').config('conf2').config.name() == 'conf2'
|
||||||
|
|
||||||
|
|
||||||
|
def test_meta_properties_submeta_deepcopy_owner():
|
||||||
|
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip")
|
||||||
|
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask")
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
|
conf1.owner.set('conf1_user')
|
||||||
|
conf1.property.read_write()
|
||||||
|
meta1 = MetaConfig([conf1], session_id='meta1')
|
||||||
|
meta1.owner.set('meta1_user')
|
||||||
|
meta2 = MetaConfig([meta1], session_id='meta2')
|
||||||
|
meta2.owner.set('meta2_user')
|
||||||
|
#
|
||||||
|
conf1.option('ip_admin_eth0').value.set('192.168.0.1')
|
||||||
|
assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user'
|
||||||
|
meta1.option('ip_admin_eth0').value.set('192.168.0.2')
|
||||||
|
assert meta1.option('ip_admin_eth0').owner.get() == 'meta1_user'
|
||||||
|
meta2.option('ip_admin_eth0').value.set('192.168.0.3')
|
||||||
|
assert meta2.option('ip_admin_eth0').owner.get() == 'meta2_user'
|
||||||
|
#
|
||||||
|
meta2_copy = conf1.config.deepcopy(session_id='conf2',
|
||||||
|
metaconfig_prefix='copy_')
|
||||||
|
meta2_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
|
||||||
|
assert meta2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3'
|
||||||
|
assert meta2_copy.option('ip_admin_eth0').owner.get() == 'meta2_user'
|
||||||
|
assert meta2_copy.option('netmask_admin_eth0').owner.get() == 'meta2_user'
|
||||||
|
#
|
||||||
|
meta1_copy = meta2_copy.config('copy_meta1')
|
||||||
|
meta1_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
|
||||||
|
assert meta1_copy.option('ip_admin_eth0').value.get() == '192.168.0.2'
|
||||||
|
assert meta1_copy.option('ip_admin_eth0').owner.get() == 'meta1_user'
|
||||||
|
assert meta1_copy.option('netmask_admin_eth0').owner.get() == 'meta1_user'
|
||||||
|
#
|
||||||
|
conf2 = meta1_copy.config('conf2')
|
||||||
|
conf2.owner.set('conf2_user')
|
||||||
|
conf2.option('netmask_admin_eth0').value.set('255.255.255.255')
|
||||||
|
assert conf2.option('netmask_admin_eth0').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_meta_properties_meta_set_value():
|
def test_meta_properties_meta_set_value():
|
||||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
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 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
|
||||||
|
|
|
@ -34,9 +34,9 @@ def test_delete_not_persisten():
|
||||||
Config(o, session_id='test_persistent', persistent=True)
|
Config(o, session_id='test_persistent', persistent=True)
|
||||||
except:
|
except:
|
||||||
c = Config(o, session_id='not_test_persistent')
|
c = Config(o, session_id='not_test_persistent')
|
||||||
assert list_sessions('all') == ['not_test_persistent']
|
assert 'not_test_persistent' in list_sessions('all')
|
||||||
del c
|
del c
|
||||||
assert list_sessions('all') == []
|
assert 'not_test_persistent' not in list_sessions('all')
|
||||||
#
|
#
|
||||||
c = Config(o, session_id='not_test_persistent')
|
c = Config(o, session_id='not_test_persistent')
|
||||||
raises(ValueError, "delete_session('not_test_persistent')")
|
raises(ValueError, "delete_session('not_test_persistent')")
|
||||||
|
|
|
@ -763,9 +763,18 @@ class TiramisuContextValue(TiramisuContext):
|
||||||
withoption=withoption,
|
withoption=withoption,
|
||||||
withvalue=withvalue)
|
withvalue=withvalue)
|
||||||
|
|
||||||
def exportation(self):
|
def exportation(self,
|
||||||
|
with_default_owner: bool=False):
|
||||||
"""export all values"""
|
"""export all values"""
|
||||||
return self.config_bag.context.cfgimpl_get_values()._p_.exportation()
|
exportation = self.config_bag.context.cfgimpl_get_values()._p_.exportation()
|
||||||
|
if not with_default_owner:
|
||||||
|
exportation = [list(exportation[0]), list(exportation[1]), list(exportation[2]), list(exportation[3])]
|
||||||
|
index = exportation[0].index(None)
|
||||||
|
exportation[0].pop(index)
|
||||||
|
exportation[1].pop(index)
|
||||||
|
exportation[2].pop(index)
|
||||||
|
exportation[3].pop(index)
|
||||||
|
return exportation
|
||||||
|
|
||||||
def importation(self, values):
|
def importation(self, values):
|
||||||
"""import values"""
|
"""import values"""
|
||||||
|
@ -778,7 +787,7 @@ class TiramisuContextOwner(TiramisuContext):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"""get default owner"""
|
"""get default owner"""
|
||||||
return self.config_bag.context.cfgimpl_get_settings().getowner()
|
return self.config_bag.context.cfgimpl_get_values().get_context_owner()
|
||||||
|
|
||||||
def set(self, owner):
|
def set(self, owner):
|
||||||
"""set default owner"""
|
"""set default owner"""
|
||||||
|
@ -787,7 +796,7 @@ class TiramisuContextOwner(TiramisuContext):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
owners.addowner(owner)
|
owners.addowner(owner)
|
||||||
obj_owner = getattr(owners, owner)
|
obj_owner = getattr(owners, owner)
|
||||||
self.config_bag.context.cfgimpl_get_settings().setowner(obj_owner)
|
self.config_bag.context.cfgimpl_get_values().set_context_owner(obj_owner)
|
||||||
|
|
||||||
|
|
||||||
class TiramisuContextProperty(TiramisuContext):
|
class TiramisuContextProperty(TiramisuContext):
|
||||||
|
|
|
@ -1135,7 +1135,7 @@ class KernelMetaConfig(KernelGroupConfig):
|
||||||
session_id,
|
session_id,
|
||||||
type_='config',
|
type_='config',
|
||||||
persistent=False):
|
persistent=False):
|
||||||
if session_id in [child._impl_name for child in self._impl_children]: # pragma: no cover
|
if session_id in [child._impl_name for child in self._impl_children]:
|
||||||
raise ConflictError(_('config name must be uniq in '
|
raise ConflictError(_('config name must be uniq in '
|
||||||
'groupconfig for {0}').format(session_id))
|
'groupconfig for {0}').format(session_id))
|
||||||
if type_ == 'config':
|
if type_ == 'config':
|
||||||
|
@ -1147,7 +1147,7 @@ class KernelMetaConfig(KernelGroupConfig):
|
||||||
optiondescription=self._impl_descr,
|
optiondescription=self._impl_descr,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
persistent=persistent)
|
persistent=persistent)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
raise ConfigError(_('unknown type {}').format(type_))
|
raise ConfigError(_('unknown type {}').format(type_))
|
||||||
# Copy context properties/permissives
|
# Copy context properties/permissives
|
||||||
config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(), config)
|
config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(), config)
|
||||||
|
|
|
@ -325,7 +325,9 @@ undefined = Undefined()
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
class Settings(object):
|
class Settings(object):
|
||||||
"``config.Config()``'s configuration options settings"
|
"``config.Config()``'s configuration options settings"
|
||||||
__slots__ = ('_owner', '_p_', '_pp_', '__weakref__')
|
__slots__ = ('_p_',
|
||||||
|
'_pp_',
|
||||||
|
'__weakref__')
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
properties,
|
properties,
|
||||||
|
@ -340,7 +342,6 @@ class Settings(object):
|
||||||
- sqlite3 -> persistent
|
- sqlite3 -> persistent
|
||||||
"""
|
"""
|
||||||
# generic owner
|
# generic owner
|
||||||
self._owner = owners.user
|
|
||||||
self._p_ = properties
|
self._p_ = properties
|
||||||
self._pp_ = permissives
|
self._pp_ = permissives
|
||||||
|
|
||||||
|
@ -779,17 +780,3 @@ class Settings(object):
|
||||||
self._read(rw_remove,
|
self._read(rw_remove,
|
||||||
rw_append,
|
rw_append,
|
||||||
context)
|
context)
|
||||||
|
|
||||||
#____________________________________________________________
|
|
||||||
# default owner methods
|
|
||||||
|
|
||||||
def setowner(self,
|
|
||||||
owner):
|
|
||||||
":param owner: sets the default value for owner at the Config level"
|
|
||||||
if owner in forbidden_owners:
|
|
||||||
raise ValueError(_('set owner "{0}" is forbidden').format(str(owner)))
|
|
||||||
|
|
||||||
self._owner = owner
|
|
||||||
|
|
||||||
def getowner(self):
|
|
||||||
return self._owner
|
|
||||||
|
|
|
@ -183,7 +183,10 @@ class Values(Cache):
|
||||||
self._values = tuple(values)
|
self._values = tuple(values)
|
||||||
|
|
||||||
# owner
|
# owner
|
||||||
def setowner(self, path, owner, index=None):
|
def setowner(self,
|
||||||
|
path,
|
||||||
|
owner,
|
||||||
|
index=None):
|
||||||
"""change owner for a path
|
"""change owner for a path
|
||||||
"""
|
"""
|
||||||
idx = self._values[0].index(path)
|
idx = self._values[0].index(path)
|
||||||
|
|
|
@ -31,7 +31,8 @@ class Values(object):
|
||||||
'__weakref__')
|
'__weakref__')
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
storage):
|
storage,
|
||||||
|
default_owner=owners.user):
|
||||||
"""
|
"""
|
||||||
Initializes the values's dict.
|
Initializes the values's dict.
|
||||||
|
|
||||||
|
@ -40,6 +41,12 @@ class Values(object):
|
||||||
"""
|
"""
|
||||||
# store the storage
|
# store the storage
|
||||||
self._p_ = storage
|
self._p_ = storage
|
||||||
|
# set default owner
|
||||||
|
self._p_.setvalue(None,
|
||||||
|
None,
|
||||||
|
default_owner,
|
||||||
|
None,
|
||||||
|
True)
|
||||||
|
|
||||||
#______________________________________________________________________
|
#______________________________________________________________________
|
||||||
# get value
|
# get value
|
||||||
|
@ -253,7 +260,7 @@ class Values(object):
|
||||||
_commit):
|
_commit):
|
||||||
|
|
||||||
context = option_bag.config_bag.context
|
context = option_bag.config_bag.context
|
||||||
owner = context.cfgimpl_get_settings().getowner()
|
owner = self.get_context_owner()
|
||||||
if 'validator' in option_bag.config_bag.properties:
|
if 'validator' in option_bag.config_bag.properties:
|
||||||
if option_bag.index is not None or option_bag.option._has_consistencies(context):
|
if option_bag.index is not None or option_bag.option._has_consistencies(context):
|
||||||
# set value to a fake config when option has dependency
|
# set value to a fake config when option has dependency
|
||||||
|
@ -610,3 +617,19 @@ class Values(object):
|
||||||
[],
|
[],
|
||||||
context,
|
context,
|
||||||
od_config_bag)
|
od_config_bag)
|
||||||
|
|
||||||
|
#____________________________________________________________
|
||||||
|
# default owner methods
|
||||||
|
def set_context_owner(self,
|
||||||
|
owner):
|
||||||
|
":param owner: sets the default value for owner at the Config level"
|
||||||
|
if owner in forbidden_owners:
|
||||||
|
raise ValueError(_('set owner "{0}" is forbidden').format(str(owner)))
|
||||||
|
|
||||||
|
self._p_.setowner(None,
|
||||||
|
owner,
|
||||||
|
index=None)
|
||||||
|
|
||||||
|
def get_context_owner(self):
|
||||||
|
return self._p_.getowner(None,
|
||||||
|
None)
|
||||||
|
|
Loading…
Reference in New Issue