copy requires from master to MasterSlaves

This commit is contained in:
Emmanuel Garette 2018-09-29 21:37:39 +02:00
parent 3a1745a885
commit 77e4fff763
3 changed files with 48 additions and 6 deletions

View File

@ -262,9 +262,7 @@ def test_multi_with_requires_that_is_masterslave():
def test_multi_with_requires_that_is_masterslave_master(): def test_multi_with_requires_that_is_masterslave_master():
b = IntOption('int', 'Test int option', multi=True) b = IntOption('int', 'Test int option', multi=True)
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True) c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = MasterSlaves("str", "", [c, b]) raises(ValueError, "MasterSlaves('str', '', [c, b])")
descr2 = OptionDescription('descr', '', [descr])
raises(ValueError, "Config(descr2)")
def test_multi_with_requires_that_is_masterslave_slave(): def test_multi_with_requires_that_is_masterslave_slave():

View File

@ -932,7 +932,6 @@ def test_master_slave_requires():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", 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'}]) requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
@ -972,6 +971,40 @@ def test_master_slave_requires():
assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError) assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError)
def test_master_slave_requires_both():
ip_admin = StrOption('ip_admin_eth0', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
raises(RequirementError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
def test_master_slave_requires_properties_invalid():
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
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'}])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',), requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])")
def test_master_slave_requires_properties_invalid_2():
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
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'}])
raises(ValueError, "MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',))")
def test_master_slave_requires_properties():
ip_admin = StrOption('ip_admin', "ip réseau autorisé")
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'}])
MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',),
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
def test_master_slave_requires_master(): def test_master_slave_requires_master():
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,

View File

@ -88,7 +88,7 @@ class MasterSlaves(OptionDescription):
master_requires = getattr(master, '_requires', None) master_requires = getattr(master, '_requires', None)
if master_requires: if master_requires:
if self.impl_getrequires(): if self.impl_getrequires():
raise RequirementError(_('master {} in MasterSlaves {} cannot have both requirement' raise RequirementError(_('master {} have requirement, but MasterSlaves {} too'
'').format(master.impl_getname(), '').format(master.impl_getname(),
self.impl_getname())) self.impl_getname()))
master_calproperties = getattr(master, '_calc_properties', None) master_calproperties = getattr(master, '_calc_properties', None)
@ -96,7 +96,18 @@ class MasterSlaves(OptionDescription):
if properties is not None: if properties is not None:
self.validate_properties(name, master_calproperties, frozenset(properties)) self.validate_properties(name, master_calproperties, frozenset(properties))
setattr(self, '_calc_properties', master_calproperties) setattr(self, '_calc_properties', master_calproperties)
setattr(self, '_requires', master_requires) setattr(self, '_requires', master_requires)
delattr(master, '_requires')
all_requires = getattr(self, '_requires', None)
if all_requires:
for requires_ in all_requires:
for require in requires_:
for require_opt, values in require[0]:
if require_opt.impl_is_multi():
if require_opt.impl_is_master_slaves():
raise ValueError(_('malformed requirements option "{0}" '
'must not be in slave for "{1}"').format(
require_opt.impl_getname(), self.impl_getname()))
def is_master(self, opt): def is_master(self, opt):
master = self._children[0][0] master = self._children[0][0]