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 # Password for DB_USER
DB_PASSWORD = 'dbpassword' DB_PASSWORD = 'dbpassword'
# Database admin username (for tasks like restarting the database)
ADMIN_USER = DB_USER
# Database host address # Database host address
DB_HOST = 'localhost' DB_HOST = 'localhost'

View File

@ -109,7 +109,7 @@ def restart_database():
local('docker restart {}'.format(dconf.CONTAINER_NAME)) local('docker restart {}'.format(dconf.CONTAINER_NAME))
else: else:
sudo('pg_ctl -D {} -w -t 600 restart -m fast'.format( 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': elif dconf.DB_TYPE == 'oracle':
run_sql_script('restartOracle.sh') run_sql_script('restartOracle.sh')
else: else:
@ -202,7 +202,7 @@ def change_conf(next_conf=None):
with open(tmp_conf_out, 'w') as f: with open(tmp_conf_out, 'w') as f:
f.write(''.join(lines)) 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) put(tmp_conf_out, dconf.DB_CONF, use_sudo=False)
local('rm -f {} {}'.format(tmp_conf_in, tmp_conf_out)) 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(): def free_cache():
if dconf.HOST_CONN != 'docker': if dconf.HOST_CONN != 'docker':
with show('everything'), settings(warn_only=True): # pylint: disable=not-context-manager 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: if res.failed:
LOG.error('%s (return code %s)', res.stderr.strip(), res.return_code) LOG.error('%s (return code %s)', res.stderr.strip(), res.return_code)

View File

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