diff --git a/patroni/api.py b/patroni/api.py index 7000fc2f..b87711b2 100644 --- a/patroni/api.py +++ b/patroni/api.py @@ -4,7 +4,7 @@ import json import logging import psycopg2 import time -import dateutil +import dateutil.parser import datetime import pytz diff --git a/patroni/ctl.py b/patroni/ctl.py index 26fef782..a0f0c565 100644 --- a/patroni/ctl.py +++ b/patroni/ctl.py @@ -5,7 +5,7 @@ Patroni Control import base64 import click import datetime -import dateutil +import dateutil.parser import json import logging import os diff --git a/patroni/scripts/wale_restore.py b/patroni/scripts/wale_restore.py index f3691907..4383e986 100755 --- a/patroni/scripts/wale_restore.py +++ b/patroni/scripts/wale_restore.py @@ -33,7 +33,7 @@ import sys import argparse -if sys.hexversion >= 0x03000000: +if sys.hexversion >= 0x0300000: long = int logger = logging.getLogger(__name__) diff --git a/patroni/utils.py b/patroni/utils.py index a200292e..9c7a9e9d 100644 --- a/patroni/utils.py +++ b/patroni/utils.py @@ -1,36 +1,17 @@ -import datetime import os import random -import six +import sys import time -import pytz -import dateutil.parser from patroni.exceptions import PatroniException +if sys.hexversion >= 0x0300000: + long = int + __interrupted_sleep = False __reap_children = False -def calculate_ttl(expiration): - """ - >>> calculate_ttl(None) - >>> calculate_ttl('2015-06-10 12:56:30.552539016Z') < 0 - True - >>> calculate_ttl('2015-06-10T12:56:30.552539016Z') < 0 - True - >>> calculate_ttl('fail-06-10T12:56:30.552539016Z') - """ - if not expiration: - return None - try: - expiration = dateutil.parser.parse(expiration) - except (ValueError, TypeError): - return None - now = datetime.datetime.now(pytz.utc) - return int((expiration - now).total_seconds()) - - def deep_compare(obj1, obj2): """ >>> deep_compare({'1': None}, {}) @@ -134,7 +115,7 @@ def strtol(value, strict=True): while i < l: try: # try to find maximally long number i += 1 # by giving to `int` longer and longer strings - ret = int(value[:i], base) if six.PY3 else long(value[:i], base) + ret = long(value[:i], base) except ValueError: # until we will not get an exception or end of the string i -= 1 break diff --git a/setup.py b/setup.py index 6af7b953..d285bbd4 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ LICENSE = 'The MIT License' URL = 'https://github.com/zalando/patroni' AUTHOR = 'Alexander Kukushkin, Oleksii Kliukin, Feike Steenbergen' AUTHOR_EMAIL = 'alexander.kukushkin@zalando.de, oleksii.kliukin@zalando.de, feike.steenbergen@zalando.de' -KEYWORDS = 'etcd governor patroni postgresql postgres ha zookeeper streaming replication' +KEYWORDS = 'etcd governor patroni postgresql postgres ha haproxy confd zookeeper exhibitor consul streaming replication' COVERAGE_XML = True COVERAGE_HTML = False diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index ec0151a2..42dcab0a 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -336,7 +336,9 @@ class TestPostgresql(unittest.TestCase): @patch('os.path.isfile', Mock(return_value=True)) @patch('os.kill', Mock(side_effect=Exception)) - @patch.object(builtins, 'open', mock_open(read_data='-999999999999999')) + @patch('os.getpid', Mock(return_value=2)) + @patch('os.getppid', Mock(return_value=2)) + @patch.object(builtins, 'open', mock_open(read_data='-1')) @patch.object(Postgresql, '_version_file_exists', Mock(return_value=True)) def test_is_running(self): self.assertFalse(self.p.is_running())