Skip to content

Instantly share code, notes, and snippets.

@Sharpie
Created March 9, 2014 23:09
Show Gist options
  • Save Sharpie/9456385 to your computer and use it in GitHub Desktop.
Save Sharpie/9456385 to your computer and use it in GitHub Desktop.

FileMapper Provider Instances

This testcase demonstrates how FileMapper provider instances will multiply. Noticebly when purging is in effect for a type.

Setup

  • Use a CentOS VM because I haven't written a target_files implementation that works on other systems.
  • Use Sharpie/puppet-filemapper_cron@repro-purging and adrienthebo/puppet-filemapper@master.
  • Install parslet: gem install parslet.

Reproduction

  • Run puppet apply cron-def.pp to define two cron resources in the root crontab.
  • Run puppet apply cron-purge.pp which will manage one of the resources and purge the rest. Puppet will say it is purging the unmanaged resource, but the unmanaged resource remains and the managed resource duplicates.

For clues, drop a pry shell into def new in filemapper.rb and watch how many things get added to @all_providers and what call stack leads to this.

Fix?

diff --git a/lib/puppetx/filemapper.rb b/lib/puppetx/filemapper.rb
index f8d93c6..b1e7455 100644
--- a/lib/puppetx/filemapper.rb
+++ b/lib/puppetx/filemapper.rb
@@ -96,6 +96,7 @@ module PuppetX::FileMapper
     # passed to self.flush_file
     def new(*args)
       obj = super
+      @all_providers.delete_if {|p| p.name == obj.name}
       @all_providers << obj
       obj
     end
cron {'test-one':
provider => 'parslet',
ensure => 'present',
command => '/bin/true',
month => '12',
user => 'root',
}
cron {'test-two':
provider => 'parslet',
ensure => 'present',
command => '/bin/false',
month => '11',
user => 'root',
}
resources { 'cron':
purge => true,
}
cron {'test-one':
provider => 'parslet',
ensure => 'present',
command => '/bin/true',
month => '12',
user => 'root',
}
mod 'filemapper', :git => 'https://github.com/adrienthebo/puppet-filemapper.git'
mod 'filemapper_cron', :git => 'https://github.com/Sharpie/puppet-filemapper_cron.git', :branch => 'repro-purging'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment