Add support of sslnegotiation client-side connection option (#3173)

It is available in PostgreSQL 17

Besides that, enable PG17 in behave tests and include PG17 to supported versions in docs.
This commit is contained in:
Alexander Kukushkin
2024-09-27 11:27:09 +02:00
committed by GitHub
parent 6b685036d0
commit e91e6b5484
9 changed files with 29 additions and 18 deletions
+9 -6
View File
@@ -29,7 +29,7 @@ def mock_open(*args, **kwargs):
@patch('patroni.psycopg.connect', psycopg_connect)
@patch('builtins.open', MagicMock())
@patch('subprocess.check_output', Mock(return_value=b"postgres (PostgreSQL) 16.2"))
@patch('subprocess.check_output', Mock(return_value=b"postgres (PostgreSQL) 17.0"))
@patch('psutil.Process.exe', Mock(return_value='/bin/dir/from/running/postgres'))
@patch('psutil.Process.__init__', Mock(return_value=None))
@patch('patroni.config_generator.get_address', Mock(return_value=(HOSTNAME, IP)))
@@ -128,7 +128,8 @@ class TestGenerateConfig(unittest.TestCase):
'password': 'qwerty',
'channel_binding': 'prefer',
'gssencmode': 'prefer',
'sslmode': 'prefer'
'sslmode': 'prefer',
'sslnegotiation': 'postgres'
},
'replication': {
'username': NO_VALUE_MSG,
@@ -177,7 +178,7 @@ class TestGenerateConfig(unittest.TestCase):
'--version'])
@patch('os.makedirs', Mock())
def test_generate_sample_config_16(self):
def test_generate_sample_config_17(self):
conf = {
'bootstrap': {
'dcs': {
@@ -213,7 +214,7 @@ class TestGenerateConfig(unittest.TestCase):
@patch('os.makedirs', Mock())
@patch('sys.stdout')
def test_generate_config_running_instance_16(self, mock_sys_stdout):
def test_generate_config_running_instance_17(self, mock_sys_stdout):
self._set_running_instance_config_vals()
with patch('builtins.open', Mock(side_effect=self._get_running_instance_open_res())), \
@@ -226,11 +227,13 @@ class TestGenerateConfig(unittest.TestCase):
@patch('os.makedirs', Mock())
@patch('sys.stdout')
def test_generate_config_running_instance_16_connect_from_env(self, mock_sys_stdout):
def test_generate_config_running_instance_17_connect_from_env(self, mock_sys_stdout):
self._set_running_instance_config_vals()
# su auth params and connect host from env
os.environ['PGCHANNELBINDING'] = \
self.config['postgresql']['authentication']['superuser']['channel_binding'] = 'disable'
os.environ['PGSSLNEGOTIATION'] = \
self.config['postgresql']['authentication']['superuser']['sslnegotiation'] = 'direct'
conf = {
'scope': 'my_cluster',
@@ -265,7 +268,7 @@ class TestGenerateConfig(unittest.TestCase):
with patch('builtins.open', Mock(side_effect=self._get_running_instance_open_res())), \
patch('sys.argv', ['patroni.py', '--generate-config']), \
patch.object(MockConnect, 'server_version', PropertyMock(return_value=160000)), \
patch.object(MockConnect, 'server_version', PropertyMock(return_value=170000)), \
self.assertRaises(SystemExit) as e:
_main()
self.assertEqual(e.exception.code, 0)
+3 -2
View File
@@ -364,6 +364,7 @@ class TestPostgresql(BaseTestPostgresql):
@patch.object(Postgresql, 'is_running', Mock(return_value=False))
@patch.object(Postgresql, 'start', Mock())
@patch.object(Postgresql, 'major_version', PropertyMock(return_value=170000))
def test_follow(self):
self.p.call_nowait(CallbackAction.ON_START)
m = RemoteMember('1', {'restore_command': '2', 'primary_slot_name': 'foo', 'conn_kwargs': {'host': 'foo,bar'}})
@@ -1169,5 +1170,5 @@ class TestPostgresql2(BaseTestPostgresql):
self.p.config.load_current_server_parameters()
self.assertTrue(all(self.p.config._server_parameters[name] == value for name, value in keep_values.items()))
self.assertEqual(dict(self.p.config._recovery_params),
{'primary_conninfo': {'host': 'a', 'port': '5433', 'passfile': '/blabla',
'gssencmode': 'prefer', 'sslmode': 'prefer', 'channel_binding': 'prefer'}})
{'primary_conninfo': {'host': 'a', 'port': '5433', 'passfile': '/blabla', 'sslmode': 'prefer',
'gssencmode': 'prefer', 'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}})