mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Fix deps compatibility, increase tests coverage i(#3233)
* Compatibility with python-json-logger>=3.1 After refactoring the old API is still working, but producing warnings and pyright also fails. Besides that improve coverage of watchdog/base.py and ctl.py * Stick to ubuntu 22.04 * Please pyright
This commit is contained in:
@@ -13,7 +13,7 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
unit:
|
unit:
|
||||||
runs-on: ${{ matrix.os }}-latest
|
runs-on: ${{ fromJson('{"ubuntu":"ubuntu-22.04","windows":"windows-latest","macos":"macos-latest"}')[matrix.os] }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -93,7 +93,7 @@ jobs:
|
|||||||
run: python -m coveralls --service=github
|
run: python -m coveralls --service=github
|
||||||
|
|
||||||
behave:
|
behave:
|
||||||
runs-on: ${{ matrix.os }}-latest
|
runs-on: ${{ fromJson('{"ubuntu":"ubuntu-22.04","windows":"windows-latest","macos":"macos-latest"}')[matrix.os] }}
|
||||||
env:
|
env:
|
||||||
DCS: ${{ matrix.dcs }}
|
DCS: ${{ matrix.dcs }}
|
||||||
ETCDVERSION: 3.4.23
|
ETCDVERSION: 3.4.23
|
||||||
@@ -186,7 +186,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: jakebailey/pyright-action@v2
|
- uses: jakebailey/pyright-action@v2
|
||||||
with:
|
with:
|
||||||
version: 1.1.389
|
version: 1.1.391
|
||||||
|
|
||||||
ydiff:
|
ydiff:
|
||||||
name: Test compatibility with the latest version of ydiff
|
name: Test compatibility with the latest version of ydiff
|
||||||
|
|||||||
+9
-6
@@ -393,13 +393,16 @@ class PatroniLogger(Thread):
|
|||||||
_LOGGER.warning('Expected log format to be a string or a list, but got "%s"', _type(logformat))
|
_LOGGER.warning('Expected log format to be a string or a list, but got "%s"', _type(logformat))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pythonjsonlogger import jsonlogger
|
try:
|
||||||
if hasattr(jsonlogger, 'RESERVED_ATTRS') \
|
from pythonjsonlogger import json as jsonlogger # pyright: ignore
|
||||||
and 'taskName' not in jsonlogger.RESERVED_ATTRS: # pyright: ignore [reportUnnecessaryContains]
|
except ImportError: # pragma: no cover
|
||||||
# compatibility with python 3.12, that added a new attribute to LogRecord
|
from pythonjsonlogger import jsonlogger
|
||||||
jsonlogger.RESERVED_ATTRS += ('taskName',)
|
if hasattr(jsonlogger, 'RESERVED_ATTRS') \
|
||||||
|
and 'taskName' not in jsonlogger.RESERVED_ATTRS: # pyright: ignore [reportPrivateImportUsage]
|
||||||
|
# compatibility with python 3.12, that added a new attribute to LogRecord
|
||||||
|
jsonlogger.RESERVED_ATTRS += ('taskName',) # pyright: ignore
|
||||||
|
|
||||||
return jsonlogger.JsonFormatter(
|
return jsonlogger.JsonFormatter( # pyright: ignore [reportPrivateImportUsage]
|
||||||
jsonformat,
|
jsonformat,
|
||||||
dateformat,
|
dateformat,
|
||||||
rename_fields=rename_fields,
|
rename_fields=rename_fields,
|
||||||
|
|||||||
@@ -140,10 +140,8 @@ class Watchdog(object):
|
|||||||
self.impl.open()
|
self.impl.open()
|
||||||
actual_timeout = self._set_timeout()
|
actual_timeout = self._set_timeout()
|
||||||
except WatchdogError as e:
|
except WatchdogError as e:
|
||||||
if self.config.mode == MODE_REQUIRED:
|
log = logger.warning if self.config.mode == MODE_REQUIRED else logger.debug
|
||||||
logger.warning("Could not activate %s: %s", self.impl.describe(), e)
|
log("Could not activate %s: %s", self.impl.describe(), e)
|
||||||
else:
|
|
||||||
logger.debug("Could not activate %s: %s", self.impl.describe(), e)
|
|
||||||
self.impl = NullWatchdog()
|
self.impl = NullWatchdog()
|
||||||
actual_timeout = self.impl.get_timeout()
|
actual_timeout = self.impl.get_timeout()
|
||||||
|
|
||||||
|
|||||||
@@ -399,6 +399,13 @@ class TestCtl(unittest.TestCase):
|
|||||||
result = self.runner.invoke(ctl, ctl_args, input='y')
|
result = self.runner.invoke(ctl, ctl_args, input='y')
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
ctl_args = ['restart', 'alpha', '--pg-version', '99.0', '--pending', '--scheduled', '2300-10-01T14:30']
|
||||||
|
# normal restart, the schedule is actually parsed, but not validated in patronictl
|
||||||
|
mock_post.return_value.status = 200
|
||||||
|
result = self.runner.invoke(ctl, ctl_args, input='y')
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert 'might be different from the ones' in result.output
|
||||||
|
|
||||||
# get restart with the non-200 return code
|
# get restart with the non-200 return code
|
||||||
# normal restart, the schedule is actually parsed, but not validated in patronictl
|
# normal restart, the schedule is actually parsed, but not validated in patronictl
|
||||||
mock_post.return_value.status = 204
|
mock_post.return_value.status = 204
|
||||||
|
|||||||
+7
-2
@@ -13,9 +13,13 @@ from patroni.config import Config
|
|||||||
from patroni.log import PatroniLogger
|
from patroni.log import PatroniLogger
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pythonjsonlogger import jsonlogger
|
try:
|
||||||
|
from pythonjsonlogger import json as jsonlogger
|
||||||
|
except ImportError:
|
||||||
|
from pythonjsonlogger import jsonlogger
|
||||||
|
|
||||||
|
jsonlogger.JsonFormatter(None, None, rename_fields={}, static_fields={})
|
||||||
|
|
||||||
jsonlogger.JsonFormatter(None, None, rename_fields={}, static_fields={})
|
|
||||||
json_formatter_is_available = True
|
json_formatter_is_available = True
|
||||||
|
|
||||||
import json # we need json.loads() function
|
import json # we need json.loads() function
|
||||||
@@ -274,6 +278,7 @@ class TestPatroniLogger(unittest.TestCase):
|
|||||||
with self.assertLogs() as captured_log:
|
with self.assertLogs() as captured_log:
|
||||||
logger = PatroniLogger()
|
logger = PatroniLogger()
|
||||||
pythonjsonlogger = Mock()
|
pythonjsonlogger = Mock()
|
||||||
|
pythonjsonlogger.json.JsonFormatter = Mock(side_effect=Exception)
|
||||||
pythonjsonlogger.jsonlogger.JsonFormatter = Mock(side_effect=Exception)
|
pythonjsonlogger.jsonlogger.JsonFormatter = Mock(side_effect=Exception)
|
||||||
with patch('builtins.__import__', Mock(return_value=pythonjsonlogger)):
|
with patch('builtins.__import__', Mock(return_value=pythonjsonlogger)):
|
||||||
logger.reload_config({'type': 'json'})
|
logger.reload_config({'type': 'json'})
|
||||||
|
|||||||
Reference in New Issue
Block a user