Skip to content

Small fixes #16

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions testgres/testgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def append_conf(self, filename, string):

return self

def pg_ctl(self, command, params):
def pg_ctl(self, command, params, command_options=[]):
"""Runs pg_ctl with specified params

This function is a workhorse for start(), stop() and reload()
Expand All @@ -294,7 +294,7 @@ def pg_ctl(self, command, params):
open(self.error_filename, "a") as file_err:

res = subprocess.call(
arguments + [command],
arguments + [command] + command_options,
stdout=file_out,
stderr=file_err
)
Expand All @@ -303,46 +303,50 @@ def pg_ctl(self, command, params):
with open(self.error_filename, "r") as errfile:
raise ClusterException(errfile.readlines()[-1])

def start(self):
def start(self, params={}):
""" Starts cluster """
logfile = os.path.join(self.logs_dir, "postgresql.log")
params = {
_params = {
"-D": self.data_dir,
"-w": None,
"-l": logfile,
}
self.pg_ctl("start", params)
_params.update(params)
self.pg_ctl("start", _params)

self.working = True

return self

def stop(self):
def stop(self, params={}):
""" Stops cluster """
params = {
_params = {
"-D": self.data_dir,
"-w": None
}
self.pg_ctl("stop", params)
_params.update(params)
self.pg_ctl("stop", _params)

self.working = False

return self

def restart(self):
def restart(self, params={}):
""" Restarts cluster """
params = {
_params = {
"-D": self.data_dir,
"-w": None
}
self.pg_ctl("restart", params)
_params.update(params)
self.pg_ctl("restart", _params)

return self

def reload(self):
def reload(self, params={}):
"""Reloads config files"""
params = {"-D": self.data_dir}
self.pg_ctl("reload", params)
_params = {"-D": self.data_dir}
_params.update(params)
self.pg_ctl("reload", _params)

return self

Expand All @@ -351,7 +355,10 @@ def cleanup(self):

# stop server if it still working
if self.working:
self.stop()
try:
self.stop()
except:
pass

# remove data directory
shutil.rmtree(self.data_dir)
Expand Down Expand Up @@ -448,10 +455,13 @@ def poll_query_until(self, dbname, query):
attemps += 1
raise QueryException("Timeout while waiting for query to return True")

def execute(self, dbname, query, username=None):
def execute(self, dbname, query, username=None, commit=False):
"""Executes the query and returns all rows"""
with self.connect(dbname, username) as node_con:
return node_con.execute(query)
res = node_con.execute(query)
if commit:
node_con.commit()
return res

def backup(self, name):
"""Performs pg_basebackup"""
Expand Down