tiramisu/test/test_mandatory.py

630 lines
24 KiB
Python
Raw Normal View History

# coding: utf-8
2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
do_autopath()
from py.test import raises
2018-03-19 08:33:53 +01:00
from tiramisu.api import TIRAMISU_VERSION
2018-08-14 22:15:40 +02:00
from tiramisu import Config
2018-03-19 08:33:53 +01:00
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
2019-02-23 19:06:23 +01:00
SymLinkOption, Leadership, undefined, Params, ParamOption
2015-10-29 09:03:13 +01:00
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups
2018-10-31 08:00:19 +01:00
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def make_description():
stro = StrOption('str', '')
subdescr = OptionDescription('sub', '', [stro], properties=('disabled',))
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
2013-04-17 22:06:10 +02:00
stroption2 = UnicodeOption('unicode2', 'Test string option',
properties=('mandatory', ))
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
stroption4 = StrOption('str4', 'Test string option', multi=True,
properties=('mandatory', ), allow_empty_list=True)
descr = OptionDescription('tiram', '', [subdescr, stroption, stroption1, stroption2, stroption3, stroption4])
return descr
2015-10-29 09:03:13 +01:00
def return_value(value):
return value
def make_description2():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
2015-10-29 09:03:13 +01:00
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
return descr
def make_description_sym():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
return descr
def make_description3():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
int1 = IntOption('int1', '', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
2015-10-29 09:03:13 +01:00
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1])
return descr
def test_mandatory_ro():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str1').value.set('yes')
api.property.read_only()
assert api.option('str1').value.get() == 'yes'
def test_mandatory_ro_dict():
descr = make_description()
api = Config(descr)
api.property.read_only()
prop = []
try:
api.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('str1').value.set('yes')
api.option('unicode2').value.set('yes')
api.property.read_only()
try:
api.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
api.property.read_write()
api.option('str3').value.set(['yes'])
api.property.read_only()
assert api.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'str4': [], 'unicode2': 'yes'}
def test_mandatory_rw():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
# not mandatory in rw
2018-03-19 08:33:53 +01:00
api.option('str1').value.get()
api.option('str1').value.set('yes')
assert api.option('str1').value.get() == 'yes'
def test_mandatory_default():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
#not mandatory in rw
2018-03-19 08:33:53 +01:00
api.option('str').value.get()
api.property.read_write()
api.option('str').value.set('yes')
api.property.read_only()
api.option('str').value.get()
api.property.read_write()
api.option('str').value.set(None)
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
2015-12-17 22:41:57 +01:00
def test_mandatory_delete():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
api.option('str').value.get()
2015-12-17 22:41:57 +01:00
try:
2018-03-19 08:33:53 +01:00
api.option('str1').value.get()
2015-12-17 22:41:57 +01:00
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str1').value.set('yes')
api.property.read_only()
assert api.option('str1').value.get() == 'yes'
api.property.pop('everything_frozen')
2015-12-17 22:41:57 +01:00
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str1').value.reset()
2015-12-17 22:41:57 +01:00
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
2018-03-19 08:33:53 +01:00
api.option('str').value.reset()
assert api.option('str1').value.get() == 'yes'
2015-12-17 22:41:57 +01:00
#valeur vide : None, '', u'', ...
def test_mandatory_none():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str1').value.set(None)
assert api.option('str1').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_empty():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str1').value.set('')
assert api.option('str1').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_multi_none():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str3').value.set([None])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str3').value.set(['yes', None])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_multi_empty():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str3').value.set([])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str3').value.set([''])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str3').value.set(['yes', ''])
assert api.option('str3').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_multi_empty_allow_empty_list():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str4').value.set([])
assert api.option('str4').owner.get() == 'user'
api.property.read_only()
prop = []
2018-03-19 08:33:53 +01:00
api.option('str4').value.get()
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str4').value.set([''])
assert api.option('str4').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str4').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str4').value.set(['yes', ''])
assert api.option('str4').owner.get() == 'user'
api.property.read_only()
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str4').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_multi_append():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str3').value.set(['yes'])
api.property.read_write()
api.option('str3').value.get().append(None)
def test_mandatory_disabled():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str1').value.get()
api.option('str1').property.add('disabled')
api.property.read_only()
pop = []
try:
2018-03-19 08:33:53 +01:00
api.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 2:
search_prop = {'disabled', 'mandatory'}
else:
search_prop = {'disabled'}
assert set(prop) == search_prop
2013-04-17 22:06:10 +02:00
def test_mandatory_unicode():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('unicode2').value.get()
api.property.read_only()
2013-04-17 22:06:10 +02:00
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('unicode2').value.get()
except PropertiesOptionError as err:
2013-04-17 22:06:10 +02:00
prop = err.proptype
2018-03-19 08:33:53 +01:00
assert 'mandatory' in prop
api.property.read_write()
api.option('unicode2').value.set(u'')
api.property.read_only()
2013-04-17 22:06:10 +02:00
prop = []
try:
2018-03-19 08:33:53 +01:00
api.option('unicode2').value.get()
except PropertiesOptionError as err:
2013-04-17 22:06:10 +02:00
prop = err.proptype
2018-03-19 08:33:53 +01:00
assert 'mandatory' in prop
2013-04-17 22:06:10 +02:00
def test_mandatory_warnings_ro():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_only()
proc = []
try:
2018-03-19 08:33:53 +01:00
api.option('str').value.get()
except PropertiesOptionError as err:
2018-03-19 08:33:53 +01:00
prop = err.proptype
assert 'mandatory' in prop
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str').value.set('a')
api.property.read_only()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_rw():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
2018-03-19 08:33:53 +01:00
api.option('str').value.set('a')
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_disabled():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
2018-11-13 12:39:51 +01:00
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
2018-03-19 08:33:53 +01:00
api.option('str').property.add('disabled')
2018-11-13 12:39:51 +01:00
assert set(api.value.mandatory()) == {'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_hidden():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
api.option('str').value.get()
2018-11-13 12:39:51 +01:00
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
2018-03-19 08:33:53 +01:00
api.option('str').property.add('hidden')
2018-11-13 12:39:51 +01:00
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_frozen():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
2018-11-13 12:39:51 +01:00
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
2018-03-19 08:33:53 +01:00
api.option('str').property.add('frozen')
api.property.read_only()
2018-11-13 12:39:51 +01:00
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
2019-02-23 19:06:23 +01:00
def test_mandatory_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
descr = OptionDescription('o', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
2019-02-23 19:06:23 +01:00
def test_mandatory_warnings_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
descr = OptionDescription('o', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
2019-02-23 19:06:23 +01:00
def test_mandatory_leader_empty():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
descr = OptionDescription('o', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.property.read_write()
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
2017-05-06 19:54:20 +02:00
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
api.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
2019-02-23 19:06:23 +01:00
def test_mandatory_warnings_leader_empty():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True)
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
descr = OptionDescription('o', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
#
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == []
2019-02-23 19:06:23 +01:00
def test_mandatory_follower():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True, properties=('mandatory', ))
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
descr = OptionDescription('o', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
2015-10-29 09:03:13 +01:00
2019-02-23 19:06:23 +01:00
def test_mandatory_warnings_follower():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
multi=True, properties=('mandatory', ))
2019-02-23 19:06:23 +01:00
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
2018-03-19 08:33:53 +01:00
descr = OptionDescription('o', '', [interface1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
2018-03-19 08:33:53 +01:00
api.property.read_write()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == []
2018-03-19 08:33:53 +01:00
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
2015-10-29 09:03:13 +01:00
def test_mandatory_warnings_symlink():
descr = make_description_sym()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str', 'str1', 'str3']
2018-03-19 08:33:53 +01:00
api.option('str').property.add('frozen')
api.property.read_only()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str', 'str1', 'str3']
2018-03-19 08:33:53 +01:00
#def test_mandatory_warnings_validate():
# descr = make_description3()
2018-08-14 23:07:07 +02:00
# api = Config(descr)
2018-03-19 08:33:53 +01:00
# api.option('str').value.set('')
2018-11-13 12:39:51 +01:00
# raises(ValueError, "list(api.value.mandatory())")
2018-03-19 08:33:53 +01:00
# api.option('str').value.set('test')
2018-11-13 12:39:51 +01:00
# raises(ValueError, "list(api.value.mandatory())")
2015-10-29 09:03:13 +01:00
def test_mandatory_warnings_validate_empty():
descr = make_description2()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_only()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str', 'str1', 'str3', 'unicode1']
2015-10-29 09:03:13 +01:00
def test_mandatory_warnings_requires():
2018-04-06 16:09:10 +02:00
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = UnicodeOption('unicode2', 'Test string option',
properties=('mandatory', ))
stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.option('str').value.set('')
api.property.read_write()
api.option('str').value.get()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2']
2018-03-19 08:33:53 +01:00
api.property.read_only()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2']
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.option('str').value.set('yes')
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
2015-10-29 09:03:13 +01:00
2019-02-23 19:06:23 +01:00
def test_mandatory_warnings_requires_leadership():
2018-04-06 16:09:10 +02:00
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option', multi=True)
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
2019-02-23 19:06:23 +01:00
leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
descr = OptionDescription('tiram', '', [stroption, leadership])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-04-06 16:09:10 +02:00
api.option('str').value.set('')
2019-02-23 19:06:23 +01:00
api.option('leader.str1').value.set(['str'])
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['str']
2018-04-06 16:09:10 +02:00
api.option('str').value.set('yes')
2019-02-23 19:06:23 +01:00
assert list(api.value.mandatory()) == ['leader.str2']
2018-04-06 16:09:10 +02:00
2019-02-23 19:06:23 +01:00
def test_mandatory_warnings_requires_leadership_follower():
2018-04-06 16:09:10 +02:00
stroption = StrOption('str', 'Test string option', multi=True)
stroption1 = StrOption('str1', 'Test string option', multi=True)
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
2019-02-23 19:06:23 +01:00
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
descr = OptionDescription('tiram', '', [leadership])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2019-02-23 19:06:23 +01:00
api.option('leader.str').value.set(['str'])
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == []
2019-02-23 19:06:23 +01:00
api.option('leader.str1', 0).value.set('yes')
assert list(api.value.mandatory()) == ['leader.str2']
2018-04-06 16:09:10 +02:00
2015-10-29 09:03:13 +01:00
def test_mandatory_od_disabled():
descr = make_description()
2018-03-19 08:33:53 +01:00
descr = OptionDescription('od', '', [descr])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
2018-03-19 08:33:53 +01:00
api.option('tiram').property.add('disabled')
2018-11-13 12:39:51 +01:00
assert list(api.value.mandatory()) == []