Skip to content

Commit 7dd98fe

Browse files
author
Stepan Neretin
committed
rethink idea of change data dir to just start node with custom data dir
1 parent fa12048 commit 7dd98fe

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

testgres/node.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,7 @@ def logs_dir(self):
315315

316316
@property
317317
def data_dir(self):
318-
# NOTE: we can't run initdb without user's args
319-
if hasattr(self, '_data_dir'):
320-
return self._data_dir
321-
else:
322-
return os.path.join(self.base_dir, DATA_DIR)
323-
324-
@data_dir.setter
325-
def data_dir(self, value):
326-
self._data_dir = value
318+
return os.path.join(self.base_dir, DATA_DIR)
327319

328320
@property
329321
def utils_log_file(self):
@@ -726,7 +718,7 @@ def get_control_data(self):
726718

727719
return out_dict
728720

729-
def slow_start(self, replica=False, dbname='template1', username=None, max_attempts=0):
721+
def slow_start(self, replica=False, dbname='template1', username=None, max_attempts=0, custom_data_dir=None):
730722
"""
731723
Starts the PostgreSQL instance and then polls the instance
732724
until it reaches the expected state (primary or replica). The state is checked
@@ -739,7 +731,7 @@ def slow_start(self, replica=False, dbname='template1', username=None, max_attem
739731
If False, waits for the instance to be in primary mode. Default is False.
740732
max_attempts:
741733
"""
742-
self.start()
734+
self.start(custom_data_dir=custom_data_dir)
743735

744736
if replica:
745737
query = 'SELECT pg_is_in_recovery()'
@@ -771,7 +763,7 @@ def _detect_port_conflict(self, log_files0, log_files1):
771763
return True
772764
return False
773765

774-
def start(self, params=[], wait=True):
766+
def start(self, params=[], wait=True, custom_data_dir=None):
775767
"""
776768
Starts the PostgreSQL node using pg_ctl if node has not been started.
777769
By default, it waits for the operation to complete before returning.
@@ -792,7 +784,7 @@ def start(self, params=[], wait=True):
792784
return self
793785

794786
_params = [self._get_bin_path("pg_ctl"),
795-
"-D", self.data_dir,
787+
"-D", custom_data_dir if custom_data_dir else self.data_dir,
796788
"-l", self.pg_log_file,
797789
"-w" if wait else '-W', # --wait or --no-wait
798790
"start"] + params # yapf: disable
@@ -868,7 +860,7 @@ def LOCAL__raise_cannot_start_node__std(from_exception):
868860
self.is_started = True
869861
return self
870862

871-
def stop(self, params=[], wait=True):
863+
def stop(self, params=[], wait=True, custom_data_dir=None):
872864
"""
873865
Stops the PostgreSQL node using pg_ctl if the node has been started.
874866
@@ -884,7 +876,7 @@ def stop(self, params=[], wait=True):
884876

885877
_params = [
886878
self._get_bin_path("pg_ctl"),
887-
"-D", self.data_dir,
879+
"-D", custom_data_dir if custom_data_dir else self.data_dir,
888880
"-w" if wait else '-W', # --wait or --no-wait
889881
"stop"
890882
] + params # yapf: disable

0 commit comments

Comments
 (0)