Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5595

Generated resource state is retrieved prematurely

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.3.2
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      2
    • Sprint:
      Client 2015-12-16
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Fix a regression in Puppet which would cause generated resources to be retrieved at generation time instead of at evaluation time.

      Description

      Issue discovered while working with the lwf/remote_file type/provider.

      Remote_file generates a file resource to enforce owner, group and mode parameters. The following is an example use of the resource.

      remote_file { 'download':
        source      => 'https://github.com/dimetron/vagrant_docker_dbora12c/archive/master.zip',
        path        => "/tmp/linuxamd64_12102_database_1of2.zip",
        verify_peer => false,
        mode        => '0644',
      }
      

      This worked as expected in Puppet 4.2.x However, in Puppet 4.3.1, there is a problem. This is the output from puppet applying this code.

      [reidmv@halcyon:~/] % puppet apply ~/src/tse-control-repo/test.pp
      Notice: Compiled catalog for halcyon.corp.puppetlabs.net in environment production in 0.06 seconds
      Notice: /Stage[main]/Main/Remote_file[download]/ensure: created
      Notice: /Stage[main]/Main/File[/tmp/linuxamd64_12102_database_1of2.zip]/ensure: created
      Notice: Applied catalog in 1.03 seconds
      [reidmv@halcyon:~/] % ls -l /tmp/linuxamd64_12102_database_1of2.zip
      -rw-r--r-- 1 reidmv staff 0 Dec 10 10:49 /tmp/linuxamd64_12102_database_1of2.zip
      [reidmv@halcyon:~/] %
      

      Notice that the generated File resource re-creates the file (as an empty file) rather than just changing the mode.

      If the code directly specifies Remote_file without mode (so no generated file resource) and the File resource explicitly, the behavior is as expected.

      remote_file { 'download':
        source      => 'https://github.com/dimetron/vagrant_docker_dbora12c/archive/master.zip',
        path        => "/tmp/linuxamd64_12102_database_1of2.zip",
        verify_peer => false,
      }
       
      file { "download":
        path => "/tmp/linuxamd64_12102_database_1of2.zip",
        mode => '0644',
      }
      

      Then Puppet outputs the following on apply:

      [reidmv@halcyon:~/] % puppet apply ~/src/tse-control-repo/test.pp
      Notice: Compiled catalog for halcyon.corp.puppetlabs.net in environment production in 0.05 seconds
      Notice: /Stage[main]/Main/Remote_file[download]/ensure: created
      Notice: /Stage[main]/Main/File[download]/mode: mode changed '0600' to '0644'
      Notice: Applied catalog in 0.92 seconds
      [reidmv@halcyon:~/] %
      

      The generated file resource fails to correctly detect that the file already exists.

      We played around with pry for a bit trying to figure out what was going on and figured out that ensure’s retrieve method was called for the generated file before the remote_file resource was evaluated. The stacktrace from when retrieve is called in 4.3.1 with the generated resource is attached (ignore the line number on the top of the stack as it's off due to our debugging code).

      The resource graphs for each manifest are attached as well.

        Attachments

        1. 01-pup-5595-init-manifest
          2 kB
        2. backtrace.txt
          3 kB
        3. generated_resource.png
          generated_resource.png
          212 kB
        4. manual_resource.png
          manual_resource.png
          180 kB

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              reid Reid Vandewiele
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Zendesk Support