r5489 - trunk/cumin/python/cumin/grid
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-28 20:15:57 +0000 (Fri, 28 Sep 2012)
New Revision: 5489
Modified:
trunk/cumin/python/cumin/grid/job.py
Log:
Oops, this should be looking for status in a tuple
Modified: trunk/cumin/python/cumin/grid/job.py
===================================================================
--- trunk/cumin/python/cumin/grid/job.py 2012-09-28 19:36:38 UTC (rev 5488)
+++ trunk/cumin/python/cumin/grid/job.py 2012-09-28 20:15:57 UTC (rev 5489)
@@ -795,8 +795,8 @@
if "property" in item:
if item["name"] == "JobStatus":
status = item["value"]
- if JobStatusInfo.get_status_string(status) in {"Completed",
- "Removed"}:
+ if JobStatusInfo.get_status_string(status) in ("Completed",
+ "Removed"):
render = False
break
return render and not error and self.edit_button.render(session) or ""
11 years, 7 months
r5488 - trunk/cumin/bin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-28 19:36:38 +0000 (Fri, 28 Sep 2012)
New Revision: 5488
Modified:
trunk/cumin/bin/cumin-admin
trunk/cumin/bin/cumin-database
Log:
Tweaks to cumin-admin and cumin-database for postgres user / setuid changes
in the previous commit
Modified: trunk/cumin/bin/cumin-admin
===================================================================
--- trunk/cumin/bin/cumin-admin 2012-09-28 19:02:09 UTC (rev 5487)
+++ trunk/cumin/bin/cumin-admin 2012-09-28 19:36:38 UTC (rev 5488)
@@ -120,11 +120,14 @@
app.db_init(schema_version_check=False)
except OperationalError:
print "Can't talk to the database"
+ print "Run 'cumin-database check' as root for more information"
if setuid_dev_user:
- error("Root did setuid to the local dev user. "\
- "Try again with --no-dev-user?")
- else:
- error("Run 'cumin-database check' as root for more information")
+ print "Hint: root did setuid to the local dev user."
+ print " Has the dev postgres user been created?"
+ print " Maybe try again with --no-dev-user"
+ elif uid != 0:
+ print "Hint: has the dev postgres user been created?"
+ sys.exit(1)
conn = app.database.get_connection()
cursor = conn.cursor()
Modified: trunk/cumin/bin/cumin-database
===================================================================
--- trunk/cumin/bin/cumin-database 2012-09-28 19:02:09 UTC (rev 5487)
+++ trunk/cumin/bin/cumin-database 2012-09-28 19:36:38 UTC (rev 5488)
@@ -298,14 +298,14 @@
if [[ $CUMIN_DEVEL_INSTANCE ]]; then
# If add_dev_user is 'yes' then we created a dev
# postgres user above, let cumin-admin setuid
- # to the dev user.
+ # to the dev user.
# Otherwise, make it setuid to the cumin user with
# logging set to /dev/null to ensure that the
- # schema is created and we don't have log ownership issues.
+ # schema is created and we don't have log ownership issues.
- # If they did not create the dev postgres user, and there
- # is no cumin user on the system, they are in trouble.
+ # If they did not create the dev postgres user, and there
+ # is no cumin user on the system, they are in trouble.
if [[ $add_dev_user == "yes" ]]; then
echo Creating schema as the \'$dev_postgres_user\' user
cumin-admin create-schema
11 years, 7 months
r5487 - in trunk: cumin/bin cumin/python/cumin etc
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-28 19:02:09 +0000 (Fri, 28 Sep 2012)
New Revision: 5487
Modified:
trunk/cumin/bin/cumin-admin
trunk/cumin/bin/cumin-database
trunk/cumin/python/cumin/config.py
trunk/etc/Profile.bash
Log:
Fix up cumin-admin and cumin-database to recognize a development instance
and prompt for the creation of a development postgres user during database
installation. The dev postgres user will be necessary to run Cumin from
the development instance since postgres is using auth ident by default and
will want to see a user mathing the developer's OS username.
Note, these changes should have no effect when Cumin is installed as
a package (runs as the 'cumin' user from /usr/bin and /usr/share/cumin)
Modified: trunk/cumin/bin/cumin-admin
===================================================================
--- trunk/cumin/bin/cumin-admin 2012-09-28 15:10:33 UTC (rev 5486)
+++ trunk/cumin/bin/cumin-admin 2012-09-28 19:02:09 UTC (rev 5487)
@@ -19,48 +19,75 @@
from cumin.admin import SchemaMissing
def main():
+
uid = os.getuid()
file_uid = os.stat(sys.argv[0]).st_uid
if uid not in (file_uid, 0):
error("You have insufficient privileges")
- if uid == 0:
- import pwd
-
- # Okay, if the file is not owned by us, then this is a local
- # (development) instance and cumin is not installed as a package.
- # In this case we need to set the effective uid as the file owner.
- # That owner should have added themselves as a postgres user so
- # auth will work.
- if file_uid != uid:
- os.seteuid(file_uid)
- else:
- # Become the cumin user so we have
- # access to the db with ident authentication
- cumin = pwd.getpwnam("cumin")
- os.seteuid(cumin[2])
-
+ # Log to stderr
setup_initial_logging()
- # Read config file, just the common section
+ # We will read the config file, but just the common section
config = CuminCommonConfig()
-
- # Set a log file default...
- home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin"))
- config.set_log(os.path.join(home, "log", "admin.log"))
-
values = config.parse()
# Get options
parser = CuminOptionParser()
+
+ # The escape string, shutdown timeout, and init-only
+ # options don't apply to us so eliminate confustion...
parser.remove_option("--es")
+ parser.remove_option("--tm")
+ parser.remove_option("--init-only")
+
+ # We do however want to add a --no-dev-user flag
+ # so that we can control setuid to the local user for
+ # development instances. This is used by cumin-database
+ # during installs to create the schema without worrying about
+ # the local user.
+ parser.add_option("--no-dev-user", action="store_true", default=False,
+ help="Do not setuid to the local user (development only)")
+
+ # And we want to set the default for the log-file option
+ # since the default is empty and we aren't picking up a value
+ # from a config section.
+
+ # cumin-database may set this to /dev/null so that log file ownership
+ # is not an issue during database install.
+ home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin"))
+ parser.set_defaults(log_file=os.path.join(home, "log", "admin.log"))
+
parser.set_usage(generate_usage())
opts, args = parser.parse_args()
# Use config values as defaults for unspecified options
apply_defaults(values.common, opts)
+ # Track what we've done for error messages...
+ setuid_dev_user = False
+
+ if uid == 0:
+ import pwd
+ # Okay, if the file is not owned by us, then this is a local
+ # development instance and cumin is not installed as a package.
+ # In this case we usually want to set the effective uid as the file owner
+ # so that log files, user export files, etc are owned by the developer.
+ # That owner should have added themselves as a postgres user so
+ # auth will work.
+
+ # However, cumin-database may turn off this behavior because
+ # it runs as root to create the database.
+ if file_uid != uid and not opts.no_dev_user:
+ setuid_dev_user = True
+ os.seteuid(file_uid)
+ else:
+ # Become the cumin user so we have
+ # access to the db with ident authentication
+ cumin = pwd.getpwnam("cumin")
+ os.seteuid(cumin[2])
+
setup_operational_logging(opts)
try:
@@ -93,7 +120,11 @@
app.db_init(schema_version_check=False)
except OperationalError:
print "Can't talk to the database"
- error("Run 'cumin-database check' as root for more information")
+ if setuid_dev_user:
+ error("Root did setuid to the local dev user. "\
+ "Try again with --no-dev-user?")
+ else:
+ error("Run 'cumin-database check' as root for more information")
conn = app.database.get_connection()
cursor = conn.cursor()
Modified: trunk/cumin/bin/cumin-database
===================================================================
--- trunk/cumin/bin/cumin-database 2012-09-28 15:10:33 UTC (rev 5486)
+++ trunk/cumin/bin/cumin-database 2012-09-28 19:02:09 UTC (rev 5487)
@@ -6,7 +6,6 @@
fi
# A workaround for running this script from the devel environment
-
if [[ -d cumin && -f etc/devel.profile ]]; then
source etc/devel.profile &> /dev/null
fi
@@ -183,6 +182,26 @@
done
}
+function add-postgres-user {
+ dev_postgres_user=$(stat -c %U $DEVEL_HOME/cumin/bin/cumin-database)
+ if [[ $dev_postgres_user ]]; then
+ cat <<EOF
+
+NOTICE: This appears to be a development instance owned by $dev_postgres_user
+
+To run Cumin as this user you *MUST* add a matching postgres user.
+Enter 'yes' to add the $dev_postgres_user user now:
+EOF
+
+ read add_dev_user
+ if [[ $add_dev_user == "yes" ]]; then
+ run "createuser --superuser ${dev_postgres_user}" postgres
+ else
+ echo No additional postgres user created
+ fi
+ fi
+}
+
function install {
check-environment || exit 1
@@ -268,11 +287,35 @@
fi
run "createuser --superuser ${dbname}" postgres
+ if [[ $CUMIN_DEVEL_INSTANCE ]]; then
+ add-postgres-user
+ fi
run "createdb --owner=${dbname} ${dbname}" postgres
- cumin-admin create-schema
- # cumin-admin add-role user
- # cumin-admin add-role admin
+ # If we are a dev instance we have to be careful
+ # when we delegate to cumin-admin to create the
+ # schema
+ if [[ $CUMIN_DEVEL_INSTANCE ]]; then
+ # If add_dev_user is 'yes' then we created a dev
+ # postgres user above, let cumin-admin setuid
+ # to the dev user.
+
+ # Otherwise, make it setuid to the cumin user with
+ # logging set to /dev/null to ensure that the
+ # schema is created and we don't have log ownership issues.
+
+ # If they did not create the dev postgres user, and there
+ # is no cumin user on the system, they are in trouble.
+ if [[ $add_dev_user == "yes" ]]; then
+ echo Creating schema as the \'$dev_postgres_user\' user
+ cumin-admin create-schema
+ else
+ echo Creating schema as the 'cumin' user
+ cumin-admin create-schema --no-dev-user --log-file=/dev/null
+ fi
+ else
+ cumin-admin create-schema
+ fi
}
function drop {
@@ -353,6 +396,9 @@
check-started || exit 1
;;
install)
+ if [[ $2 == "--devel" ]]; then
+ CUMIN_DEVEL_INSTANCE=2
+ fi
confirm-install
echo "The database is installed"
;;
Modified: trunk/cumin/python/cumin/config.py
===================================================================
--- trunk/cumin/python/cumin/config.py 2012-09-28 15:10:33 UTC (rev 5486)
+++ trunk/cumin/python/cumin/config.py 2012-09-28 19:02:09 UTC (rev 5487)
@@ -60,9 +60,6 @@
self.section = CuminConfigSection(self, self.section_name)
- def set_log(self, log):
- self.section.log_file.default = log
-
class CuminWebConfig(CuminConfig):
def __init__(self, section_name="web", strict_section="False"):
super(CuminWebConfig, self).__init__(section_name)
@@ -300,9 +297,9 @@
OptionParser.__init__(self)
self.add_option("--init-only", action="store_true", default=False)
- self.add_option("--es", default="")
+ self.add_option("--es", default="", help="Escape string (used by master)")
- self.add_option("--tm", default="5", type=int)
+ self.add_option("--tm", default="5", type=int, help="Shutdown timeout (used by master)")
# Defaults for these come later from the config
Modified: trunk/etc/Profile.bash
===================================================================
--- trunk/etc/Profile.bash 2012-09-28 15:10:33 UTC (rev 5486)
+++ trunk/etc/Profile.bash 2012-09-28 19:02:09 UTC (rev 5487)
@@ -1,6 +1,12 @@
export DEVEL_HOME="$PWD"
export DEVEL_MODULES="mint cumin basil parsley wooly rosemary sage"
+# This will control certain things, like whether or not
+# cumin-database prompts you for the creation of a
+# database superuser to match your account during install
+export CUMIN_DEVEL_INSTANCE=1
+
+
if [[ -z "$DEVEL_ORIGINAL_PATH" ]]; then
export DEVEL_ORIGINAL_PATH="$PATH"
fi
11 years, 7 months
r5486 - in trunk/cumin: bin etc python/cumin
by croberts@fedoraproject.org
Author: croberts
Date: 2012-09-28 15:10:33 +0000 (Fri, 28 Sep 2012)
New Revision: 5486
Added:
trunk/cumin/python/cumin/kerbauth.py
Modified:
trunk/cumin/bin/cumin-web
trunk/cumin/etc/cumin.conf
trunk/cumin/python/cumin/authenticator.py
trunk/cumin/python/cumin/config.py
Log:
BZ 799129: Enabling kerberos authentication. Using python-kerberos library to perform authentication against configured kerberos_server and kerberos_realm.
Modified: trunk/cumin/bin/cumin-web
===================================================================
--- trunk/cumin/bin/cumin-web 2012-09-27 19:35:54 UTC (rev 5485)
+++ trunk/cumin/bin/cumin-web 2012-09-28 15:10:33 UTC (rev 5486)
@@ -70,6 +70,10 @@
cumin.ldap_tls_cacertdir = values.ldap_tls_cacertdir
cumin.ldap_tls_cacertfile = values.ldap_tls_cacertfile
+def set_kerberos_configs(cumin, values):
+ cumin.kerberos_server = values.kerberos_server
+ cumin.kerberos_realm = values.kerberos_realm
+
def check_cert_files(opts):
# If a certificate or key file has been specified,
# check to make sure that both exist and that the
@@ -214,6 +218,7 @@
set_aviary_configs(cumin, values)
set_wallaby_configs(cumin, values, broker_uris)
set_ldap_configs(cumin, values)
+ set_kerberos_configs(cumin, values)
# Not used right now
#cumin.auth_create_ondemand = values.auth_create_ondemand
Modified: trunk/cumin/etc/cumin.conf
===================================================================
--- trunk/cumin/etc/cumin.conf 2012-09-27 19:35:54 UTC (rev 5485)
+++ trunk/cumin/etc/cumin.conf 2012-09-28 15:10:33 UTC (rev 5486)
@@ -120,6 +120,8 @@
# ldap_tls_cacertfile:
# ldap_tls_cacertdir:
# ldap_timeout: 30
+# kerberos_server:
+# kerberos_realm:
#notification-timeout: 180
# Number of seconds that a message in the yellow notification banner
@@ -352,6 +354,17 @@
## ldap_timeout: 30
## Timeout in seconds for connections to an LDAP server
+## kerberos_server:
+## setting this [in addition to auth:kerb and kerberos_realm] will activate
+## kerberos authentication for cumin. The kerberos_server string should
+## be either the IP address or FQDN of the kerberos_server.
+
+## kerberos_realm:
+## setting this [in addition to auth:kerb and kerberos_server] will activate
+## kerberos authentication for cumin. This should be set to the realm
+## defined by your kerberos server. Typically, this value will be in all caps
+## and look like "EXAMPLE.COM"
+
## [data]
## log-file:
Modified: trunk/cumin/python/cumin/authenticator.py
===================================================================
--- trunk/cumin/python/cumin/authenticator.py 2012-09-27 19:35:54 UTC (rev 5485)
+++ trunk/cumin/python/cumin/authenticator.py 2012-09-28 15:10:33 UTC (rev 5486)
@@ -10,6 +10,7 @@
from subprocess import PIPE
from psycopg2 import IntegrityError
import syslog
+from kerbauth import CuminAuthenticatorKerberos
# Send sensitive authentication logs to syslog
# but use this for other stuff. We want to keep
@@ -382,12 +383,12 @@
log.debug("Authenticator: 'change' not supported by script")
return False
+authen_map = {'script' : CuminAuthenticatorScript}
if have_ldap:
- authen_map = {'ldap': CuminAuthenticatorLDAP,
- 'ldaps': CuminAuthenticatorLDAP,
- 'script': CuminAuthenticatorScript}
-else:
- authen_map = {'script': CuminAuthenticatorScript}
+ authen_map['ldap'] = CuminAuthenticatorLDAP
+ authen_map['ldaps'] = CuminAuthenticatorLDAP
+if CuminAuthenticatorKerberos.isKerbAvail():
+ authen_map['kerb'] = CuminAuthenticatorKerberos
class CuminAuthenticator(object):
def __init__(self, app, log_authentication=True):
Modified: trunk/cumin/python/cumin/config.py
===================================================================
--- trunk/cumin/python/cumin/config.py 2012-09-27 19:35:54 UTC (rev 5485)
+++ trunk/cumin/python/cumin/config.py 2012-09-28 15:10:33 UTC (rev 5486)
@@ -141,6 +141,12 @@
param = ConfigParameter(self, "ldap_timeout", int)
param.default = 30
+
+ param = ConfigParameter(self, "kerberos_server", str)
+ param.default = ""
+
+ param = ConfigParameter(self, "kerberos_realm", str)
+ param.default = ""
self.log_file = ConfigParameter(self, "log-file", str)
Added: trunk/cumin/python/cumin/kerbauth.py
===================================================================
--- trunk/cumin/python/cumin/kerbauth.py (rev 0)
+++ trunk/cumin/python/cumin/kerbauth.py 2012-09-28 15:10:33 UTC (rev 5486)
@@ -0,0 +1,37 @@
+import logging
+try:
+ import kerberos
+ have_kerberos = True
+except:
+ have_kerberos = False
+
+log = logging.getLogger("cumin.kerbauth")
+
+
+class CuminAuthenticatorKerberos(object):
+ def __init__(self, mech, app):
+ log.info("Initializing %s", self)
+ self.kerb_url = app.kerberos_server
+ self.kerb_realm = app.kerberos_realm
+ if (self.kerb_url is not None and self.kerb_realm is not None
+ and self.kerb_url is not "" and self.kerb_realm is not ""):
+ self.valid = True
+ else:
+ self.valid = False
+ log.info("Required values for kerberos_server and kerberos_realm not set")
+
+ def authenticate(self, username, password):
+ log.debug("Authenticating for user %s against %s", (username, self.__class__.__name__))
+ isAuth = False
+ if self.valid:
+ try:
+ isAuth = kerberos.checkPassword(username, password, self.kerb_url, self.kerb_realm)
+ except Exception, e:
+ log.debug("Auth failed %s" % e)
+ else:
+ log.error("Kerberos authentication failed due to an invalid kerberos server/realm config")
+ return isAuth
+
+ @staticmethod
+ def isKerbAvail():
+ return have_kerberos
\ No newline at end of file
Property changes on: trunk/cumin/python/cumin/kerbauth.py
___________________________________________________________________
Added: svn:mime-type
+ text/plain
11 years, 7 months
r5485 - in trunk/cumin: model/upgrades python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-27 19:35:54 +0000 (Thu, 27 Sep 2012)
New Revision: 5485
Added:
trunk/cumin/model/upgrades/1.3_to_1.3a
Modified:
trunk/cumin/python/cumin/admin.py
Log:
Bump the schema version from 1.3 to 1.3a
Check the db auth configuration in the upgrade script and apply
the changes in 1.1_to_1.1a if they have not already been applied.
Since this is the end of the schema version, everything should
be back in sync at this point for users that missed 1.1_to_1.1a.
Added: trunk/cumin/model/upgrades/1.3_to_1.3a
===================================================================
--- trunk/cumin/model/upgrades/1.3_to_1.3a (rev 0)
+++ trunk/cumin/model/upgrades/1.3_to_1.3a 2012-09-27 19:35:54 UTC (rev 5485)
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+import subprocess
+import os
+import re
+
+# The cumin db auth changes can be missed if users
+# have a schema version already > 1.1 when they run
+# cumin-amdin upgrade-schema since the auth changes were
+# injected in the change from 1.1 to 1.1a.
+
+# Therefore, we scan for the pg_hba.conf changes here.
+# If everything is right, there will be no action.
+# Otherwise, the 1.1_to_1.1a script will be run
+# (it touches only db config data for auth).
+# With the subsequent version change 1.3a, everyone
+# should be on the same page regardess of path
+
+PG_HBA_CONF = "/var/lib/pgsql/data/pg_hba.conf"
+
+home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin"))
+
+old = re.compile("^\s*(local|host|hostssl|hostnossl)\s*cumin\s*cumin.*trust\s*$")
+lines = file(PG_HBA_CONF).readlines()
+for l in lines:
+ if old.match(l):
+ # Okay, we have old config lines to get rid of.
+ subprocess.Popen(os.path.join(home, "model/upgrades/1.1_to_1.1a"),
+ shell=True).wait()
+ break
Property changes on: trunk/cumin/model/upgrades/1.3_to_1.3a
___________________________________________________________________
Added: svn:executable
+ *
Modified: trunk/cumin/python/cumin/admin.py
===================================================================
--- trunk/cumin/python/cumin/admin.py 2012-09-27 19:20:39 UTC (rev 5484)
+++ trunk/cumin/python/cumin/admin.py 2012-09-27 19:35:54 UTC (rev 5485)
@@ -7,7 +7,7 @@
log = logging.getLogger("cumin.admin")
-schema_version = "1.3"
+schema_version = "1.3a"
class SchemaMissing(Exception):
pass
11 years, 7 months
r5484 - trunk/cumin/model/upgrades
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-27 19:20:39 +0000 (Thu, 27 Sep 2012)
New Revision: 5484
Added:
trunk/cumin/model/upgrades/1.1a_to_1.2
Removed:
trunk/cumin/model/upgrades/1.1_to_1.2
Modified:
trunk/cumin/model/upgrades/1.2_to_1.3
Log:
Fix up schema upgrade scripts to use new auth mechanism
Deleted: trunk/cumin/model/upgrades/1.1_to_1.2
===================================================================
--- trunk/cumin/model/upgrades/1.1_to_1.2 2012-09-27 19:08:47 UTC (rev 5483)
+++ trunk/cumin/model/upgrades/1.1_to_1.2 2012-09-27 19:20:39 UTC (rev 5484)
@@ -1,5 +0,0 @@
-#!/bin/bash
-echo alter table \"com.redhat.grid\".\"Submission\" add column \"Suspended\" bigint | psql -d cumin -U cumin -h localhost
-echo alter table \"com.redhat.grid\".\"Submission_samples\" add column \"Suspended\" bigint | psql -d cumin -U cumin -h localhost
-echo alter table \"com.redhat.grid\".\"Submission\" add column \"TransferringOutput\" bigint | psql -d cumin -U cumin -h localhost
-echo alter table \"com.redhat.grid\".\"Submission_samples\" add column \"TransferringOutput\" bigint | psql -d cumin -U cumin -h localhost
Copied: trunk/cumin/model/upgrades/1.1a_to_1.2 (from rev 5482, trunk/cumin/model/upgrades/1.1_to_1.2)
===================================================================
--- trunk/cumin/model/upgrades/1.1a_to_1.2 (rev 0)
+++ trunk/cumin/model/upgrades/1.1a_to_1.2 2012-09-27 19:20:39 UTC (rev 5484)
@@ -0,0 +1,5 @@
+#!/bin/bash
+su - postgres -c 'echo alter table \"com.redhat.grid\".\"Submission\" add column \"Suspended\" bigint'
+su - postgres -c 'echo alter table \"com.redhat.grid\".\"Submission_samples\" add column \"Suspended\" bigint'
+su - postgres -c 'echo alter table \"com.redhat.grid\".\"Submission\" add column \"TransferringOutput\" bigint'
+su - postgres -c 'echo alter table \"com.redhat.grid\".\"Submission_samples\" add column \"TransferringOutput\" bigint'
Modified: trunk/cumin/model/upgrades/1.2_to_1.3
===================================================================
--- trunk/cumin/model/upgrades/1.2_to_1.3 2012-09-27 19:08:47 UTC (rev 5483)
+++ trunk/cumin/model/upgrades/1.2_to_1.3 2012-09-27 19:20:39 UTC (rev 5484)
@@ -1,69 +1,48 @@
#!/bin/bash
-echo 'create schema "com.redhat.grid.plumage"' | psql -d cumin -U cumin -h localhost
-echo 'create sequence "com.redhat.grid.plumage"."OSUtil_id_seq"' | psql -d cumin -U cumin -h localhost
-echo 'create table "com.redhat.grid.plumage"."OSUtil" ("_id" int8 not null,"host" text not null,"ts" timestamp not null,"total" int8 not null,"used" int8 not null,"unused" int8 not null,"owner" int8 not null,"efficiency" float4 not null,constraint "OSUtil_pk" primary key ("_id"))'| psql -d cumin -U cumin -h localhost
-echo 'create table "com.redhat.grid.plumage"."OSUtil_samples" ("ts" timestamp not null,"total" int8 not null,"used" int8 not null,"unused" int8 not null,"owner" int8 not null,"efficiency" float4 not null)'| psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN freemem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN usedmem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN availmem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN totalmem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN freecpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN usedcpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN availcpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil" ADD COLUMN totalcpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN freemem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN usedmem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN availmem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN totalmem int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN freecpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN usedcpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN availcpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'ALTER TABLE "com.redhat.grid.plumage"."OSUtil_samples" ADD COLUMN totalcpu int8 NOT NULL DEFAULT 0' | psql -d cumin -U cumin -h localhost
-echo 'DROP TABLE "com.redhat.cumin"."BrokerGroup" cascade' | psql -d cumin -U cumin -h localhost
-echo 'DROP TABLE "com.redhat.cumin"."BrokerGroup_samples" cascade' | psql -d cumin -U cumin -h localhost
-echo 'DROP TABLE "com.redhat.cumin"."BrokerGroupMapping" cascade' | psql -d cumin -U cumin -h localhost
-echo 'DROP TABLE "com.redhat.cumin"."BrokerGroupMapping_samples" cascade' | psql -d cumin -U cumin -h localhost
-echo 'DROP SEQUENCE "com.redhat.cumin"."BrokerGroup_id_seq"' | psql -d cumin -U cumin -h localhost
-echo 'DROP SEQUENCE "com.redhat.cumin"."BrokerGroupMapping_id_seq"' | psql -d cumin -U cumin -h localhost
-echo 'create schema "com.redhat.cumin.messaging"' | psql -d cumin -U cumin -h localhost
-echo 'create sequence "com.redhat.cumin.messaging"."BrokerGroup_id_seq"'| psql -d cumin -U cumin -h localhost
-echo 'create sequence "com.redhat.cumin.messaging"."BrokerGroupMapping_id_seq"'| psql -d cumin -U cumin -h localhost
-echo 'create table "com.redhat.cumin.messaging"."BrokerGroup" (
- "_id" int8 not null,
- "_qmf_agent_id" text not null,
- "_qmf_object_id" text not null,
- "_qmf_create_time" timestamp not null,
- "_qmf_update_time" timestamp not null,
- "_qmf_delete_time" timestamp,
- "name" text not null,
- "description" text,
- constraint "BrokerGroup_pk" primary key ("_id"),
- constraint "BrokerGroup_qmf_id_uq" unique ("_qmf_agent_id", "_qmf_object_id")
- )' | psql -d cumin -U cumin -h localhost
-echo 'create table "com.redhat.cumin.messaging"."BrokerGroup_samples" (
- "_qmf_agent_id" text not null,
- "_qmf_object_id" text not null,
- "_qmf_update_time" timestamp not null
- )' | psql -d cumin -U cumin -h localhost
-echo 'create table "com.redhat.cumin.messaging"."BrokerGroupMapping" (
- "_id" int8 not null,
- "_qmf_agent_id" text not null,
- "_qmf_object_id" text not null,
- "_qmf_create_time" timestamp not null,
- "_qmf_update_time" timestamp not null,
- "_qmf_delete_time" timestamp,
- "_broker_id" int8,
- "_group_id" int8,
- constraint "BrokerGroupMapping_pk" primary key ("_id"),
- constraint "BrokerGroupMapping_qmf_id_uq" unique ("_qmf_agent_id", "_qmf_object_id")
- )' | psql -d cumin -U cumin -h localhost
-echo 'create table "com.redhat.cumin.messaging"."BrokerGroupMapping_samples" (
- "_qmf_agent_id" text not null,
- "_qmf_object_id" text not null,
- "_qmf_update_time" timestamp not null
- )' | psql -d cumin -U cumin -h localhost
-echo 'create index "BrokerGroup_samples_qmf_id_idx" on "com.redhat.cumin.messaging"."BrokerGroup_samples" ("_qmf_agent_id", "_qmf_object_id")' | psql -d cumin -U cumin -h localhost
-echo 'create index "BrokerGroupMapping_samples_qmf_id_idx" on "com.redhat.cumin.messaging"."BrokerGroupMapping_samples" ("_qmf_agent_id", "_qmf_object_id")' | psql -d cumin -U cumin -h localhost
-echo 'alter table "com.redhat.cumin.messaging"."BrokerGroupMapping"
- add constraint "_broker_id_fk" foreign key ("_broker_id") references "org.apache.qpid.broker"."Broker" ("_id") on update cascade on delete set null,
- add constraint "_group_id_fk" foreign key ("_group_id") references "com.redhat.cumin.messaging"."BrokerGroup" ("_id") on update cascade on delete set null' | psql -d cumin -U cumin -h localhost
+
+function run {
+ su - postgres -c "echo $1 | psql -d cumin"
+}
+
+run 'create schema \"com.redhat.grid.plumage\"'
+run 'create sequence \"com.redhat.grid.plumage\".\"OSUtil_id_seq\"'
+run 'create table \"com.redhat.grid.plumage\".\"OSUtil\" \(\"_id\" int8 not null,\"host\" text not null,\"ts\" timestamp not null,\"total\" int8 not null,\"used\" int8 not null,\"unused\" int8 not null,\"owner\" int8 not null,\"efficiency\" float4 not null,constraint \"OSUtil_pk\" primary key \(\"_id\"\)\)'
+run 'create table \"com.redhat.grid.plumage\".\"OSUtil_samples\" \(\"ts\" timestamp not null,\"total\" int8 not null,\"used\" int8 not null,\"unused\" int8 not null,\"owner\" int8 not null,\"efficiency\" float4 not null\)'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN freemem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN usedmem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN availmem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN totalmem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN freecpu int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN usedcpu int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN availcpu int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil\" ADD COLUMN totalcpu int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN freemem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN usedmem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN availmem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN totalmem int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN freecpu int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN usedcpu int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN availcpu int8 NOT NULL DEFAULT 0'
+run 'ALTER TABLE \"com.redhat.grid.plumage\".\"OSUtil_samples\" ADD COLUMN totalcpu int8 NOT NULL DEFAULT 0'
+run 'DROP TABLE \"com.redhat.cumin\".\"BrokerGroup\" cascade'
+run 'DROP TABLE \"com.redhat.cumin\".\"BrokerGroup_samples\" cascade'
+run 'DROP TABLE \"com.redhat.cumin\".\"BrokerGroupMapping\" cascade'
+run 'DROP TABLE \"com.redhat.cumin\".\"BrokerGroupMapping_samples\" cascade'
+run 'DROP SEQUENCE \"com.redhat.cumin\".\"BrokerGroup_id_seq\"'
+run 'DROP SEQUENCE \"com.redhat.cumin\".\"BrokerGroupMapping_id_seq\"'
+run 'create schema \"com.redhat.cumin.messaging\"'
+run 'create sequence \"com.redhat.cumin.messaging\".\"BrokerGroup_id_seq\"'
+run 'create sequence \"com.redhat.cumin.messaging\".\"BrokerGroupMapping_id_seq\"'
+
+run 'create table \"com.redhat.cumin.messaging\".\"BrokerGroup\" \(\"_id\" int8 not null,\"_qmf_agent_id\" text not null,\"_qmf_object_id\" text not null,\"_qmf_create_time\" timestamp not null,\"_qmf_update_time\" timestamp not null,\"_qmf_delete_time\" timestamp,\"name\" text not null,\"description\" text,constraint \"BrokerGroup_pk\" primary key \(\"_id\"\),constraint \"BrokerGroup_qmf_id_uq\" unique \(\"_qmf_agent_id\", \"_qmf_object_id\"\)\)'
+
+run 'create table \"com.redhat.cumin.messaging\".\"BrokerGroup_samples\" \(\"_qmf_agent_id\" text not null,\"_qmf_object_id\" text not null,\"_qmf_update_time\" timestamp not null\)'
+
+run 'create table \"com.redhat.cumin.messaging\".\"BrokerGroupMapping\" \(\"_id\" int8 not null,\"_qmf_agent_id\" text not null,\"_qmf_object_id\" text not null,\"_qmf_create_time\" timestamp not null,\"_qmf_update_time\" timestamp not null,\"_qmf_delete_time\" timestamp,\"_broker_id\" int8,\"_group_id\" int8,constraint \"BrokerGroupMapping_pk\" primary key \(\"_id\"\),constraint \"BrokerGroupMapping_qmf_id_uq\" unique \(\"_qmf_agent_id\", \"_qmf_object_id\"\)\)'
+
+run 'create table \"com.redhat.cumin.messaging\".\"BrokerGroupMapping_samples\" \(\"_qmf_agent_id\" text not null,\"_qmf_object_id\" text not null,\"_qmf_update_time\" timestamp not null\)'
+
+run 'create index \"BrokerGroup_samples_qmf_id_idx\" on \"com.redhat.cumin.messaging\".\"BrokerGroup_samples\" \(\"_qmf_agent_id\", \"_qmf_object_id\"\)'
+run 'create index \"BrokerGroupMapping_samples_qmf_id_idx\" on \"com.redhat.cumin.messaging\".\"BrokerGroupMapping_samples\" \(\"_qmf_agent_id\", \"_qmf_object_id\"\)'
+
+run 'alter table \"com.redhat.cumin.messaging\".\"BrokerGroupMapping\" add constraint \"_broker_id_fk\" foreign key \(\"_broker_id\"\) references \"org.apache.qpid.broker\".\"Broker\" \(\"_id\"\) on update cascade on delete set null, add constraint \"_group_id_fk\" foreign key \(\"_group_id\"\) references \"com.redhat.cumin.messaging\".\"BrokerGroup\" \(\"_id\"\) on update cascade on delete set null'
11 years, 7 months
r5483 - trunk/cumin/bin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-27 19:08:47 +0000 (Thu, 27 Sep 2012)
New Revision: 5483
Modified:
trunk/cumin/bin/cumin-admin
Log:
Error in handle_create_schema, need to get conn/cursor from app.create_schema()
(merge damage)
Modified: trunk/cumin/bin/cumin-admin
===================================================================
--- trunk/cumin/bin/cumin-admin 2012-09-26 21:48:37 UTC (rev 5482)
+++ trunk/cumin/bin/cumin-admin 2012-09-27 19:08:47 UTC (rev 5483)
@@ -304,7 +304,7 @@
def handle_create_schema(app, cursor, opts, args):
try:
- app.admin.create_schema(cursor)
+ conn, cursor = app.admin.create_schema(cursor)
except ProgrammingError:
error("The schema already exists")
11 years, 7 months
r5482 - in trunk/cumin: bin etc python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-26 21:48:37 +0000 (Wed, 26 Sep 2012)
New Revision: 5482
Modified:
trunk/cumin/bin/cumin-admin
trunk/cumin/bin/cumin-database
trunk/cumin/etc/cumin.conf
trunk/cumin/python/cumin/admin.py
trunk/cumin/python/cumin/config.py
trunk/cumin/python/cumin/database.py
Log:
Use standard PostgreSQL authentication instead of modified pg_hba.conf
BZ846345
Modified: trunk/cumin/bin/cumin-admin
===================================================================
--- trunk/cumin/bin/cumin-admin 2012-09-26 21:35:31 UTC (rev 5481)
+++ trunk/cumin/bin/cumin-admin 2012-09-26 21:48:37 UTC (rev 5482)
@@ -26,7 +26,20 @@
error("You have insufficient privileges")
if uid == 0:
- os.setuid(file_uid)
+ import pwd
+
+ # Okay, if the file is not owned by us, then this is a local
+ # (development) instance and cumin is not installed as a package.
+ # In this case we need to set the effective uid as the file owner.
+ # That owner should have added themselves as a postgres user so
+ # auth will work.
+ if file_uid != uid:
+ os.seteuid(file_uid)
+ else:
+ # Become the cumin user so we have
+ # access to the db with ident authentication
+ cumin = pwd.getpwnam("cumin")
+ os.seteuid(cumin[2])
setup_initial_logging()
@@ -105,7 +118,9 @@
error("Only schema commands are allowed until the schema is repaired")
try:
- handler(app, cursor, opts, args[1:])
+ res = handler(app, cursor, opts, args[1:])
+ if type(res) is tuple:
+ conn, cursor = res
conn.commit()
finally:
cursor.close()
@@ -256,17 +271,28 @@
script = os.path.join(upgrade_dir, steps[0]+"_to_"+steps[1])
print "Executing script %s" % script
- cmd = [script]
- res = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE)
- out, err = res.communicate()
- if res.returncode != 0:
- print "Script exited with error code %s" % res.returncode
- if out:
- print "Script stdout:\n%s" % out
- if err:
- print "Script stderr:\n%s" % err
+ res = subprocess.Popen(script, shell=True).wait()
+ if res != 0:
+ print "Script exited with error code %s" % res
break
else:
+ # Well, some upgrade scripts might restart the server
+ # Get the connection back. Try multiple, the server
+ # may be in the process of starting
+ conn = None
+ for i in range(20):
+ try:
+ conn = app.database.get_connection()
+ break
+ except:
+ import time
+ time.sleep(0.5)
+ if conn is None:
+ print "Upgrade failed, unable to write "\
+ "new schema version."
+ return
+
+ cursor = conn.cursor()
app.admin.update_schema_version(cursor, steps[1])
curr = app.admin.get_schema_version(cursor)
@@ -274,6 +300,7 @@
print "Upgrade failed, schema is version %s" % curr
else:
print "Upgrade to schema version %s succeeded" % target
+ return conn, cursor
def handle_create_schema(app, cursor, opts, args):
try:
@@ -285,6 +312,8 @@
app.admin.add_role(cursor, "admin")
print "The schema is created"
+ if conn and cursor:
+ return conn, cursor
def handle_check_schema(app, cursor, opts, args):
try:
Modified: trunk/cumin/bin/cumin-database
===================================================================
--- trunk/cumin/bin/cumin-database 2012-09-26 21:35:31 UTC (rev 5481)
+++ trunk/cumin/bin/cumin-database 2012-09-26 21:48:37 UTC (rev 5482)
@@ -102,18 +102,8 @@
fi
}
-function check-configured {
- grep "$dbname" "$pghbaconf" &> /dev/null || {
- echo "Error: The database is not configured"
- if [ "$1" != noadvice ]; then
- echo "Hint: Run 'cumin-database install'"
- fi
- return 1
- }
-}
-
function check-created {
- psql -d cumin -U cumin -h localhost -c '\q' &> /dev/null || {
+ su - postgres -c 'echo \\q | psql -d cumin' &> /dev/null || {
echo "Error: The database is not created"
if [ "$1" != noadvice ]; then
echo "Hint: Run 'cumin-database install'"
@@ -125,7 +115,7 @@
function check-created-wait {
for ((c=0; c<=30; c++))
do
- res="$(psql -d cumin -U cumin -h localhost -c '\q' 2>&1)" || true
+ res="$(su - postgres -c 'echo \\q | psql -d cumin' 2>&1)" || true
case $res in
*"could not connect"* | *"database system is starting up"*)
if [ $c -eq 0 ] ; then
@@ -165,8 +155,6 @@
* It will initialize the postgresql database cluster if it isn't
already initialized.
- * It will alter postgresql configuration files.
-
If you already have a custom-configured postgresql install, you may
not want to proceed.
@@ -200,11 +188,6 @@
check-initialized &> /dev/null || initialize
- check-configured &> /dev/null || {
- configure
- restart > /dev/null
- }
-
check-started &> /dev/null || start > /dev/null
check-created-wait &> /dev/null || create
@@ -275,35 +258,9 @@
}
}
-function configure {
- check-environment || exit 1
- check-initialized || exit 1
-
- if check-configured &> /dev/null; then
- echo "Error: The database server is already configured"
- echo "(Note, the server must be restarted after configuration."
- echo " If it has not been restarted since configuration, use"
- echo " 'cumin-database stop' and 'cumin-database start' to restart it)"
- exit 1
- fi
-
- python <<EOF
-import os
-import sys
-
-home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin"))
-sys.path.append(os.path.join(home, "python"))
-
-from cumin.database import modify_pghba_conf
-
-modify_pghba_conf('${pghbaconf}', '${dbname}', 'cumin')
-EOF
-}
-
function create {
check-environment || exit 1
check-started || exit 1
- check-configured || exit 1
if check-created &> /dev/null; then
echo "Error: The database is already created"
@@ -313,7 +270,7 @@
run "createuser --superuser ${dbname}" postgres
run "createdb --owner=${dbname} ${dbname}" postgres
- cumin-admin create-schema > /dev/null
+ cumin-admin create-schema
# cumin-admin add-role user
# cumin-admin add-role admin
}
@@ -366,7 +323,6 @@
start Start the database server
stop Stop the database server
initialize Create the main database cluster
- configure Configure the main database cluster
create Create the user, database, and schema
drop Discard the database user, database, and all data
EOF
@@ -383,10 +339,6 @@
check-initialized $2 || exit 1
echo "OK"
- echo -n "Checking configuration ...... "
- check-configured $2 || exit 1
- echo "OK"
-
echo -n "Checking server ............. "
check-started $2 || exit 1
echo "OK"
@@ -416,17 +368,6 @@
initialize
echo "The database server is initialized"
;;
- configure)
- configure && {
- echo "The database server is configured"
- $(postgresql_str status) &> /dev/null && {
- echo -e "\nAfter configuration the server must be restarted."
- echo -e "Would you like to restart the server now?\n"
- get-explicit-confirmation
- restart
- }
- }
- ;;
create)
create
echo "The database is created"
Modified: trunk/cumin/etc/cumin.conf
===================================================================
--- trunk/cumin/etc/cumin.conf 2012-09-26 21:35:31 UTC (rev 5481)
+++ trunk/cumin/etc/cumin.conf 2012-09-26 21:48:37 UTC (rev 5482)
@@ -15,7 +15,7 @@
# to the common section.
[common]
-# database: dbname=cumin user=cumin host=localhost
+# database: dbname=cumin
# brokers: localhost:5672
# sasl-mech-list: [default, 'anonymous' or 'plain digest-md5' with usr/passw]
# wallaby-broker: [default, first item in 'brokers' list]
Modified: trunk/cumin/python/cumin/admin.py
===================================================================
--- trunk/cumin/python/cumin/admin.py 2012-09-26 21:35:31 UTC (rev 5481)
+++ trunk/cumin/python/cumin/admin.py 2012-09-26 21:48:37 UTC (rev 5482)
@@ -25,6 +25,46 @@
return writer.getvalue()
def create_schema(self, cursor):
+
+ # Check for meta scripts in the upgrade
+ # dir associated with the schema version.
+ # This lets us associate external tasks
+ # with schema version numbers.
+ upgrade_dir = os.path.join(self.app.home, "model/upgrades")
+ try:
+ target = None
+ scripts = os.listdir(upgrade_dir)
+ for s in scripts:
+ if s == "create_%s" % schema_version:
+ target = os.path.join(upgrade_dir, s)
+ break
+ except:
+ # nothing, we assume
+ pass
+
+ conn = None
+ if target:
+ res = subprocess.Popen(target, shell=True).wait()
+ if res != 0:
+ print "Executed script %s" % target
+ print "Script exited with error code %s" % res
+ raise Exception("Schema not created")
+ else:
+ # Well, some scripts might restart the server
+ # Get the connection back. Try multiple, the server
+ # may be in the process of starting
+ for i in range(20):
+ try:
+ conn = self.app.database.get_connection()
+ break
+ except:
+ import time
+ time.sleep(0.5)
+ if conn is None:
+ print "Can't connect to the database."
+ raise Exception("Schema not created")
+ cursor = conn.cursor()
+
cursor.execute(self.get_schema())
cls = self.app.model.com_redhat_cumin.Info
@@ -33,6 +73,7 @@
obj.schema_version = schema_version
obj.fake_qmf_values()
obj.save(cursor)
+ return conn, cursor
def update_schema_version(self, cursor, version):
cls = self.app.model.com_redhat_cumin.Info
Modified: trunk/cumin/python/cumin/config.py
===================================================================
--- trunk/cumin/python/cumin/config.py 2012-09-26 21:35:31 UTC (rev 5481)
+++ trunk/cumin/python/cumin/config.py 2012-09-26 21:48:37 UTC (rev 5482)
@@ -126,7 +126,7 @@
super(CuminConfigSection, self).__init__(config, name, strict_section)
param = ConfigParameter(self, "database", str)
- param.default = "dbname=cumin user=cumin host=localhost"
+ param.default = "dbname=cumin"
# Put this here, because authentication is something that
# might need to be done commonly
Modified: trunk/cumin/python/cumin/database.py
===================================================================
--- trunk/cumin/python/cumin/database.py 2012-09-26 21:35:31 UTC (rev 5481)
+++ trunk/cumin/python/cumin/database.py 2012-09-26 21:48:37 UTC (rev 5482)
@@ -68,45 +68,3 @@
def __repr__(self):
return self.__class__.__name__
-def modify_pghba_conf(path, database_name, user_name):
- comment_or_empty_line_pattern = re.compile('^\w*#|^\w*$')
- record_pattern = re.compile('^\w*(local|host|hostssl|hostnossl)')
-
- file = open(path, "r")
-
- lines = list()
- first_record_index = None
-
- for i, line in enumerate(file):
- lines.append(line)
-
- if record_pattern.match(line):
- if first_record_index is None:
- first_record_index = i
-
- tokens = line.split()
-
- if tokens[1] == database_name:
- raise Exception("This file already contains a " + \
- "%s record" % database_name)
- elif comment_or_empty_line_pattern.match(line):
- pass
- else:
- raise Exception("This doesn't look like a pg_hba.conf file")
-
- file.close()
-
- if first_record_index is None:
- first_record_index = len(lines)
-
- line = "host %s %s ::1/128 trust\n" % (database_name, user_name)
- lines.insert(first_record_index, line)
- line = "host %s %s 127.0.0.1/32 trust\n" % (database_name, user_name)
- lines.insert(first_record_index, line)
-
- file = open(path, "w")
-
- for line in lines:
- file.write(line)
-
- file.close()
11 years, 7 months
r5481 - trunk/wooly/python/wooly
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-26 21:35:31 +0000 (Wed, 26 Sep 2012)
New Revision: 5481
Modified:
trunk/wooly/python/wooly/__init__.py
Log:
Difference in return result of urlparse.urlparse requires hardwired indices
BZ847940
Modified: trunk/wooly/python/wooly/__init__.py
===================================================================
--- trunk/wooly/python/wooly/__init__.py 2012-09-26 21:06:23 UTC (rev 5480)
+++ trunk/wooly/python/wooly/__init__.py 2012-09-26 21:35:31 UTC (rev 5481)
@@ -540,6 +540,15 @@
def validate_redirect(self, session, url, env):
+ # Sigh, urlparse returns a different result in Python 2.4 and
+ # Python 2.6 so we have to index ourselves.
+ SCHEME = 0
+ NETLOC = 1
+ PATH = 2
+ PARAMS = 3
+ QUERY = 4
+ FRAGMENT = 5
+
def netloc(env):
if 'HTTP_HOST' in env:
return env['HTTP_HOST']
@@ -549,13 +558,13 @@
if type(url) in (str, unicode):
res = urlparse.urlparse(url)
# Path will be an index into our dictionary of pages
- p = res.path
+ p = res[PATH]
if p.startswith("/"):
p = p[1:]
if not p in self.app.pages_by_name or \
- (res.scheme and res.scheme != env['wsgi.url_scheme']) or \
- (res.netloc and res.netloc != netloc(env)):
+ (res[SCHEME] and res[SCHEME] != env['wsgi.url_scheme']) or \
+ (res[NETLOC] and res[NETLOC] != netloc(env)):
session.add_notice(Notice("Invalid redirect, " \
"returning to main page"))
url = self.lookup_mainpage(session)
11 years, 7 months
r5480 - in trunk/cumin/python/cumin: . grid
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-09-26 21:06:23 +0000 (Wed, 26 Sep 2012)
New Revision: 5480
Modified:
trunk/cumin/python/cumin/grid/job.py
trunk/cumin/python/cumin/model.py
Log:
Submission membership checks on job control actions
BZ837047
Modified: trunk/cumin/python/cumin/grid/job.py
===================================================================
--- trunk/cumin/python/cumin/grid/job.py 2012-09-26 20:56:34 UTC (rev 5479)
+++ trunk/cumin/python/cumin/grid/job.py 2012-09-26 21:06:23 UTC (rev 5480)
@@ -104,43 +104,58 @@
return (self.parent,
"Logged in user does not own the specified submission")
- def do_process(self, session):
- super(JobFrame, self).do_process(session)
+ def get_job_ad(self, session, id=None, job_id=None):
+ if id is None:
+ id = self.id.get(session)
+ if job_id is None:
+ job_id = self.job_id.get(session)
+ submission, job_server, sched = self.get_trifecta(session, id)
+ results = self.app.remote.get_job_ad(job_server, job_id,
+ sched.Name, submission,
+ default={'JobAd': {}})
+ return results
- # Make sure that the job belongs to the designated submission.
- id = self.id.get(session)
- submission, js, sched = self.get_trifecta(session, id)
+ def check_submission_membership(self, session, sub_id, job_id):
+ frame = None
+ message = ""
+ submission, js, sched = self.get_trifecta(session, sub_id)
summaries = self.app.model.get_submission_job_summaries(submission,
sched.Name)
- okay = False
- frame = None
- message = ""
- if summaries.data is None:
+
+ # Make sure that the job belongs to the designated submission.
+ # None = no data
+ # True/False indicates job is a member of the submission
+ okay = summaries.check_submission_membership(job_id)
+
+ if okay is None:
# Well, someone is requesting a particular job but we have no
# data yet so we don't know if it is legit or not. Redirect
# to the parent frame, but without a notice. Normally data should
# be present because the trail through Cumin goes to the submission
# job list first, with a link to a particular job.
frame = self.parent
- else:
- job_id = self.job_id.get(session)
- for summary in summaries.data:
- if str(summary["ClusterId"]) + "." + \
- str(summary["ProcId"]) == job_id:
- okay = True
- break
+ elif not okay:
+ frame = self.parent
+ message = "Job %s is not part "\
+ "of the specified submission" % job_id
- if not okay:
- frame = self.parent
- message = "The specified job is not part "\
- "of the specified submission"
+ return okay, frame, message
+ def do_process(self, session):
+ super(JobFrame, self).do_process(session)
+
+ # Make sure that the job belongs to the designated submission.
+ sub_id = self.id.get(session)
+ job_id = self.job_id.get(session)
+ okay, frame, message = self.check_submission_membership(session,
+ sub_id, job_id)
# If the check failed and there is not yet a redirect
# value, set the redirect. Add the notice in either case.
- if not self.get_redirect(session) and frame:
- self.set_redirect(session, frame, message)
- elif message:
- session.add_notice(Notice(message))
+ if not okay:
+ if not self.get_redirect(session) and frame:
+ self.set_redirect(session, frame, message)
+ elif message:
+ session.add_notice(Notice(message))
class JobAdModes(ModeSet):
def __init__(self, app, name, check_viewable):
@@ -453,15 +468,14 @@
return ": ".join(reason)
def process_submit(self, session):
- self.validate(session)
+ selection = self.selection.get(session)
+ submission, scheduler = self.get_submission_sched(session)
+ self.validate(session, selection, submission, scheduler)
+
errors = self.errors.get(session)
if not errors:
- selection = self.selection.get(session)
reason = self.get_reason(session, self.verb)
-
- submission, scheduler = self.get_submission_sched(session)
-
self.task.invoke(session, selection, scheduler, reason, submission)
self.task.exit_with_redirect(session)
@@ -482,24 +496,45 @@
reason = self.reason.render(session)
return "<table class=\"FormFieldSet\"><tbody>%s</tbody></table>%s" % (reason, content)
- def validate(self, session):
+ def validate(self, session,
+ selection=None, submission=None, sched=None):
super(JobObjectSelectorTaskForm, self).validate(session)
if not self.errors.get(session) and \
self.app.authorizator.is_enforcing():
+
+ if selection is None:
+ selection = self.get_selection(session)
+ if submission is None or sched is None:
+ submission, sched = self.get_submission_sched(session)
+
# Check here to make sure the logged in user owns
# the submission or is an admin
login = session.client_session.attributes["login_session"]
if "admin" not in login.group:
user = login.user.name
- submission_id = self.submission_id.get(session)
- cls = self.app.model.com_redhat_grid.Submission
- submission = cls.get_object_by_id(session.cursor,
- submission_id)
if hasattr(submission, "Owner") and submission.Owner != user:
f = FormError("The logged in user does not "\
"own this submission.")
self.errors.add(session, f)
-
+
+ # Check that the job is a member of the submission
+ summaries = self.app.model.get_submission_job_summaries(submission,
+ sched.Name)
+
+ # Make sure that the job belongs to the designated submission.
+ # None = no data
+ # True/False indicates job is a member of the submission
+ for sel in selection:
+ okay = summaries.check_submission_membership(sel)
+ if okay is None:
+ f = FormError("Unable to verify job %s" \
+ " is a member of the submission" % sel)
+ self.errors.add(session, f)
+ elif not okay:
+ f = FormError("Job %s is not part of" \
+ " the specified submission" % sel)
+ self.errors.add(session, f)
+
class JobAdsSet(PropertySet):
types = {0: "expression",
1: "integer",
@@ -518,13 +553,8 @@
self.do_check_viewable = False
def get_job_ad(self, session):
- id = self.frame.id.get(session)
- submission, job_server, sched = self.frame.get_trifecta(session, id)
- job_id = self.frame.job_id.get(session)
- results = self.app.remote.get_job_ad(job_server, job_id,
- sched.Name, submission,
- default={'JobAd': {}})
- return results
+ # defer to the frame because it's got all the data
+ return self.frame.get_job_ad(session)
def check_job_owner(self, session, ad):
error = None
@@ -543,7 +573,7 @@
results = self.get_job_ad(session)
error = None
if results.error:
- error = results.error
+ error = results.error
elif self.do_check_viewable:
error = self.check_job_owner(session, results.data['JobAd'])
@@ -628,13 +658,12 @@
if not ad_list and not error:
ad_list = list()
- id = self.frame.id.get(session)
- submission, job_server, sched = self.frame.get_trifecta(session, id)
- job_id = self.frame.job_id.get(session)
- results = self.app.remote.get_job_ad(job_server, job_id,
- sched.Name, submission,
- default={'JobAd': {}})
- error = results.error
+ error = None
+ results = self.get_job_ad(session)
+ if results.error:
+ error = results.error
+ elif self.do_check_viewable:
+ error = self.check_job_owner(session, results.data['JobAd'])
self.qmf_error.set(session, error)
ads = results.data['JobAd']
cls = self.app.model.job_meta_data
@@ -1266,18 +1295,31 @@
super(JobActionForm, self).validate(session)
if not self.errors.get(session) and \
self.app.authorizator.is_enforcing():
+ id = self.id.get(session)
+
+ # Make sure that the job belongs to the designated submission.
+ job_id = self.job_id.get(session)
+ okay, frame, message = \
+ self.task.frame.check_submission_membership(session, id, job_id)
+ if not okay:
+ if not message:
+ message = "Unable to verify this job" \
+ " is a member of the submission"
+ f = FormError(message)
+ self.errors.add(session, f)
+ return
+
# Check here to make sure the logged in user owns
- # the job or is an admin
+ # the submission and job or is an admin
login = session.client_session.attributes["login_session"]
if "admin" not in login.group:
user = login.user.name
- id = self.id.get(session)
submission = self.task.frame.get_submission(session, id)
if hasattr(submission, "Owner") and submission.Owner != user:
f = FormError("The logged in user does not "\
"own this submission.")
self.errors.add(session, f)
-
+
class ReasonField(NoXMLStringField):
def render_title(self, session):
return "Reason"
Modified: trunk/cumin/python/cumin/model.py
===================================================================
--- trunk/cumin/python/cumin/model.py 2012-09-26 20:56:34 UTC (rev 5479)
+++ trunk/cumin/python/cumin/model.py 2012-09-26 21:06:23 UTC (rev 5480)
@@ -809,6 +809,19 @@
super(SubmissionJobSummaryStore, self).delete()
+ def check_submission_membership(self, job_id):
+
+ # Make sure that the job belongs to the designated submission.
+ okay = None
+ if self.data is not None:
+ okay = False
+ for summary in self.data:
+ if str(summary["ClusterId"]) + "." + \
+ str(summary["ProcId"]) == job_id:
+ okay = True
+ break
+ return okay
+
class NegotiatorGroupNamesStore(ObjectStore):
def __init__(self, model, negotiator):
super(NegotiatorGroupNamesStore, self).__init__(model)
11 years, 7 months