2013-05-31 23:29:20 +02:00
|
|
|
# coding: utf-8
|
2015-07-24 17:54:10 +02:00
|
|
|
from autopath import do_autopath
|
|
|
|
do_autopath()
|
|
|
|
|
2013-06-29 18:41:14 +02:00
|
|
|
from copy import copy
|
2015-11-29 23:03:08 +01:00
|
|
|
from tiramisu.setting import groups
|
2013-05-31 23:29:20 +02:00
|
|
|
from tiramisu import setting
|
|
|
|
setting.expires_time = 1
|
2013-07-03 15:04:15 +02:00
|
|
|
from tiramisu.option import IPOption, OptionDescription, BoolOption, IntOption, StrOption
|
2013-05-31 23:29:20 +02:00
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.error import PropertiesOptionError, RequirementError
|
|
|
|
from py.test import raises
|
|
|
|
|
|
|
|
|
|
|
|
def test_requires():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.ip_address_service
|
|
|
|
c.activate_service = False
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
2014-02-04 21:40:07 +01:00
|
|
|
c.activate_service = True
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
|
|
|
|
def test_requires_with_requires():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.cfgimpl_get_settings()[b].append('test')
|
|
|
|
c.ip_address_service
|
|
|
|
c.activate_service = False
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
c.activate_service = True
|
|
|
|
c.ip_address_service
|
2013-05-31 23:29:20 +02:00
|
|
|
|
|
|
|
|
2013-12-09 18:56:29 +01:00
|
|
|
def test_requires_invalid():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
2015-11-29 23:03:08 +01:00
|
|
|
a
|
2013-12-09 18:56:29 +01:00
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires='string')")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'unknown': True}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'expected': False, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': 'string'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'transitive': 'string'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'same_action': 'string'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': 'string', 'expected': False, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
|
|
|
|
|
|
|
|
|
2013-06-13 14:43:51 +02:00
|
|
|
def test_requires_same_action():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'new'}])
|
2013-06-13 14:43:51 +02:00
|
|
|
|
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False,
|
|
|
|
'action': 'disabled', 'inverse': False,
|
|
|
|
'transitive': True, 'same_action': False}])
|
2013-06-13 14:43:51 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.cfgimpl_get_settings().append('new')
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 14:43:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['new']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 14:43:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2013-07-03 15:04:15 +02:00
|
|
|
def test_multiple_requires():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
|
|
|
{'option': a, 'expected': 'ok', 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.ip_address_service
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
|
2013-09-02 17:13:07 +02:00
|
|
|
def test_multiple_requires_cumulative():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
|
|
|
{'option': a, 'expected': 'yes', 'action': 'hidden'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.ip_address_service
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
|
2013-09-02 19:47:00 +02:00
|
|
|
def test_multiple_requires_cumulative_inverse():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
|
|
|
{'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
|
|
|
|
|
2013-07-03 15:04:15 +02:00
|
|
|
def test_multiple_requires_inverse():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
|
|
|
{'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2013-06-10 15:19:00 +02:00
|
|
|
def test_requires_transitive():
|
2013-05-31 23:29:20 +02:00
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
2013-06-10 15:19:00 +02:00
|
|
|
|
2013-05-31 23:29:20 +02:00
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2014-04-12 11:53:58 +02:00
|
|
|
def test_requires_transitive_owner():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
|
|
|
|
d = IPOption('ip_address_service_web', '',
|
|
|
|
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
#no more default value
|
|
|
|
c.ip_address_service_web = '1.1.1.1'
|
|
|
|
c.activate_service = False
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2013-06-10 15:19:00 +02:00
|
|
|
def test_requires_transitive_bis():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
abis = BoolOption('activate_service_bis', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
2013-06-10 15:19:00 +02:00
|
|
|
|
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
2013-06-10 15:19:00 +02:00
|
|
|
od = OptionDescription('service', '', [a, abis, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
#
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-10 15:19:00 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-10 15:19:00 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
|
|
|
def test_requires_transitive_hidden_disabled():
|
2013-05-31 23:29:20 +02:00
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['hidden']
|
|
|
|
raises(RequirementError, 'c.ip_address_service_web')
|
|
|
|
|
|
|
|
|
2013-06-10 15:19:00 +02:00
|
|
|
def test_requires_not_transitive():
|
2013-05-31 23:29:20 +02:00
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False,
|
|
|
|
'action': 'disabled', 'transitive': False}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
c.ip_address_service_web
|
2013-06-13 12:15:46 +02:00
|
|
|
|
|
|
|
|
2016-10-12 22:17:04 +02:00
|
|
|
def test_requires_not_transitive_not_same_action():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
d = IPOption('ip_address_service_web', '',
|
|
|
|
requires=[{'option': b, 'expected': False,
|
|
|
|
'action': 'hidden', 'transitive': False}])
|
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
raises(RequirementError, "c.ip_address_service_web")
|
|
|
|
|
|
|
|
|
2013-06-13 12:15:46 +02:00
|
|
|
def test_requires_None():
|
|
|
|
a = BoolOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
|
2013-06-13 12:15:46 +02:00
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 12:15:46 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
c.activate_service = False
|
|
|
|
c.ip_address_service
|
2013-06-28 11:59:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_requires_multi_disabled():
|
|
|
|
a = BoolOption('activate_service', '')
|
|
|
|
b = IntOption('num_service', '')
|
|
|
|
c = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': True, 'action': 'disabled'},
|
|
|
|
{'option': b, 'expected': 1, 'action': 'disabled'}])
|
2013-06-28 11:59:51 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, c])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = False
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.num_service = 1
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
2013-06-29 18:41:14 +02:00
|
|
|
|
2013-06-28 11:59:51 +02:00
|
|
|
def test_requires_multi_disabled_inverse():
|
|
|
|
a = BoolOption('activate_service', '')
|
|
|
|
b = IntOption('num_service', '')
|
|
|
|
c = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': True,
|
|
|
|
'action': 'disabled', 'inverse': True},
|
|
|
|
{'option': b, 'expected': 1,
|
|
|
|
'action': 'disabled', 'inverse': True}])
|
2013-06-28 11:59:51 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, c])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = False
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.num_service = 1
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
c.ip_address_service
|
2013-06-29 18:41:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_requires_multi_disabled_2():
|
|
|
|
a = BoolOption('a', '')
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
c = BoolOption('c', '')
|
|
|
|
d = BoolOption('d', '')
|
|
|
|
e = BoolOption('e', '')
|
|
|
|
f = BoolOption('f', '')
|
|
|
|
g = BoolOption('g', '')
|
|
|
|
h = BoolOption('h', '')
|
|
|
|
i = BoolOption('i', '')
|
|
|
|
j = BoolOption('j', '')
|
|
|
|
k = BoolOption('k', '')
|
|
|
|
l = BoolOption('l', '')
|
|
|
|
m = BoolOption('m', '')
|
|
|
|
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
|
|
|
requires = []
|
|
|
|
for boo in list_bools:
|
|
|
|
requires.append({'option': boo, 'expected': True, 'action': 'disabled'})
|
|
|
|
z = IPOption('z', '', requires=requires)
|
|
|
|
y = copy(list_bools)
|
|
|
|
y.append(z)
|
|
|
|
od = OptionDescription('service', '', y)
|
|
|
|
cfg = Config(od)
|
|
|
|
cfg.read_write()
|
|
|
|
|
|
|
|
cfg.z
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, True)
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, False)
|
|
|
|
if boo == m:
|
|
|
|
cfg.z
|
|
|
|
else:
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
|
|
|
def test_requires_multi_disabled_inverse_2():
|
|
|
|
a = BoolOption('a', '')
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
c = BoolOption('c', '')
|
|
|
|
d = BoolOption('d', '')
|
|
|
|
e = BoolOption('e', '')
|
|
|
|
f = BoolOption('f', '')
|
|
|
|
g = BoolOption('g', '')
|
|
|
|
h = BoolOption('h', '')
|
|
|
|
i = BoolOption('i', '')
|
|
|
|
j = BoolOption('j', '')
|
|
|
|
k = BoolOption('k', '')
|
|
|
|
l = BoolOption('l', '')
|
|
|
|
m = BoolOption('m', '')
|
|
|
|
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
|
|
|
requires = []
|
|
|
|
for boo in list_bools:
|
|
|
|
requires.append({'option': boo, 'expected': True, 'action': 'disabled',
|
|
|
|
'inverse': True})
|
|
|
|
z = IPOption('z', '', requires=requires)
|
|
|
|
y = copy(list_bools)
|
|
|
|
y.append(z)
|
|
|
|
od = OptionDescription('service', '', y)
|
|
|
|
cfg = Config(od)
|
|
|
|
cfg.read_write()
|
|
|
|
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, True)
|
|
|
|
if boo == m:
|
|
|
|
cfg.z
|
|
|
|
else:
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, False)
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
2013-08-22 22:46:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_requires_requirement_append():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
2013-08-24 16:30:46 +02:00
|
|
|
str(c.cfgimpl_get_settings())
|
|
|
|
str(c.cfgimpl_get_settings()[b])
|
2013-08-22 22:46:02 +02:00
|
|
|
raises(ValueError, 'c.cfgimpl_get_settings()[b].append("disabled")')
|
2013-08-24 16:30:46 +02:00
|
|
|
c.activate_service = False
|
|
|
|
# disabled is now set, test to remove disabled before store in storage
|
|
|
|
c.cfgimpl_get_settings()[b].append("test")
|
2013-08-22 22:57:32 +02:00
|
|
|
|
|
|
|
|
2013-12-09 18:56:29 +01:00
|
|
|
def test_requires_different_inverse():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
2015-11-29 23:03:08 +01:00
|
|
|
a
|
2013-12-09 18:56:29 +01:00
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])")
|
|
|
|
|
|
|
|
|
2013-08-22 22:57:32 +02:00
|
|
|
def test_requires_recursive_path():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('base', '', [od1])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
raises(RequirementError, 'c.service.a')
|
2013-08-24 16:30:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_properties_with_None_path():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('base', '', [od1])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
raises(ValueError, "c.cfgimpl_get_settings()._getproperties(a)")
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_item():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '')
|
|
|
|
od1 = OptionDescription('service', '', [a, b])
|
|
|
|
od = OptionDescription('base', '', [od1])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
raises(ValueError, 'c.cfgimpl_get_settings()[a] = ("test",)')
|
2013-09-02 19:47:00 +02:00
|
|
|
|
|
|
|
|
2015-12-22 22:06:14 +01:00
|
|
|
def test_optiondescription_requires():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('ip_address_service', '', multi=True)
|
|
|
|
a, b
|
|
|
|
OptionDescription('service', '', [b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
|
|
|
|
|
|
|
|
def test_optiondescription_requires_multi():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '', multi=True)
|
|
|
|
a, b
|
|
|
|
raises(ValueError, "OptionDescription('service', '', [a], requires=[{'option': b, 'expected': False, 'action': 'disabled'}])")
|
|
|
|
|
|
|
|
|
2013-09-02 19:47:00 +02:00
|
|
|
def test_properties_conflict():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
2015-11-29 23:03:08 +01:00
|
|
|
a
|
2013-09-02 19:47:00 +02:00
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
2015-11-29 23:03:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_master_slave_requires():
|
|
|
|
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,
|
|
|
|
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
|
|
|
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
interface1.impl_set_group_type(groups.master)
|
|
|
|
maconfig = OptionDescription('toto', '', [interface1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
|
|
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.2')
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
|
|
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.2']
|
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0[0] is None
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]")
|
2016-10-12 20:49:56 +02:00
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0[1] = '192.168.1.2'
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0[1] is None
|
|
|
|
cfg.ip_admin_eth0.netmask_admin_eth0[1] = '255.255.255.255'
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0[1] == '255.255.255.255'
|
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0[1] = '192.168.1.1'
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]")
|
2015-11-30 15:55:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_master_slave_requires_no_master():
|
|
|
|
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
|
|
|
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,
|
|
|
|
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
|
|
|
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
|
|
interface1.impl_set_group_type(groups.master)
|
|
|
|
maconfig = OptionDescription('toto', '', [activate, interface1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
|
|
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.2')
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0[0] is None
|
|
|
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.2']
|
|
|
|
cfg.activate = False
|
|
|
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
|
|
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.2', '192.168.1.1']
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0")
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[0]")
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]")
|
2016-10-12 20:49:56 +02:00
|
|
|
cfg.activate = True
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None, None]
|
|
|
|
cfg.ip_admin_eth0.netmask_admin_eth0 = [None, '255.255.255.255']
|
|
|
|
assert cfg.ip_admin_eth0.netmask_admin_eth0[1] == '255.255.255.255'
|
|
|
|
cfg.activate = False
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0")
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[0]")
|
|
|
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]")
|