Bug #20365
openec2 key pair recreation does not work
Description
irb(main):001:0> ComputeResource.find_by(:name => 'EC2 jenkins').recreate
2017-07-20T14:24:13 [app] [I] removing key from compute resource EC2 jenkins (EC2): foreman-6e7770f50-c23f-471e-9d3d-c2939796e4d7
2017-07-20T14:24:15 [app] [W] Failed to generate key pair
| ActiveRecord::RecordInvalid: Validation failed: »Compute resource« has already been taken
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/validations.rb:79:in `raise_record_invalid'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/validations.rb:43:in `save!'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:291:in `block in save!'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:220:in `transaction'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:291:in `save!'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/persistence.rb:51:in `create!'
| /Users/f0218175/foremandev/foreman/app/models/concerns/key_pair_compute_resource.rb:43:in `setup_key_pair'
| /Users/f0218175/foremandev/foreman/app/models/concerns/key_pair_compute_resource.rb:23:in `recreate'
| (irb):1:in `irb_binding'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/workspace.rb:87:in `eval'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/workspace.rb:87:in `evaluate'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/context.rb:380:in `evaluate'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb.rb:489:in `block (2 levels) in eval_input'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb.rb:623:in `signal_status'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb.rb:486:in `block in eval_input'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/ruby-lex.rb:246:in `block (2 levels) in each_top_level_statement'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `loop'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `catch'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `each_top_level_statement'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb.rb:485:in `eval_input'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb.rb:395:in `block in start'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb.rb:394:in `catch'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/irb.rb:394:in `start'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/commands/console.rb:110:in `start'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/commands/console.rb:9:in `start'
| /Users/f0218175/foremandev/foreman/lib/tasks/console.rake:8:in `block in <top (required)>'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
| /Users/f0218175/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/rake:23:in `load'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/rake:23:in `<main>'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `eval'
| /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `<main>'
2017-07-20T14:24:15 [app] [I] removing key from compute resource EC2 jenkins (EC2): foreman-6e7770f50-c23f-471e-9d3d-c2939796e4d7
ActiveRecord::RecordInvalid: Validation failed: »Compute resource« has already been taken
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/validations.rb:79:in `raise_record_invalid'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/validations.rb:43:in `save!'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:291:in `block in save!'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:220:in `transaction'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/transactions.rb:291:in `save!'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/activerecord-4.2.9/lib/active_record/persistence.rb:51:in `create!'
from /Users/f0218175/foremandev/foreman/app/models/concerns/key_pair_compute_resource.rb:43:in `setup_key_pair'
from /Users/f0218175/foremandev/foreman/app/models/concerns/key_pair_compute_resource.rb:23:in `recreate'
from (irb):1
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/commands/console.rb:110:in `start'
... 7 levels...
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/rake:23:in `load'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/rake:23:in `<main>'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `eval'
from /Users/f0218175/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `<main>'