Author: tmckay
Date: 2013-03-15 20:48:54 +0000 (Fri, 15 Mar 2013)
New Revision: 5742
Modified:
trunk/cumin/bin/cumin-admin
Log:
Pass db connection along with cursor to handler routines so
that it can be closed if necessary. Close in handle_upgrade_schema.
Modified: trunk/cumin/bin/cumin-admin
===================================================================
--- trunk/cumin/bin/cumin-admin 2013-03-15 18:33:56 UTC (rev 5741)
+++ trunk/cumin/bin/cumin-admin 2013-03-15 20:48:54 UTC (rev 5742)
@@ -152,7 +152,7 @@
error("Only schema commands are allowed until the schema is
repaired")
try:
- res = handler(app, cursor, opts, args[1:])
+ res = handler(app, conn, cursor, opts, args[1:])
if type(res) is tuple:
conn, cursor = res
conn.commit()
@@ -266,14 +266,16 @@
# Look for the next jump
curr = latest
-def handle_print_schema(app, cursor, opts, args):
+def handle_print_schema(app, conn, cursor, opts, args):
print app.admin.get_schema(),
-def handle_upgrade_schema(app, cursor, opts, args):
+def handle_upgrade_schema(app, conn, cursor, opts, args):
try:
curr = app.admin.get_schema_version(cursor)
except SchemaMissing:
error("The schema is missing, run 'cumin-admin
create-schema'")
+ conn.close()
+ cursor.close()
target = app.admin.get_target_schema_version()
if curr == target:
@@ -304,7 +306,7 @@
for steps in upgrade_path:
script = os.path.join(upgrade_dir, steps[0]+"_to_"+steps[1])
print "Executing script %s" % script
-
+
res = subprocess.Popen(script, shell=True).wait()
if res != 0:
print "Script exited with error code %s" % res
@@ -336,7 +338,7 @@
print "Upgrade to schema version %s succeeded" % target
return conn, cursor
-def handle_create_schema(app, cursor, opts, args):
+def handle_create_schema(app, conn, cursor, opts, args):
try:
conn, cursor = app.admin.create_schema(cursor)
except ProgrammingError:
@@ -349,7 +351,7 @@
if conn and cursor:
return conn, cursor
-def handle_check_schema(app, cursor, opts, args):
+def handle_check_schema(app, conn, cursor, opts, args):
try:
schema_version = app.admin.check_schema(cursor)
except SchemaMissing:
@@ -359,7 +361,7 @@
print "The schema is OK (schema version %s)" % schema_version
-def handle_drop_schema(app, cursor, opts, args):
+def handle_drop_schema(app, conn, cursor, opts, args):
try:
app.admin.drop_schema(cursor)
print "The schema is dropped"
@@ -392,7 +394,7 @@
return users, roles_by_user_id
-def handle_list_users(app, cursor, opts, args):
+def handle_list_users(app, conn, cursor, opts, args):
print " ID Name Roles"
print "---- -------------------- --------------------"
@@ -418,7 +420,7 @@
if externals > 0:
print "(%i external user%s, indicated by *)" % (externals,
ess(externals))
-def handle_external_user(app, cursor, opts, args):
+def handle_external_user(app, conn, cursor, opts, args):
try:
name = args[0]
except IndexError:
@@ -432,7 +434,7 @@
app.admin.add_assignment(cursor, user, role)
print "External user '%s' is added" % name
-def handle_external_sync(app, cursor, opts, args):
+def handle_external_sync(app, conn, cursor, opts, args):
print "This command is not supported at this time."
return
@@ -452,7 +454,7 @@
if errors:
print("Errors reported, check logs for details.")
-def handle_expunge_users(app, cursor, opts, args):
+def handle_expunge_users(app, conn, cursor, opts, args):
print("This will remove all users from Cumin's database.")
print("Hint: you may want to backup Cumin's user database "\
@@ -470,7 +472,7 @@
print("\nNo users removed.")
-def handle_add_role(app, cursor, opts, args):
+def handle_add_role(app, conn, cursor, opts, args):
print("\nNot implemented.")
return
@@ -490,7 +492,7 @@
print "Role '%s' is added" % name
-def handle_add_user(app, cursor, opts, args):
+def handle_add_user(app, conn, cursor, opts, args):
try:
name = args[0]
except IndexError:
@@ -515,7 +517,7 @@
app.admin.add_assignment(cursor, user, role)
print "User '%s' is added" % name
-def handle_export_users(app, cursor, opts, args):
+def handle_export_users(app, conn, cursor, opts, args):
try:
fname = args[0]
@@ -533,7 +535,7 @@
for user in users:
w.writerow([user.name, user.password] + roles_by_user_id[user._id])
-def handle_import_users(app, cursor, opts, args):
+def handle_import_users(app, conn, cursor, opts, args):
try:
fname = args[0]
@@ -593,7 +595,7 @@
warn("Role '%s' does not exist, "\
"skipping this role for user '%s'" % (role_name,
info[0]))
-def handle_remove_user(app, cursor, opts, args):
+def handle_remove_user(app, conn, cursor, opts, args):
try:
name = args[0]
except IndexError:
@@ -606,7 +608,7 @@
user.delete(cursor)
print "User '%s' is removed" % name
-def handle_list_roles(app, cursor, opts, args):
+def handle_list_roles(app, conn, cursor, opts, args):
cls = app.model.com_redhat_cumin.Role
roles = cls.get_selection(cursor)
@@ -621,14 +623,14 @@
print
print "(%i user%s found)" % (count, ess(count))
-def handle_add_assignment(app, cursor, opts, args):
+def handle_add_assignment(app, conn, cursor, opts, args):
user, role = get_user_and_role(app, cursor, args)
app.admin.add_assignment(cursor, user, role)
print "User '%s' is assigned to role '%s'" % (user.name,
role.name)
-def handle_remove_assignment(app, cursor, opts, args):
+def handle_remove_assignment(app, conn, cursor, opts, args):
user, role = get_user_and_role(app, cursor, args)
assignment = app.admin.get_assignment(cursor, user, role)
@@ -661,7 +663,7 @@
return user, role
-def handle_change_password(app, cursor, opts, args):
+def handle_change_password(app, conn, cursor, opts, args):
try:
user_name = args[0]
except IndexError:
@@ -678,7 +680,7 @@
user.save(cursor)
print "Password of user '%s' is changed" % user.name
-def handle_load_demo_data(app, cursor, opts, args):
+def handle_load_demo_data(app, conn, cursor, opts, args):
cls = app.model.com_redhat_cumin.BrokerGroup
for name in ("Engineering", "Marketing", "Sales"):