APIError => ConfigError

This commit is contained in:
egarette@silique.fr 2023-04-27 11:44:52 +02:00
parent 1d18cc74b7
commit 30cd543a21
14 changed files with 62 additions and 67 deletions

View file

@ -11,7 +11,7 @@ do_autopath()
from tiramisu import Config, MetaConfig, \ from tiramisu import Config, MetaConfig, \
StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \ StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \
submulti, undefined, owners, Params, ParamOption, Calculation submulti, undefined, owners, Params, ParamOption, Calculation
from tiramisu.error import PropertiesOptionError, APIError, ConfigError, LeadershipError from tiramisu.error import PropertiesOptionError, ConfigError, LeadershipError
ICON = u'\u2937' ICON = u'\u2937'
OPTIONS_TYPE = {'str': {'type': str, OPTIONS_TYPE = {'str': {'type': str,
@ -148,7 +148,7 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
if isleader: if isleader:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
with raises(APIError): with raises(ConfigError):
cfg_.option(pathwrite, 0).value.set(first_value[0]) cfg_.option(pathwrite, 0).value.set(first_value[0])
if not set_permissive: if not set_permissive:
cfg_.option(pathwrite).value.set([first_value[0]]) cfg_.option(pathwrite).value.set([first_value[0]])
@ -165,7 +165,7 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
with raises(PropertiesOptionError): with raises(PropertiesOptionError):
cfg_.forcepermissive.option(pathwrite).value.set([first_value[0]]) cfg_.forcepermissive.option(pathwrite).value.set([first_value[0]])
if len(first_value) > 1: if len(first_value) > 1:
with raises(APIError): with raises(ConfigError):
cfg_.unrestraint.option(pathwrite).value.set(first_value[1]) cfg_.unrestraint.option(pathwrite).value.set(first_value[1])
elif isfollower: elif isfollower:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
@ -183,7 +183,7 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
cfg_.option(pathwrite, 1).value.set(second_value) cfg_.option(pathwrite, 1).value.set(second_value)
with raises(PropertiesOptionError): with raises(PropertiesOptionError):
cfg_.forcepermissive.option(pathwrite, 1).value.set(second_value) cfg_.forcepermissive.option(pathwrite, 1).value.set(second_value)
with raises(APIError): with raises(ConfigError):
cfg_.unrestraint.option(pathwrite).value.set([second_value, second_value]) cfg_.unrestraint.option(pathwrite).value.set([second_value, second_value])
else: else:
@ -202,7 +202,7 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
cfg_.option(pathwrite).value.set(first_value) cfg_.option(pathwrite).value.set(first_value)
with raises(PropertiesOptionError): with raises(PropertiesOptionError):
cfg_.forcepermissive.option(pathwrite).value.set(first_value) cfg_.forcepermissive.option(pathwrite).value.set(first_value)
#FIXME raises(APIError, "cfg_.unrestraint.option(pathwrite).value.set(first_value)") #FIXME raises(ConfigError, "cfg_.unrestraint.option(pathwrite).value.set(first_value)")
def _getproperties(multi, isfollower, kwargs): def _getproperties(multi, isfollower, kwargs):

View file

@ -13,7 +13,7 @@ from tiramisu import Config
from tiramisu.i18n import _ from tiramisu.i18n import _
from tiramisu import Config, IntOption, FloatOption, ChoiceOption, \ from tiramisu import Config, IntOption, FloatOption, ChoiceOption, \
BoolOption, StrOption, SymLinkOption, OptionDescription, undefined BoolOption, StrOption, SymLinkOption, OptionDescription, undefined
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError, APIError from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError
def make_description(): def make_description():
@ -293,7 +293,7 @@ def test_duplicated_option_diff_od():
def test_cannot_assign_value_to_option_description(): def test_cannot_assign_value_to_option_description():
od1 = make_description() od1 = make_description()
cfg = Config(od1) cfg = Config(od1)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('gc').value.set(3) cfg.option('gc').value.set(3)
# assert not list_sessions() # assert not list_sessions()

View file

@ -9,7 +9,7 @@ from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, FilenameOption, SymLinkOption, IPOption, \ BoolOption, FilenameOption, SymLinkOption, IPOption, \
PortOption, NetworkOption, NetmaskOption, BroadcastOption, \ PortOption, NetworkOption, NetmaskOption, BroadcastOption, \
DomainnameOption, OptionDescription DomainnameOption, OptionDescription
from tiramisu.error import PropertiesOptionError, ValueWarning, APIError from tiramisu.error import PropertiesOptionError, ValueWarning, ConfigError
import warnings import warnings
@ -112,7 +112,7 @@ def test_make_dict_not_value(config_type):
cfg.property.read_write() cfg.property.read_write()
cfg.permissive.add('hidden') cfg.permissive.add('hidden')
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
with raises(APIError): with raises(ConfigError):
cfg.option('s1.a').value.dict() cfg.option('s1.a').value.dict()

View file

@ -7,7 +7,7 @@ import pytest
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetworkOption, NetmaskOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetworkOption, NetmaskOption, \
StrOption, OptionDescription, Leadership, Config StrOption, OptionDescription, Leadership, Config
from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, ConfigError from tiramisu.error import LeadershipError, PropertiesOptionError, ConfigError
groups.family = groups.GroupType('family') groups.family = groups.GroupType('family')
@ -267,7 +267,7 @@ def test_not_groups_len(config_type):
od1 = OptionDescription('root', '', [interface1]) od1 = OptionDescription('root', '', [interface1])
cfg = Config(od1) cfg = Config(od1)
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() cfg.option('ip_admin_eth0.ip_admin_eth0').value.len()
@ -437,9 +437,9 @@ def test_groups_with_leader_index_mandatory(config_type):
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
# index is mandatory # index is mandatory
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('ip_admin_eth0.netmask_admin_eth0').value.reset() cfg.option('ip_admin_eth0.netmask_admin_eth0').value.reset()
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('ip_admin_eth0.netmask_admin_eth0').value.get() cfg.option('ip_admin_eth0.netmask_admin_eth0').value.get()
@ -542,9 +542,9 @@ def test_values_with_leader_and_followers1(config_type):
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
if config_type != 'tiramisu-api': if config_type != 'tiramisu-api':
# FIXME # FIXME
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('ip_admin_eth0.netmask_admin_eth0').value.set([None]) cfg.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0) cfg.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api': if config_type == 'tiramisu-api':
cfg.send() cfg.send()
@ -608,7 +608,7 @@ def test_reset_values_with_leader_and_followers_default(config_type):
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
with pytest.raises(APIError): with pytest.raises(ConfigError):
# index is mandatory # index is mandatory
cfg.option('ip_admin_eth0.netmask_admin_eth0').owner.get() cfg.option('ip_admin_eth0.netmask_admin_eth0').owner.get()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
@ -653,7 +653,7 @@ def test_values_with_leader_and_followers_follower(config_type):
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api': if config_type != 'tiramisu-api':
# FIXME # FIXME
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1) cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)
#reset #reset
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
@ -905,14 +905,14 @@ def test_wrong_index():
cfg = Config(od1) cfg = Config(od1)
cfg.property.read_write() cfg.property.read_write()
assert cfg.option('od.ip_admin_eth0.ip_admin_eth0').option.get() assert cfg.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get() cfg.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()
assert cfg.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get() assert cfg.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert cfg.option('od.ip_admin_eth0').option.get() assert cfg.option('od.ip_admin_eth0').option.get()
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('od.ip_admin_eth0', 0).option.get() cfg.option('od.ip_admin_eth0', 0).option.get()
assert cfg.option('od').option.get() assert cfg.option('od').option.get()
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('od', 0).option.get() cfg.option('od', 0).option.get()
# assert not list_sessions() # assert not list_sessions()

View file

@ -7,7 +7,7 @@ from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOpt
IPOption, OptionDescription, Leadership, Config, GroupConfig, MetaConfig, \ IPOption, OptionDescription, Leadership, Config, GroupConfig, MetaConfig, \
Calculation, Params, ParamOption, ParamValue, calc_value, ParamSelfOption, \ Calculation, Params, ParamOption, ParamValue, calc_value, ParamSelfOption, \
valid_network_netmask, valid_not_equal valid_network_netmask, valid_not_equal
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError, APIError from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError
from .config import config_type, get_config from .config import config_type, get_config
@ -418,7 +418,7 @@ def test_not_meta():
GroupConfig([conf2, conf2], name='conf8') GroupConfig([conf2, conf2], name='conf8')
grp = GroupConfig([conf1, conf2]) grp = GroupConfig([conf1, conf2])
assert grp.config.type() == 'groupconfig' assert grp.config.type() == 'groupconfig'
with pytest.raises(APIError): with pytest.raises(ConfigError):
grp.option('od1.i1').value.get() grp.option('od1.i1').value.get()
conf1, conf2 = grp.config.list() conf1, conf2 = grp.config.list()
errors = grp.value.set('od1.i1', 7) errors = grp.value.set('od1.i1', 7)
@ -547,7 +547,7 @@ def test_meta_leadership_value():
meta = MetaConfig([conf1, conf2], name="meta") meta = MetaConfig([conf1, conf2], name="meta")
conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8']) conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8'])
assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
with pytest.raises(APIError): with pytest.raises(ConfigError):
conf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get() conf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get()
# #
conf1.option('ip_admin_eth0.ip_admin_eth0').value.reset() conf1.option('ip_admin_eth0.ip_admin_eth0').value.reset()

