Addressed Dongsheng's review comments.

This commit is contained in:
dvanaken 2019-11-18 11:23:15 -05:00 committed by Dana Van Aken
parent 6a58c52762
commit a0c60afc3c
3 changed files with 16 additions and 9 deletions

View File

@ -34,6 +34,9 @@ DB_USER = 'dbuser'
# Password for DB_USER
DB_PASSWORD = 'dbpassword'
# Database admin username (for tasks like restarting the database)
ADMIN_USER = DB_USER
# Database host address
DB_HOST = 'localhost'

View File

@ -109,7 +109,7 @@ def restart_database():
local('docker restart {}'.format(dconf.CONTAINER_NAME))
else:
sudo('pg_ctl -D {} -w -t 600 restart -m fast'.format(
dconf.PG_DATADIR), user=dconf.DB_USER)
dconf.PG_DATADIR), user=dconf.ADMIN_USER, capture=False)
elif dconf.DB_TYPE == 'oracle':
run_sql_script('restartOracle.sh')
else:
@ -202,7 +202,7 @@ def change_conf(next_conf=None):
with open(tmp_conf_out, 'w') as f:
f.write(''.join(lines))
run('cp {0} {0}.ottertune.bak'.format(dconf.DB_CONF))
sudo('cp {0} {0}.ottertune.bak'.format(dconf.DB_CONF))
put(tmp_conf_out, dconf.DB_CONF, use_sudo=False)
local('rm -f {} {}'.format(tmp_conf_in, tmp_conf_out))
@ -275,7 +275,7 @@ def save_next_config(next_config, t=None):
def free_cache():
if dconf.HOST_CONN != 'docker':
with show('everything'), settings(warn_only=True): # pylint: disable=not-context-manager
res = sudo("sync && echo 3 | tee /proc/sys/vm/drop_caches")
res = sudo("sh -c \"echo 3 > /proc/sys/vm/drop_caches\"")
if res.failed:
LOG.error('%s (return code %s)', res.stderr.strip(), res.return_code)

View File

@ -54,12 +54,14 @@ def parse_bool(value):
@task
def run(cmd, **kwargs):
def run(cmd, capture=True, **kwargs):
capture = parse_bool(capture)
try:
if dconf.HOST_CONN == 'remote':
res = _run(cmd, **kwargs)
elif dconf.HOST_CONN == 'local':
res = local(cmd, capture=True, **kwargs)
res = local(cmd, capture=capture, **kwargs)
else: # docker
opts = ''
cmdd = cmd
@ -67,7 +69,7 @@ def run(cmd, **kwargs):
cmdd = cmd[:-1].strip()
opts = '-d '
res = local('docker exec {} -ti {} /bin/bash -c "{}"'.format(
opts, dconf.CONTAINER_NAME, cmdd), capture=True, **kwargs)
opts, dconf.CONTAINER_NAME, cmdd), capture=capture, **kwargs)
except TypeError as e:
err = str(e).strip()
if 'unexpected keyword argument' in err:
@ -80,7 +82,9 @@ def run(cmd, **kwargs):
@task
def sudo(cmd, user=None, **kwargs):
def sudo(cmd, user=None, capture=True, **kwargs):
capture = parse_bool(capture)
if dconf.HOST_CONN == 'remote':
res = _sudo(cmd, user=user, **kwargs)
@ -88,7 +92,7 @@ def sudo(cmd, user=None, **kwargs):
pre_cmd = 'sudo '
if user:
pre_cmd += '-u {} '.format(user)
res = local(pre_cmd + cmd, capture=True, **kwargs)
res = local(pre_cmd + cmd, capture=capture, **kwargs)
else: # docker
user = user or 'root'
@ -96,7 +100,7 @@ def sudo(cmd, user=None, **kwargs):
if user == 'root':
opts += ' -w /'
res = local('docker exec {} {} /bin/bash -c "{}"'.format(
opts, dconf.CONTAINER_NAME, cmd), capture=True)
opts, dconf.CONTAINER_NAME, cmd), capture=capture)
return res