mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-26 15:40:21 +00:00
Determine preferable local address to connect through.
If listen contains '*' or 0.0.0.0 - connect via localhost In all other cases pick the first one.
This commit is contained in:
@@ -57,8 +57,14 @@ class Postgresql:
|
||||
self.members = [] # list of already existing replication slots
|
||||
|
||||
def get_local_address(self):
|
||||
# TODO: try to get unix_socket_directory from postmaster.pid
|
||||
return self.listen_addresses.split(',')[0].strip() + ':' + self.port
|
||||
listen_addresses = self.listen_addresses.split(',')
|
||||
local_address = listen_addresses[0].strip() # take first address from listen_addresses
|
||||
|
||||
for la in listen_addresses:
|
||||
if la.strip() in ['*', '0.0.0.0']: # we are listening on *
|
||||
local_address = 'localhost' # connection via localhost is preferred
|
||||
break
|
||||
return local_address + ':' + self.port
|
||||
|
||||
def connection(self):
|
||||
if not self._connection or self._connection.closed != 0:
|
||||
|
||||
@@ -91,7 +91,7 @@ class TestPostgresql(unittest.TestCase):
|
||||
|
||||
def set_up(self):
|
||||
subprocess.call = subprocess_call
|
||||
self.p = Postgresql({'name': 'test0', 'data_dir': 'data/test0', 'listen': '127.0.0.1, 127.0.0.2:5432',
|
||||
self.p = Postgresql({'name': 'test0', 'data_dir': 'data/test0', 'listen': '127.0.0.1, *:5432',
|
||||
'connect_address': '127.0.0.2:5432',
|
||||
'pg_hba': [{'type': 'hostssl', 'database': 'all', 'user': 'all', 'address': '0.0.0.0/0',
|
||||
'method': 'md5'}, {'type': 'host', 'database': 'all', 'user': 'all',
|
||||
|
||||
Reference in New Issue
Block a user