Bug 1945321

Summary: foreman-rake katello:correct_puppet_environments fails when trying to make changes
Product: Red Hat Satellite Reporter: Joniel Pasqualetto <jpasqual>
Component: Tasks PluginAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED DUPLICATE QA Contact: Peter Ondrejka <pondrejk>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.8.0CC: aruzicka, wpinheir
Target Milestone: Unspecified   
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-04-05 13:32:09 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joniel Pasqualetto 2021-03-31 16:37:31 UTC
Description of problem:
Running "foreman-rake katello:correct_puppet_environments" works fine (COMMIT=false is implicit), but when changing it to COMMIT=true it fails.


Version-Release number of selected component (if applicable):

Satellite 6.8

How reproducible:

Always

Steps to Reproduce:
1. Delete a repository on pulp, so there are changes to be made:
# pulp-admin puppet repo delete --repo-id 1-test2-v2_0-puppet-a968298d-b8f8-4daa-8f13-25c767521d3c
This command may be exited via ctrl+c without affecting the request.


[\]
Running...

Repository [1-test2-v2_0-puppet-a968298d-b8f8-4daa-8f13-25c767521d3c]
successfully deleted



2. Run the rake with commit=false:

~~~
# foreman-rake katello:correct_puppet_environments
All operations will be skipped.  Re-run with COMMIT=true to perform corrections.
Processing Puppet Environment 1/50: 1-RHEL7-v1_0-puppet-70fe1e72-5cf1-4667-b780-e0c1171a15fe (1)
Processing Puppet Environment 2/50: 1-RHEL8-v1_0-puppet-cf725cb1-7194-43b2-8046-3d34fe59b055 (2)
Processing Puppet Environment 3/50: 1-RHEL7-v2_0-puppet-391a7dde-3b44-4369-8533-d8e1141424be (3)

(...)

Processing Puppet Environment 50/50: 1-test2-v2_0-puppet-a968298d-b8f8-4daa-8f13-25c767521d3c (56)
Content View Puppet Environment 56 Missing, Creating.
~~~

See, that environment 56 is missing (the one I deleted on step 1):

3. Run it again with COMMIT=true:

~~~
# foreman-rake katello:correct_puppet_environments COMMIT=true
Processing Puppet Environment 1/50: 1-RHEL7-v1_0-puppet-70fe1e72-5cf1-4667-b780-e0c1171a15fe (1)
Processing Puppet Environment 2/50: 1-RHEL8-v1_0-puppet-cf725cb1-7194-43b2-8046-3d34fe59b055 (2)

(...)

Processing Puppet Environment 50/50: 1-test2-v2_0-puppet-a968298d-b8f8-4daa-8f13-25c767521d3c (56)
Content View Puppet Environment 56 Missing, Creating.
rake aborted!
The Dynflow world was not initialized yet. If your plugin uses it, make sure to call Rails.application.dynflow.require! in some initializer
/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.7/lib/dynflow/rails.rb:75:in `world'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-2.0.3/lib/foreman_tasks.rb:23:in `trigger'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-2.0.3/lib/foreman_tasks.rb:29:in `block in trigger_task'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-2.0.3/lib/foreman_tasks.rb:49:in `block in rails_safe_trigger_task'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-2.0.3/lib/foreman_tasks.rb:48:in `rails_safe_trigger_task'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-2.0.3/lib/foreman_tasks.rb:27:in `trigger_task'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-2.0.3/lib/foreman_tasks.rb:58:in `sync_task'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.16.0.18/lib/katello/tasks/repository.rake:157:in `handle_missing_puppet_env'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.16.0.18/lib/katello/tasks/repository.rake:80:in `block (3 levels) in <top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:70:in `block (2 levels) in find_each'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:70:in `each'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:70:in `block in find_each'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:136:in `block in find_in_batches'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:238:in `block in in_batches'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:222:in `loop'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:222:in `in_batches'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:135:in `find_in_batches'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/relation/batches.rb:69:in `find_each'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.16.0.18/lib/katello/tasks/repository.rake:77:in `with_index'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.16.0.18/lib/katello/tasks/repository.rake:77:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => katello:correct_puppet_environments
(See full trace by running task with --trace)

~~~

Actual results:

Rake fails and don't recreate the missing repository

Expected results:
Rake would recreate the missing repository

Additional info:

Comment 2 Joniel Pasqualetto 2021-03-31 16:55:46 UTC
Workaround:

Edit the file /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.16.0.18/lib/katello/tasks/repository.rake and look to line 71. Its content should be like below:

~~~
  task :correct_puppet_environments => ["environment", "check_ping"] do
~~~

Change it to:

~~~
  task :correct_puppet_environments => ["environment", "disable_dynflow", "check_ping"] do
~~~

Comment 3 Brad Buckingham 2021-04-05 13:32:09 UTC

*** This bug has been marked as a duplicate of bug 1908101 ***