View file

@ -8,7 +8,7 @@ from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
OptionDescription, Leadership, Config, GroupConfig, MixConfig, \ OptionDescription, Leadership, Config, GroupConfig, MixConfig, \
MetaConfig, Params, ParamOption, ParamValue, ParamSelfOption, Calculation, \ MetaConfig, Params, ParamOption, ParamValue, ParamSelfOption, Calculation, \
valid_network_netmask valid_network_netmask
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError, APIError from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError
owners.addowner('mix1') owners.addowner('mix1')
owners.addowner('mix2') owners.addowner('mix2')

View file

@ -6,9 +6,7 @@ do_autopath()
import pytest import pytest
import warnings import warnings
from tiramisu.error import ValueWarning, APIError from tiramisu.error import ConfigError, ValueWarning
from tiramisu.error import APIError, ConfigError
from tiramisu import IntOption, SymLinkOption, OptionDescription, Config, Calculation, groups from tiramisu import IntOption, SymLinkOption, OptionDescription, Config, Calculation, groups
from tiramisu.i18n import _ from tiramisu.i18n import _
@ -71,9 +69,9 @@ def test_option_unknown():
od = OptionDescription('od', '', [i]) od = OptionDescription('od', '', [i])
cfg = Config(od) cfg = Config(od)
# #
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('test').unknown.get() cfg.option('test').unknown.get()
with pytest.raises(APIError): with pytest.raises(ConfigError):
# only choice # only choice
cfg.option('test').value.list() cfg.option('test').value.list()
@ -267,9 +265,9 @@ def test_asign_optiondescription():
od1 = OptionDescription('od', '', [i]) od1 = OptionDescription('od', '', [i])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('od').value.set('test') cfg.option('od').value.set('test')
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('od').value.reset() cfg.option('od').value.reset()
# assert not list_sessions() # assert not list_sessions()
@ -322,5 +320,5 @@ def test_option_unknown_func():
i3 = IntOption('test3', 'description', min_number=3, max_number=6, warnings_only=True) i3 = IntOption('test3', 'description', min_number=3, max_number=6, warnings_only=True)
od = OptionDescription('od', '', [i1, i2, i3]) od = OptionDescription('od', '', [i1, i2, i3])
cfg = Config(od) cfg = Config(od)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('test1').value.unknown() cfg.option('test1').value.unknown()

