backend/server/action_extra_data/scap.py | 40 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-)
New commits: commit 551d93c71d1b037b4711c1a9e51ca79b7f222df4 Author: Simon Lukasik slukasik@redhat.com Date: Thu Mar 29 15:25:23 2012 +0200
Truncate data which are longer than db allows
While this kind of problems should be rare enough given the limits, it should definitelly not end up as ISE.
Addressing: SQLError: (12899, 'ORA-12899: value too large for column "SPACEWALK"."RHNXCCDFIDENT"."IDENTIFIER" (actual: 83, maximum: 80)\n ORA-06512: at "SPACEWALK.INSERT_XCCDF_IDENT", line 7\nORA-06512: at "SPACEWALK.LOOKUP_XCCDF_IDENT", line 32\n ORA-01403: no data found\n', 'insert into rhnXccdfRuleIdentMap (rresult_id, ident_id) values ( :rr_id, lookup_xccdf_ident(:system, :ident) )')
diff --git a/backend/server/action_extra_data/scap.py b/backend/server/action_extra_data/scap.py index e21cc10..b4329b6 100644 --- a/backend/server/action_extra_data/scap.py +++ b/backend/server/action_extra_data/scap.py @@ -54,20 +54,29 @@ def _process_testresult(tr, server_id, action_id, benchmark, profile, errors): h = rhnSQL.prepare(_query_insert_tresult, blob_map={'errors': 'errors'}) h.execute(server_id=server_id, action_id=action_id, - bench_id=benchmark.getAttribute('id'), - bench_version=benchmark.getAttribute('version'), + bench_id=_truncate(benchmark.getAttribute('id'), 120), + bench_version=_truncate(benchmark.getAttribute('version'), 80), profile_id=profile.getAttribute('id'), - profile_title=profile.getAttribute('title'), - identifier=tr.getAttribute('id'), + profile_title=_truncate(profile.getAttribute('title'), 120), + identifier=_truncate(tr.getAttribute('id'), 120), start_time=start_time.replace('T',' '), end_time=tr.getAttribute('end-time').replace('T', ' '), errors=errors ) h = rhnSQL.prepare(_query_get_tresult) h.execute(server_id=server_id, action_id=action_id) - _process_ruleresults(h.fetchone()[0], tr) + testresult_id = h.fetchone()[0] + if not _process_ruleresults(testresult_id, tr): + h = rhnSQL.prepare(_query_update_errors, blob_map={'errors': 'errors'}) + h.execute(testresult_id=testresult_id, + errors=errors + + '\nSome text strings were truncated when saving to the database.') + +truncated = False
def _process_ruleresults(testresult_id, tr): + global truncated + truncated = False inserts = {'rr_id': [], 'system': [], 'ident': []} for result in tr.childNodes: for rr in result.childNodes: @@ -75,12 +84,20 @@ def _process_ruleresults(testresult_id, tr):
inserts['rr_id'].append(rr_id) inserts['system'].append('#IDREF#') - inserts['ident'].append(rr.getAttribute('id')) + inserts['ident'].append(_truncate(rr.getAttribute('id'), 100)) for ident in rr.childNodes: inserts['rr_id'].append(rr_id) - inserts['system'].append(ident.getAttribute('system')) - inserts['ident'].append(_get_text(ident)) + inserts['system'].append(_truncate(ident.getAttribute('system'), 80)) + inserts['ident'].append(_truncate(_get_text(ident), 100)) _store_idents(inserts) + return not truncated + +def _truncate(string, max_len): + global truncated + if len(string) > max_len: + truncated = True + return string[:max_len-3] + "..." + return string
def _create_rresult(testresult_id, result_label): rr_id = rhnSQL.Sequence("rhn_xccdf_rresult_id_seq")() @@ -163,3 +180,10 @@ values ( lookup_xccdf_ident(:system, :ident) ) """) + +_query_update_errors = rhnSQL.Statement(""" +update rhnXccdfTestresult +set errors = :errors +where id = :testresult_id +""") +
spacewalk-commits@lists.fedorahosted.org