Skip to content

Commit

Permalink
Improved exception handling in /swarm/test_db.py (#3738)
Browse files Browse the repository at this point in the history
* fix asterisk password bug in test_db.py

* raise and handle pymysql error

* clean up exception handling in db test
  • Loading branch information
pianomanfrazier authored and rhyolight committed Jul 6, 2017
1 parent b1ec8e3 commit d5389fd
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions examples/swarm/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ def testDbConnection(host, port, user, passwd):
cursor.execute("INSERT INTO db_test VALUES ('testing123', 123)")
cursor.execute("DROP TABLE IF EXISTS db_test")
cursor.execute("DROP DATABASE IF EXISTS nupic_db_test")
return True

except pymysql.err.OperationalError:
return False
print ("Couldn't connect to the database or you don't have the "
"permissions required to create databases and tables. "
"Please ensure you have MySQL\n installed, running, "
"accessible using the NuPIC configuration settings, "
"and the user specified has permission to create both "
"databases and tables.")
raise


def dbValidator():
Expand All @@ -83,7 +88,7 @@ def dbValidator():
host = Configuration.get("nupic.cluster.database.host")
port = int(Configuration.get("nupic.cluster.database.port"))
user = Configuration.get("nupic.cluster.database.user")
passwd = "*" * len(Configuration.get("nupic.cluster.database.passwd"))
passwd = Configuration.get("nupic.cluster.database.passwd")


print "This script will validate that your MySQL is setup correctly for "
Expand All @@ -103,18 +108,11 @@ def dbValidator():
print " host : ", host
print " port : ", port
print " user : ", user
print " passwd : ", passwd
print " passwd : ", "*" * len(passwd)


if testDbConnection(host, port, user, passwd):
print "Connection successful!!"
else:
print ("Couldn't connect to the database or you don't have the "
"permissions required to create databases and tables. "
"Please ensure you have MySQL\n installed, running, "
"accessible using the NuPIC configuration settings, "
"and the user specified has permission to create both "
"databases and tables.")
testDbConnection(host, port, user, passwd)
print "Connection successful!!"

if __name__ == "__main__":
dbValidator()

0 comments on commit d5389fd

Please sign in to comment.