mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Partially revert patroni@8c5ab4c (#3180)
Still check against `postgres --describe-config` if a GUC does not have a validator but is a valid postgres GUC
This commit is contained in:
+10
-1
@@ -3,7 +3,7 @@ import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
from unittest.mock import Mock, patch, PropertyMock
|
||||
|
||||
import urllib3
|
||||
|
||||
@@ -20,6 +20,15 @@ class SleepException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
mock_available_gucs = PropertyMock(return_value={
|
||||
'cluster_name', 'constraint_exclusion', 'force_parallel_mode', 'hot_standby', 'listen_addresses', 'max_connections',
|
||||
'max_locks_per_transaction', 'max_prepared_transactions', 'max_replication_slots', 'max_stack_depth',
|
||||
'max_wal_senders', 'max_worker_processes', 'port', 'search_path', 'shared_preload_libraries',
|
||||
'stats_temp_directory', 'synchronous_standby_names', 'track_commit_timestamp', 'unix_socket_directories',
|
||||
'vacuum_cost_delay', 'vacuum_cost_limit', 'wal_keep_size', 'wal_level', 'wal_log_hints', 'zero_damaged_pages',
|
||||
'autovacuum', 'wal_segment_size', 'wal_block_size', 'shared_buffers', 'wal_buffers', 'fork_specific_param',
|
||||
})
|
||||
|
||||
GET_PG_SETTINGS_RESULT = [
|
||||
('wal_segment_size', '2048', '8kB', 'integer', 'internal'),
|
||||
('wal_block_size', '8192', None, 'integer', 'internal'),
|
||||
|
||||
@@ -10,13 +10,14 @@ from patroni.postgresql.bootstrap import Bootstrap
|
||||
from patroni.postgresql.cancellable import CancellableSubprocess
|
||||
from patroni.postgresql.config import ConfigHandler, get_param_diff
|
||||
|
||||
from . import BaseTestPostgresql, psycopg_connect
|
||||
from . import BaseTestPostgresql, mock_available_gucs, psycopg_connect
|
||||
|
||||
|
||||
@patch('subprocess.call', Mock(return_value=0))
|
||||
@patch('subprocess.check_output', Mock(return_value=b"postgres (PostgreSQL) 12.1"))
|
||||
@patch('patroni.psycopg.connect', psycopg_connect)
|
||||
@patch('os.rename', Mock())
|
||||
@patch.object(Postgresql, 'available_gucs', mock_available_gucs)
|
||||
class TestBootstrap(BaseTestPostgresql):
|
||||
|
||||
@patch('patroni.postgresql.CallbackExecutor', Mock())
|
||||
|
||||
@@ -78,6 +78,7 @@ class TestPatroni(unittest.TestCase):
|
||||
@patch.object(etcd.Client, 'read', etcd_read)
|
||||
@patch.object(Thread, 'start', Mock())
|
||||
@patch.object(AbstractEtcdClientWithFailover, '_get_machines_list', Mock(return_value=['http://remotehost:2379']))
|
||||
@patch.object(Postgresql, '_get_gucs', Mock(return_value={'foo': True, 'bar': True}))
|
||||
def setUp(self):
|
||||
self._handlers = logging.getLogger().handlers[:]
|
||||
RestApiServer._BaseServer__is_shut_down = Mock()
|
||||
@@ -111,6 +112,7 @@ class TestPatroni(unittest.TestCase):
|
||||
@patch.object(etcd.Client, 'delete', Mock())
|
||||
@patch.object(AbstractEtcdClientWithFailover, '_get_machines_list', Mock(return_value=['http://remotehost:2379']))
|
||||
@patch.object(Thread, 'join', Mock())
|
||||
@patch.object(Postgresql, '_get_gucs', Mock(return_value={'foo': True, 'bar': True}))
|
||||
def test_patroni_patroni_main(self):
|
||||
with patch('subprocess.call', Mock(return_value=1)):
|
||||
with patch.object(Patroni, 'run', Mock(side_effect=SleepException)):
|
||||
|
||||
@@ -15,7 +15,7 @@ import patroni.psycopg as psycopg
|
||||
|
||||
from patroni import global_config
|
||||
from patroni.async_executor import CriticalTask
|
||||
from patroni.collections import CaseInsensitiveDict
|
||||
from patroni.collections import CaseInsensitiveDict, CaseInsensitiveSet
|
||||
from patroni.dcs import RemoteMember
|
||||
from patroni.exceptions import PatroniException, PostgresConnectionException
|
||||
from patroni.postgresql import Postgresql, STATE_NO_RESPONSE, STATE_REJECT
|
||||
@@ -29,7 +29,8 @@ from patroni.postgresql.validator import _get_postgres_guc_validators, _load_pos
|
||||
ValidatorFactoryInvalidType, ValidatorFactoryNoType
|
||||
from patroni.utils import RetryFailedError
|
||||
|
||||
from . import BaseTestPostgresql, GET_PG_SETTINGS_RESULT, MockCursor, MockPostmaster, psycopg_connect
|
||||
from . import BaseTestPostgresql, GET_PG_SETTINGS_RESULT, \
|
||||
mock_available_gucs, MockCursor, MockPostmaster, psycopg_connect
|
||||
|
||||
mtime_ret = {}
|
||||
|
||||
@@ -100,6 +101,7 @@ Data page checksum version: 0
|
||||
@patch('subprocess.call', Mock(return_value=0))
|
||||
@patch('subprocess.check_output', Mock(return_value=b"postgres (PostgreSQL) 12.1"))
|
||||
@patch('patroni.psycopg.connect', psycopg_connect)
|
||||
@patch.object(Postgresql, 'available_gucs', mock_available_gucs)
|
||||
class TestPostgresql(BaseTestPostgresql):
|
||||
|
||||
@patch('subprocess.call', Mock(return_value=0))
|
||||
@@ -107,6 +109,7 @@ class TestPostgresql(BaseTestPostgresql):
|
||||
@patch('patroni.postgresql.CallbackExecutor', Mock())
|
||||
@patch.object(Postgresql, 'get_major_version', Mock(return_value=140000))
|
||||
@patch.object(Postgresql, 'is_running', Mock(return_value=True))
|
||||
@patch.object(Postgresql, 'available_gucs', mock_available_gucs)
|
||||
def setUp(self):
|
||||
super(TestPostgresql, self).setUp()
|
||||
self.p.config.write_postgresql_conf()
|
||||
@@ -912,11 +915,12 @@ class TestPostgresql(BaseTestPostgresql):
|
||||
not_none_values = (
|
||||
('foo.bar', 'foo', 160003), # name, value, version
|
||||
("allow_in_place_tablespaces", 'true', 130008),
|
||||
("restrict_nonsystem_relation_kind", 'view', 160005)
|
||||
("restrict_nonsystem_relation_kind", 'view', 160005),
|
||||
('fork_specific_param', 'no_validation_file', 170001),
|
||||
)
|
||||
for i in not_none_values:
|
||||
self.assertIsNotNone(
|
||||
transform_postgresql_parameter_value(i[2], i[0], i[1])
|
||||
transform_postgresql_parameter_value(i[2], i[0], i[1], mock_available_gucs.return_value)
|
||||
)
|
||||
|
||||
none_values = (
|
||||
@@ -926,7 +930,7 @@ class TestPostgresql(BaseTestPostgresql):
|
||||
)
|
||||
for i in none_values:
|
||||
self.assertIsNone(
|
||||
transform_postgresql_parameter_value(i[2], i[0], i[1])
|
||||
transform_postgresql_parameter_value(i[2], i[0], i[1], mock_available_gucs.return_value)
|
||||
)
|
||||
if i[3]:
|
||||
mock_warning.assert_called_once_with(
|
||||
@@ -1155,6 +1159,12 @@ class TestPostgresql2(BaseTestPostgresql):
|
||||
def setUp(self):
|
||||
super(TestPostgresql2, self).setUp()
|
||||
|
||||
@patch('subprocess.check_output', Mock(return_value='\n'.join(mock_available_gucs.return_value).encode('utf-8')))
|
||||
def test_available_gucs(self):
|
||||
gucs = self.p.available_gucs
|
||||
self.assertIsInstance(gucs, CaseInsensitiveSet)
|
||||
self.assertEqual(gucs, mock_available_gucs.return_value)
|
||||
|
||||
def test_cluster_info_query(self):
|
||||
self.assertIn('diff(pg_catalog.pg_current_wal_flush_lsn(', self.p.cluster_info_query)
|
||||
self.p._major_version = 90600
|
||||
|
||||
+3
-1
@@ -7,11 +7,12 @@ from patroni.collections import CaseInsensitiveSet
|
||||
from patroni.dcs import Cluster, ClusterConfig, Status, SyncState
|
||||
from patroni.postgresql import Postgresql
|
||||
|
||||
from . import BaseTestPostgresql, psycopg_connect
|
||||
from . import BaseTestPostgresql, mock_available_gucs, psycopg_connect
|
||||
|
||||
|
||||
@patch('subprocess.call', Mock(return_value=0))
|
||||
@patch('patroni.psycopg.connect', psycopg_connect)
|
||||
@patch.object(Postgresql, 'available_gucs', mock_available_gucs)
|
||||
class TestSync(BaseTestPostgresql):
|
||||
|
||||
@patch('subprocess.call', Mock(return_value=0))
|
||||
@@ -19,6 +20,7 @@ class TestSync(BaseTestPostgresql):
|
||||
@patch('patroni.postgresql.CallbackExecutor', Mock())
|
||||
@patch.object(Postgresql, 'get_major_version', Mock(return_value=140000))
|
||||
@patch.object(Postgresql, 'is_running', Mock(return_value=True))
|
||||
@patch.object(Postgresql, 'available_gucs', mock_available_gucs)
|
||||
def setUp(self):
|
||||
super(TestSync, self).setUp()
|
||||
self.p.config.write_postgresql_conf()
|
||||
|
||||
Reference in New Issue
Block a user