2013-05-31 23:29:20 +02:00
|
|
|
# coding: utf-8
|
|
|
|
import autopath
|
2013-06-29 18:41:14 +02:00
|
|
|
from copy import copy
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['new']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
|
|
|
except PropertiesOptionError, 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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = False
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.num_service = 1
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = False
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.num_service = 1
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
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
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, False)
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
|
|
|
except PropertiesOptionError, err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|