|
8 | 8 | import time
|
9 | 9 |
|
10 | 10 | from enum import Enum
|
| 11 | +from six import raise_from |
11 | 12 |
|
12 | 13 | from .cache import cached_initdb as _cached_initdb
|
13 | 14 |
|
|
40 | 41 | reserve_port as _reserve_port, \
|
41 | 42 | release_port as _release_port, \
|
42 | 43 | default_username as _default_username, \
|
43 |
| - execute_utility as _execute_utility, \ |
44 |
| - explain_exception as _explain_exception |
| 44 | + execute_utility as _execute_utility |
45 | 45 |
|
46 | 46 |
|
47 | 47 | class NodeStatus(Enum):
|
@@ -110,7 +110,7 @@ def utils_log_name(self):
|
110 | 110 |
|
111 | 111 | @property
|
112 | 112 | def pg_log_name(self):
|
113 |
| - return os.path.join(self.data_dir, _PG_LOG_FILE) |
| 113 | + return os.path.join(self.logs_dir, _PG_LOG_FILE) |
114 | 114 |
|
115 | 115 | def _create_recovery_conf(self, username, master):
|
116 | 116 | # yapf: disable
|
@@ -148,37 +148,25 @@ def _maybe_stop_logger(self):
|
148 | 148 | self._logger.stop()
|
149 | 149 |
|
150 | 150 | def _format_verbose_error(self):
|
151 |
| - # choose log_filename |
152 |
| - log_filename = self.pg_log_name |
153 |
| - |
154 |
| - # choose conf_filename |
155 |
| - conf_filename = os.path.join(self.data_dir, "postgresql.conf") |
156 |
| - |
157 |
| - # choose hba_filename |
158 |
| - hba_filename = os.path.join(self.data_dir, "pg_hba.conf") |
| 151 | + # list of important files |
| 152 | + files = [ |
| 153 | + os.path.join(self.data_dir, "postgresql.conf"), |
| 154 | + os.path.join(self.data_dir, "recovery.conf"), |
| 155 | + os.path.join(self.data_dir, "pg_hba.conf"), |
| 156 | + self.pg_log_name # main log file |
| 157 | + ] |
159 | 158 |
|
160 |
| - # choose recovery_filename |
161 |
| - recovery_filename = os.path.join(self.data_dir, "recovery.conf") |
| 159 | + error_text = "" |
162 | 160 |
|
163 |
| - def print_node_file(node_file): |
164 |
| - if os.path.exists(node_file): |
165 |
| - try: |
166 |
| - with io.open(node_file, "r") as f: |
167 |
| - return f.read().decode('utf-8') |
168 |
| - except Exception: |
169 |
| - pass |
170 |
| - return "### file not found ###\n" |
| 161 | + for f in files: |
| 162 | + # skip missing files |
| 163 | + if not os.path.exists(f): |
| 164 | + continue |
171 | 165 |
|
172 |
| - # yapf: disable |
173 |
| - error_text = ( |
174 |
| - u"{}:\n----\n{}\n" # log file, e.g. postgresql.log |
175 |
| - u"{}:\n----\n{}\n" # postgresql.conf |
176 |
| - u"{}:\n----\n{}\n" # pg_hba.conf |
177 |
| - u"{}:\n----\n{}\n" # recovery.conf |
178 |
| - ).format(log_filename, print_node_file(log_filename), |
179 |
| - conf_filename, print_node_file(conf_filename), |
180 |
| - hba_filename, print_node_file(hba_filename), |
181 |
| - recovery_filename, print_node_file(recovery_filename)) |
| 166 | + # append contents |
| 167 | + with io.open(f, "r") as _f: |
| 168 | + lines = _f.read() |
| 169 | + error_text += u"{}:\n----\n{}\n".format(f, lines) |
182 | 170 |
|
183 | 171 | return error_text
|
184 | 172 |
|
@@ -410,12 +398,12 @@ def start(self, params=[]):
|
410 | 398 |
|
411 | 399 | try:
|
412 | 400 | _execute_utility(_params, self.utils_log_name)
|
413 |
| - except ExecUtilException: |
| 401 | + except ExecUtilException as e: |
414 | 402 | msg = (
|
415 | 403 | u"Cannot start node\n"
|
416 | 404 | u"{}\n" # pg_ctl log
|
417 | 405 | ).format(self._format_verbose_error())
|
418 |
| - raise StartNodeException(msg) |
| 406 | + raise_from(StartNodeException(msg), e) |
419 | 407 |
|
420 | 408 | self._maybe_start_logger()
|
421 | 409 |
|
@@ -468,12 +456,12 @@ def restart(self, params=[]):
|
468 | 456 |
|
469 | 457 | try:
|
470 | 458 | _execute_utility(_params, self.utils_log_name)
|
471 |
| - except ExecUtilException: |
| 459 | + except ExecUtilException as e: |
472 | 460 | msg = (
|
473 | 461 | u"Cannot restart node\n"
|
474 | 462 | u"{}\n" # pg_ctl log
|
475 | 463 | ).format(self._format_verbose_error())
|
476 |
| - raise StartNodeException(msg) |
| 464 | + raise_from(StartNodeException(msg), e) |
477 | 465 |
|
478 | 466 | self._maybe_start_logger()
|
479 | 467 |
|
@@ -837,7 +825,7 @@ def catchup(self, dbname='postgres', username=None):
|
837 | 825 | query=wait_lsn.format(lsn),
|
838 | 826 | max_attempts=0) # infinite
|
839 | 827 | except Exception as e:
|
840 |
| - raise CatchUpException(_explain_exception(e)) |
| 828 | + raise_from(CatchUpException('Failed to catch up'), e) |
841 | 829 |
|
842 | 830 | def pgbench(self, dbname='postgres', stdout=None, stderr=None, options=[]):
|
843 | 831 | """
|
|
0 commit comments