Login
Log in using an SSO provider:
Fedora Account System
Red Hat Associate
Red Hat Customer
Login using a Red Hat Bugzilla account
Forgot Password
Create an Account
Red Hat Bugzilla – Attachment 301932 Details for
Bug 406261
3.16: Bugzilla/SanityCheck.pm
Home
New
Search
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh90 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
[?]
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
patch to enable specific sanitychecks and diff checks in sanitycheck.cgi and sanitycheck.pl
sanitycheck_patch (text/plain), 35.00 KB, created by
Noura El hawary
on 2008-04-10 06:20:15 UTC
(
hide
)
Description:
patch to enable specific sanitychecks and diff checks in sanitycheck.cgi and sanitycheck.pl
Filename:
MIME Type:
Creator:
Noura El hawary
Created:
2008-04-10 06:20:15 UTC
Size:
35.00 KB
patch
obsolete
>Index: sanitycheck.cgi >=================================================================== >RCS file: /cvs/qa/rh_bugzilla_3/sanitycheck.cgi,v >retrieving revision 1.2 >diff -p -u -r1.2 sanitycheck.cgi >--- sanitycheck.cgi 2 Apr 2008 18:48:27 -0000 1.2 >+++ sanitycheck.cgi 10 Apr 2008 06:07:41 -0000 >@@ -23,6 +23,7 @@ > # Max Kanat-Alexander <mkanat@bugzilla.org> > # Marc Schumann <wurblzap@gmail.com> > # Frédéric Buclin <LpSolit@gmail.com> >+# Noura Elhawary <nelhawar@redhat.com> > > use strict; > >@@ -96,6 +97,28 @@ unless (Bugzilla->usage_mode == USAGE_MO > || ThrowTemplateError($template->error()); > } > >+# check if any cgi params were set for specific checks >+# if not then all checks should run >+my $check_all = 1; >+ >+my @check_params = qw( >+ foreign_keys >+ profile_loginnames >+ keyword_cache >+ general_bug_check >+ control_values >+ unsent_emails >+ flag_check >+); >+for my $chk (@check_params) { >+ if ($cgi->param($chk)){ >+ $check_all = 0; >+ } >+} >+if ($check_all) { >+ $cgi->param($_, 1) foreach @check_params; >+} >+ > ########################################################################### > # Users with 'editkeywords' privs only can only check keywords. > ########################################################################### >@@ -390,124 +413,168 @@ sub CrossCheck { > } > } > >-CrossCheck('classifications', 'id', >- ['products', 'classification_id']); >- >-CrossCheck("keyworddefs", "id", >- ["keywords", "keywordid"]); >+if ($cgi->param('foreign_keys')) { >+ $cgi->param('output' , ''); >+ >+ CrossCheck('classifications', 'id', >+ ['products', 'classification_id']); >+ >+ CrossCheck("keyworddefs", "id", >+ ["keywords", "keywordid"]); >+ >+ CrossCheck("fielddefs", "id", >+ ["bugs_activity", "fieldid"], >+ ['profiles_activity', 'fieldid']); >+ >+ CrossCheck("flagtypes", "id", >+ ["flags", "type_id"], >+ ["flagexclusions", "type_id"], >+ ["flaginclusions", "type_id"]); >+ >+ CrossCheck("bugs", "bug_id", >+ ["bugs_activity", "bug_id"], >+ ["bug_group_map", "bug_id"], >+ ["attachments", "bug_id"], >+ ["cc", "bug_id"], >+ ["longdescs", "bug_id"], >+ ["dependencies", "blocked"], >+ ["dependencies", "dependson"], >+ ['flags', 'bug_id'], >+ ["votes", "bug_id"], >+ ["keywords", "bug_id"], >+ ["duplicates", "dupe_of", "dupe"], >+ ["duplicates", "dupe", "dupe_of"], >+ # REDHAT EXTENSION START 406261 >+ ["bz_it_map", "bz_id", "it_id"], >+ ["ext_bz_bug_map", "bug_id", "ext_bz_id"]); >+ # REDHAT EXTENSION END 406261 >+ >+ CrossCheck("groups", "id", >+ ["bug_group_map", "group_id"], >+ ['category_group_map', 'group_id'], >+ ["group_group_map", "grantor_id"], >+ ["group_group_map", "member_id"], >+ ["group_control_map", "group_id"], >+ ["namedquery_group_map", "group_id"], >+ ["user_group_map", "group_id"], >+ ["flagtypes", "grant_group_id"], >+ ["flagtypes", "request_group_id"], >+ # REDHAT EXTENSION START 406261 >+ ["flagtypes", "view_group_id"]); >+ # REDHAT EXTENSION END 406261 >+ >+ CrossCheck("namedqueries", "id", >+ ["namedqueries_link_in_footer", "namedquery_id"], >+ ["namedquery_group_map", "namedquery_id"], >+ ); >+ >+ CrossCheck("profiles", "userid", >+ ['profiles_activity', 'userid'], >+ ['profiles_activity', 'who'], >+ ['email_setting', 'user_id'], >+ ['profile_setting', 'user_id'], >+ ["bugs", "reporter", "bug_id"], >+ ["bugs", "assigned_to", "bug_id"], >+ ["bugs", "qa_contact", "bug_id"], >+ ["attachments", "submitter_id", "bug_id"], >+ ['flags', 'setter_id', 'bug_id'], >+ ['flags', 'requestee_id', 'bug_id'], >+ ["bugs_activity", "who", "bug_id"], >+ ["cc", "who", "bug_id"], >+ ['quips', 'userid'], >+ ["votes", "who", "bug_id"], >+ ["longdescs", "who", "bug_id"], >+ ["logincookies", "userid"], >+ ["namedqueries", "userid"], >+ ["namedqueries_link_in_footer", "user_id"], >+ ['series', 'creator', 'series_id'], >+ ["watch", "watcher"], >+ ["watch", "watched"], >+ ['whine_events', 'owner_userid'], >+ ["tokens", "userid"], >+ ["user_group_map", "user_id"], >+ ["components", "initialowner", "name"], >+ ["components", "initialqacontact", "name"], >+ ["component_cc", "user_id"]); >+ >+ CrossCheck("products", "id", >+ ["bugs", "product_id", "bug_id"], >+ ["components", "product_id", "name"], >+ ["milestones", "product_id", "value"], >+ ["versions", "product_id", "value"], >+ ["group_control_map", "product_id"], >+ ["flaginclusions", "product_id", "type_id"], >+ ["flagexclusions", "product_id", "type_id"]); >+ >+ CrossCheck("components", "id", >+ ["component_cc", "component_id"], >+ ["bugs", "component_id"], >+ ["flagexclusions", "component_id", "type_id"], >+ ["flaginclusions", "component_id", "type_id"]); >+ >+ # Check the former enum types -mkanat@bugzilla.org >+ CrossCheck("bug_status", "value", >+ ["bugs", "bug_status", "bug_id"]); >+ >+ CrossCheck("resolution", "value", >+ ["bugs", "resolution", "bug_id"]); >+ >+ CrossCheck("bug_severity", "value", >+ ["bugs", "bug_severity", "bug_id"]); >+ >+ CrossCheck("op_sys", "value", >+ ["bugs", "op_sys", "bug_id"]); >+ >+ CrossCheck("priority", "value", >+ ["bugs", "priority", "bug_id"]); >+ >+ CrossCheck("rep_platform", "value", >+ ["bugs", "rep_platform", "bug_id"]); >+ >+ CrossCheck('series', 'series_id', >+ ['series_data', 'series_id']); >+ >+ CrossCheck('series_categories', 'id', >+ ['series', 'category'], >+ ["category_group_map", "category_id"], >+ ["series", "subcategory", "name"]); >+ >+ # REDHAT EXTENSION START 406261 >+ CrossCheck("external_bugzilla", "id", >+ ["ext_bz_bug_map", "ext_bz_id", "bug_id"]); >+ # REDHAT EXTENSION END 406261 >+ >+ CrossCheck('whine_events', 'id', >+ ['whine_queries', 'eventid'], >+ ['whine_schedules', 'eventid']); >+ >+ CrossCheck('attachments', 'attach_id', >+ ['attach_data', 'id'], >+ ['bugs_activity', 'attach_id']); >+ >+ CrossCheck('bug_status', 'id', >+ ['status_workflow', 'old_status'], >+ ['status_workflow', 'new_status']); >+ >+ DoubleCrossCheck('attachments', 'bug_id', 'attach_id', >+ ['flags', 'bug_id', 'attach_id'], >+ ['bugs_activity', 'bug_id', 'attach_id']); >+ >+ DoubleCrossCheck("components", "product_id", "id", >+ ["bugs", "product_id", "component_id", "bug_id"], >+ ['flagexclusions', 'product_id', 'component_id'], >+ ['flaginclusions', 'product_id', 'component_id']); >+ >+ DoubleCrossCheck("versions", "product_id", "value", >+ ["bugs", "product_id", "version", "bug_id"]); >+ >+ DoubleCrossCheck("milestones", "product_id", "value", >+ ["bugs", "product_id", "target_milestone", "bug_id"], >+ ["products", "id", "defaultmilestone", "name"]); > >-CrossCheck("fielddefs", "id", >- ["bugs_activity", "fieldid"], >- ['profiles_activity', 'fieldid']); >- >-CrossCheck("flagtypes", "id", >- ["flags", "type_id"]); >- >-CrossCheck("bugs", "bug_id", >- ["bugs_activity", "bug_id"], >- ["bug_group_map", "bug_id"], >- ["attachments", "bug_id"], >- ["cc", "bug_id"], >- ["longdescs", "bug_id"], >- ["dependencies", "blocked"], >- ["dependencies", "dependson"], >- ['flags', 'bug_id'], >- ["votes", "bug_id"], >- ["keywords", "bug_id"], >- ["duplicates", "dupe_of", "dupe"], >- ["duplicates", "dupe", "dupe_of"]); >- >-CrossCheck("groups", "id", >- ["bug_group_map", "group_id"], >- ['category_group_map', 'group_id'], >- ["group_group_map", "grantor_id"], >- ["group_group_map", "member_id"], >- ["group_control_map", "group_id"], >- ["namedquery_group_map", "group_id"], >- ["user_group_map", "group_id"]); >- >-CrossCheck("namedqueries", "id", >- ["namedqueries_link_in_footer", "namedquery_id"], >- ["namedquery_group_map", "namedquery_id"], >- ); >- >-CrossCheck("profiles", "userid", >- ['profiles_activity', 'userid'], >- ['profiles_activity', 'who'], >- ['email_setting', 'user_id'], >- ['profile_setting', 'user_id'], >- ["bugs", "reporter", "bug_id"], >- ["bugs", "assigned_to", "bug_id"], >- ["bugs", "qa_contact", "bug_id"], >- ["attachments", "submitter_id", "bug_id"], >- ['flags', 'setter_id', 'bug_id'], >- ['flags', 'requestee_id', 'bug_id'], >- ["bugs_activity", "who", "bug_id"], >- ["cc", "who", "bug_id"], >- ['quips', 'userid'], >- ["votes", "who", "bug_id"], >- ["longdescs", "who", "bug_id"], >- ["logincookies", "userid"], >- ["namedqueries", "userid"], >- ["namedqueries_link_in_footer", "user_id"], >- ['series', 'creator', 'series_id'], >- ["watch", "watcher"], >- ["watch", "watched"], >- ['whine_events', 'owner_userid'], >- ["tokens", "userid"], >- ["user_group_map", "user_id"], >- ["components", "initialowner", "name"], >- ["components", "initialqacontact", "name"], >- ["component_cc", "user_id"]); >- >-CrossCheck("products", "id", >- ["bugs", "product_id", "bug_id"], >- ["components", "product_id", "name"], >- ["milestones", "product_id", "value"], >- ["versions", "product_id", "value"], >- ["group_control_map", "product_id"], >- ["flaginclusions", "product_id", "type_id"], >- ["flagexclusions", "product_id", "type_id"]); >- >-CrossCheck("components", "id", >- ["component_cc", "component_id"]); >- >-# Check the former enum types -mkanat@bugzilla.org >-CrossCheck("bug_status", "value", >- ["bugs", "bug_status", "bug_id"]); >- >-CrossCheck("resolution", "value", >- ["bugs", "resolution", "bug_id"]); >- >-CrossCheck("bug_severity", "value", >- ["bugs", "bug_severity", "bug_id"]); >- >-CrossCheck("op_sys", "value", >- ["bugs", "op_sys", "bug_id"]); >- >-CrossCheck("priority", "value", >- ["bugs", "priority", "bug_id"]); >- >-CrossCheck("rep_platform", "value", >- ["bugs", "rep_platform", "bug_id"]); >- >-CrossCheck('series', 'series_id', >- ['series_data', 'series_id']); >- >-CrossCheck('series_categories', 'id', >- ['series', 'category']); >- >-CrossCheck('whine_events', 'id', >- ['whine_queries', 'eventid'], >- ['whine_schedules', 'eventid']); >- >-CrossCheck('attachments', 'attach_id', >- ['attach_data', 'id']); >- >-CrossCheck('bug_status', 'id', >- ['status_workflow', 'old_status'], >- ['status_workflow', 'new_status']); >+ $cgi->param('foreign_keys_report', $cgi->param('output')); > >+} > ########################################################################### > # Perform double field referential (cross) checks > ########################################################################### >@@ -566,41 +633,37 @@ sub DoubleCrossCheck { > } > } > >-DoubleCrossCheck('attachments', 'bug_id', 'attach_id', >- ['flags', 'bug_id', 'attach_id'], >- ['bugs_activity', 'bug_id', 'attach_id']); >- >-DoubleCrossCheck("components", "product_id", "id", >- ["bugs", "product_id", "component_id", "bug_id"], >- ['flagexclusions', 'product_id', 'component_id'], >- ['flaginclusions', 'product_id', 'component_id']); >- >-DoubleCrossCheck("versions", "product_id", "value", >- ["bugs", "product_id", "version", "bug_id"]); >- >-DoubleCrossCheck("milestones", "product_id", "value", >- ["bugs", "product_id", "target_milestone", "bug_id"], >- ["products", "id", "defaultmilestone", "name"]); >- > ########################################################################### > # Perform login checks > ########################################################################### > >-Status('profile_login_start'); >+if ($cgi->param('profile_loginnames')) { > >-my $sth = $dbh->prepare(q{SELECT userid, login_name FROM profiles}); >-$sth->execute; >+ $cgi->param('output', ''); > >-while (my ($id, $email) = $sth->fetchrow_array) { >- validate_email_syntax($email) >- || Status('profile_login_alert', {id => $id, email => $email}, 'alert'); >-} >+ Status('profile_login_start'); > >+ my $sth = $dbh->prepare(q{SELECT userid, login_name FROM profiles}); >+ $sth->execute; >+ >+ while (my ($id, $email) = $sth->fetchrow_array) { >+ validate_email_syntax($email) >+ || Status('profile_login_alert', {id => $id, email => $email}, 'alert'); >+ } >+ >+ $cgi->param('profile_loginnames_report', $cgi->param('output')); >+} > ########################################################################### > # Perform vote/keyword cache checks > ########################################################################### > >-check_votes_or_keywords(); >+if ($cgi->param('keyword_cache')) { >+ $cgi->param('output', ''); >+ >+ check_votes_or_keywords(); >+ >+ $cgi->param('keyword_cache_report', $cgi->param('output')); >+} > > sub check_votes_or_keywords { > my $check = shift || 'all'; >@@ -777,52 +840,57 @@ sub _check_keywords { > # Check for flags being in incorrect products and components > ########################################################################### > >-Status('flag_check_start'); >+if ($cgi->param('flag_check')) { > >-my $invalid_flags = $dbh->selectall_arrayref( >- 'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id >- FROM flags >- INNER JOIN bugs >- ON flags.bug_id = bugs.bug_id >- LEFT JOIN flaginclusions AS i >- ON flags.type_id = i.type_id >- AND (bugs.product_id = i.product_id OR i.product_id IS NULL) >- AND (bugs.component_id = i.component_id OR i.component_id IS NULL) >- WHERE i.type_id IS NULL'); >- >-my @invalid_flags = @$invalid_flags; >- >-$invalid_flags = $dbh->selectall_arrayref( >- 'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id >- FROM flags >- INNER JOIN bugs >- ON flags.bug_id = bugs.bug_id >- INNER JOIN flagexclusions AS e >- ON flags.type_id = e.type_id >- WHERE (bugs.product_id = e.product_id OR e.product_id IS NULL) >- AND (bugs.component_id = e.component_id OR e.component_id IS NULL)'); >- >-push(@invalid_flags, @$invalid_flags); >- >-if (scalar(@invalid_flags)) { >- if ($cgi->param('remove_invalid_flags')) { >- Status('flag_deletion_start'); >- my @flag_ids = map {$_->[0]} @invalid_flags; >- # Silently delete these flags, with no notification to requesters/setters. >- $dbh->do('DELETE FROM flags WHERE id IN (' . join(',', @flag_ids) .')'); >- Status('flag_deletion_end'); >- } >- else { >- foreach my $flag (@$invalid_flags) { >- my ($flag_id, $bug_id, $attach_id) = @$flag; >- Status('flag_alert', >- {flag_id => $flag_id, attach_id => $attach_id, bug_id => $bug_id}, >- 'alert'); >+ $cgi->param('output', ''); >+ >+ Status('flag_check_start'); >+ >+ my $invalid_flags = $dbh->selectall_arrayref( >+ 'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id >+ FROM flags >+ INNER JOIN bugs >+ ON flags.bug_id = bugs.bug_id >+ LEFT JOIN flaginclusions AS i >+ ON flags.type_id = i.type_id >+ AND (bugs.product_id = i.product_id OR i.product_id IS NULL) >+ AND (bugs.component_id = i.component_id OR i.component_id IS NULL) >+ WHERE i.type_id IS NULL'); >+ >+ my @invalid_flags = @$invalid_flags; >+ >+ $invalid_flags = $dbh->selectall_arrayref( >+ 'SELECT DISTINCT flags.id, flags.bug_id, flags.attach_id >+ FROM flags >+ INNER JOIN bugs >+ ON flags.bug_id = bugs.bug_id >+ INNER JOIN flagexclusions AS e >+ ON flags.type_id = e.type_id >+ WHERE (bugs.product_id = e.product_id OR e.product_id IS NULL) >+ AND (bugs.component_id = e.component_id OR e.component_id IS NULL)'); >+ >+ push(@invalid_flags, @$invalid_flags); >+ >+ if (scalar(@invalid_flags)) { >+ if ($cgi->param('remove_invalid_flags')) { >+ Status('flag_deletion_start'); >+ my @flag_ids = map {$_->[0]} @invalid_flags; >+ # Silently delete these flags, with no notification to requesters/setters. >+ $dbh->do('DELETE FROM flags WHERE id IN (' . join(',', @flag_ids) .')'); >+ Status('flag_deletion_end'); >+ } >+ else { >+ foreach my $flag (@$invalid_flags) { >+ my ($flag_id, $bug_id, $attach_id) = @$flag; >+ Status('flag_alert', >+ {flag_id => $flag_id, attach_id => $attach_id, bug_id => $bug_id}, >+ 'alert'); >+ } >+ Status('flag_fix'); > } >- Status('flag_fix'); > } >+ $cgi->param('flag_check_report', 'output'); > } >- > ########################################################################### > # General bug checks > ########################################################################### >@@ -848,113 +916,134 @@ sub BugCheck { > } > } > >-Status('bug_check_creation_date'); >- >-BugCheck("bugs WHERE creation_ts IS NULL", 'bug_check_creation_date_error_text', >- 'repair_creation_date', 'bug_check_creation_date_repair_text'); >+if ($cgi->param('general_bug_check')) { >+ >+ $cgi->param('output', ''); >+ >+ Status('bug_check_creation_date'); > >-Status('bug_check_res_dupl'); >+ BugCheck("bugs WHERE creation_ts IS NULL", 'bug_check_creation_date_error_text', >+ 'repair_creation_date', 'bug_check_creation_date_repair_text'); > >-BugCheck("bugs INNER JOIN duplicates ON bugs.bug_id = duplicates.dupe " . >- "WHERE bugs.resolution != 'DUPLICATE'", 'bug_check_res_dupl_error_text'); >+ Status('bug_check_res_dupl'); > >-BugCheck("bugs LEFT JOIN duplicates ON bugs.bug_id = duplicates.dupe WHERE " . >- "bugs.resolution = 'DUPLICATE' AND " . >- "duplicates.dupe IS NULL", 'bug_check_res_dupl_error_text2'); >+ BugCheck("bugs INNER JOIN duplicates ON bugs.bug_id = duplicates.dupe " . >+ "WHERE bugs.resolution != 'DUPLICATE'", 'bug_check_res_dupl_error_text'); > >-Status('bug_check_status_res'); >+ BugCheck("bugs LEFT JOIN duplicates ON bugs.bug_id = duplicates.dupe WHERE " . >+ "bugs.resolution = 'DUPLICATE' AND " . >+ "duplicates.dupe IS NULL", 'bug_check_res_dupl_error_text2'); > >-my @open_states = map($dbh->quote($_), BUG_STATE_OPEN); >-my $open_states = join(', ', @open_states); >+ Status('bug_check_status_res'); > >-BugCheck("bugs WHERE bug_status IN ($open_states) AND resolution != ''", >- 'bug_check_status_res_error_text'); >-BugCheck("bugs WHERE bug_status NOT IN ($open_states) AND resolution = ''", >- 'bug_check_status_res_error_text2'); >+ my @open_states = map($dbh->quote($_), BUG_STATE_OPEN); >+ my $open_states = join(', ', @open_states); > >-Status('bug_check_status_everconfirmed'); >+ BugCheck("bugs WHERE bug_status IN ($open_states) AND resolution != ''", >+ 'bug_check_status_res_error_text'); >+ BugCheck("bugs WHERE bug_status NOT IN ($open_states) AND resolution = ''", >+ 'bug_check_status_res_error_text2'); > >-BugCheck("bugs WHERE bug_status = 'UNCONFIRMED' AND everconfirmed = 1", >- 'bug_check_status_everconfirmed_error_text'); >+ Status('bug_check_status_everconfirmed'); > >-my @confirmed_open_states = grep {$_ ne 'UNCONFIRMED'} BUG_STATE_OPEN; >-my $confirmed_open_states = join(', ', map {$dbh->quote($_)} @confirmed_open_states); >+ BugCheck("bugs WHERE bug_status = 'UNCONFIRMED' AND everconfirmed = 1", >+ 'bug_check_status_everconfirmed_error_text'); > >-BugCheck("bugs WHERE bug_status IN ($confirmed_open_states) AND everconfirmed = 0", >- 'bug_check_status_everconfirmed_error_text2'); >+ my @confirmed_open_states = grep {$_ ne 'UNCONFIRMED'} BUG_STATE_OPEN; >+ my $confirmed_open_states = join(', ', map {$dbh->quote($_)} @confirmed_open_states); > >-Status('bug_check_votes_everconfirmed'); >+ BugCheck("bugs WHERE bug_status IN ($confirmed_open_states) AND everconfirmed = 0", >+ 'bug_check_status_everconfirmed_error_text2'); > >-BugCheck("bugs INNER JOIN products ON bugs.product_id = products.id " . >- "WHERE everconfirmed = 0 AND votestoconfirm <= votes", >- 'bug_check_votes_everconfirmed_error_text'); >+ Status('bug_check_votes_everconfirmed'); > >+ BugCheck("bugs INNER JOIN products ON bugs.product_id = products.id " . >+ "WHERE everconfirmed = 0 AND votestoconfirm <= votes", >+ 'bug_check_votes_everconfirmed_error_text'); >+ >+ $cgi->param('general_bug_check_report', $cgi->param('output')); >+} > ########################################################################### > # Control Values > ########################################################################### > >-# Checks for values that are invalid OR >-# not among the 9 valid combinations >-Status('bug_check_control_values'); >-my $groups = join(", ", (CONTROLMAPNA, CONTROLMAPSHOWN, CONTROLMAPDEFAULT, >-CONTROLMAPMANDATORY)); >-my $query = qq{ >- SELECT COUNT(product_id) >- FROM group_control_map >- WHERE membercontrol NOT IN( $groups ) >- OR othercontrol NOT IN( $groups ) >- OR ((membercontrol != othercontrol) >- AND (membercontrol != } . CONTROLMAPSHOWN . q{) >- AND ((membercontrol != } . CONTROLMAPDEFAULT . q{) >- OR (othercontrol = } . CONTROLMAPSHOWN . q{)))}; >- >-my $entries = $dbh->selectrow_array($query); >-Status('bug_check_control_values_alert', {entries => $entries}, 'alert') if $entries; >- >-Status('bug_check_control_values_violation'); >-BugCheck("bugs >- INNER JOIN bug_group_map >- ON bugs.bug_id = bug_group_map.bug_id >- LEFT JOIN group_control_map >- ON bugs.product_id = group_control_map.product_id >- AND bug_group_map.group_id = group_control_map.group_id >- WHERE ((group_control_map.membercontrol = " . CONTROLMAPNA . ") >- OR (group_control_map.membercontrol IS NULL))", >- 'bug_check_control_values_error_text', >- 'createmissinggroupcontrolmapentries', >- 'bug_check_control_values_repair_text'); >- >-BugCheck("bugs >- INNER JOIN group_control_map >- ON bugs.product_id = group_control_map.product_id >- INNER JOIN groups >- ON group_control_map.group_id = groups.id >- LEFT JOIN bug_group_map >- ON bugs.bug_id = bug_group_map.bug_id >- AND group_control_map.group_id = bug_group_map.group_id >- WHERE group_control_map.membercontrol = " . CONTROLMAPMANDATORY . " >- AND bug_group_map.group_id IS NULL >- AND groups.isactive != 0", >- 'bug_check_control_values_error_text2'); >+if ($cgi->param('control_values')) { >+ >+ $cgi->param('output', ''); >+ >+ # Checks for values that are invalid OR >+ # not among the 9 valid combinations >+ Status('bug_check_control_values'); >+ my $groups = join(", ", (CONTROLMAPNA, CONTROLMAPSHOWN, CONTROLMAPDEFAULT, >+ CONTROLMAPMANDATORY)); >+ my $query = qq{ >+ SELECT COUNT(product_id) >+ FROM group_control_map >+ WHERE membercontrol NOT IN( $groups ) >+ OR othercontrol NOT IN( $groups ) >+ OR ((membercontrol != othercontrol) >+ AND (membercontrol != } . CONTROLMAPSHOWN . q{) >+ AND ((membercontrol != } . CONTROLMAPDEFAULT . q{) >+ OR (othercontrol = } . CONTROLMAPSHOWN . q{)))}; >+ >+ my $entries = $dbh->selectrow_array($query); >+ Status('bug_check_control_values_alert', {entries => $entries}, 'alert') if $entries; >+ >+ Status('bug_check_control_values_violation'); >+ BugCheck("bugs >+ INNER JOIN bug_group_map >+ ON bugs.bug_id = bug_group_map.bug_id >+ LEFT JOIN group_control_map >+ ON bugs.product_id = group_control_map.product_id >+ AND bug_group_map.group_id = group_control_map.group_id >+ WHERE ((group_control_map.membercontrol = " . CONTROLMAPNA . ") >+ OR (group_control_map.membercontrol IS NULL))", >+ 'bug_check_control_values_error_text', >+ 'createmissinggroupcontrolmapentries', >+ 'bug_check_control_values_repair_text'); >+ >+ BugCheck("bugs >+ INNER JOIN group_control_map >+ ON bugs.product_id = group_control_map.product_id >+ INNER JOIN groups >+ ON group_control_map.group_id = groups.id >+ LEFT JOIN bug_group_map >+ ON bugs.bug_id = bug_group_map.bug_id >+ AND group_control_map.group_id = bug_group_map.group_id >+ WHERE group_control_map.membercontrol = " . CONTROLMAPMANDATORY . " >+ AND bug_group_map.group_id IS NULL >+ AND groups.isactive != 0", >+ 'bug_check_control_values_error_text2'); >+ >+ $cgi->param('control_values_report', $cgi->param('output')); >+} > > ########################################################################### > # Unsent mail > ########################################################################### > >-Status('unsent_bugmail_check'); >+if ($cgi->param('unsent_emails')) { >+ >+ $cgi->param('output' , ''); >+ >+ Status('unsent_bugmail_check'); > >-my $time = $dbh->sql_interval(30, 'MINUTE'); >-my $badbugs = $dbh->selectcol_arrayref(qq{ >- SELECT bug_id >- FROM bugs >- WHERE (lastdiffed IS NULL OR lastdiffed < delta_ts) >- AND delta_ts < now() - $time >- ORDER BY bug_id}); >+ my $time = $dbh->sql_interval(30, 'MINUTE'); >+ my $badbugs = $dbh->selectcol_arrayref(qq{ >+ SELECT bug_id >+ FROM bugs >+ WHERE (lastdiffed IS NULL OR lastdiffed < delta_ts) >+ AND delta_ts < now() - $time >+ ORDER BY bug_id}); >+ >+ >+ if (scalar(@$badbugs > 0)) { >+ Status('unsent_bugmail_alert', {badbugs => $badbugs}, 'alert'); >+ Status('unsent_bugmail_fix'); >+ } > >+ $cgi->param('unsent_emails_report', $cgi->param('output')); > >-if (scalar(@$badbugs > 0)) { >- Status('unsent_bugmail_alert', {badbugs => $badbugs}, 'alert'); >- Status('unsent_bugmail_fix'); > } > > ########################################################################### >Index: sanitycheck.pl >=================================================================== >RCS file: /cvs/qa/rh_bugzilla_3/sanitycheck.pl,v >retrieving revision 1.2 >diff -p -u -r1.2 sanitycheck.pl >--- sanitycheck.pl 31 Jan 2008 17:48:09 -0000 1.2 >+++ sanitycheck.pl 10 Apr 2008 06:07:50 -0000 >@@ -18,6 +18,7 @@ > # Frédéric Buclin. All Rights Reserved. > # > # Contributor(s): Frédéric Buclin <LpSolit@gmail.com> >+# Noura Elhawary <nelhawar@redhat.com> > > use strict; > >@@ -32,49 +33,157 @@ use Bugzilla::Mailer; > use Getopt::Long; > use Pod::Usage; > >-my $verbose = 0; # Return all comments if true, else errors only. >+use English qw( -no_match_vars ); >+use Text::Diff; >+ >+my $verbose = 0; # Return all comments if true, else errors only. > my $login = ''; # Login name of the user which is used to call sanitycheck.cgi. >-my $help = 0; # Has user asked for help on this script? >+my $help = 0; # Has user asked for help on this script? >+ >+my %options = ( 'verbose' => \$verbose, 'login' => \$login, 'help' => \$help ); > >-my $result = GetOptions('verbose' => \$verbose, >- 'login=s' => \$login, >- 'help|h|?' => \$help); >+my @OptionDefs = ( >+ 'foreign_keys', 'profile_loginnames', >+ 'keyword_cache', 'general_bug_check', >+ 'control_values', 'unsent_emails', >+ 'flag_check', 'diff_report' >+); >+ >+# check options >+my @Checks = qw( >+ foreign_keys >+ profile_loginnames >+ keyword_cache >+ general_bug_check >+ control_values >+ unsent_emails >+ flag_check >+); > >-pod2usage({-verbose => 1, -exitval => 1}) if $help; >+GetOptions( \%options, 'verbose', 'login=s', 'help|h|?', @OptionDefs ); >+ >+pod2usage( { -verbose => 1, -exitval => 1 } ) if $help; > > Bugzilla->usage_mode(USAGE_MODE_CMDLINE); > > # Be sure a login name if given. > $login || ThrowUserError('invalid_username'); > >-my $user = new Bugzilla::User({ name => $login }) >- || ThrowUserError('invalid_username', { name => $login }); >+my $user = new Bugzilla::User( { name => $login } ) >+ || ThrowUserError( 'invalid_username', { name => $login } ); > >-my $cgi = Bugzilla->cgi; >+my $cgi = Bugzilla->cgi; > my $template = Bugzilla->template; > > # Authenticate using this user account. > Bugzilla->set_user($user); > >-# Pass this param to sanitycheck.cgi. >-$cgi->param('verbose', $verbose); >+# build check list >+my @checks; >+for my $check (@Checks) { >+ if ( $options{$check} ) { >+ $cgi->param( $check, 1 ); >+ push @checks, $check; >+ } >+} >+ >+# if no checks given on command line then assume all checks >+if ( @checks == 0 ) { >+ push @checks, @Checks; >+ $cgi->param( $_, 1 ) foreach @checks; >+} > >+# run checks and report >+my $msg_body = ''; # accumulate check reports here >+ >+# Pass this param to sanitycheck.cgi. >+$cgi->param( 'verbose', $verbose ); > require 'sanitycheck.cgi'; > >-# Now it's time to send an email to the user if there is something to notify. >-if ($cgi->param('output')) { >+for my $check (@checks) { >+ >+ my $out_rpt = $check . "_report"; >+ >+ # Now it's time to send an email to the user if there is something to notify. > my $message; > my $vars = {}; >- $vars->{'addressee'} = $user->email; >- $vars->{'output'} = $cgi->param('output'); >+ $vars->{'addressee'} = $user->email; >+ $vars->{'output'} = $cgi->param($out_rpt); > $vars->{'error_found'} = $cgi->param('error_found') ? 1 : 0; > >- $template->process('email/sanitycheck.txt.tmpl', $vars, \$message) >- || ThrowTemplateError($template->error()); >+ $template->process( 'email/sanitycheck.txt.tmpl', $vars, \$message ) >+ || ThrowTemplateError( $template->error() ); >+ >+ # full_report if given then report in case of FAIL or PASS >+ # otherwise only report in case of FAIL >+ if ( $options{diff_report} ) { >+ $msg_body .= create_diff_report( $check, $message ); >+ } >+ else { >+ $msg_body .= create_report( $check, $message ); >+ } >+} >+ >+if ( Bugzilla->params->{mail_delivery_method} eq 'None' ) { >+ print "$msg_body\n"; >+} >+else { >+ MessageToMTA($msg_body); >+} >+ >+# returns string report >+sub create_report { >+ my ( $check, $rpt ) = @_; >+ >+ my $check_rpt = >+ "Check: $check\n====================================" >+ . "===============================\n$rpt\n"; >+ >+ return $check_rpt; >+} >+ >+# returns empty string '' if no difference, otherwise a string representing the diff report >+sub create_diff_report { >+ my ( $check, $rpt ) = @_; >+ >+ my $report = create_report( $check, $rpt ); >+ >+ my $baseline_fn = $check . ".orig"; >+ >+ $baseline_fn = "data/sanitycheck/$baseline_fn"; >+ >+ if ( not -e $baseline_fn ) { >+ create_report_file( $baseline_fn, $report ); >+ return ''; >+ } >+ >+ # write the current report to a file to diff it against >+ # the baseline report >+ my $rpt_file = 'rpt_tmp_file'; >+ create_report_file( $rpt_file, $report ); >+ >+ my $diff = diff $baseline_fn, $rpt_file; > >- MessageToMTA($message); >+ if ($diff) { >+ return "Difference Check: $check\n" >+ . "===================================================================\n" >+ . "$diff\n\n"; >+ } >+ >+ unlink $rpt_file; >+ return ''; > } > >+sub create_report_file { >+ >+ my ( $file_name, $report ) = @_; >+ open my $FILE, ">", $file_name >+ or die "Couldn't open '$file_name' : $OS_ERROR"; >+ print {$FILE} $report >+ or die "Couldn't write to '$file_name': $OS_ERROR"; >+ close $FILE or die "Couldn't close '$file_name': $OS_ERROR"; >+ >+} > > __END__ > >@@ -86,6 +195,8 @@ sanitycheck.pl - Perl script to perform > > ./sanitycheck.pl [--help] > ./sanitycheck.pl [--verbose] --login <user@domain.com> >+ ./sanitycheck.pl [check_name] --login <user@domain.com> >+ ./sanitycheck.pl [check_name] [--diff_report] --login <user@domain.com> > > =head1 OPTIONS > >@@ -107,10 +218,70 @@ This should be passed the email address > running the Sanity Check process, a user with the editcomponents priv. This > user will receive an email with the results of the script run. > >+=item B<--diff_report> >+ >+Generates only diff report for checks by comparing freshly generated check report >+with stored report for that check. >+ >+=item B<check_name> >+ >+This can be any one of the following checknames or a combination of them: >+ >+=over >+ >+=item B<--foreign_keys> >+ >+Performs referential integrity checks (cross and double cross). >+ >+=item B<--profile_loginname> >+ >+Performs login email checks for format and lowercase. >+ >+=item B<--keyword_cache> >+ >+Performs vote/keyword cache checks. >+ >+=item B<--general_bug_check> >+ >+Performs general bug checks ex: resolutions, statuses etc. >+ >+=item B<--control_values> >+ >+Performs group control values are validation check. >+ >+=item B<--unsent_emails> >+ >+Performs checks for bugs that have changes but no mail sent for at least half an hour. >+ >+=item B<--flag_check> >+ >+Check for flags being in incorrect products and components. >+ >+=back >+ > =back > > =head1 DESCRIPTION > > This script provides a way of running a 'Sanity Check' on the database > via either a CLI or cron. It is equivalent to calling sanitycheck.cgi >-via a web broswer. >+via a web broswer with an extra feature for generating diff sanitycheck >+reports. If the user specified the checks they want to perform then only >+those checks will be performed, otherwise all checks will be performed. >+ >+The generated check reports can be of three types: >+ >+"full reports" >+ that include errors as well as successful checks, to get >+ those the --verbose option must be set. >+ >+"fail reports" >+ that include only errors in the reports, to get those >+ the --verbose must be ignored. >+ >+"diff reports" >+ to produce diff check reports. freshly generated reports >+ are diffed against original ones kept in the data/sanitycheck >+ dir and the result is the desired diff reports. to get those >+ the --diff_report option must be set. >+
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
dkl
: review-
nelhawar
: review? (
kbaker
)
Actions:
View
|
Diff
Attachments on
bug 406261
:
301931
|
301932
|
302299
|
302332
|
302410