fixed formatting

This commit is contained in:
dvanaken 2019-11-08 06:42:32 -05:00 committed by Dana Van Aken
parent 9055516737
commit 2a3b075516
2 changed files with 24 additions and 23 deletions

View File

@ -27,7 +27,7 @@ from utils import (file_exists, get, load_driver_conf, parse_bool,
put, run, run_sql_script, sudo, FabricException) put, run, run_sql_script, sudo, FabricException)
# Loads the driver config file (defaults to driver_config.py) # Loads the driver config file (defaults to driver_config.py)
dconf = load_driver_conf() dconf = load_driver_conf() # pylint: disable=invalid-name
# Fabric settings # Fabric settings
fabric_output.update({ fabric_output.update({
@ -108,7 +108,8 @@ def restart_database():
# in the container is postgres itself # in the container is postgres itself
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(dconf.PG_DATADIR), user=dconf.DB_USER) sudo('pg_ctl -D {} -w -t 600 restart -m fast'.format(
dconf.PG_DATADIR), user=dconf.DB_USER)
elif dconf.DB_TYPE == 'oracle': elif dconf.DB_TYPE == 'oracle':
run_sql_script('restartOracle.sh') run_sql_script('restartOracle.sh')
else: else:
@ -138,7 +139,7 @@ def create_user():
if dconf.DB_TYPE == 'postgres': if dconf.DB_TYPE == 'postgres':
sql = "CREATE USER {} SUPERUSER PASSWORD '{}';".format(dconf.DB_USER, dconf.DB_PASSWORD) sql = "CREATE USER {} SUPERUSER PASSWORD '{}';".format(dconf.DB_USER, dconf.DB_PASSWORD)
run("PGPASSWORD={} psql -c \\\"{}\\\" -U postgres -h {}".format( run("PGPASSWORD={} psql -c \\\"{}\\\" -U postgres -h {}".format(
dconf.DB_PASSWORD, sql, dconf.DB_USER, dconf.DB_HOST)) dconf.DB_PASSWORD, sql, dconf.DB_HOST))
elif dconf.DB_TYPE == 'oracle': elif dconf.DB_TYPE == 'oracle':
run_sql_script('createUser.sh', dconf.DB_USER, dconf.DB_PASSWORD) run_sql_script('createUser.sh', dconf.DB_USER, dconf.DB_PASSWORD)
else: else:
@ -272,7 +273,7 @@ def save_next_config(next_config, t=None):
@task @task
def free_cache(): def free_cache():
if dconf.HOST_CONN != 'docker': # Read-only file system if dconf.HOST_CONN != 'docker': # pylint: disable=not-context-manager
with show('everything'), settings(warn_only=True): with show('everything'), settings(warn_only=True):
res = sudo("sync && echo 3 | tee /proc/sys/vm/drop_caches") res = sudo("sync && echo 3 | tee /proc/sys/vm/drop_caches")
if res.failed: if res.failed:
@ -417,20 +418,20 @@ def dump_database():
if file_exists(dumpfile): if file_exists(dumpfile):
LOG.info('%s already exists ! ', dumpfile) LOG.info('%s already exists ! ', dumpfile)
return False return False
LOG.info('Dump database %s to %s', dconf.DB_NAME, dumpfile)
if dconf.DB_TYPE == 'oracle':
run_sql_script('dumpOracle.sh', dconf.DB_USER, dconf.DB_PASSWORD,
dconf.DB_NAME, dconf.DB_DUMP_DIR)
elif dconf.DB_TYPE == 'postgres':
run('PGPASSWORD={} pg_dump -U {} -h {} -F c -d {} > {}'.format(
dconf.DB_PASSWORD, dconf.DB_USER, dconf.DB_HOST, dconf.DB_NAME,
dumpfile))
else: else:
LOG.info('Dump database %s to %s', dconf.DB_NAME, dumpfile) raise Exception("Database Type {} Not Implemented !".format(dconf.DB_TYPE))
return True
if dconf.DB_TYPE == 'oracle':
run_sql_script('dumpOracle.sh', dconf.DB_USER, dconf.DB_PASSWORD,
dconf.DB_NAME, dconf.DB_DUMP_DIR)
elif dconf.DB_TYPE == 'postgres':
run('PGPASSWORD={} pg_dump -U {} -h {} -F c -d {} > {}'.format(
dconf.DB_PASSWORD, dconf.DB_USER, dconf.DB_HOST, dconf.DB_NAME,
dumpfile))
else:
raise Exception("Database Type {} Not Implemented !".format(dconf.DB_TYPE))
return True
@task @task

View File

@ -4,14 +4,14 @@ import os
from fabric.api import hide, local, settings, task from fabric.api import hide, local, settings, task
from fabric.api import get as _get, put as _put, run as _run, sudo as _sudo from fabric.api import get as _get, put as _put, run as _run, sudo as _sudo
dconf = None dconf = None # pylint: disable=invalid-name
def load_driver_conf(): def load_driver_conf():
# The default config file is 'driver_config.py' but you can use # The default config file is 'driver_config.py' but you can use
# set the env 'DRIVER_CONFIG' to the path of a different config # set the env 'DRIVER_CONFIG' to the path of a different config
# file to override it. # file to override it.
global dconf global dconf # pylint: disable=global-statement,invalid-name
if not dconf: if not dconf:
driver_conf = os.environ.get('DRIVER_CONFIG', 'driver_config') driver_conf = os.environ.get('DRIVER_CONFIG', 'driver_config')
if driver_conf.endswith('.py'): if driver_conf.endswith('.py'):
@ -67,8 +67,8 @@ 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), opts, dconf.CONTAINER_NAME, cmdd),
capture=True, **kwargs) capture=True, **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:
@ -150,14 +150,14 @@ def run_sql_script(scriptfile, *args):
@task @task
def file_exists(filename): def file_exists(filename):
with settings(warn_only=True), hide('warnings'): with settings(warn_only=True), hide('warnings'): # pylint: disable=not-context-manager
res = run('[ -f {} ]'.format(filename)) res = run('[ -f {} ]'.format(filename))
return res.return_code == 0 return res.return_code == 0
@task @task
def dir_exists(dirname): def dir_exists(dirname):
with settings(warn_only=True), hide('warnings'): with settings(warn_only=True), hide('warnings'): # pylint: disable=not-context-manager
res = run('[ -d {} ]'.format(dirname)) res = run('[ -d {} ]'.format(dirname))
return res.return_code == 0 return res.return_code == 0