VMM/config: Updated Dovecot version check. v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Sun, 09 Feb 2014 14:37:51 +0000
branchv0.7.x
changeset 716 915c14b21db3
parent 715 c6a33da1aa93
child 717 22f61779d34f
VMM/config: Updated Dovecot version check. Renamed function check_version_format() -> check_dovecot_version(). Now this function checks also if misc.dovecot_version >= MIN_DOVECOT_VERSION.
VirtualMailManager/config.py
--- a/VirtualMailManager/config.py	Sat Feb 08 18:36:30 2014 +0000
+++ b/VirtualMailManager/config.py	Sun Feb 09 14:37:51 2014 +0000
@@ -16,8 +16,9 @@
 from io import StringIO
 
 from VirtualMailManager.common import VERSION_RE, \
-     exec_ok, expand_path, get_unicode, lisdir, size_in_bytes, version_hex
-from VirtualMailManager.constants import CONF_ERROR
+     exec_ok, expand_path, get_unicode, lisdir, size_in_bytes, version_hex, \
+     version_str
+from VirtualMailManager.constants import CONF_ERROR, MIN_DOVECOT_VERSION
 from VirtualMailManager.errors import ConfigError, VMMError
 from VirtualMailManager.maillocation import known_format
 from VirtualMailManager.password import verify_scheme as _verify_scheme
@@ -345,7 +346,7 @@
                 'crypt_sha256_rounds': LCO(int, 5000, self.getint),
                 'crypt_sha512_rounds': LCO(int, 5000, self.getint),
                 'dovecot_version': LCO(str, None, self.hexversion,
-                                       check_version_format),
+                                       check_dovecot_version),
                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
                                        verify_scheme),
             },
@@ -430,9 +431,10 @@
         """Check settings for which the possible values are known."""
         if not miss_vers:
             value = self.get('misc', 'dovecot_version')
-            if not VERSION_RE.match(value):
-                self._missing['misc'] = ['version: ' +
-                        _("Not a valid Dovecot version: '%s'") % value]
+            try:
+                checked = check_dovecot_version(value)
+            except ConfigValueError as err:
+                self._missing['misc'] = ['dovecot_version: %s' % str(err)]
         # section database
         db_err = []
         value = self.dget('database.sslmode')
@@ -497,14 +499,18 @@
     return value
 
 
-def check_version_format(version_string):
-    """Check if the *version_string* has the proper format, e.g.: '1.2.3'.
+def check_dovecot_version(version_string):
+    """Check if the *version_string* has the proper format, e.g.: '2.0.0',
+    and if the configured version is >= MIN_DOVECOT_VERSION.
     Returns the validated version string if it has the expected format.
     Otherwise a `ConfigValueError` will be raised.
     """
     if not VERSION_RE.match(version_string):
         raise ConfigValueError(_("Not a valid Dovecot version: '%s'") %
                                get_unicode(version_string))
+    if version_hex(version_string) < MIN_DOVECOT_VERSION:
+        raise ConfigValueError(_("vmm requires Dovecot >= %s") %
+                               version_str(MIN_DOVECOT_VERSION))
     return version_string