View file

@ -6,7 +6,7 @@ import pytest
from tiramisu.setting import owners, groups from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, Leadership, Config StrOption, OptionDescription, SymLinkOption, Leadership, Config
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIError from tiramisu.error import ConfigError, ConstError, PropertiesOptionError
from .config import config_type, get_config from .config import config_type, get_config
@ -54,7 +54,7 @@ def test_owner_unknown_func(config_type):
od1 = OptionDescription('tiramisu', '', [gcdummy]) od1 = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(od1) cfg = Config(od1)
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
with pytest.raises(APIError): with pytest.raises(ConfigError):
owner = cfg.option('dummy').owner.unknown() owner = cfg.option('dummy').owner.unknown()
# assert not list_sessions() # assert not list_sessions()
@ -200,9 +200,9 @@ def test_setowner_optiondescription(config_type):
od1 = OptionDescription('tiramisu', '', [descr1]) od1 = OptionDescription('tiramisu', '', [descr1])
cfg = Config(od1) cfg = Config(od1)
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('tiramisu').owner.get() cfg.option('tiramisu').owner.get()
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('tiramisu').owner.set('user') cfg.option('tiramisu').owner.set('user')
# assert not list_sessions() # assert not list_sessions()
@ -219,7 +219,7 @@ def test_setowner_symlinkoption(config_type):
assert not cfg.option('tiramisu.symdummy').owner.isdefault() assert not cfg.option('tiramisu.symdummy').owner.isdefault()
if config_type == 'tiramisu-api': if config_type == 'tiramisu-api':
cfg.send() cfg.send()
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg_ori.option('tiramisu.symdummy').owner.set('user') cfg_ori.option('tiramisu.symdummy').owner.set('user')
# assert not list_sessions() # assert not list_sessions()

