Yet another remote_file problem (Chef 0.7)


#1

Hi,

As stated earlier I’m no ruby expert, but I think something is
severely broken in either ruby 1.8.7 or Chef’s usage of tempfile.

From the doc of Tempfile.close: “If you don‘t explicitly unlink the
temporary file, the removal will be delayed until the object is
finalized.”

Note that the tempfile used for download is closed in rest.rb, but I’m
not sure about how finalization works in ruby (but since the file
object is returned I guess it shouldn’t be finalized here???)

I’ve added 3 logging statements to remove_file.rb so it now looks like
this:

         # The remote filehandle
         raw_file = get_from_uri(source)    ||
                    get_from_server(source,  

@current_resource.checksum) ||
get_from_local_cookbook(source)

Chef::Log.info(“Got file #{raw_file.path} exists: #{::File.exists?
(raw_file.path)}”)
# If the file exists
if ::File.exists?(@new_resource.path)
# And it matches the checksum of the raw file
Chef::Log.info(“Got file2 #{raw_file.path} exists: #{::File.exists?
(raw_file.path)}”)
@new_resource.checksum(self.checksum(raw_file.path))
if @new_resource.checksum != @current_resource.checksum
Chef::Log.info(“Got file3 #{raw_file.path} exists: #{::File.exists?
(raw_file.path)}”)
# Updating target file, let’s perform a backup!

Here’s the output running on ruby 1.8.6 where it looks ok

[Thu, 11 Jun 2009 18:38:51 +0200] DEBUG: /fzweb-1.war 100% done
(9734480 of 9734480)
[Thu, 11 Jun 2009 18:38:51 +0200] INFO: Got file /tmp/chef-rest.
17761.0 exists: true
[Thu, 11 Jun 2009 18:38:51 +0200] INFO: Got file2 /tmp/chef-rest.
17761.0 exists: true
[Thu, 11 Jun 2009 18:38:51 +0200] INFO: Got file3 /tmp/chef-rest.
17761.0 exists: true
[Thu, 11 Jun 2009 18:38:51 +0200] DEBUG: remote_file[fzzone_war]
changed from
7bfcea33219f784a44edc7f8841708589be764e96de04180f884c0f56438299a to
f18463d301b65a6c161669d0de190293f78480b3ed88590215ea30947cf8dfbf
[Thu, 11 Jun 2009 18:38:51 +0200] INFO: Updating
remote_file[fzzone_war] at /usr/share/jetty6/webapps/ROOT.war
[Thu, 11 Jun 2009 18:38:51 +0200] INFO: Backing up
remote_file[fzzone_war] to /usr/share/jetty6/webapps/
ROOT.war.chef-20090611183851
[Thu, 11 Jun 2009 18:38:52 +0200] INFO: Removing backup of
remote_file[fzzone_war] at /usr/share/jetty6/webapps/
ROOT.war.chef-20090611180913

And here from ruby 1.8.7 where the Tempfile suddenly disappears???

[Thu, 11 Jun 2009 18:19:49 +0200] DEBUG: /fzweb-1.war 100% done
(9734480 of 9734480)
[Thu, 11 Jun 2009 18:19:49 +0200] INFO: Got file /tmp/chef-
rest20090611-17114-1j4cd5f-0 exists: true
[Thu, 11 Jun 2009 18:19:49 +0200] INFO: Got file2 /tmp/chef-
rest20090611-17114-1j4cd5f-0 exists: true
[Thu, 11 Jun 2009 18:19:50 +0200] INFO: Got file3 /tmp/chef-
rest20090611-17114-1j4cd5f-0 exists: false
[Thu, 11 Jun 2009 18:19:50 +0200] DEBUG: remote_file[fz_war] changed
from e699e0dcd2b75494b86c9ae3d1bb1d97a69d259b3371f65e43a7b7dcd368c24e
to 7bfcea33219f784a44edc7f8841708589be764e96de04180f884c0f56438299a
[Thu, 11 Jun 2009 18:19:50 +0200] INFO: Updating remote_file[fz_war]
at /usr/share/jetty6/webapps/ROOT.war
[Thu, 11 Jun 2009 18:19:50 +0200] INFO: Backing up remote_file[fz_war]
to /usr/share/jetty6/webapps/ROOT.war.chef-20090611181950
[Thu, 11 Jun 2009 18:19:50 +0200] ERROR: remote_file[fz_war] (/var/lib/
gems/1.8/gems/chef-0.7.0/lib/chef/recipe.rb line 189) had an error:
No such file or directory - /tmp/chef-rest20090611-17114-1j4cd5f-0

Any clues? Is this a problem in Chef or Ruby 1.8.7? If the latter you
might want to warn against using 1.8.7 for Chef (which is a shame
since it’s default on Ubuntu 9.04)

/Jeppe