What is build_duration and how is it determined?

I see a new row in Foreman 1.19 titled “Build Duration” Mine are all n/a. We dont use tokens, I assume this duration # is determined off of token times? Can anyone expand on this feature?

Anyone?

Hello Jeff, well this should work. There are two fields for every host initiated_at and installed_at. When both set, the difference is calculated, regardless of tokens:

  def build_duration(host)
    return _('N/A') if host.initiated_at.nil? || host.installed_at.nil?
    if host.installed_at.nil?
      time_ago_in_words(host.initiated_at, include_seconds: true) + " (in progress)"
    else
      distance_of_time_in_words(host.initiated_at, host.installed_at, include_seconds: true)
    end
  end

Interesting. It shows N/A for every host (virtual or discovered), and every OS (ESX, Windows, RHEL). Ive tried tokens and no tokens. Any ideas? Seems like a really cool feature that my users would love to have!

You can run these commands and gimme the output?

foreman-rake console:

host = Host.find_by(name: 'myhostname.example.com')
host.initiated_at
host.installed_at

Please run this with a freshly (re-)installed host and replace the hostname.

Alright. We just kicked off one, and nothing:

irb(main):018:0* host = Host.find_by(name: 'shared69187dsm1.lab.beer.town')
=> #<Host::Managed id: 6689, name: "shared69187dsm1.lab.beer.town", last_compile: nil, last_report: nil, updated_at: "2018-09-17 16:37:27", created_at: "2018-09-17 16:29:18", root_pass: "UGFzc3dvcmQ1", architecture_id: 3, operatingsystem_id: 75, environment_id: 1, ptable_id: 199, medium_id: 9, build: false, comment: "", disk: "", installed_at: "2018-09-17 16:37:23", model_id: nil, hostgroup_id: 182, owner_id: 216, owner_type: "User", enabled: true, puppet_ca_proxy_id: 1, managed: true, use_image: nil, image_file: nil, uuid: "501805b2-de48-fc3e-5bee-2bf5752d15fd", compute_resource_id: 20, puppet_proxy_id: 1, certname: nil, image_id: nil, organization_id: nil, location_id: nil, type: "Host::Managed", otp: nil, realm_id: nil, compute_profile_id: 7, provision_method: "build", grub_pass: "UGFzc3dvcmQ1", discovery_rule_id: nil, global_status: 0, lookup_value_matcher: "fqdn=shared69187dsm1.lab.beer.town", pxe_loader: "None", initiated_at: nil, build_errors: nil>

irb(main):019:0> host.initiated_at
=> nil

irb(main):020:0> host.installed_at
=> Mon, 17 Sep 2018 16:37:23 UTC +00:00

However, I did find one that does have a Build Duration. Funny thing is it was on a failed deployment:

irb(main):026:0* host = Host.find_by(name: 'shared-dsm1.lab.beer.town')
=> #<Host::Managed id: 6685, name: "shared-dsm1.lab.beer.town", last_compile: nil, last_report: "2018-09-17 15:03:29", updated_at: "2018-09-17 16:57:18", created_at: "2018-09-17 13:45:59", root_pass: "UGFzc3dvcmQ1", architecture_id: 3, operatingsystem_id: 75, environment_id: 1, ptable_id: 199, medium_id: 9, build: false, comment: "", disk: "", installed_at: "2018-09-17 14:26:20", model_id: 1, hostgroup_id: 25, owner_id: 216, owner_type: "User", enabled: true, puppet_ca_proxy_id: 1, managed: true, use_image: nil, image_file: nil, uuid: "50185246-bb36-f59c-45b5-8bd15be6903a", compute_resource_id: 20, puppet_proxy_id: 1, certname: "shared-dsm1.lab.beer.town", image_id: nil, organization_id: nil, location_id: nil, type: "Host::Managed", otp: nil, realm_id: nil, compute_profile_id: nil, provision_method: "build", grub_pass: "UGFzc3dvcmQ1", discovery_rule_id: nil, global_status: 2, lookup_value_matcher: "fqdn=shared-dsm1.lab.beer.town", pxe_loader: "None", initiated_at: "2018-09-17 14:18:02", build_errors: nil>

irb(main):027:0> host.initiated_at
=> Mon, 17 Sep 2018 14:18:02 UTC +00:00

irb(main):028:0> host.installed_at
=> Mon, 17 Sep 2018 14:26:20 UTC +00:00

Side note: The build time will always be irrelevant for Windows hosts. Windows requires Build to be marked Installed after the WIM (windows image) file is done expanding. That only takes about 5-10 mins. Then it needs to reboot and actually configure windows, but the only way to do that is mark the host as Installed, so that upon next boot it will grab the Finish erb template script. That process then takes 40-90 minutes. Its been a headache with Foreman/Windows Deployments since as long as I can remember. Im not sure how to resolve it.

Field initiatedAt is called via setBuild method, it it possible that when you check Build checkbox it does not run this code. Sounds like a bug.

I think the problem is in this change https://github.com/theforeman/foreman/pull/5228/files#r259788488
I also spotted some wrong behaviour and opened Bug #26124: Build duration wrong during rebuild - Foreman

1 Like

Field initiatedAt is called via setBuild method, it it possible that when you check Build checkbox it does not run this code. Sounds like a bug.

This is also true. When building a new host, initiated_at doesn’t get set.

I have a simillar problem with foreman-1.20.

New host hast its token but when the kickstart finish it dissapears, so token + build duration = n/a

Is there any solution?

kind regards

The patch hasn’t been merged yet.