diff --git a/src/rougail/annotator/service.py b/src/rougail/annotator/service.py index f7858be4..2639972b 100644 --- a/src/rougail/annotator/service.py +++ b/src/rougail/annotator/service.py @@ -216,7 +216,7 @@ class ServiceAnnotator: variable.opt = self.objectspace.paths.get_variable(value) variable.multi = None needed_type = self.objectspace.types[dtd_key_type] - if needed_type != 'variable' and variable.opt.type != needed_type: + if needed_type not in ('variable', variable.opt.type): msg = _(f'"{value}" in "{elttype}" must be a variable with type ' f'"{needed_type}" not "{variable.opt.type}"') raise DictConsistencyError(msg, 58, elt.xmlfiles) @@ -239,9 +239,9 @@ class ServiceAnnotator: ): if service_name in self.uniq_overrides: - msg = _(f'only one override is allowed by service, ' - f'please use a variable multiple if you want have more than one IP') - raise DictConsistencyError(msg, 69, ip.xmlfiles) + msg = _('only one override is allowed by service, ' + 'please use a variable multiple if you want have more than one IP') + raise DictConsistencyError(msg, 69, override.xmlfiles) self.uniq_overrides.append(service_name) override.name = service_name if not hasattr(override, 'engine'): @@ -260,8 +260,6 @@ class ServiceAnnotator: msg = _(f'attribute "source" is mandatory for the file "{file_.name}" ' f'"({service_name})"') raise DictConsistencyError(msg, 34, file_.xmlfiles) - if not file_.source: - del file_.source if not hasattr(file_, 'engine'): file_.engine = RougailConfig['default_engine'] @@ -270,11 +268,14 @@ class ServiceAnnotator: service_name, ) -> None: if service_name in self.uniq_ip: - msg = _(f'only one IP is allowed by service, ' - f'please use a variable multiple if you want have more than one IP') + msg = _('only one IP is allowed by service, ' + 'please use a variable multiple if you want have more than one IP') raise DictConsistencyError(msg, 67, ip.xmlfiles) self.uniq_ip.append(service_name) variable = self.objectspace.paths.get_variable(ip.name) + if variable.type not in ['ip', 'network', 'network_cidr']: + msg = _('ip cannot be linked to "{variable.type}" variable') + raise DictConsistencyError(msg, 70, ip.xmlfiles) if variable.type in ['ip', 'network_cidr'] and hasattr(ip, 'netmask'): msg = _(f'ip with ip_type "{variable.type}" must not have netmask') raise DictConsistencyError(msg, 59, ip.xmlfiles) diff --git a/src/rougail/template/base.py b/src/rougail/template/base.py index e351bc76..98735f5c 100644 --- a/src/rougail/template/base.py +++ b/src/rougail/template/base.py @@ -298,22 +298,22 @@ class RougailBaseTemplate: self.post_instance() chdir(ori_dir) - def post_instance(self): + def post_instance(self): # pragma: no cover pass def _instance_ip(self, *args, - ) -> None: + ) -> None: # pragma: no cover raise NotImplementedError(_('cannot instanciate this service type ip')) def _instance_files(self, *args, - ) -> None: + ) -> None: # pragma: no cover raise NotImplementedError(_('cannot instanciate this service type file')) def _instance_overrides(self, *args, - ) -> None: + ) -> None: # pragma: no cover raise NotImplementedError(_('cannot instanciate this service type override')) async def load_variables(self, diff --git a/tests/dictionaries/80file_wrong_type/00-base.xml b/tests/dictionaries/80file_wrong_type/00-base.xml new file mode 100644 index 00000000..41f2f638 --- /dev/null +++ b/tests/dictionaries/80file_wrong_type/00-base.xml @@ -0,0 +1,13 @@ + + + + + file_name + + + + + /etc/mailname + + + diff --git a/tests/dictionaries/80file_wrong_type/__init__.py b/tests/dictionaries/80file_wrong_type/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80file_wrong_type/errno_58 b/tests/dictionaries/80file_wrong_type/errno_58 new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80override_twice/00-base.xml b/tests/dictionaries/80override_twice/00-base.xml new file mode 100644 index 00000000..8345c642 --- /dev/null +++ b/tests/dictionaries/80override_twice/00-base.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + non + + + + + diff --git a/tests/dictionaries/80override_twice/__init__.py b/tests/dictionaries/80override_twice/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80override_twice/errno_69 b/tests/dictionaries/80override_twice/errno_69 new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80services_ip_twice/00-base.xml b/tests/dictionaries/80services_ip_twice/00-base.xml new file mode 100644 index 00000000..62e32106 --- /dev/null +++ b/tests/dictionaries/80services_ip_twice/00-base.xml @@ -0,0 +1,19 @@ + + + + + + + nut_monitor_host + nut_monitor_host + + + + + + 192.168.0.1 + + + + diff --git a/tests/dictionaries/80services_ip_twice/__init__.py b/tests/dictionaries/80services_ip_twice/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80services_ip_twice/errno_67 b/tests/dictionaries/80services_ip_twice/errno_67 new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80services_ip_wrong_type/00-base.xml b/tests/dictionaries/80services_ip_wrong_type/00-base.xml new file mode 100644 index 00000000..9d94e645 --- /dev/null +++ b/tests/dictionaries/80services_ip_wrong_type/00-base.xml @@ -0,0 +1,18 @@ + + + + + + + nut_monitor_host + + + + + + 192.168.0.1 + + + + diff --git a/tests/dictionaries/80services_ip_wrong_type/__init__.py b/tests/dictionaries/80services_ip_wrong_type/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80services_ip_wrong_type/errno_70 b/tests/dictionaries/80services_ip_wrong_type/errno_70 new file mode 100644 index 00000000..e69de29b