mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Make pyscopg2 version parsing more robust (#1052)
non-released version can have unparsable suffixes, for example 2.8.3.dev0
This commit is contained in:
+8
-1
@@ -173,10 +173,17 @@ def check_psycopg2():
|
||||
min_psycopg2 = (2, 5, 4)
|
||||
min_psycopg2_str = '.'.join(map(str, min_psycopg2))
|
||||
|
||||
def parse_version(version):
|
||||
for e in version.split('.'):
|
||||
try:
|
||||
yield int(e)
|
||||
except ValueError:
|
||||
break
|
||||
|
||||
try:
|
||||
import psycopg2
|
||||
version_str = psycopg2.__version__.split(' ')[0]
|
||||
version = tuple(map(int, version_str.split('.')))
|
||||
version = tuple(parse_version(version_str))
|
||||
if version < min_psycopg2:
|
||||
fatal('Patroni requires psycopg2>={0}, but only {1} is available', min_psycopg2_str, version_str)
|
||||
except ImportError:
|
||||
|
||||
@@ -159,5 +159,5 @@ class TestPatroni(unittest.TestCase):
|
||||
def test_check_psycopg2(self):
|
||||
with patch.object(builtins, '__import__', Mock(side_effect=ImportError)):
|
||||
self.assertRaises(SystemExit, check_psycopg2)
|
||||
with patch.object(psycopg2, '__version__', return_value='2.5.3 a b c'):
|
||||
with patch.object(psycopg2, '__version__', return_value='2.5.3.dev1 a b c'):
|
||||
self.assertRaises(SystemExit, check_psycopg2)
|
||||
|
||||
Reference in New Issue
Block a user