Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1357583 - After converting host from discovered to managed, calling save! on the host does not persist the conversion
Summary: After converting host from discovered to managed, calling save! on the host d...
Keywords:
Status: CLOSED DUPLICATE of bug 1347992
Alias: None
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Discovery Plugin
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified vote
Target Milestone: Unspecified
Assignee: Lukas Zapletal
QA Contact: Katello QA List
URL:
Whiteboard:
Depends On: 1359032
Blocks: rhci-common-installer
TreeView+ depends on / blocked
 
Reported: 2016-07-18 14:50 UTC by Fabian von Feilitzsch
Modified: 2016-09-22 11:11 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-09-22 11:11:53 UTC


Attachments (Terms of Use)

Description Fabian von Feilitzsch 2016-07-18 14:50:39 UTC
Description of problem:

This is a known interaction in Rails (< 4.1.6) between ActiveRecord::Base#becomes and ActiveRecord::Base#save!. The issue is that the save! call creates an UPDATE like this: 


    UPDATE "hosts" SET ... WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."id" = 18  [...]


The WHERE clause there matches nothing, because the record in the database still has a type of Host::Discovered. An UPDATE on an empty set doesn't raise an error, so execution continues, and the transaction is not rolled back. This means, if you convert a host from discovered to managed and then save! it inside a transaction, all of the SQL statements that handle deleting the discovered attributes, adding entries to hosts/puppetclasses/operating systems/hostgroups etc succeed, and at the end you are left with a broken discovered host with no attributes, that can't even be deleted because of database constraints.

This is only an issue in Rails versions <= 4.1.5, it was fixed with this commit in Rails 4.1.6: https://github.com/rails/rails/commit/257d65ed2ceb14dca6b1319355ed4f8a73540498 . Here is the associated issue: https://github.com/rails/rails/issues/14785

Version-Release number of selected component (if applicable):
6.2.0

How reproducible:
100%

Steps to Reproduce:
1. Create a discovered host
2. Inside a transaction
  a. Use the HostConverter.to_managed to convert the host from discovered to managed
  b. Call host.save!

Actual results:
After the transaction, the host is of type Host::Discovered, but its attributes have been nilled out. Hostgroups/puppetclasses/operating systems all have entries related to the discovered host, which prevents me from deleting it.

Expected results:
After the transaction, the host is of type Host::Managed

Additional info:
from foreman-rake console, I ran ActiveRecord::VERSION::STRING and it output "4.1.5". If we can bump up to any Rails version >= 4.1.6, this issue should go away without any additional work.

Comment 5 Lukas Zapletal 2016-07-22 06:52:43 UTC
Fabian, thanks for report and deep investigation.

We encountered similar problems in the upstream, we haven't figured out and we removed explicit transactions from the codebase as a result. Current stable version Foreman 1.12 does not have it, also we ship it against Rails 4.2.5.

But Satellite 6.2 is a different story. The explicit transaction removal patch did not make it there yet and we still use Rails 4.1.5 version which is affected as you found out. Therefore Satellite 6.2 is affected and we need to handle this.

Comment 8 Lukas Zapletal 2016-09-22 11:11:53 UTC
Transaction were removed in 6.2.1.

*** This bug has been marked as a duplicate of bug 1347992 ***


Note You need to log in before you can comment on or make changes to this bug.