- Notifications
You must be signed in to change notification settings - Fork35
Skip ssl check#149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Uh oh!
There was an error while loading.Please reload this page.
Closed
Skip ssl check#149
Changes from1 commit
Commits
Show all changes
15 commits Select commitHold shift + click to select a range
1b10a54
Add ability to skip ssl when connect to PostgresNode
104a127
Don't reserve a new port if port was set up
19ef23f
Fix flake8 style
43c91c0
Fix test_the_same_port
1e8d912
Fix failed test_ports_management
f1d28b4
Add env variable TESTGRES_SKIP_SSL
e729c2f
Fix sys.modules instead globals
dc4b4c3
Move _get_ssl_options in separate function
547081e
Merge branch 'master' into skip-ssl-check
dmitry-lipetskfb6205d
Merge branch 'master' into skip-ssl-check
dmitry-lipetsk67f23a7
Merge branch 'master' into skip-ssl-check
dmitry-lipetskb67ae42
Merge branch 'master' into skip-ssl-check
dmitry-lipetskbe972e0
Merge branch 'master' into skip-ssl-check
dmitry-lipetsk0781132
Merge branch 'master' into skip-ssl-check
dmitry-lipetskfa6d751
[BUG FIX] TestgresRemoteTests.test_safe_psql__expect_error is corrected
dmitry-lipetskFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Don't reserve a new port if port was set up
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
88 changes: 56 additions & 32 deletionstestgres/node.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -96,7 +96,6 @@ | ||
from .operations.os_ops import ConnectionParams | ||
from .operations.local_ops import LocalOperations | ||
InternalError = pglib.InternalError | ||
ProgrammingError = pglib.ProgrammingError | ||
@@ -487,7 +486,7 @@ def init(self, initdb_params=None, cached=True, **kwargs): | ||
os_ops=self.os_ops, | ||
params=initdb_params, | ||
bin_path=self.bin_dir, | ||
cached=cached) | ||
# initialize default config files | ||
self.default_conf(**kwargs) | ||
@@ -717,9 +716,9 @@ def slow_start(self, replica=False, dbname='template1', username=None, max_attem | ||
OperationalError}, | ||
max_attempts=max_attempts) | ||
def start(self, params=None, wait: bool =True) -> 'PostgresNode': | ||
""" | ||
Starts the PostgreSQL node using pg_ctl ifthenode has not been started. | ||
By default, it waits for the operation to complete before returning. | ||
Optionally, it can return immediately without waiting for the start operation | ||
to complete by setting the `wait` parameter to False. | ||
@@ -731,45 +730,62 @@ def start(self, params=[], wait=True): | ||
Returns: | ||
This instance of :class:`.PostgresNode`. | ||
""" | ||
if params is None: | ||
params = [] | ||
if self.is_started: | ||
return self | ||
_params = [ | ||
self._get_bin_path("pg_ctl"), | ||
"-D", self.data_dir, | ||
"-l", self.pg_log_file, | ||
"-w" if wait else '-W', # --wait or --no-wait | ||
"start" | ||
] + params # yapf: disable | ||
max_retries = 5 | ||
sleep_interval = 5 # seconds | ||
for attempt in range(max_retries): | ||
try: | ||
exit_status, out, error = execute_utility(_params, self.utils_log_file, verbose=True) | ||
if error and 'does not exist' in error: | ||
raise Exception | ||
break # Exit the loop if successful | ||
except Exception as e: | ||
if self._handle_port_conflict(): | ||
if attempt < max_retries - 1: | ||
logging.info(f"Retrying start operation (Attempt {attempt + 2}/{max_retries})...") | ||
time.sleep(sleep_interval) | ||
continue | ||
else: | ||
logging.error("Reached maximum retry attempts. Unable to start node.") | ||
raise StartNodeException("Cannot start node after multiple attempts", | ||
self._collect_special_files()) from e | ||
raise StartNodeException("Cannot start node", self._collect_special_files()) from e | ||
self._maybe_start_logger() | ||
self.is_started = True | ||
return self | ||
def _handle_port_conflict(self) -> bool: | ||
""" | ||
Checks for a port conflict and attempts to resolve it by changing the port. | ||
Returns True if the port was changed, False otherwise. | ||
""" | ||
files = self._collect_special_files() | ||
if any(len(file) > 1 and 'Is another postmaster already running on port' in file[1].decode() for file in files): | ||
dmitry-lipetsk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
logging.warning(f"Port conflict detected on port {self.port}.") | ||
if self._should_free_port: | ||
logging.warning("Port reservation skipped due to _should_free_port setting.") | ||
return False | ||
self.port = reserve_port() | ||
dmitry-lipetsk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
self.set_auto_conf({'port': str(self.port)}) | ||
logging.info(f"Port changed to {self.port}.") | ||
return True | ||
return False | ||
def stop(self, params=None, wait=True): | ||
""" | ||
Stops the PostgreSQL node using pg_ctl if the node has been started. | ||
@@ -780,6 +796,8 @@ def stop(self, params=[], wait=True): | ||
Returns: | ||
This instance of :class:`.PostgresNode`. | ||
""" | ||
if params is None: | ||
params = [] | ||
if not self.is_started: | ||
return self | ||
@@ -812,7 +830,7 @@ def kill(self, someone=None): | ||
os.kill(self.auxiliary_pids[someone][0], sig) | ||
self.is_started = False | ||
def restart(self, params=None): | ||
""" | ||
Restart this node using pg_ctl. | ||
@@ -823,6 +841,8 @@ def restart(self, params=[]): | ||
This instance of :class:`.PostgresNode`. | ||
""" | ||
if params is None: | ||
params = [] | ||
_params = [ | ||
self._get_bin_path("pg_ctl"), | ||
"-D", self.data_dir, | ||
@@ -844,7 +864,7 @@ def restart(self, params=[]): | ||
return self | ||
def reload(self, params=None): | ||
""" | ||
Asynchronously reload config files using pg_ctl. | ||
@@ -855,6 +875,8 @@ def reload(self, params=[]): | ||
This instance of :class:`.PostgresNode`. | ||
""" | ||
if params is None: | ||
params = [] | ||
_params = [ | ||
self._get_bin_path("pg_ctl"), | ||
"-D", self.data_dir, | ||
@@ -1587,7 +1609,7 @@ def pgbench_table_checksums(self, dbname="postgres", | ||
return {(table, self.table_checksum(table, dbname)) | ||
for table in pgbench_tables} | ||
def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options=None): | ||
""" | ||
Update or remove configuration options in the specified configuration file, | ||
updates the options specified in the options dictionary, removes any options | ||
@@ -1603,6 +1625,8 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}): | ||
Defaults to an empty set. | ||
""" | ||
# parse postgresql.auto.conf | ||
if rm_options is None: | ||
rm_options = {} | ||
path = os.path.join(self.data_dir, config) | ||
lines = self.os_ops.readlines(path) | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.