View file

@ -5,7 +5,7 @@ do_autopath()
import pytest import pytest
from tiramisu import IntOption, StrOption, OptionDescription, Config from tiramisu import IntOption, StrOption, OptionDescription, Config
from tiramisu.error import PropertiesOptionError, ConfigError, APIError from tiramisu.error import PropertiesOptionError, ConfigError
from .config import config_type, get_config from .config import config_type, get_config
@ -21,7 +21,7 @@ def test_forcepermissive_and_unrestraint(config_type):
cfg_ori.property.read_write() cfg_ori.property.read_write()
cfg_ori.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type) cfg = get_config(cfg_ori, config_type)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg_ori.unrestraint.forcepermissive.add('disabled') cfg_ori.unrestraint.forcepermissive.add('disabled')

View file

@ -6,7 +6,7 @@ from .config import config_type, get_config
from tiramisu import BoolOption, StrOption, SymLinkOption, \ from tiramisu import BoolOption, StrOption, SymLinkOption, \
OptionDescription, Leadership, Config, Calculation, calc_value, Params, ParamOption, ParamValue OptionDescription, Leadership, Config, Calculation, calc_value, Params, ParamOption, ParamValue
from tiramisu.error import PropertiesOptionError, ConfigError, APIError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
@ -43,7 +43,7 @@ def test_symlink_assign_option(config_type):
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
cfg = Config(od1) cfg = Config(od1)
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('c').value.set(True) cfg.option('c').value.set(True)
# assert not list_sessions() # assert not list_sessions()
@ -55,7 +55,7 @@ def test_symlink_del_option(config_type):
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
cfg = Config(od1) cfg = Config(od1)
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('c').value.reset() cfg.option('c').value.reset()
# assert not list_sessions() # assert not list_sessions()
@ -191,7 +191,7 @@ def test_symlink_assign(config_type):
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
cfg = Config(od1) cfg = Config(od1)
cfg = get_config(cfg, config_type) cfg = get_config(cfg, config_type)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('c').value.set(True) cfg.option('c').value.set(True)
# assert not list_sessions() # assert not list_sessions()
@ -250,7 +250,7 @@ def test_symlink_with_leader(config_type):
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'leader': ['val1', 'val2']} assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'leader': ['val1', 'val2']}
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
with pytest.raises(APIError): with pytest.raises(ConfigError):
cfg.option('leader').value.pop(0) cfg.option('leader').value.pop(0)
# assert not list_sessions() # assert not list_sessions()
@ -269,13 +269,13 @@ def test_symlink_with_follower(config_type):
# #
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'default' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'default'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'default' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'default'
with pytest.raises(APIError): with pytest.raises(ConfigError):
assert cfg.option('follower', 0).owner.get() == 'default' assert cfg.option('follower', 0).owner.get() == 'default'
assert cfg.option('follower').owner.get() == 'default' assert cfg.option('follower').owner.get() == 'default'
# #
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
with pytest.raises(APIError): with pytest.raises(ConfigError):
assert cfg.option('follower', 0).value.get() == None assert cfg.option('follower', 0).value.get() == None
assert cfg.option('follower').value.get() == [None, None] assert cfg.option('follower').value.get() == [None, None]
# #
@ -284,13 +284,13 @@ def test_symlink_with_follower(config_type):
# #
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
with pytest.raises(APIError): with pytest.raises(ConfigError):
assert cfg.option('follower', 0).value.get() == None assert cfg.option('follower', 0).value.get() == None
assert cfg.option('follower').value.get() == [None, 'val3'] assert cfg.option('follower').value.get() == [None, 'val3']
# #
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'default' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'default'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
with pytest.raises(APIError): with pytest.raises(ConfigError):
assert cfg.option('follower', 0).owner.get() == 'default' assert cfg.option('follower', 0).owner.get() == 'default'
assert cfg.option('follower').owner.get() == 'user' assert cfg.option('follower').owner.get() == 'user'
# assert not list_sessions() # assert not list_sessions()

