Project

General

Profile

Bug #17463

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

Added by Tomáš Strachota over 3 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Category:
Puppet integration
Target version:
Difficulty:
Triaged:
Bugzilla link:

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 orgs/locations are disabledClosed2017-03-23
Related to Foreman - Bug #18996: User#visible_environments limits to misspelt "view_environemnts" permissionsClosed2017-03-23
Related to Foreman - Bug #20340: Updating puppet environment which is not associated with organization creates internal server errorResolved2017-07-19
Related to Foreman - Bug #20418: Set proper taxonomy scope when importing puppet classesClosed2017-07-26
Related to Katello - Bug #19338: CV publishing with puppet module does not add puppet classClosed2017-04-20
Related to Foreman - Bug #21503: Importing puppet classes fails when switching to different orgClosed2017-10-30

Associated revisions

Revision 273f928c (diff)
Added by Ondřej Pražák over 3 years ago

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

Revision 55c37b71 (diff)
Added by Dominic Cleal over 3 years ago

refs #17463 - require test helper for smart proxy mixin

History

#1 Updated by Ondřej Pražák over 3 years ago

  • Assignee set to Ondřej Pražák

#2 Updated by The Foreman Bot over 3 years ago

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

#3 Updated by Anonymous over 3 years ago

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

#4 Updated by The Foreman Bot over 3 years ago

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

#5 Updated by Dominic Cleal over 3 years ago

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

#6 Updated by Dominic Cleal over 3 years ago

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

#7 Updated by Ohad Levy over 3 years ago

  • Legacy Backlogs Release (now unused) set to 209

#8 Updated by Marek Hulán almost 3 years ago

  • Related to Bug #20340: Updating puppet environment which is not associated with organization creates internal server error added

#9 Updated by Ondřej Pražák almost 3 years ago

  • Related to Bug #20418: Set proper taxonomy scope when importing puppet classes added

#10 Updated by Ondřej Pražák almost 3 years ago

  • Related to Bug #19338: CV publishing with puppet module does not add puppet class added

#11 Updated by Ondřej Pražák over 2 years ago

  • Related to Bug #21503: Importing puppet classes fails when switching to different org added

Also available in: Atom PDF