Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved exception handling in /swarm/test_db.py #3738

Merged
merged 3 commits into from
Jul 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()