From 29914051e0e64a4db19f11d12efa82ae99159b48 Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 6 Feb 2013 17:19:56 +0100 Subject: [PATCH] master groups that have multis --- test/test_parsing_group.py | 25 +++++++++++++++++++------ tiramisu/option.py | 6 +++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/test/test_parsing_group.py b/test/test_parsing_group.py index c7b442d..b726c2b 100644 --- a/test/test_parsing_group.py +++ b/test/test_parsing_group.py @@ -82,21 +82,34 @@ def test_iter_on_empty_group(): pass assert [] == list(config) +def test_groups_with_master(): + 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) + interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + interface1.set_group_type(groups.master) + assert interface1.get_group_type() == groups.master + def test_allowed_groups(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé") - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau") + 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) interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) raises(ConfigError, "interface1.set_group_type('toto')") def test_master_not_valid_name(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé") - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau") + 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) invalid_group = OptionDescription('interface1', '', [ip_admin_eth0, netmask_admin_eth0]) raises(ConfigError, "invalid_group.set_group_type(groups.master)") def test_sub_group_in_master_group(): - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé") - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau") + 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) subgroup = OptionDescription("subgroup", '', []) invalid_group = OptionDescription('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0]) raises(ConfigError, "invalid_group.set_group_type(groups.master)") + +def test_group_has_always_multis(): + 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") + group = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + raises(ConfigError, "group.set_group_type(groups.master)") diff --git a/tiramisu/option.py b/tiramisu/option.py index 0d397f1..e805213 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -489,7 +489,11 @@ class OptionDescription(HiddenBaseType, DisabledBaseType): for child in self._children: if isinstance(child, OptionDescription): raise ConfigError("master group {} shall not have " - "a subgroup".format(self._name)) + "a subgroup".format(self._name)) + if not child.multi: + raise ConfigError("not allowed option {0} in group {1}" + ": this option is not a multi".format(child._name, + self._name)) if child._name == self._name: identical_master_child_name = True if not identical_master_child_name: