diff --git a/test/test_config_domain.py b/test/test_config_domain.py index ab6e00e..a491350 100644 --- a/test/test_config_domain.py +++ b/test/test_config_domain.py @@ -7,7 +7,8 @@ from tiramisu.option import DomainnameOption, OptionDescription def test_domainname(): d = DomainnameOption('d', '') - od = OptionDescription('a', '', [d]) + e = DomainnameOption('e', '', "toto.com") + od = OptionDescription('a', '', [d, e]) c = Config(od) c.d = 'toto.com' raises(ValueError, "c.d = 'toto'") @@ -21,7 +22,8 @@ def test_domainname(): def test_domainname_netbios(): d = DomainnameOption('d', '', type_='netbios') - od = OptionDescription('a', '', [d]) + e = DomainnameOption('e', '', "toto", type_='netbios') + od = OptionDescription('a', '', [d, e]) c = Config(od) raises(ValueError, "c.d = 'toto.com'") c.d = 'toto' @@ -30,7 +32,8 @@ def test_domainname_netbios(): def test_domainname_hostname(): d = DomainnameOption('d', '', type_='hostname') - od = OptionDescription('a', '', [d]) + e = DomainnameOption('e', '', "toto", type_='hostname') + od = OptionDescription('a', '', [d, e]) c = Config(od) raises(ValueError, "c.d = 'toto.com'") c.d = 'toto' diff --git a/tiramisu/option.py b/tiramisu/option.py index 6fc9395..970d348 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -528,7 +528,6 @@ class NetmaskOption(Option): class DomainnameOption(Option): __slots__ = ('_opt_type', '_type', '_allow_ip') _opt_type = 'domainname' - #allow_ip def __init__(self, name, doc, default=None, default_multi=None, requires=None, multi=False, callback=None, @@ -538,6 +537,12 @@ class DomainnameOption(Option): #hostname: to identify the device #domainname: #fqdn: with tld, not supported yet + if type_ not in ['netbios', 'hostname', 'domainname']: + raise ValueError(_('unknown type_ {0} for hostname').format(type_)) + self._type = type_ + if allow_ip not in [True, False]: + raise ValueError(_('allow_ip must be a boolean')) + self._allow_ip = allow_ip super(DomainnameOption, self).__init__(name, doc, default=default, default_multi=default_multi, callback=callback, @@ -547,10 +552,6 @@ class DomainnameOption(Option): validator=validator, validator_args=validator_args, properties=properties) - if type_ not in ['netbios', 'hostname', 'domainname']: - raise ValueError(_('unknown type_ {0} for hostname').format(type_)) - self._type = type_ - self._allow_ip = allow_ip def _validate(self, value): if self._allow_ip is True: