The reports:expire doesn't work for ArfReport # foreman-rake reports:expire days=0 report_type="ForemanOpenscap::ArfReport" It produced a log D, [2018-06-18T15:39:52.098271 #6509] DEBUG -- : SQL (0.3ms) DELETE FROM "reports" WHERE "reports"."type" IN ('ForemanOpenscap::ArfReport') AND (1=0) AND (reports.created_at < '2018-06-18 10:09:52') I, [2018-06-18T15:39:52.098582 #6509] INFO -- : 2018-06-18 10:09:52 UTC: Expired 0 Foreman openscap/arf reports The above query has condition --> AND (1=0) Workaround: diff --git a/lib/tasks/reports.rake b/lib/tasks/reports.rake index fb4400d..e2b7cc2 100644 --- a/lib/tasks/reports.rake +++ b/lib/tasks/reports.rake @@ -30,8 +30,9 @@ namespace :reports do conditions = {} conditions[:timerange] = ENV['days'].to_i.days if ENV['days'] conditions[:status] = ENV['status'].to_i if ENV['status'] - - report_type.expire(conditions) + User.as_anonymous_admin do + report_type.expire(conditions) + end end end
Created redmine issue https://projects.theforeman.org/issues/24257 from this bug
Upstream bug assigned to mhulan
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/24257 has been resolved.
FailedQA Version tested: Satellite 6.5 snap 4 I see error on # foreman-rake reports:expire days=0 report_type="ForemanOpenscap::ArfReport" --trace /usr/share/foreman/lib/foreman.rb:8: warning: already initialized constant Foreman::UUID_REGEXP /usr/share/foreman/lib/foreman.rb:8: warning: previous definition of UUID_REGEXP was here ** Invoke reports:expire (first_time) ** Invoke environment (first_time) ** Execute environment /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/content_facet_host_extensions.rb:7: warning: already initialized constant Katello::Concerns::ContentFacetHostExtensions::ERRATA_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/content_facet_host_extensions.rb:7: warning: previous definition of ERRATA_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/content_facet_host_extensions.rb:14: warning: already initialized constant Katello::Concerns::ContentFacetHostExtensions::TRACE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/content_facet_host_extensions.rb:14: warning: previous definition of TRACE_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:13: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::SUBSCRIPTION_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:13: warning: previous definition of SUBSCRIPTION_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:21: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::SLA_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:21: warning: previous definition of SLA_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:26: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::USAGE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:26: warning: previous definition of USAGE_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:31: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::ROLE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:31: warning: previous definition of ROLE_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:36: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::ADDONS_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:36: warning: previous definition of ADDONS_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:41: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::PURPOSE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.9.0.rc2/app/models/katello/concerns/subscription_facet_host_extensions.rb:41: warning: previous definition of PURPOSE_STATUS_MAP was here ** Execute reports:expire rake aborted! TypeError: can't convert NilClass into time interval /usr/share/foreman/app/models/report.rb:99:in `sleep' /usr/share/foreman/app/models/report.rb:99:in `block in expire' /usr/share/foreman/app/models/report.rb:82:in `loop' /usr/share/foreman/app/models/report.rb:82:in `expire' /usr/share/foreman/lib/tasks/reports.rake:39:in `block (3 levels) in <top (required)>' /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:100:in `as' /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:106:in `as_anonymous_admin' /usr/share/foreman/lib/tasks/reports.rake:38:in `block (2 levels) in <top (required)>' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:251:in `each' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain' /opt/rh/rh-ruby25/root/usr/share/ruby/monitor.rb:226:in `mon_synchronize' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:188:in `invoke_with_call_chain' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:116:in `each' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/lib/rake/application.rb:80:in `run' /opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/exe/rake:27:in `<top (required)>' /opt/rh/rh-ruby25/root/usr/bin/rake:23:in `load' /opt/rh/rh-ruby25/root/usr/bin/rake:23:in `<main>' Tasks: TOP => reports:expire
ok, this looks as unrelated issue, easy workaround should be just putting sleep_time=0 to command line, valid bug though
This has been fixed by https://projects.theforeman.org/issues/24900 and just needs to be cherry-picked
VERIFIED Version tested: Satellite 6.5.0 snap 12 # foreman-rake reports:expire days=0 report_type="ForemanOpenscap::ArfReport" --trace /usr/share/foreman/lib/foreman.rb:8: warning: already initialized constant Foreman::UUID_REGEXP /usr/share/foreman/lib/foreman.rb:8: warning: previous definition of UUID_REGEXP was here ** Invoke reports:expire (first_time) ** Invoke environment (first_time) ** Execute environment /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/content_facet_host_extensions.rb:7: warning: already initialized constant Katello::Concerns::ContentFacetHostExtensions::ERRATA_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/content_facet_host_extensions.rb:7: warning: previous definition of ERRATA_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/content_facet_host_extensions.rb:14: warning: already initialized constant Katello::Concerns::ContentFacetHostExtensions::TRACE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/content_facet_host_extensions.rb:14: warning: previous definition of TRACE_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:13: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::SUBSCRIPTION_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:13: warning: previous definition of SUBSCRIPTION_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:21: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::SLA_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:21: warning: previous definition of SLA_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:26: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::USAGE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:26: warning: previous definition of USAGE_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:31: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::ROLE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:31: warning: previous definition of ROLE_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:36: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::ADDONS_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:36: warning: previous definition of ADDONS_STATUS_MAP was here /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:41: warning: already initialized constant Katello::Concerns::SubscriptionFacetHostExtensions::PURPOSE_STATUS_MAP /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.10.0.12/app/models/katello/concerns/subscription_facet_host_extensions.rb:41: warning: previous definition of PURPOSE_STATUS_MAP was here ** Execute reports:expire 2019-01-25T06:23:53 [I|app|] Starting Foreman openscap/arf reports expiration before 2019-01-25 11:23:53 status not set batch size 1000 sleep 0.2 2019-01-25T06:23:53 [I|app|] Expired 646 Foreman openscap/arf reports at rate 2385 rec/sec 2019-01-25T06:23:54 [I|app|] Total Foreman openscap/arf reports expired: 646, duration: 0 min(s) 2019-01-25T06:30:57 [I|app|] Starting Foreman openscap/arf reports expiration before 2019-01-25 11:30:57 status not set batch size 1000 sleep 0.2 2019-01-25T06:30:57 [D|sql|] (0.3ms) BEGIN 2019-01-25T06:30:57 [D|sql|] (1.0ms) SELECT "reports"."id" FROM "reports" WHERE "reports"."type" IN ('ForemanOpenscap::ArfReport') AND (created_at < '2019-01-25 11:30:57') LIMIT $1 [["LIMIT", 1000]] 2019-01-25T06:30:57 [D|sql|] (0.3ms) COMMIT
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2019:1222