97 lines
3.8 KiB
Diff
97 lines
3.8 KiB
Diff
From 01d40a4a1384156928131aea6f93f5e2cddc90b7 Mon Sep 17 00:00:00 2001
|
|
From: Alexander Kukushkin <cyberdemn@gmail.com>
|
|
Date: Wed, 5 Jan 2022 09:53:33 +0100
|
|
Subject: [PATCH] Compatibility with latest psutil and setuptools (#2155)
|
|
|
|
Issues don't affect Patroni code, only unit-tests
|
|
---
|
|
setup.py | 9 ++++-----
|
|
tests/test_cancellable.py | 4 ++--
|
|
tests/test_postmaster.py | 8 ++++----
|
|
3 files changed, 10 insertions(+), 11 deletions(-)
|
|
|
|
Index: patroni/setup.py
|
|
===================================================================
|
|
--- patroni.orig/setup.py
|
|
+++ patroni/setup.py
|
|
@@ -5,6 +5,7 @@
|
|
"""
|
|
|
|
import inspect
|
|
+import logging
|
|
import os
|
|
import sys
|
|
|
|
@@ -132,12 +133,8 @@ class PyTest(Command):
|
|
except Exception:
|
|
raise RuntimeError('py.test is not installed, run: pip install pytest')
|
|
|
|
- import logging
|
|
- silence = logging.WARNING
|
|
- logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=os.getenv('LOGLEVEL', silence))
|
|
-
|
|
args = ['--verbose', 'tests', '--doctest-modules', MAIN_PACKAGE] +\
|
|
- ['-s' if logging.getLogger().getEffectiveLevel() < silence else '--capture=fd']
|
|
+ ['-s' if logging.getLogger().getEffectiveLevel() < logging.WARNING else '--capture=fd']
|
|
if self.cov:
|
|
args += self.cov
|
|
|
|
@@ -161,6 +158,8 @@ def read(fname):
|
|
|
|
|
|
def setup_package(version):
|
|
+ logging.basicConfig(format='%(message)s', level=os.getenv('LOGLEVEL', logging.WARNING))
|
|
+
|
|
# Assemble additional setup commands
|
|
cmdclass = {'test': PyTest, 'flake8': Flake8}
|
|
|
|
Index: patroni/tests/test_cancellable.py
|
|
===================================================================
|
|
--- patroni.orig/tests/test_cancellable.py
|
|
+++ patroni/tests/test_cancellable.py
|
|
@@ -27,8 +27,8 @@ class TestCancellableSubprocess(unittest
|
|
def test_cancel(self):
|
|
self.c._process = Mock()
|
|
self.c._process.is_running.return_value = True
|
|
- self.c._process.children.side_effect = psutil.Error()
|
|
- self.c._process.suspend.side_effect = psutil.Error()
|
|
+ self.c._process.children.side_effect = psutil.NoSuchProcess(123)
|
|
+ self.c._process.suspend.side_effect = psutil.AccessDenied()
|
|
self.c.cancel()
|
|
self.c._process.is_running.side_effect = [True, False]
|
|
self.c.cancel()
|
|
Index: patroni/tests/test_postmaster.py
|
|
===================================================================
|
|
--- patroni.orig/tests/test_postmaster.py
|
|
+++ patroni/tests/test_postmaster.py
|
|
@@ -73,7 +73,7 @@ class TestPostmasterProcess(unittest.Tes
|
|
|
|
# all processes successfully stopped
|
|
mock_children.return_value = [Mock()]
|
|
- mock_children.return_value[0].kill.side_effect = psutil.Error
|
|
+ mock_children.return_value[0].kill.side_effect = psutil.NoSuchProcess(123)
|
|
self.assertTrue(proc.signal_kill())
|
|
|
|
# postmaster has gone before suspend
|
|
@@ -81,17 +81,17 @@ class TestPostmasterProcess(unittest.Tes
|
|
self.assertTrue(proc.signal_kill())
|
|
|
|
# postmaster has gone before we got a list of children
|
|
- mock_suspend.side_effect = psutil.Error()
|
|
+ mock_suspend.side_effect = psutil.AccessDenied()
|
|
mock_children.side_effect = psutil.NoSuchProcess(123)
|
|
self.assertTrue(proc.signal_kill())
|
|
|
|
# postmaster has gone after we got a list of children
|
|
- mock_children.side_effect = psutil.Error()
|
|
+ mock_children.side_effect = psutil.AccessDenied()
|
|
mock_kill.side_effect = psutil.NoSuchProcess(123)
|
|
self.assertTrue(proc.signal_kill())
|
|
|
|
# failed to kill postmaster
|
|
- mock_kill.side_effect = psutil.AccessDenied(123)
|
|
+ mock_kill.side_effect = psutil.AccessDenied()
|
|
self.assertFalse(proc.signal_kill())
|
|
|
|
@patch('psutil.Process.__init__', Mock())
|