2012-07-13 09:42:14 +02:00
|
|
|
import autopath
|
|
|
|
from py.test import raises
|
|
|
|
|
2013-05-10 22:32:42 +02:00
|
|
|
from tiramisu.setting import owners, groups
|
2013-04-22 09:19:05 +02:00
|
|
|
from tiramisu.config import Config
|
2013-05-08 18:14:42 +02:00
|
|
|
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
|
|
|
OptionDescription
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_not_equal():
|
|
|
|
a = IntOption('a', '')
|
|
|
|
b = IntOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
a.impl_add_consistency('not_equal', b)
|
2013-05-08 18:14:42 +02:00
|
|
|
c = Config(od)
|
|
|
|
assert c.a is None
|
|
|
|
assert c.b is None
|
|
|
|
c.a = 1
|
|
|
|
del(c.a)
|
|
|
|
c.a = 1
|
|
|
|
raises(ValueError, "c.b = 1")
|
|
|
|
c.b = 2
|
|
|
|
|
|
|
|
|
2013-05-10 15:10:06 +02:00
|
|
|
def test_consistency_not_equal_multi():
|
|
|
|
a = IntOption('a', '', multi=True)
|
|
|
|
b = IntOption('b', '', multi=True)
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
a.impl_add_consistency('not_equal', b)
|
|
|
|
c = Config(od)
|
|
|
|
assert c.a == []
|
|
|
|
assert c.b == []
|
|
|
|
c.a = [1]
|
|
|
|
del(c.a)
|
|
|
|
c.a = [1]
|
|
|
|
raises(ValueError, "c.b = [1]")
|
|
|
|
c.b = [2]
|
|
|
|
|
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
def test_consistency_default():
|
|
|
|
a = IntOption('a', '', 1)
|
|
|
|
b = IntOption('b', '', 1)
|
2013-05-10 15:10:06 +02:00
|
|
|
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_default_diff():
|
|
|
|
a = IntOption('a', '', 3)
|
|
|
|
b = IntOption('b', '', 1)
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
a.impl_add_consistency('not_equal', b)
|
2013-05-08 18:14:42 +02:00
|
|
|
c = Config(od)
|
|
|
|
raises(ValueError, "c.a = 1")
|
|
|
|
c.a = 2
|
|
|
|
c.b = 3
|
2013-08-24 22:32:54 +02:00
|
|
|
assert c.getowner(a) is owners.user
|
2013-05-08 18:14:42 +02:00
|
|
|
raises(ValueError, "del(c.a)")
|
2013-08-24 22:32:54 +02:00
|
|
|
assert c.getowner(a) is owners.user
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_ip_netmask():
|
|
|
|
a = IPOption('a', '')
|
|
|
|
b = NetmaskOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
b.impl_add_consistency('ip_netmask', a)
|
2013-05-08 18:14:42 +02:00
|
|
|
c = Config(od)
|
|
|
|
c.a = '192.168.1.1'
|
|
|
|
c.b = '255.255.255.0'
|
|
|
|
c.a = '192.168.1.2'
|
|
|
|
c.b = '255.255.255.255'
|
|
|
|
c.b = '255.255.255.0'
|
|
|
|
raises(ValueError, "c.a = '192.168.1.0'")
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_network_netmask():
|
|
|
|
a = NetworkOption('a', '')
|
|
|
|
b = NetmaskOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
2013-05-10 15:10:06 +02:00
|
|
|
b.impl_add_consistency('network_netmask', a)
|
2013-05-08 18:14:42 +02:00
|
|
|
c = Config(od)
|
|
|
|
c.a = '192.168.1.1'
|
|
|
|
c.b = '255.255.255.255'
|
|
|
|
del(c.b)
|
|
|
|
c.a = '192.168.1.0'
|
|
|
|
c.b = '255.255.255.0'
|
|
|
|
raises(ValueError, "c.a = '192.168.1.1'")
|
2013-05-10 15:10:06 +02:00
|
|
|
|
|
|
|
|
2013-05-10 22:32:42 +02:00
|
|
|
def test_consistency_ip_netmask_error_multi():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '')
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
raises(ValueError, "b.impl_add_consistency('ip_netmask', a)")
|
|
|
|
|
|
|
|
|
2013-05-10 15:10:06 +02:00
|
|
|
def test_consistency_ip_netmask_multi():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
b.impl_add_consistency('ip_netmask', a)
|
|
|
|
c = Config(od)
|
|
|
|
c.a = ['192.168.1.1']
|
|
|
|
c.b = ['255.255.255.0']
|
|
|
|
c.a = ['192.168.1.2']
|
|
|
|
c.b = ['255.255.255.255']
|
|
|
|
c.b = ['255.255.255.0']
|
|
|
|
raises(ValueError, "c.a = ['192.168.1.0']")
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_network_netmask_multi():
|
|
|
|
a = NetworkOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
od = OptionDescription('od', '', [a, b])
|
|
|
|
b.impl_add_consistency('network_netmask', a)
|
|
|
|
c = Config(od)
|
|
|
|
c.a = ['192.168.1.1']
|
|
|
|
c.b = ['255.255.255.255']
|
|
|
|
del(c.b)
|
|
|
|
c.a = ['192.168.1.0']
|
|
|
|
c.b = ['255.255.255.0']
|
|
|
|
raises(ValueError, "c.a = ['192.168.1.1']")
|
2013-05-10 22:32:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_ip_netmask_multi_master():
|
|
|
|
a = IPOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
od = OptionDescription('a', '', [a, b])
|
|
|
|
od.impl_set_group_type(groups.master)
|
|
|
|
b.impl_add_consistency('ip_netmask', a)
|
|
|
|
c = Config(od)
|
|
|
|
c.a = ['192.168.1.1']
|
|
|
|
c.b = ['255.255.255.0']
|
|
|
|
c.a = ['192.168.1.2']
|
|
|
|
c.b = ['255.255.255.255']
|
|
|
|
c.b = ['255.255.255.0']
|
|
|
|
raises(ValueError, "c.a = ['192.168.1.0']")
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_network_netmask_multi_master():
|
|
|
|
a = NetworkOption('a', '', multi=True)
|
|
|
|
b = NetmaskOption('b', '', multi=True)
|
|
|
|
od = OptionDescription('a', '', [a, b])
|
|
|
|
od.impl_set_group_type(groups.master)
|
|
|
|
b.impl_add_consistency('network_netmask', a)
|
|
|
|
c = Config(od)
|
|
|
|
c.a = ['192.168.1.1']
|
|
|
|
c.b = ['255.255.255.255']
|
|
|
|
del(c.b)
|
|
|
|
c.a = ['192.168.1.0']
|
|
|
|
c.b = ['255.255.255.0']
|
|
|
|
raises(ValueError, "c.a = ['192.168.1.1']")
|