View file

@ -20,7 +20,7 @@ from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \ from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
ParamValue, ParamIndex, ParamSuffix, ParamInformation, ParamSelfInformation ParamValue, ParamIndex, ParamSuffix, ParamInformation, ParamSelfInformation
from .option import * from .option import *
from .error import APIError from .error import ConfigError
from .api import Config, MetaConfig, GroupConfig, MixConfig from .api import Config, MetaConfig, GroupConfig, MixConfig
from .option import __all__ as all_options from .option import __all__ as all_options
from .setting import owners, groups, undefined from .setting import owners, groups, undefined
@ -40,7 +40,7 @@ allfuncs = ['Calculation',
'MixConfig', 'MixConfig',
'GroupConfig', 'GroupConfig',
'Config', 'Config',
'APIError', 'ConfigError',
'undefined', 'undefined',
'owners', 'owners',
'groups', 'groups',

View file

@ -22,7 +22,7 @@ from functools import wraps
from copy import deepcopy from copy import deepcopy
from .error import APIError, ConfigError, LeadershipError, PropertiesOptionError, ValueErrorWarning from .error import ConfigError, LeadershipError, PropertiesOptionError, ValueErrorWarning
from .i18n import _ from .i18n import _
from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \ from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \
FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES, EXPIRATION_TIME FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES, EXPIRATION_TIME
@ -92,7 +92,7 @@ class CommonTiramisu(TiramisuHelp):
self._validate_properties, self._validate_properties,
) )
except AssertionError as err: except AssertionError as err:
raise APIError(str(err)) raise ConfigError(str(err))
except Exception as err: except Exception as err:
raise err raise err
return options_bag return options_bag
@ -136,13 +136,13 @@ def option_type(typ):
option.get_type() == 'choice' and 'choice' in types)): option.get_type() == 'choice' and 'choice' in types)):
if not option.impl_is_optiondescription() and not option.impl_is_symlinkoption() and option.impl_is_follower(): if not option.impl_is_optiondescription() and not option.impl_is_symlinkoption() and option.impl_is_follower():
if 'with_index' in types and args[0]._index is not None: if 'with_index' in types and args[0]._index is not None:
raise APIError(_(f'please do not specify index ({args[0].__class__.__name__}.{func.__name__})')) raise ConfigError(_(f'please do not specify index ({args[0].__class__.__name__}.{func.__name__})'))
if 'with_index' not in types and args[0]._index is None: if 'with_index' not in types and args[0]._index is None:
raise APIError(_(f'please specify index with a follower option ({args[0].__class__.__name__}.{func.__name__})')) raise ConfigError(_(f'please specify index with a follower option ({args[0].__class__.__name__}.{func.__name__})'))
elif args[0]._index is not None: elif args[0]._index is not None:
raise APIError(_(f'please specify an index only for follower option ({args[0].__class__.__name__}.{func.__name__})')) raise ConfigError(_(f'please specify an index only for follower option ({args[0].__class__.__name__}.{func.__name__})'))
return func(args[0], options_bag, *args[1:], **kwargs) return func(args[0], options_bag, *args[1:], **kwargs)
raise APIError(_(f'please specify a valid sub function ({args[0].__class__.__name__}.{func.__name__})')) raise ConfigError(_(f'please specify a valid sub function ({args[0].__class__.__name__}.{func.__name__})'))
wrapped.func = func wrapped.func = func
return wrapped return wrapped
return wrapper return wrapper
@ -163,7 +163,7 @@ class CommonTiramisuOption(CommonTiramisu):
self._config_bag = config_bag self._config_bag = config_bag
def __getattr__(self, subfunc): def __getattr__(self, subfunc):
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise ConfigError(_('please specify a valid sub function ({})').format(subfunc))
class _TiramisuOptionWalk: class _TiramisuOptionWalk:
@ -853,7 +853,7 @@ class TiramisuOption(CommonTiramisu, TiramisuConfig):
self._index, self._index,
self._config_bag, self._config_bag,
) )
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise ConfigError(_('please specify a valid sub function ({})').format(subfunc))
@option_type('optiondescription') @option_type('optiondescription')
def find(self, def find(self,
@ -1522,7 +1522,7 @@ class TiramisuAPI(TiramisuHelp):
self._orig_config_bags) self._orig_config_bags)
elif subfunc in ['forcepermissive', 'unrestraint']: elif subfunc in ['forcepermissive', 'unrestraint']:
if self._orig_config_bags: if self._orig_config_bags:
raise APIError(_('do not use unrestraint and forcepermissive together')) raise ConfigError(_('do not use unrestraint and forcepermissive together'))
config_bag = self._config_bag.copy() config_bag = self._config_bag.copy()
if subfunc == 'unrestraint': if subfunc == 'unrestraint':
config_bag.unrestraint() config_bag.unrestraint()
@ -1546,7 +1546,7 @@ class TiramisuAPI(TiramisuHelp):
# del config_bag.permissives # del config_bag.permissives
return self._registers[subfunc](config_bag, return self._registers[subfunc](config_bag,
self._orig_config_bags) self._orig_config_bags)
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise ConfigError(_('please specify a valid sub function ({})').format(subfunc))
def __dir__(self): def __dir__(self):
return list(self._registers.keys()) + ['unrestraint', 'forcepermissive', 'config'] return list(self._registers.keys()) + ['unrestraint', 'forcepermissive', 'config']

