Bug 1432775

Summary: host never leaves build mode when token expires during build
Product: Red Hat Satellite Reporter: Evgeni Golov <egolov>
Component: ProvisioningAssignee: Dmitri Dolguikh <ddolguik>
Status: CLOSED ERRATA QA Contact: Peter Ondrejka <pondrejk>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.2.8CC: dmitri, inecas, jcallaha, mtenheuv, oshtaier, tbrisker
Target Milestone: 6.4.0Keywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-10-16 18:52:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Evgeni Golov 2017-03-16 07:32:33 UTC
Description of problem:
When building hosts, the templates get rendered using a token that is valid for a certain amount of time.
This token is also verified in the "built" template, which is suposed to flip the host from "in build" to "build finished".
Thus if you start your deployment while the token was still OK, and it expires *during* the build, the state will not be switched and the machine will boot in build mode again on next reboot.
The new build will error out, but the machine will remain in the booted broken build system and will not boot from local disc.

The problem is because of:
The unattended "built" template calls "find_host_by_token" which calls "Host.for_token(token).first" (see app/controllers/unattended_controller.rb)
for_token is defined as
  scope :for_token, ->(token) { joins(:token).where(:tokens => { :value => token }).where("expires >= ?", Time.now.utc.to_s(:db)).select('hosts.*') }
(in app/models/concerns/hostext/token.rb upstream, app/models/host/managed.rb in satellite 6.2)
thus the host is never found and the "built" mode flip is never executed.


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


How reproducible:


Steps to Reproduce:
1. put host in build mode
2. wait till token is almost expired
3. boot and build machine

Actual results:
host is not marked as "finished"/"built" when token expires before /unattended/built is called

Expected results:
host is marked as built

Additional info:
Not sure if it would be better to have the built template not verify the token expiry, or extend the token for some time when the actual build starts. Or maybe just have a clenaup task that flips all machines that have expired tokens into "built" state.

Comment 2 Dmitri Dolguikh 2017-04-05 10:33:47 UTC
Created upstream issue: http://projects.theforeman.org/issues/19173

Comment 4 Satellite Program 2017-05-17 18:30:03 UTC
Connecting redmine issue http://projects.theforeman.org/issues/19173 from this bug

Comment 5 Satellite Program 2017-05-17 20:12:03 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/19173 has been resolved.

Comment 7 Peter Ondrejka 2018-09-25 14:22:30 UTC
Verified on Sat 6.4 snap 23 using libvirt host and various lengths of "Token duration" setting. With right duration, the host starts to build, meanwhile build is marked as 'token expired', then when build finishes, it is again marked as Installed. After that, machine reboots as expected.

Comment 8 Bryan Kearney 2018-10-16 18:52:17 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:2927