Project

General

Profile

Bug #29

TimeWithZone with String failed

Added by Matt Moran over 9 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Importers
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

Getting the below on the second run of the script with a new host. Changing /var/www/html/foreman/app/models/host.rb:177

--- if last_compile.nil? or (last_compile + 1.minute < facts.values[:_timestamp])
+++ if last_compile.nil? or ((last_compile + 1.minute).to_s < facts.values[:_timestamp])

Fixes the issue.

  1. rake puppet:import:hosts_and_facts RAILS_ENV=production --trace
    (in /var/www/html/foreman)
    • Invoke puppet:import:hosts_and_facts (first_time)
    • Invoke environment (first_time)
    • Execute environment
    • Execute puppet:import:hosts_and_facts
      Importing from /var/lib/puppet/yaml/facts
      Importing localhost
      Tue Sep 22 17:23:01 +0100 2009
      rake aborted!
      comparison of ActiveSupport::TimeWithZone with String failed
      /var/www/html/foreman/app/models/host.rb:178:in `<'
      /var/www/html/foreman/app/models/host.rb:178:in `importFacts'
      /var/www/html/foreman/app/models/host.rb:167:in `importHostAndFacts'
      /var/www/html/foreman/lib/tasks/puppet.rake:34
      /var/www/html/foreman/lib/tasks/puppet.rake:31:in `each'
      /var/www/html/foreman/lib/tasks/puppet.rake:31
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
      /usr/lib/ruby/1.8/monitor.rb:238:in `synchronize'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
      /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
      /usr/bin/rake:19:in `load'
      /usr/bin/rake:19

Associated revisions

History

#1 Updated by Ohad Levy over 9 years ago

  • Category set to Importers
  • Status changed from New to Assigned
  • Assignee set to Ohad Levy
  • Priority changed from High to Normal
  • Target version set to 0.1-2

strange enough, this doesnt happen in my setup, as the facts.values[:_timestamp] is a datetime object.

which version of Puppet are you using?

Does it happen to you also when you use the http importer? Puppet_Facts

#2 Updated by Matt Moran over 9 years ago

I'm running puppet 0.25, maybe this is the issue? Probably some ruby beforehand to check what type the values are before doing the compare? I haven't tried the http importer yet.

#3 Updated by Ohad Levy over 9 years ago

Matt Moran wrote:

I'm running puppet 0.25, maybe this is the issue? Probably some ruby beforehand to check what type the values are before doing the compare? I haven't tried the http importer yet.

no, I've tested with 0.25 and 0.24 :(

I'll appreciate it if you can give the http importer a try, nevertheless, I don't expect a big difference.

I'll try to see if your patch breaks any other tests before committing it.

#4 Updated by Ohad Levy over 9 years ago

  • Status changed from Assigned to Feedback
  • Assignee changed from Ohad Levy to Matt Moran

could you test if the following diff is working for you?

diff --git a/app/models/host.rb b/app/models/host.rb
index 0996274..4502808 100644
--- a/app/models/host.rb
+++ b/app/models/host.rb
@@ -176,9 +176,10 @@ class Host < Puppet::Rails::Host

     # we are not importing facts for hosts in build state (e.g. waiting for a re-installation)
     raise "Host is pending for Build" if build
-
-    if last_compile.nil? or (last_compile + 1.minute < facts.values[:_timestamp])
-      self.last_compile = facts.values[:_timestamp]
+    time = facts.values[:_timestamp]
+    time = time.to_time if time.is_a?(String)
+    if last_compile.nil? or (last_compile + 1.minute < time)
+      self.last_compile = time
       begin
       # save all other facts
       if self.respond_to?("merge_facts")

The main reason I'm changing your patch is that I dont want it to be stored as a string.
Thanks

#5 Updated by Matt Moran over 9 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

Works for me.

Also available in: Atom PDF