Remove spurious sys.exits

This removes sys.exits which are never called and moves one try-except
block to the lines in which the exception is actually raised.

Change-Id: Idb5bde84136208dc39d877b4b66b39a433d85375
This commit is contained in:
Grzegorz Grasza (xek) 2017-09-01 10:38:17 +00:00
parent 53c5679b17
commit 80c6e725bc

View File

@ -53,7 +53,6 @@ else:
# Get the connection string for the service db # Get the connection string for the service db
if "OPENSTACK_CONFIG_FILE" in os.environ: if "OPENSTACK_CONFIG_FILE" in os.environ:
try:
os_conf = os.environ['OPENSTACK_CONFIG_FILE'] os_conf = os.environ['OPENSTACK_CONFIG_FILE']
if "OPENSTACK_CONFIG_DB_SECTION" in os.environ: if "OPENSTACK_CONFIG_DB_SECTION" in os.environ:
os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION'] os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION']
@ -65,6 +64,7 @@ if "OPENSTACK_CONFIG_FILE" in os.environ:
else: else:
logger.critical('environment variable OPENSTACK_CONFIG_DB_KEY not set') logger.critical('environment variable OPENSTACK_CONFIG_DB_KEY not set')
sys.exit(1) sys.exit(1)
try:
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
logger.info("Using {0} as db config source".format(os_conf)) logger.info("Using {0} as db config source".format(os_conf))
config.read(os_conf) config.read(os_conf)
@ -74,7 +74,7 @@ if "OPENSTACK_CONFIG_FILE" in os.environ:
logger.info("Got config from {0}".format(os_conf)) logger.info("Got config from {0}".format(os_conf))
except: except:
logger.critical("Tried to load config from {0} but failed.".format(os_conf)) logger.critical("Tried to load config from {0} but failed.".format(os_conf))
sys.exit(1) raise
elif "DB_CONNECTION" in os.environ: elif "DB_CONNECTION" in os.environ:
user_db_conn = os.environ['DB_CONNECTION'] user_db_conn = os.environ['DB_CONNECTION']
logger.info('Got config from DB_CONNECTION env var') logger.info('Got config from DB_CONNECTION env var')
@ -99,7 +99,6 @@ try:
except: except:
logger.critical('Could not connect to database as root user') logger.critical('Could not connect to database as root user')
raise raise
sys.exit(1)
# User DB engine # User DB engine
try: try:
@ -112,7 +111,6 @@ try:
except: except:
logger.critical('Could not get user database config') logger.critical('Could not get user database config')
raise raise
sys.exit(1)
# Create DB # Create DB
try: try:
@ -121,7 +119,6 @@ try:
except: except:
logger.critical("Could not create database {0}".format(database)) logger.critical("Could not create database {0}".format(database))
raise raise
sys.exit(1)
# Create DB User # Create DB User
try: try:
@ -132,7 +129,6 @@ try:
except: except:
logger.critical("Could not create user {0} for {1}".format(user, database)) logger.critical("Could not create user {0} for {1}".format(user, database))
raise raise
sys.exit(1)
# Test connection # Test connection
try: try:
@ -143,7 +139,6 @@ try:
except: except:
logger.critical('Could not connect to database as user') logger.critical('Could not connect to database as user')
raise raise
sys.exit(1)
logger.info('Finished DB Management') logger.info('Finished DB Management')
{{- end }} {{- end }}