Bug #19631
ActiveRecord::RecordNotSaved when deleting compute resources with key pairs
Description
Steps to Reproduce:
1.goto Infrastructure>Compute resources
2.Create EC2 compute resource
3.goto Infrastructure>Compute resources
4.delete the created compute resource
2017-05-23T11:30:56 24905450 [app] [I] Started DELETE "/compute_resources/6-ec2" for ::1 at 2017-05-23 11:30:56 +0000 2017-05-23T11:30:56 24905450 [app] [I] Processing by ComputeResourcesController#destroy as HTML 2017-05-23T11:30:56 24905450 [app] [I] Parameters: {"authenticity_token"=>"...", "id"=>"6-ec2"} 2017-05-23T11:30:56 24905450 [app] [I] Current user: admin (administrator) 2017-05-23T11:30:56 24905450 [app] [D] Setting current user thread-local variable to admin 2017-05-23T11:30:56 24905450 [app] [D] Setting current organization thread-local variable to none 2017-05-23T11:30:56 24905450 [app] [D] Setting current location thread-local variable to none 2017-05-23T11:30:56 24905450 [app] [I] removing EC2: ec2 key foreman-6532cca12-32bf-4841-b323-5d205e563e99 D, [2017-05-23T11:30:56.334010 #14496] DEBUG -- : String does not start with the prefix 'encrypted-', so Foreman::Model::EC2 ec2 was not decrypted 2017-05-23T11:30:56 24905450 [app] [D] String does not start with the prefix 'encrypted-', so Foreman::Model::EC2 ec2 was not decrypted 2017-05-23T11:30:57 24905450 [app] [I] Completed 422 Unprocessable Entity in 1251ms (ActiveRecord: 15.8ms) 2017-05-23T11:30:57 24905450 [app] [F] | ActiveRecord::RecordNotSaved (You cannot call create unless the parent is saved): | app/models/concerns/key_pair_compute_resource.rb:44:in `destroy_key_pair' | app/controllers/compute_resources_controller.rb:69:in `destroy' | app/controllers/concerns/application_shared.rb:15:in `set_timezone' | app/models/concerns/foreman/thread_session.rb:32:in `clear_thread' | app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller' | /home/vagrant/projects/katello/lib/katello/params_parser_wrapper.rb:12:in `call' | lib/middleware/catch_json_parse_errors.rb:8:in `call' | lib/middleware/tagged_logging.rb:18:in `call'
Related issues
Associated revisions
Fixes #19631 - ComputeResource with KeyPair can be removed
The concern for removing the compute resources with keypairs was trying
to destroy the compute resource too early. Also, this deletion already
happened because of the has_one :dependency => :destroy relation
This fixes the problem and adds tests to ensure the relation works.
(cherry picked from commit 91f8ffb1fbd210057fbdc9c4613c9805f62ea0ac)
History
#1
Updated by Ondřej Pražák almost 6 years ago
- Subject changed from Not able to delete EC2 compute resource to Not able to delete EC2 compute resource
- Category changed from VM management to Compute resources - EC2
- Target version set to 115
#2
Updated by Ondřej Pražák almost 6 years ago
- Priority changed from Normal to High
#3
Updated by Dominic Cleal almost 6 years ago
- Related to Feature #17015: Add ability to get private keys or use existing key pairs when provisioning on EC2 added
#4
Updated by Dominic Cleal almost 6 years ago
- Legacy Backlogs Release (now unused) set to 248
The CR's key pair concern appears to have changed in #17015 from calling .destroy to .destroy! on the key pair associated to the CR when the CR's destroyed. It could have been failing silently prior to this change. It is probably superfluous as the CR to key pair association has dependent => destroy.
Setting 1.15.1 release as it appears to be a regression.
#5
Updated by Dominic Cleal almost 6 years ago
- Subject changed from Not able to delete EC2 compute resource to ActiveRecord::RecordNotSaved when deleting compute resources with key pairs
- Category changed from Compute resources - EC2 to Compute resources
#6
Updated by The Foreman Bot almost 6 years ago
- Status changed from New to Ready For Testing
- Assignee set to Daniel Lobato Garcia
- Pull request https://github.com/theforeman/foreman/pull/4554 added
#7
Updated by Anonymous almost 6 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 91f8ffb1fbd210057fbdc9c4613c9805f62ea0ac.
#8
Updated by Anonymous about 5 years ago
- Related to Refactor #22938: test 'should remove the key pair on compute resource deletion' fails with Rails 5.2 added
Fixes #19631 - ComputeResource with KeyPair can be removed
The concern for removing the compute resources with keypairs was trying
to destroy the compute resource too early. Also, this deletion already
happened because of the has_one :dependency => :destroy relation
This fixes the problem and adds tests to ensure the relation works.