Actions
Bug #17463
closedImporting classes for a new org fails when the environment already exist in a different org
Difficulty:
Triaged:
Bugzilla link:
Description
Steps to reproduce:
- import classes in the default organization
- create a new organization B
- create a new user "john", assign him only to organization B
- 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)
Actions