backend/server/action_extra_data/configfiles.py | 38 ++++----------
backend/server/action_extra_data/script.py | 28 +---------
backend/server/rhnAction.py | 40 +++++++++------
backend/server/rhnSQL/__init__.py | 4 -
backend/server/rhnSQL/driver_cx_Oracle.py | 29 +++++++++-
backend/server/rhnSQL/driver_postgresql.py | 2
web/modules/rhn/RHN/DB/DataSource/xml/config_queries.xml | 5 +
7 files changed, 72 insertions(+), 74 deletions(-)
New commits:
commit 25263f4c806c5eda910b4b5f26eb4030a92118df
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Mar 14 16:34:49 2011 +0100
no more need for special insert when diff is empty
diff --git a/backend/server/action_extra_data/configfiles.py
b/backend/server/action_extra_data/configfiles.py
index 4554199..ca00f7f 100644
--- a/backend/server/action_extra_data/configfiles.py
+++ b/backend/server/action_extra_data/configfiles.py
@@ -257,11 +257,6 @@ def _lookup_action_revision_id(server_id, action_id, path):
return None
return row['id']
-_query_add_result_identical = rhnSQL.Statement("""
- insert into rhnActionConfigRevisionResult
- (action_config_revision_id, result)
- values (:action_config_revision_id, NULL)
-""")
_query_add_result_diff = rhnSQL.Statement("""
insert into rhnActionConfigRevisionResult
(action_config_revision_id, result)
@@ -271,16 +266,15 @@ def _add_result(action_config_revision_id, diff):
log_debug(4, action_config_revision_id, diff)
- if not diff:
- # Just add an empty row
- h = rhnSQL.prepare(_query_add_result_identical)
- h.execute(action_config_revision_id=action_config_revision_id)
- return
-
- if type(diff) == UnicodeType:
- diff = unicode.encode(diff,'utf-8')
-
- h = rhnSQL.prepare(_query_add_result_diff, blob_map={'result':
'result'})
+ if diff:
+ blob_map = {'result': 'result'}
+ if type(diff) == UnicodeType:
+ diff = unicode.encode(diff,'utf-8')
+ else:
+ blob_map = None
+ diff = None
+
+ h = rhnSQL.prepare(_query_add_result_diff, blob_map=blob_map)
h.execute(action_config_revision_id=action_config_revision_id,
result=diff)
commit 62b26924d03ecaafb4ab4e9935100be67d8dd930
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Mar 11 09:07:42 2011 +0100
removed unused _query_get_output_row (code removed in previous commit)
diff --git a/backend/server/action_extra_data/script.py
b/backend/server/action_extra_data/script.py
index f3f0eac..25136a9 100644
--- a/backend/server/action_extra_data/script.py
+++ b/backend/server/action_extra_data/script.py
@@ -49,15 +49,6 @@ select :server_id,
where ascript.action_id = :action_id
""")
-_query_get_output_row = rhnSQL.Statement("""
-select asr.output
- from rhnServerActionScriptResult asr,
- rhnActionScript ascript
- where ascript.action_id = :action_id
- and asr.server_id = :server_id
- and asr.action_script_id = ascript.id
-""")
-
def run(server_id, action_id, data={}):
log_debug(3)
commit 1966210148756644c244fed259e93d2b4f2d5cef
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Mar 11 09:06:36 2011 +0100
set the blob directly in insert
diff --git a/backend/server/action_extra_data/script.py
b/backend/server/action_extra_data/script.py
index 5772408..f3f0eac 100644
--- a/backend/server/action_extra_data/script.py
+++ b/backend/server/action_extra_data/script.py
@@ -41,7 +41,7 @@ insert into rhnServerActionScriptResult (
)
select :server_id,
ascript.id,
- empty_blob(),
+ :output,
TO_DATE(:process_start, 'YYYY-MM-DD HH24:MI:SS'),
TO_DATE(:process_end, 'YYYY-MM-DD HH24:MI:SS'),
:return_code
@@ -83,23 +83,12 @@ def run(server_id, action_id, data={}):
log_debug(4, "script output", output)
- h = rhnSQL.prepare(_query_initial_store)
+ h = rhnSQL.prepare(_query_initial_store, blob_map={'output':
'output'})
h.execute(server_id=server_id,
action_id=action_id,
process_start=process_start,
process_end=process_end,
- return_code=return_code
+ return_code=return_code,
+ output=output
)
- # edit the created blob
- h = rhnSQL.prepare(_query_get_output_row)
- h.execute(server_id=server_id, action_id=action_id)
-
- if not output:
- log_debug(4, "No output sent by client")
- return
-
- row = h.fetchone_dict()
- lob = row['output']
-
- lob.write(output)
commit c795aaae8e3d6d68418c066fc0c190fb60e7df08
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Mar 11 11:39:21 2011 +0100
set blob directly in insert (PG)
fixing
Traceback (most recent call last):
...
File
"/usr/lib/python2.4/site-packages/spacewalk/server/action_extra_data/configfiles.py",
line 295, in _add_result
result.write(diff)
AttributeError: 'buffer' object has no attribute 'write'
diff --git a/backend/server/action_extra_data/configfiles.py
b/backend/server/action_extra_data/configfiles.py
index e69b693..4554199 100644
--- a/backend/server/action_extra_data/configfiles.py
+++ b/backend/server/action_extra_data/configfiles.py
@@ -265,12 +265,7 @@ _query_add_result_identical = rhnSQL.Statement("""
_query_add_result_diff = rhnSQL.Statement("""
insert into rhnActionConfigRevisionResult
(action_config_revision_id, result)
- values (:action_config_revision_id, empty_blob())
-""")
-_query_update_result = rhnSQL.Statement("""
- select result from rhnActionConfigRevisionResult
- where action_config_revision_id = :action_config_revision_id
- for update
+ values (:action_config_revision_id, :result)
""")
def _add_result(action_config_revision_id, diff):
@@ -282,17 +277,13 @@ def _add_result(action_config_revision_id, diff):
h.execute(action_config_revision_id=action_config_revision_id)
return
- h = rhnSQL.prepare(_query_add_result_diff)
- h.execute(action_config_revision_id=action_config_revision_id)
-
- h = rhnSQL.prepare(_query_update_result)
- h.execute(action_config_revision_id=action_config_revision_id)
- row = h.fetchone_dict()
- result = row['result']
if type(diff) == UnicodeType:
diff = unicode.encode(diff,'utf-8')
- result.write(diff)
+ h = rhnSQL.prepare(_query_add_result_diff, blob_map={'result':
'result'})
+ h.execute(action_config_revision_id=action_config_revision_id,
+ result=diff)
+
_query_lookup_old_diffs = rhnSQL.Statement("""
select acr.id
from rhnActionConfigRevision acr
commit d58c8ddb886f27dbf117c721d6655a351e0be755
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Mar 11 17:01:38 2011 +0100
support for direct blob insert for oracle
diff --git a/backend/server/rhnSQL/__init__.py b/backend/server/rhnSQL/__init__.py
index d607e6e..5c6736c 100644
--- a/backend/server/rhnSQL/__init__.py
+++ b/backend/server/rhnSQL/__init__.py
@@ -186,11 +186,11 @@ def database():
def cursor():
db = __test_DB()
return db.cursor()
-def prepare(sql, params=None):
+def prepare(sql, params=None, blob_map=None):
db = __test_DB()
if isinstance(sql, Statement):
sql = sql.statement
- return db.prepare(sql, params=params)
+ return db.prepare(sql, params=params, blob_map=blob_map)
def execute(sql, *args, **kwargs):
db = __test_DB()
return apply(db.execute, (sql, ) + args, kwargs)
diff --git a/backend/server/rhnSQL/driver_cx_Oracle.py
b/backend/server/rhnSQL/driver_cx_Oracle.py
index 7dbdbe4..608301b 100644
--- a/backend/server/rhnSQL/driver_cx_Oracle.py
+++ b/backend/server/rhnSQL/driver_cx_Oracle.py
@@ -26,6 +26,7 @@ import cx_Oracle
import sys
import string
import os
+import re
import types
from spacewalk.server import rhnSQL
@@ -48,12 +49,13 @@ class Cursor(sql_base.Cursor):
"""
OracleError = cx_Oracle.DatabaseError
- def __init__(self, dbh, sql=None, force=None):
+ def __init__(self, dbh, sql=None, force=None, blob_map=None):
try:
sql_base.Cursor.__init__(self, dbh=dbh, sql=sql,
force=force)
self._type_mapping = ORACLE_TYPE_MAPPING
+ self.blob_map = blob_map
except sql_base.SQLSchemaError, e:
(errno, errmsg) = e.errno, e.errmsg
if 900 <= errno <= 999:
@@ -92,6 +94,13 @@ class Cursor(sql_base.Cursor):
% (self.sql, params))
if self.sql is None:
raise rhnException("Cannot execute empty cursor")
+ if self.blob_map:
+ blob_content = {}
+ for orig_blob_var in self.blob_map.keys():
+ new_blob_var = orig_blob_var + '_blob'
+ blob_content[new_blob_var] = kw[orig_blob_var]
+ kw[new_blob_var] = self.var(cx_Oracle.BLOB)
+ del kw[orig_blob_var]
modified_params = self._munge_args(kw)
try:
@@ -121,6 +130,10 @@ class Cursor(sql_base.Cursor):
raise
else:
self.reparsed = 0 # reset the reparsed counter
+
+ if self.blob_map:
+ for blob_var, content in blob_content.items():
+ kw[blob_var].getvalue().write(content)
# Munge back the values
self._unmunge_args(kw, modified_params)
return retval
@@ -261,7 +274,6 @@ class Cursor(sql_base.Cursor):
blob.write(data)
-
class Procedure(sql_base.Procedure):
OracleError = cx_Oracle.DatabaseError
@@ -437,15 +449,24 @@ class Database(sql_base.Database):
return self._cursor_class(dbh=self.dbh)
# pass-through functions for when you want to do SQL yourself
- def prepare(self, sql, force=0, params=None):
+ def prepare(self, sql, force=0, params=None, blob_map = None):
# Abuse the map calls to get rid of SQL comments and extra spaces
sql = string.join(filter(lambda a: len(a),
map(string.strip,
map(lambda a: (a + " ")[:string.find(a, '--')],
string.split(sql, "\n")))),
" ")
+ if blob_map:
+ col_list = []
+ bind_list = []
+ for bind_var, column in blob_map.items():
+ r=re.compile(":%s" % bind_var)
+ sql = re.sub(r, 'empty_blob()', sql)
+ col_list.append(column)
+ bind_list.append(":%s_blob" % bind_var)
+ sql += " returning %s into %s" %(','.join(col_list),
','.join(bind_list))
# this way we only hit the network once for each sql statement
- return self._cursor_class(dbh=self.dbh, sql=sql, force=force)
+ return self._cursor_class(dbh=self.dbh, sql=sql, force=force, blob_map=blob_map)
def procedure(self, name):
try:
diff --git a/backend/server/rhnSQL/driver_postgresql.py
b/backend/server/rhnSQL/driver_postgresql.py
index 2e9f02d..c65d98b 100644
--- a/backend/server/rhnSQL/driver_postgresql.py
+++ b/backend/server/rhnSQL/driver_postgresql.py
@@ -183,7 +183,7 @@ class Database(sql_base.Database):
"Exception information: %s" % sys.exc_info()[1])
self.connect() # only allow one try
- def prepare(self, sql, force=0, params=None):
+ def prepare(self, sql, force=0, params=None, blob_map=None):
if params != None: # support for anonymour plpgsql
sql = re.sub(r'/\*pg_cs\*/\s*cursor', '', sql)
sql = re.sub(r'/\*pg (.+?)\*/', '\g<1>', sql)
commit 3fd9dc08327d15d16d4307bfe847cb0878b85ac3
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Mar 11 10:56:45 2011 +0100
replaced 'connect by prior' with recursive function in python (PG)
diff --git a/backend/server/rhnAction.py b/backend/server/rhnAction.py
index e2a27f4..325489f 100644
--- a/backend/server/rhnAction.py
+++ b/backend/server/rhnAction.py
@@ -92,35 +92,43 @@ def update_server_action(server_id, action_id, status,
result_code=None,
result_message=result_message[:1024])
+_query_lookup_action_childs = rhnSQL.Statement("""
+ select a.id
+ from rhnAction a
+ join rhnServerAction sa
+ on sa.action_id = a.id
+ where prerequisite = :action_id
+ and sa.server_id = :server_id
+""")
+
_query_lookup_action = rhnSQL.Statement("""
select sa.action_id, sa.status
- from rhnServerAction sa,
- (
- select id
- from rhnAction
- start with id = :action_id
- connect by prior id = prerequisite
- ) a
+ from rhnServerAction sa
where sa.server_id = :server_id
- and sa.action_id = a.id
+ and sa.action_id = :action_id
""")
def invalidate_action(server_id, action_id):
log_debug(4, server_id, action_id)
h = rhnSQL.prepare(_query_lookup_action)
- h.execute(server_id=server_id, action_id=action_id)
+ h_child = rhnSQL.prepare(_query_lookup_action_childs)
+ return _invalidate_action_recursive(server_id, action_id, h, h_child)
- # Data structures for the update
+def _invalidate_action_recursive(server_id, action_id, h, h_child):
+ h_child.execute(server_id=server_id, action_id=action_id)
a_ids = []
+ # invalidate childs first
while 1:
- row = h.fetchone_dict()
+ row = h_child.fetchone_dict()
if not row:
break
-
- if row['status'] == 3:
- # Already failed
- continue
- c_action_id = row['action_id']
+ child_ids = _invalidate_action_recursive(server_id, row['id'], h,
h_child)
+ a_ids.append(child_ids)
+ h.execute(server_id=server_id, action_id=action_id)
+ s_row = h.fetchone_dict()
+ if s_row and s_row['status'] <> 3:
+ # not already failed
+ c_action_id = s_row['action_id']
a_ids.append(c_action_id)
update_server_action(server_id=server_id, action_id=c_action_id,
status=3, result_code=-100, result_message="Prerequisite failed")
commit d4acd9796d661ab044ead4242bae7aba02cc263b
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Mar 10 17:04:17 2011 +0100
670793 - don't fail on non-ascii config files
diff --git a/backend/server/action_extra_data/configfiles.py
b/backend/server/action_extra_data/configfiles.py
index 1f95a3e..e69b693 100644
--- a/backend/server/action_extra_data/configfiles.py
+++ b/backend/server/action_extra_data/configfiles.py
@@ -15,6 +15,7 @@
# config file-related error handling functions
#
+from types import UnicodeType
from spacewalk.common import log_debug, log_error, rhnFlags
from spacewalk.server import rhnSQL
from spacewalk.server.rhnServer import server_kickstart
@@ -288,6 +289,8 @@ def _add_result(action_config_revision_id, diff):
h.execute(action_config_revision_id=action_config_revision_id)
row = h.fetchone_dict()
result = row['result']
+ if type(diff) == UnicodeType:
+ diff = unicode.encode(diff,'utf-8')
result.write(diff)
_query_lookup_old_diffs = rhnSQL.Statement("""
commit f752cc6680932cf1245f3260347367030b49e8ca
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Mar 10 14:45:20 2011 +0100
made /network/systems/details/history/event.pxt work on postgresql
fixing
ERROR: syntax error at or near ")" at character 573
diff --git a/web/modules/rhn/RHN/DB/DataSource/xml/config_queries.xml
b/web/modules/rhn/RHN/DB/DataSource/xml/config_queries.xml
index 167d892..03044c7 100644
--- a/web/modules/rhn/RHN/DB/DataSource/xml/config_queries.xml
+++ b/web/modules/rhn/RHN/DB/DataSource/xml/config_queries.xml
@@ -130,17 +130,18 @@ SELECT CFN.path,
ACR.id AS ACTION_REVISION_ID,
CFF.name AS FAILURE_REASON,
rhn_config_channel.action_diff_revision_status(ACR.id) AS STATUS
- FROM rhnConfigFileFailure CFF,
+ FROM
rhnConfigFileName CFN,
rhnConfigFile CF,
rhnConfigRevision CR,
rhnActionConfigRevision ACR
+ LEFT JOIN rhnConfigFileFailure CFF
+ ON ACR.failure_id = CFF.id
WHERE ACR.action_id = :aid
AND ACR.server_id = :sid
AND ACR.config_revision_id = CR.id
AND CR.config_file_id = CF.id
AND CF.config_file_name_id = CFN.id
- AND ACR.failure_id = CFF.id (+)
ORDER BY UPPER(CFN.path)
</query>
</mode>