View file

@ -25,7 +25,7 @@ from typing import Optional, List, Any, Union
from .error import PropertiesOptionError, ConfigError, ConflictError, \ from .error import PropertiesOptionError, ConfigError, ConflictError, \
LeadershipError, APIError LeadershipError
from .option import SynDynOptionDescription, DynOptionDescription, Leadership, Option from .option import SynDynOptionDescription, DynOptionDescription, Leadership, Option
from .option.baseoption import BaseOption from .option.baseoption import BaseOption
from .setting import OptionBag, ConfigBag, Settings, undefined, groups from .setting import OptionBag, ConfigBag, Settings, undefined, groups
@ -790,7 +790,7 @@ class _CommonConfig(_SubConfig):
if idx == last_idx: if idx == last_idx:
if option_index is not None: if option_index is not None:
if option.impl_is_optiondescription() or option.impl_is_symlinkoption() or not option.impl_is_follower(): if option.impl_is_optiondescription() or option.impl_is_symlinkoption() or not option.impl_is_follower():
raise APIError('index must be set only with a follower option') raise ConfigError('index must be set only with a follower option')
if leadership_length is not None: if leadership_length is not None:
length = leadership_length length = leadership_length
else: else:

View file

@ -132,7 +132,8 @@ class ConfigError(Exception):
or if a calculation cannot be carried out""" or if a calculation cannot be carried out"""
def __init__(self, def __init__(self,
exp, exp,
ori_err=None): ori_err=None,
):
super().__init__(exp) super().__init__(exp)
self.ori_err = ori_err self.ori_err = ori_err
@ -209,7 +210,3 @@ class ValueOptionError(_CommonError, ValueError):
class ValueErrorWarning(ValueWarning): class ValueErrorWarning(ValueWarning):
tmpl = _('"{0}" is an invalid {1} for "{2}"') tmpl = _('"{0}" is an invalid {1} for "{2}"')
class APIError(Exception):
pass