Bug #17463

Importing classes for a new org fails when the environment already exist in a different org

Added by Tomáš Strachota 6 months ago. Updated about 1 month ago.

Status:Closed
Priority:Normal
Assigned To:Ondřej Pražák
Category:Puppet integration
Target version:Team Marek backlog
Difficulty: Bugzilla link:1246865
Found in release: Pull request:https://github.com/theforeman/foreman/pull/4371, https://github.com/theforeman/foreman/pull/4242
Story points-
Velocity based estimate-
Release1.15.0Release relationshipAuto

Description

Steps to reproduce:

  1. import classes in the default organization
  2. create a new organization B
  3. create a new user "john", assign him only to organization B
  4. run: hammer -u john proxy import-classes --id 1

The import currently fails with:

# hammer -u john proxy import-classes --id 1
Import of puppet classes failed:
  Validation failed: Organization ids Invalid organizations selection, you must select at least one of yours, Name has already been taken

Importing classes for a specific environment works fine (hammer -u john proxy import-classes --id 1 --environment production).

Expected results:
The api should automatically select user's orgs and import environments and classes for all of them. The api (and hammer) should also provide a parameter for selecting specific organization(s) for the import.

Additional info:
Relevant part of server log:

2016-11-23T12:03:31 5257aa7d [app] [I] Processing by Api::V2::SmartProxiesController#import_puppetclasses as JSON                                           
2016-11-23T12:03:31 5257aa7d [app] [I]   Parameters: {"dryrun"=>false, "apiv"=>"v2", "environment_id"=>"1", "id"=>"1", "smart_proxy"=>{}}
2016-11-23T12:03:31 5257aa7d [app] [I] Authorized user john(john)
2016-11-23T12:03:32 5257aa7d [app] [I] Completed 200 OK in 587ms (Views: 0.2ms | ActiveRecord: 32.6ms)
2016-11-23T12:03:39 923d3497 [app] [I] Started POST "/api/smart_proxies/1/import_puppetclasses" for fe80::5054:ff:fef5:1b57 at 2016-11-23 12:03:39 +0000    
2016-11-23T12:03:39 923d3497 [app] [I] Processing by Api::V2::SmartProxiesController#import_puppetclasses as JSON                                           
2016-11-23T12:03:39 923d3497 [app] [I]   Parameters: {"dryrun"=>false, "apiv"=>"v2", "id"=>"1", "smart_proxy"=>{}}
2016-11-23T12:03:39 923d3497 [app] [I] Authorized user john(john)
2016-11-23T12:03:41 923d3497 [app] [W] Action failed                                                                                                        
 | ActiveRecord::RecordInvalid: Validation failed: Organization ids Invalid organizations selection, you must select at least one of yours, Name has already been taken                                                                                                                                                 
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/validations.rb:79:in `raise_record_invalid'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/validations.rb:43:in `save!'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:291:in `block in save!'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:220:in `transaction'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:291:in `save!'
 | /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/persistence.rb:51:in `create!'
 | /root/foreman/foreman/app/services/puppet_class_importer.rb:269:in `find_or_create_env'
 | /root/foreman/foreman/app/services/puppet_class_importer.rb:192:in `add_classes_to_foreman'
 | /root/foreman/foreman/app/services/puppet_class_importer.rb:59:in `block in obsolete_and_new'
 | /root/foreman/foreman/app/services/puppet_class_importer.rb:57:in `each'
 | /root/foreman/foreman/app/services/puppet_class_importer.rb:57:in `obsolete_and_new'
 | /root/foreman/foreman/app/controllers/concerns/api/import_puppetclasses_common_controller.rb:42:in `import_puppetclasses'
 ...
2016-11-23T12:03:41 923d3497 [app] [I]   Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (0.6ms)
2016-11-23T12:03:41 923d3497 [app] [I] Completed 500 Internal Server Error in 2183ms (Views: 2.3ms | ActiveRecord: 33.4ms)


Related issues

Related to Foreman - Bug #18995: Puppet class import removes existing environments when or... Closed 03/23/2017
Related to Foreman - Bug #18996: User#visible_environments limits to misspelt "view_enviro... Closed 03/23/2017

Associated revisions

Revision 273f928c
Added by Ondřej Pražák 2 months ago

Fixes #17463 - Detect user's orgs when importing from puppet

Revision 55c37b71
Added by Dominic Cleal 2 months ago

refs #17463 - require test helper for smart proxy mixin

History

#1 Updated by Ondřej Pražák 4 months ago

  • Assigned To set to Ondřej Pražák

#2 Updated by The Foreman Bot 4 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4242 added

#3 Updated by Anonymous 2 months ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#4 Updated by The Foreman Bot 2 months ago

  • Pull request https://github.com/theforeman/foreman/pull/4371 added

#5 Updated by Dominic Cleal 2 months ago

  • Related to Bug #18995: Puppet class import removes existing environments when orgs/locations are disabled added

#6 Updated by Dominic Cleal 2 months ago

  • Related to Bug #18996: User#visible_environments limits to misspelt "view_environemnts" permissions added

#7 Updated by Ohad Levy about 1 month ago

  • Release set to 1.15.0

Also available in: Atom PDF